Beispiel #1
0
 public void Update(GameTime gameTime)
 {
     currentKeyboardState = Keyboard.GetState();
     if (currentKeyboardState.IsKeyDown(Keys.W) || currentKeyboardState.IsKeyDown(Keys.Up))
     {
         spaceship.GoForward();
     }
     if (currentKeyboardState.IsKeyDown(Keys.S) || currentKeyboardState.IsKeyDown(Keys.Down))
     {
         spaceship.GoBack();
     }
     if (currentKeyboardState.IsKeyDown(Keys.A) || currentKeyboardState.IsKeyDown(Keys.Left))
     {
         spaceship.GoLeft();
     }
     if (currentKeyboardState.IsKeyDown(Keys.D) || currentKeyboardState.IsKeyDown(Keys.Right))
     {
         spaceship.GoRight();
     }
     if (currentKeyboardState.IsKeyDown(Keys.E))
     {
         spaceship.TurnRight();
     }
     if (currentKeyboardState.IsKeyDown(Keys.Q))
     {
         spaceship.TurnLeft();
     }
     if (currentKeyboardState.IsKeyDown(Keys.Space))
     {
         spaceship.Fire();
     }
     //DebugString.toPrint = spaceship.HP + "   " + spaceship.AP;
     //spaceship.Update(gameTime);
 }
Beispiel #2
0
        public void Update(GameTime gameTime)
        {
            currentKeyboardState = Keyboard.GetState();

            //Стратегия?
            //Vector2 direction = -spaceship.position + world.playerShip.position;
            Vector2 direction = world.ShortestPath(spaceship.position, world.playerShip.position);

            float angle = AngleFunc.Diff(direction.angle(), spaceship.angle);

            if (angle - spaceship.angularSpeed * 20 > 0)
            {
                spaceship.TurnLeft();
            }
            else
            {
                spaceship.TurnRight();
            }

            bool  slowDown = spaceship.speed.Length() > 10;
            float sp       = spaceship.speed.angle();

            bool facedForward = Math.Abs(AngleFunc.Diff(spaceship.speed.angle(), spaceship.angle)) < (float)Math.PI / 2;
            bool facedRight   = Math.Abs(AngleFunc.Diff(spaceship.speed.angle(), spaceship.angle + (float)Math.PI / 2)) < (float)Math.PI / 2;

            /*
             * DebugString.toPrint += "\n" + AngleFunc.Diff(spaceship.speed.angle(), spaceship.angle).ToString();
             * DebugString.toPrint += "\n" + spaceship.speed.Length().ToString();
             * DebugString.toPrint += "\n" + turning_right;*/

            if (slowDown)
            {
                if (facedForward)
                {
                    spaceship.GoBack();
                }
                else
                {
                    spaceship.GoForward();
                }
                if (facedRight)
                {
                    spaceship.GoLeft();
                }
                else
                {
                    spaceship.GoRight();
                }
            }
            else
            {
                spaceship.GoForward();
            }
            if (Math.Abs(angle) < 0.15f)
            {
                spaceship.Fire();
            }
        }