Exemplo 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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Draws the level's map, player, NPCs, and objects currently on screen
 /// </summary>
 /// <param name="batch">The SpriteBatch to perform the drawing</param>
 public void draw(SpriteBatch batch)
 {
     batch.Draw(map, Vector2.Zero, Color.White);
     foreach (Pit pit in pits)
     {
         pit.draw(batch);
         if (debug)
         {
             game.outline(batch, pit.getBounds());
         }
     }
     foreach (PressButton p in pressButtons)
     {
         p.draw(batch);
         if (debug)
         {
             game.outline(batch, p.getBounds());
         }
     }
     foreach (Projectile p in projectiles)
     {
         p.draw(batch);
         if (debug)
         {
             game.outline(batch, p.getBounds());
         }
     }
     foreach (GameObject o in objects)
     {
         if (o.isOnScreen(game))
         {
             o.draw(batch, mode);
         }
         if (debug)
         {
             game.outline(batch, o.getBounds());
         }
     }
     foreach (Cubicle c in cubicles)
     {
         c.draw(batch, debug);
     }
     foreach (Token t in tokens)
     {
         t.draw(batch, mode);
         if (debug && !t.isCollected())
         {
             game.outline(batch, t.getBounds());
         }
     }
     foreach (Key k in keys)
     {
         k.draw(batch, mode);
         if (debug && !k.isCollected())
         {
             game.outline(batch, k.getBounds());
         }
     }
     foreach (Door d in doors)
     {
         batch.Draw(d.getTexture(), d.getBounds(), Color.White);
         if (debug)
         {
             game.outline(batch, d.getBounds());
         }
     }
     foreach (Wall w in walls)
     {
         batch.Draw(w.getTexture(), w.getBounds(), Color.White);
         if (debug)
         {
             game.outline(batch, w.getBounds());
         }
     }
     foreach (Barrier b in barriers)
     {
         b.draw(batch);
         if (debug)
         {
             game.outline(batch, b.getBounds());
         }
     }
     foreach (Npc n in npcs)
     {
         n.draw(batch);
         n.getDefinition().drawThought(batch);
         if (n.wasHit() && n.getCombatTicks() < 250)
         {
             n.getDisplayBar().draw(batch);
             n.getHitsplat().draw(batch);
         }
         if (debug)
         {
             game.outline(batch, n.getBounds());
             game.outline(batch, n.getLineOfSight());
         }
     }
     batch.Draw(player.getTexture(), player.getBounds(), Color.White);
     if (debug)
     {
         game.outline(batch, player.getBounds());
     }
     playerManager.getKeyBox().draw(batch);
     playerManager.getHealthBar().draw(batch);
     playerManager.getManaBar().draw(batch);
     playerManager.getPowerBar().draw(batch);
     oldText = text;
     text    = inputManager.getDropText();
     if (text != null)
     {
         if (textTicks < 300)
         {
             if (text != oldText)
             {
                 textTicks = 0;
             }
             Vector2 size = game.getDropFont().MeasureString(text);
             dropLocation = new Vector2(game.getWidth() / 2.0F - (size.X / 2.0F), game.getHeight() / 2.0F - (size.Y / 2.0F));
             batch.DrawString(game.getDropFont(), text, dropLocation, Color.DodgerBlue);
             textTicks++;
         }
         else
         {
             text      = null;
             textTicks = 0;
             inputManager.setDropText(null);
         }
     }
 }