Ejemplo n.º 1
0
        private void updateNormal(GameTime time)
        {
            if (!(collisionManager.getObjectCollision(player, true) is PlayerLimitationField))
            {
                playerManager.setManaLimit(true);
                playerManager.setHealthLimit(true);
            }
            if (playerManager.getHealthCooldown() == 35 && playerManager.getHealthLimit() && playerManager.getManaLimit())
            {
                playerManager.regenerateHealth();
                playerManager.regenerateMana();
            }
            foreach (Npc n in level.getNpcs())
            {
                NpcDefinition def = n.getDefinition();
                if (def.getHints().Length > 0 && def.isShowing())
                {
                    def.update(false);
                }
            }
            GameObject gCollision = collisionManager.getObjectCollision(player, true);

            if (gCollision != null && gCollision is Token)
            {
                Token t = (Token)gCollision;
                level.takeCollectible(t);
                playerManager.incrementExperience(t.getExp());
                playerManager.levelMana(t.getManaIncrementationValue());
                PauseMenu pause = (PauseMenu)level.getScreen("Pause");
                pause.setExperience(pause.getExperience() + t.getExp());
                dropText = "+ " + t.getExp() + " EXP";
                t.playEffect();
            }
            else if (gCollision != null && gCollision is Key)
            {
                Key k = (Key)gCollision;
                level.takeCollectible(k);
                k.setUnlocked(true);
                level.unlockDoors();
                k.playEffect();
            }
            else if (gCollision != null && gCollision is Door)
            {
                Door d = (Door)gCollision;
                if (d.isUnlocked())
                {
                    int next = (game.getLevelIndex()) + (d.continues() ? 1 : -1);
                    if (next == 7)
                    {
                        gameState = GameState.Outro;
                        finished  = true;
                        return;
                    }
                    Song current = level.getSong();
                    level.setActive(false);
                    game.setLevel(next);
                    prevLevel = level;
                    level     = game.getLevel(next);
                    PauseMenu pause = (PauseMenu)level.getScreen("Pause");
                    pause.setLevel(next);
                    if (current != level.getSong())
                    {
                        MediaPlayer.Stop();
                        MediaPlayer.Play(level.getSong());
                        if (d.continues())
                        {
                            game.getLevel(next - 2).setLooped(false);
                            prevLevel.setLooped(false);
                        }
                        else
                        {
                            level.setLooped(false);
                            prevLevel.setLooped(false);
                        }
                        level.setLooped(true);
                    }
                    game.setLevel(level);
                    deathManager = new DeathManager(this);
                    setDeathManager(deathManager);
                    collisionManager.getLevel().setActive(false);
                    level.setInputManager(this);
                    collisionManager.setLevel(level);
                    level.setActive(true);
                    if (d.continues())
                    {
                        player.setLocation(level.getPlayerOrigin());
                    }
                    else
                    {
                        player.setLocation(level.getPlayerReentryPoint());
                    }
                    playerManager.getKeyBox().update(this);
                }
                else if (game.getLevelIndex() == 0)
                {
                    Numberpad num = (Numberpad)level.getScreen("Numberpad");
                    if (!num.isSolved())
                    {
                        if (gameState == GameState.Normal)
                        {
                            if (showPuzzle)
                            {
                                gameState = GameState.Puzzle;
                                level.setActive(false);
                            }
                        }
                    }
                    else
                    {
                        d.setUnlocked(true);
                    }
                }
            }
            else if (gCollision != null && gCollision is Pit)
            {
                Pit p = (Pit)gCollision;
                p.update(this);
                if (p is Laser)
                {
                    Laser laser = (Laser)p;
                    if (laser.isActivated())
                    {
                        p.playEffect();
                    }
                }
                else
                {
                    p.playEffect();
                }
                if (p is PlayerLimitationField)
                {
                    PlayerLimitationField plf = (PlayerLimitationField)p;
                    plf.update(this);
                    plf.playEffect();
                }
            }
            if (lastKeyState.IsKeyDown(Keys.M) && currentKeyState.IsKeyUp(Keys.M))
            {
                if (gameState == GameState.Normal)
                {
                    gameState = GameState.PauseMenu;
                    level.setActive(false);
                }
                else
                {
                    gameState = GameState.Normal;
                    level.setActive(true);
                }
            }
            else if (lastKeyState.IsKeyDown(Keys.E) && currentKeyState.IsKeyUp(Keys.E))
            {
                if (mindRead.validate())
                {
                    playerManager.depleteMana(mindRead.getManaCost());
                    foreach (Npc n in level.getNpcs())
                    {
                        if (player.getDistance(n) <= 200)
                        {
                            NpcDefinition def = n.getDefinition();
                            if (def.getHints().Length > 0)
                            {
                                def.update(true);
                            }
                        }
                    }
                }
            }
            if (playerManager.getManaLimit())
            {
                mindRead.activate(level);
                SlowTime slowmo = (SlowTime)playerManager.getPowers()[0];
                if (lastKeyState.IsKeyDown(Keys.A) && currentKeyState.IsKeyUp(Keys.A))
                {
                    if (slowmo.validate())
                    {
                        playerManager.depleteMana(slowmo.getManaCost());
                    }
                }
                slowmo.activate(level);
                Dash dash = (Dash)playerManager.getPowers()[1];
                if (lastKeyState.IsKeyDown(Keys.W) && currentKeyState.IsKeyUp(Keys.W))
                {
                    if (dash.validate())
                    {
                        playerManager.depleteMana(dash.getManaCost());
                    }
                }
                dash.activate(level);
                Confuse confuse = (Confuse)playerManager.getPowers()[2];
                if (lastKeyState.IsKeyDown(Keys.S) && currentKeyState.IsKeyUp(Keys.S))
                {
                    if (confuse.validate())
                    {
                        playerManager.depleteMana(confuse.getManaCost());
                    }
                }
                confuse.activate(level);
            }
            Entity eCollision = collisionManager.getEntityCollision(player);

            if (currentKeyState.IsKeyDown(Keys.Up))
            {
                showPuzzle = true;
                player.setDirection(Direction.North);
                player.updateMovement();
                player.setDestination(new Vector2(player.getLocation().X, player.getLocation().Y - velocity));
                if (player.getDestination().Y >= 0 && collisionManager.isValid(player, false))
                {
                    player.deriveY(-velocity);
                }
                else
                {
                    if (!(collisionManager.getObjectCollision(player, false) is Door))
                    {
                        player.setDestination(player.getLocation());
                    }
                    if (eCollision != null)
                    {
                        eCollision.setDestination(eCollision.getLocation());
                    }
                }
            }
            else if (lastKeyState.IsKeyDown(Keys.Up) && currentKeyState.IsKeyUp(Keys.Up))
            {
                stagnant = true;
            }
            else if (currentKeyState.IsKeyDown(Keys.Down))
            {
                showPuzzle = true;
                player.setDirection(Direction.South);
                player.updateMovement();
                player.setDestination(new Vector2(player.getLocation().X, player.getLocation().Y + velocity));
                if (player.getDestination().Y <= height - player.getTexture().Height&& collisionManager.isValid(player, false))
                {
                    player.deriveY(velocity);
                }
                else
                {
                    if (!(collisionManager.getObjectCollision(player, false) is Door))
                    {
                        player.setDestination(player.getLocation());
                    }
                    if (eCollision != null)
                    {
                        eCollision.setDestination(eCollision.getLocation());
                    }
                }
            }
            else if (lastKeyState.IsKeyDown(Keys.Down) && currentKeyState.IsKeyUp(Keys.Down))
            {
                stagnant = true;
            }
            else if (currentKeyState.IsKeyDown(Keys.Left))
            {
                showPuzzle = true;
                player.setDirection(Direction.West);
                player.updateMovement();
                player.setDestination(new Vector2(player.getLocation().X - velocity, player.getLocation().Y));
                if (player.getDestination().X >= 0 && collisionManager.isValid(player, false))
                {
                    player.deriveX(-velocity);
                }
                else
                {
                    if (!(collisionManager.getObjectCollision(player, false) is Door))
                    {
                        player.setDestination(player.getLocation());
                    }
                    if (eCollision != null)
                    {
                        eCollision.setDestination(eCollision.getLocation());
                    }
                }
            }
            else if (lastKeyState.IsKeyDown(Keys.Left) && currentKeyState.IsKeyUp(Keys.Left))
            {
                stagnant = true;
            }
            else if (currentKeyState.IsKeyDown(Keys.Right))
            {
                showPuzzle = true;
                player.setDirection(Direction.East);
                player.updateMovement();
                player.setDestination(new Vector2(player.getLocation().X + velocity, player.getLocation().Y));
                if (player.getDestination().X <= width - 64 && collisionManager.isValid(player, false))
                {
                    player.deriveX(velocity);
                }
                else
                {
                    if (!(collisionManager.getObjectCollision(player, false) is Door))
                    {
                        player.setDestination(player.getLocation());
                    }
                    if (eCollision != null)
                    {
                        eCollision.setDestination(eCollision.getLocation());
                    }
                }
            }
            else if (lastKeyState.IsKeyDown(Keys.Right) && currentKeyState.IsKeyUp(Keys.Right))
            {
                stagnant = true;
            }
            else
            {
                player.setDestination(player.getLocation());
            }
            if (currentKeyState.IsKeyDown(Keys.Space) && playerManager.getManaLimit())
            {
                double ms = time.TotalGameTime.TotalMilliseconds;
                if ((player.getLastFired() == -1 || ms - player.getLastFired() >= player.getProjectile().getCooldown()) && playerManager.getMana() >= 5)
                {
                    level.addProjectile(player.createProjectile(ms));
                    playerManager.depleteMana(5);
                }
            }
            if (lastKeyState.IsKeyDown(Keys.Q) && currentKeyState.IsKeyUp(Keys.Q))
            {
                gameState = GameState.TelekinesisSelect;
                level.setMode(1);
            }
        }