Пример #1
0
        public override void Fire(Animation animation, GameTime gameTime)
        {
            if (Target != null && Target.IsAlive())
            {
                var bullet = new FreezeBullet(this, this.Damage, Target, 0.5);
                bullet.SetColor(Microsoft.Xna.Framework.Color.Blue);
                bullet.SetSize(16, 16);
                bullet.SetPosition(X, Y);
                bullet.SetSpeed(300);
                bullet.SetScene(Scene);
                Sprite.Layer.AddSprite(bullet.Sprite);

                Scene.AddBullet(bullet);
            }
        }
Пример #2
0
        public void Update(float seconds)
        {
            if (timeUntilNextShot > 0)
            {
                timeUntilNextShot -= seconds;
            }
            Viewport viewport = game.GraphicsDevice.Viewport;

            if (keyState.IsKeyDown(Keys.Right))
            {
                rotation += 5 * seconds;
            }
            if (keyState.IsKeyDown(Keys.Left))
            {
                rotation -= 5 * seconds;
            }

            if (keyState.IsKeyDown(Keys.Up))
            {
                speed.X += acceleration * seconds * (float)Math.Sin(sprite.rotation);
                speed.Y -= acceleration * seconds * (float)Math.Cos(sprite.rotation);

                //Animate the ship's rockets while up is being pressed
                sprite.Animate(spriteReel, seconds, 0.3f);
            }

            //if the player is not holding up, reset the texture to the default shipSprite
            else
            {
                sprite.texture = game.Content.Load <Texture2D>(@"Sprites/shipSprite");
            }

            if (keyState.IsKeyDown(Keys.Down))
            {
                speed.X -= acceleration * seconds * (float)Math.Sin(sprite.rotation);
                speed.Y += acceleration * seconds * (float)Math.Cos(sprite.rotation);
            }

            if (speed.LengthSquared() > maximumSpeed * maximumSpeed)
            {
                speed.Normalize();
                speed *= maximumSpeed;
            }


            position += speed * seconds;
            if (position.X > viewport.Width)
            {
                sprite.position.X -= viewport.Width;
            }
            if (position.X < 0)
            {
                sprite.position.X += viewport.Width;
            }

            if (position.Y > viewport.Height)
            {
                sprite.position.Y -= viewport.Height;
            }
            if (position.Y < 0)
            {
                sprite.position.Y += viewport.Height;
            }

            if (timeUntilNextShot <= 0 && keyState.IsKeyDown(Keys.Space))
            {
                scene.AddBullet(rotation, position, speed);
                timeUntilNextShot = 0.5f;
            }

            circle.position = sprite.position;
        }