FlyingAnimFrame currentFrame = FlyingAnimFrame.Straight; // fly straight public PlayerShip(Texture2D texture) { // set up the rectangles for the ship's animation: // ideally this would be stored in an external file animFly = new List <Rectangle> { new Rectangle(0, 140, 23, 29), // flying far left new Rectangle(24, 140, 23, 29), new Rectangle(48, 140, 23, 29), // flying straight new Rectangle(72, 140, 23, 29), new Rectangle(96, 140, 23, 29), // flying far right }; // these should be defined in an external file: health = 100; maxHealth = health; damage = 10; xPos = 400; yPos = 500; speed = 5; state = 0x00; team = Team.Player; gunBarrelOffset = new Vector2(20.0f, -2.0f); // TODO: find the exact barrel offset sprite = new Sprite(texture, animFly[2], 2.0); // TODO: get rid of magic numbers! // PlayerShip specific: currentAnim = ShipAnim.FlyStraight; }
public PlayerShip(Texture2D texture) { // set up the rectangles for the ship's animation: // ideally this would be stored in an external file animFly = new List<Rectangle> { new Rectangle(0, 140, 23, 29), // flying far left new Rectangle(24, 140, 23, 29), new Rectangle(48, 140, 23, 29), // flying straight new Rectangle(72, 140, 23, 29), new Rectangle(96, 140, 23, 29), // flying far right }; // these should be defined in an external file: health = 100; maxHealth = health; damage = 10; xPos = 400; yPos = 500; speed = 5; state = 0x00; team = Team.Player; gunBarrelOffset = new Vector2(20.0f, -2.0f); // TODO: find the exact barrel offset sprite = new Sprite(texture, animFly[2], 2.0); // TODO: get rid of magic numbers! // PlayerShip specific: currentAnim = ShipAnim.FlyStraight; }
// the user has issued a command // the ship will attempt to comply public void SendCommand(PlayerCommand command, GameTime gameTime) { float timeScale = (float)gameTime.ElapsedGameTime.TotalSeconds; timeScale = 1.0f; // default animation -- may get overwritten later in SendCommand: currentAnim = ShipAnim.FlyStraight; switch (command) { case PlayerCommand.Idle: { // no commands from the user break; } case PlayerCommand.FlyLeft: { xPos -= (int)(speed * timeScale); if (xPos <= 0) { xPos = 0; } currentAnim = ShipAnim.FlyLeft; break; } case PlayerCommand.FlyRight: { xPos += (int)(speed * timeScale); if (xPos >= 700) { xPos = 700; } currentAnim = ShipAnim.FlyRight; break; } case PlayerCommand.FlyForward: { yPos -= (int)(speed * timeScale); if (yPos <= 0) { yPos = 0; } break; } case PlayerCommand.FlyBackward: { yPos += (int)(speed * timeScale); if (yPos >= 500) { yPos = 500; // TODO: get rid of magic numbers } break; } case PlayerCommand.Fire: { fireCooldownRemaining = fireDelay; break; } case PlayerCommand.AltFire: { break; } default: { break; } } }
// the user has issued a command // the ship will attempt to comply public void SendCommand(PlayerCommand command, GameTime gameTime) { float timeScale = (float)gameTime.ElapsedGameTime.TotalSeconds; timeScale = 1.0f; // default animation -- may get overwritten later in SendCommand: currentAnim = ShipAnim.FlyStraight; switch(command) { case PlayerCommand.Idle: { // no commands from the user break; } case PlayerCommand.FlyLeft: { xPos -= (int)(speed * timeScale); if (xPos <= 0) xPos = 0; currentAnim = ShipAnim.FlyLeft; break; } case PlayerCommand.FlyRight: { xPos += (int)(speed * timeScale); if (xPos >= 700) xPos = 700; currentAnim = ShipAnim.FlyRight; break; } case PlayerCommand.FlyForward: { yPos -= (int)(speed * timeScale); if (yPos <= 0) yPos = 0; break; } case PlayerCommand.FlyBackward: { yPos += (int)(speed * timeScale); if (yPos >= 500) yPos = 500; // TODO: get rid of magic numbers break; } case PlayerCommand.Fire: { fireCooldownRemaining = fireDelay; break; } case PlayerCommand.AltFire: { break; } default: { break; } } }