コード例 #1
0
 protected void ProcessInputState(float delta)
 {
     foreach (Key k in kbd.GetPressedKeys()) {
         if (k == Key.Space && ship.Visible) {
             //Fire guns
             lastBullet += delta;
             if (lastBullet > bulletSpacing) {
                 BulletSprite bullet = new BulletSprite(bulletTileSet);
                 //Calculate bullet start position, outside ship boundaries
                 float radAngle = Geometry.DegreeToRadian(ship.Angle);
                 int yOffset = (int) ( bulletFireRadius * Math.Sin((double)radAngle));
                 int xOffset = (int) ( bulletFireRadius * Math.Cos((double)radAngle));
                 bullet.PositionY = (ship.PositionY) + shipTileSet.ExtentY + yOffset;
                 //the -4 below is a small nudge to center up the bullets
                 bullet.PositionX = (ship.PositionX) + shipTileSet.ExtentX + xOffset - 4;
                 bullet.Angle = ship.Angle;
                 bullet.Velocity = 150f;
                 bullet.AnimationSpeed = 0f;
                 bullet.CanCollide = true;
                 bullet.LimitLifespan(2f); //only 2 seconds to live
                 sm.AddSprite(bullet);
                 lastBullet = 0f;
                 if (totalScore > 0) totalScore--; //lose a point for each bullet
                 shipSounds |= Sounds.ShipFire;
             }
         }
         if (k == Key.Left)  ship.PrevFrame();
         if (k == Key.Right) ship.NextFrame();
         if (k == Key.Up) {
             ship.Thrust();
             shipSounds |= Sounds.ShipThrust;
         }
         if (k == Key.Down) {
             //Put on the brakes!
             ship.VelocityX = 0f;
             ship.VelocityY = 0f;
             shipSounds |= Sounds.ShipBrake;
         }
         if (k == Key.Escape) {
             kbd.Unacquire(); //release the keyboard device
             kbd.Dispose();
             Application.Exit();
         }
         if (k == Key.Home) {
             //resets ship to starting position
             ship.PositionY = (float)this.Height/2;
             ship.PositionX = (float)this.Width/2;
             ship.VelocityX = 0f;
             ship.VelocityY = 0f;
             ship.Angle = 0.0f;
             ship.Frame = 10;
         }
         //if (k == Key.D) sm.ShowList();
     }
 }
コード例 #2
0
 protected void ProcessInputState(float delta)
 {
     foreach (Key k in kbd.GetPressedKeys())
     {
         if (k == Key.Space && ship.Visible)
         {
             //Fire guns
             lastBullet += delta;
             if (lastBullet > bulletSpacing)
             {
                 BulletSprite bullet = new BulletSprite(bulletTileSet);
                 //Calculate bullet start position, outside ship boundaries
                 float radAngle = Geometry.DegreeToRadian(ship.Angle);
                 int   yOffset  = (int)(bulletFireRadius * Math.Sin((double)radAngle));
                 int   xOffset  = (int)(bulletFireRadius * Math.Cos((double)radAngle));
                 bullet.PositionY = (ship.PositionY) + shipTileSet.ExtentY + yOffset;
                 //the -4 below is a small nudge to center up the bullets
                 bullet.PositionX      = (ship.PositionX) + shipTileSet.ExtentX + xOffset - 4;
                 bullet.Angle          = ship.Angle;
                 bullet.Velocity       = 150f;
                 bullet.AnimationSpeed = 0f;
                 bullet.CanCollide     = true;
                 bullet.LimitLifespan(2f); //only 2 seconds to live
                 sm.AddSprite(bullet);
                 lastBullet = 0f;
                 if (totalScore > 0)
                 {
                     totalScore--;                 //lose a point for each bullet
                 }
                 shipSounds |= Sounds.ShipFire;
             }
         }
         if (k == Key.Left)
         {
             ship.PrevFrame();
         }
         if (k == Key.Right)
         {
             ship.NextFrame();
         }
         if (k == Key.Up)
         {
             ship.Thrust();
             shipSounds |= Sounds.ShipThrust;
         }
         if (k == Key.Down)
         {
             //Put on the brakes!
             ship.VelocityX = 0f;
             ship.VelocityY = 0f;
             shipSounds    |= Sounds.ShipBrake;
         }
         if (k == Key.Escape)
         {
             kbd.Unacquire(); //release the keyboard device
             kbd.Dispose();
             Application.Exit();
         }
         if (k == Key.Home)
         {
             //resets ship to starting position
             ship.PositionY = (float)this.Height / 2;
             ship.PositionX = (float)this.Width / 2;
             ship.VelocityX = 0f;
             ship.VelocityY = 0f;
             ship.Angle     = 0.0f;
             ship.Frame     = 10;
         }
         //if (k == Key.D) sm.ShowList();
     }
 }