예제 #1
0
        public override void Update(GameTime gameTime)
        {
            if (drawEquipment)
            {
                inventoryManager.Update(gameTime);
            }

            if (!isPaused)
            {
                player.Update(gameTime, player);
                sprite.Update(gameTime);


                foreach (Enemy e in enemies)
                {
                    e.Update(gameTime, player);
                }

                foreach (NPC n in npcs)
                {
                    n.Update(gameTime, player);
                }

                int x = enemies.Count;
                for (int i = 0; i < x; i++)
                {
                    if (enemies[i].RemoveThisElement == true)
                    {
                        enemies.Remove(enemies[i]);
                        x--;
                    }
                }

                UpdateMouse();

                Vector2 motion    = new Vector2();
                Vector2 direction = new Vector2();

                int rotationAngle = 0;
                //TODO: Iškelti į veikėjo klasę. Bindinti mygtukus su CommandManager
                if (InputHandler.KeyDown(Keys.W))
                {
                    motion.Y = -1;
                }
                else if (InputHandler.KeyDown(Keys.S))
                {
                    motion.Y = 1;
                }
                if (InputHandler.KeyDown(Keys.A))
                {
                    motion.X = -1;
                }
                else if (InputHandler.KeyDown(Keys.D))
                {
                    motion.X = 1;
                }
                if (InputHandler.LeftMouseButtonState == ButtonState.Pressed)
                {
                    oldState = ButtonState.Pressed;
                }
                if (InputHandler.LeftMouseButtonState == ButtonState.Released && oldState == ButtonState.Pressed)
                {
                    direction     = new Vector2(InputHandler.MouseState.X, InputHandler.MouseState.Y);
                    rotationAngle = InputHandler.GetDegrees(sprite.Origin, player.Camera.Position);
                    gun.Add(direction, sprite.Origin - player.Camera.Position, 50, rotationAngle);
                    oldState          = ButtonState.Released;
                    player.IsShooting = true;
                    //Console.WriteLine(sprite.Position);
                    deagleShot.Play();
                }
                gun.Update(enemies);

                if (motion != Vector2.Zero)
                {
                    if (MediaPlayer.State != MediaState.Playing)
                    {
                        MediaPlayer.Play(walkingSound);
                    }
                    if (!player.IsShooting)
                    {
                        sprite.IsAnimating         = true;
                        shootingSprite.IsAnimating = false;
                    }
                    else
                    {
                        sprite.IsAnimating                  = false;
                        shootingSprite.IsAnimating          = true;
                        shootingSprite.AnimateOnceAndResume = true;
                        shootingSprite.Update(gameTime);
                        if (!shootingSprite.AnimateOnceAndResume)
                        {
                            player.IsShooting = false;
                        }
                    }
                    motion.Normalize();

                    sprite.Position = collisionsManager.DetectCollisions(motion, sprite.Position);
                    sprite.LockToMap();
                    shootingSprite.Position = collisionsManager.DetectCollisions(motion, shootingSprite.Position);
                    shootingSprite.LockToMap();

                    if (player.Camera.CameraMode == CameraMode.Follow)
                    {
                        player.Camera.LockToSprite(sprite);
                    }

                    if (PlayerPositionChanged != null)
                    {
                        Point playerPos = Engine.VectorToCellIso(sprite.Position);
                        PlayerPositionChanged(playerPos, null);
                    }
                }
                else
                {
                    MediaPlayer.Stop();
                    //sprite.IsAnimating = false;
                    //shootingSprite.IsAnimating = false;
                    if (!player.IsShooting)
                    {
                        sprite.IsAnimating         = false;
                        shootingSprite.IsAnimating = false;
                    }
                    else
                    {
                        sprite.IsAnimating                  = false;
                        shootingSprite.IsAnimating          = true;
                        shootingSprite.AnimateOnceAndResume = true;
                        shootingSprite.Update(gameTime);
                        if (!shootingSprite.AnimateOnceAndResume)
                        {
                            player.IsShooting = false;
                        }
                    }
                }

                //if (InputHandler.KeyReleased(Keys.C))
                //{
                //    player.Camera.ToggleCameraMode();
                //    if (player.Camera.CameraMode == CameraMode.Follow)
                //        player.Camera.LockToSprite(sprite);
                //}

                missionManager.Update(gameTime);
            }

            dialogueManager.Update(gameTime);
            hudManager.Update(gameTime);
            if (!isPaused)
            {
                commandManager.Update(gameTime);
            }

            popUpManager.Update(gameTime);
            gameInterface.Update(gameTime);
            notifications.Update(gameTime);

            base.Update(gameTime);
        }