class PlayerAnimation : ZilchComponent { [Property] var PlayerStand : SpriteSource = null; [Property] var PlayerWalk : SpriteSource = null; [Property] var PlayerJump : SpriteSource = null; [Property] var PlayerSlash : SpriteSource = null; [Property] var Projectile : Archetype = null; [Property] var ShotSpeed : Real = 20; function Initialize(init : CogInitializer) { Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate); } function OnLogicUpdate(event : UpdateEvent) { // standing state if(this.Owner.Sprite.SpriteSource == this.PlayerStand) { if(Zero.Keyboard.KeyIsDown(Keys.Left) || Zero.Keyboard.KeyIsDown(Keys.Right)) { this.Owner.Sprite.SpriteSource = this.PlayerWalk; } if(Zero.Keyboard.KeyIsPressed(Keys.Up)) { this.Owner.Sprite.SpriteSource = this.PlayerJump; } // player slashes and sends out a bullet if(Zero.Keyboard.KeyIsDown(Keys.Space)) { this.Owner.Sprite.SpriteSource = this.PlayerSlash; var bullet = this.Space.CreateAtPosition(this.Projectile, this.Owner.Transform.Translation); //send beam in reverse direction if (this.Owner.Sprite.FlipX == true){ if (bullet != null) { var direction = -this.Owner.Orientation.WorldForward; direction = Math.Normalize(direction); bullet.RigidBody.Velocity = direction * this.ShotSpeed; } } if (this.Owner.Sprite.FlipX == false){ if (bullet != null) { var direction = this.Owner.Orientation.WorldForward; direction = Math.Normalize(direction); bullet.RigidBody.Velocity = direction * this.ShotSpeed; } } } } // walking state else if(this.Owner.Sprite.SpriteSource == this.PlayerWalk) { if(Zero.Keyboard.KeyIsDown(Keys.Left) == false && Zero.Keyboard.KeyIsDown(Keys.Right) == false) { this.Owner.Sprite.SpriteSource = this.PlayerStand; } if(Zero.Keyboard.KeyIsPressed(Keys.Up)) { this.Owner.Sprite.SpriteSource = this.PlayerJump; } } // jumping state else if(this.Owner.Sprite.SpriteSource == this.PlayerJump) { if(this.Owner.SweptController.Grounded) { this.Owner.Sprite.SpriteSource = this.PlayerStand; } } // slashing state (needs some more work) else if(this.Owner.Sprite.SpriteSource == this.PlayerSlash) { if(Zero.Keyboard.KeyIsDown(Keys.Space) == false) { this.Owner.Sprite.SpriteSource = this.PlayerStand; } } } }