Exemplo n.º 1
0
        public void Update(KeyboardState keyboard, MouseState mouse, Engine engine)
        {
            // Rortational Origin
            Rectangle originRect = new Rectangle((int) position.X, (int) position.Y,
                (int) texture.Width, (int) texture.Height);
            origin = new Vector2(originRect.Width / 2, originRect.Height / 2);

            int playerSpeed = 2;

            if (keyboard.IsKeyDown(Keys.A))
                position.X -= playerSpeed;

            if (keyboard.IsKeyDown(Keys.D))
                position.X += playerSpeed;

            if (keyboard.IsKeyDown(Keys.W))
                position.Y -= playerSpeed;

            if (keyboard.IsKeyDown(Keys.S))
                position.Y += playerSpeed;

            float deltaY = mouse.Y - position.Y;
            float deltaX = mouse.X - position.X;
            float radians = (float) Math.Atan2(deltaY, deltaX);
            setRotation(radians);
        }
Exemplo n.º 2
0
        public void Update(Player player, KeyboardState keyboard, MouseState mouse, Engine engine)
        {
            // Rortational Origin
            Rectangle originRect = new Rectangle((int)position.X, (int)position.Y,
                (int)texture.Width, (int)texture.Height);
            origin = new Vector2(originRect.Width / 2, originRect.Height / 2);

            int viewDistance = 200;

            double distance = Math.Sqrt(Math.Pow(player.position.X - position.X, 2) +
                Math.Pow(player.position.Y - position.Y, 2));

            if (distance < viewDistance)
            {
                float deltaX = player.position.X - position.X;
                float deltaY = player.position.Y - position.Y;
                float radians = (float)Math.Atan2(deltaY, deltaX);
                setRotation(radians);

                float zombieSpeed = 1.5f;
                float dx = (float) Math.Cos(rotation) * zombieSpeed;
                float dy = (float) Math.Sin(rotation) * zombieSpeed;
                position.X += dx;
                position.Y += dy;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Engine game = new Engine())
     {
         game.Run();
     }
 }