Ejemplo n.º 1
0
        /// <summary>
        /// Handles how the power operates
        /// </summary>
        /// <param name="level">The level the power is activating on</param>
        public override void activate(Level level)
        {
            manager = level.getCollisionManager();
            if (activated)
            {
                Vector2 destination;
                if (duration < 15)
                {
                    switch (level.getPlayer().getDirection())
                    {
                    case Direction.North:
                        destination = new Vector2(level.getPlayer().getLocation().X, level.getPlayer().getLocation().Y - 6);
                        level.getPlayer().setDestination(destination);
                        if (level.getPlayer().getDestination().Y >= 0 && manager.isValid(level.getPlayer(), false))
                        {
                            level.getPlayer().deriveY(-6);
                        }
                        break;

                    case Direction.South:
                        destination = new Vector2(level.getPlayer().getLocation().X, level.getPlayer().getLocation().Y + 6);
                        level.getPlayer().setDestination(destination);
                        if (level.getPlayer().getDestination().Y <= 416 && manager.isValid(level.getPlayer(), false))
                        {
                            level.getPlayer().deriveY(6);
                        }
                        break;

                    case Direction.West:
                        destination = new Vector2(level.getPlayer().getLocation().X - 6, level.getPlayer().getLocation().Y);
                        level.getPlayer().setDestination(destination);
                        if (level.getPlayer().getDestination().X >= 0 && manager.isValid(level.getPlayer(), false))
                        {
                            level.getPlayer().deriveX(-6);
                        }
                        break;

                    case Direction.East:
                        destination = new Vector2(level.getPlayer().getLocation().X + 6, level.getPlayer().getLocation().Y);
                        level.getPlayer().setDestination(destination);
                        if (level.getPlayer().getDestination().X <= 736 && manager.isValid(level.getPlayer(), false))
                        {
                            level.getPlayer().deriveX(6);
                        }
                        break;
                    }
                    updateDuration();
                }
                else
                {
                    setActivated(false);
                }
            }
            updateCooldown();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Handles how the power operates
 /// </summary>
 /// <param name="level">The level the power is activating on</param>
 public override void activate(Level level)
 {
     manager = level.getCollisionManager();
     if (activated) {
         Vector2 destination;
         if (duration < 15) {
             switch (level.getPlayer().getDirection()) {
                 case Direction.North:
                     destination = new Vector2(level.getPlayer().getLocation().X, level.getPlayer().getLocation().Y - 6);
                     level.getPlayer().setDestination(destination);
                     if (level.getPlayer().getDestination().Y >= 0 && manager.isValid(level.getPlayer(), false)) {
                         level.getPlayer().deriveY(-6);
                     }
                     break;
                 case Direction.South:
                     destination = new Vector2(level.getPlayer().getLocation().X, level.getPlayer().getLocation().Y + 6);
                     level.getPlayer().setDestination(destination);
                     if (level.getPlayer().getDestination().Y <= 416 && manager.isValid(level.getPlayer(), false)) {
                         level.getPlayer().deriveY(6);
                     }
                     break;
                 case Direction.West:
                     destination = new Vector2(level.getPlayer().getLocation().X - 6, level.getPlayer().getLocation().Y);
                     level.getPlayer().setDestination(destination);
                     if (level.getPlayer().getDestination().X >= 0 && manager.isValid(level.getPlayer(), false)) {
                         level.getPlayer().deriveX(-6);
                     }
                     break;
                 case Direction.East:
                     destination = new Vector2(level.getPlayer().getLocation().X + 6, level.getPlayer().getLocation().Y);
                     level.getPlayer().setDestination(destination);
                     if (level.getPlayer().getDestination().X <= 736 && manager.isValid(level.getPlayer(), false)) {
                         level.getPlayer().deriveX(6);
                     }
                     break;
             }
             updateDuration();
         } else {
             setActivated(false);
         }
     }
     updateCooldown();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the npc's direction and movement, if it has been sufficient time between interactions
        /// </summary>
        public void update()
        {
            npc.setDirection(directions[state]);
            if (stagnant && wait < delays[state])
            {
                wait++;
                return;
            }
            else if (stagnant)
            {
                stagnant = false;
                wait     = 0;
                state    = (state + 1) % path.Length;
                npc.setDirection(directions[state]);
            }
            if (stuckFrames >= STILL_FRAMES)
            {
                npc.updateStill();
                stuckFrames = 0;
            }
            switch (npc.getDirection())
            {
            case Direction.North:
                if (npc.getLocation().Y > path[state])
                {
                    if (ticks >= SKIPPED_FRAMES)
                    {
                        npc.setDestination(new Vector2(npc.getLocation().X, npc.getLocation().Y - npc.getVelocity()));
                        if (collisionManager.isValid(npc, false))
                        {
                            stuckFrames = 0;
                            npc.deriveY(-npc.getVelocity());
                            npc.updateMovement();
                        }
                        else
                        {
                            stuckFrames++;
                        }
                        ticks = 0;
                    }
                    else
                    {
                        ticks++;
                    }
                }
                if (npc.getLocation().Y <= path[state])
                {
                    stagnant = true;
                }
                break;

            case Direction.South:
                if (npc.getLocation().Y < path[state])
                {
                    if (ticks >= SKIPPED_FRAMES)
                    {
                        npc.setDestination(new Vector2(npc.getLocation().X, npc.getLocation().Y + npc.getVelocity()));
                        if (collisionManager.isValid(npc, false))
                        {
                            stuckFrames = 0;
                            npc.deriveY(npc.getVelocity());
                            npc.updateMovement();
                        }
                        else
                        {
                            stuckFrames++;
                        }
                        ticks = 0;
                    }
                    else
                    {
                        ticks++;
                    }
                }
                if (npc.getLocation().Y >= path[state])
                {
                    stagnant = true;
                }
                break;

            case Direction.West:
                if (npc.getLocation().X > path[state])
                {
                    if (ticks >= SKIPPED_FRAMES)
                    {
                        npc.setDestination(new Vector2(npc.getLocation().X - npc.getVelocity(), npc.getLocation().Y));
                        if (collisionManager.isValid(npc, false))
                        {
                            stuckFrames = 0;
                            npc.deriveX(-npc.getVelocity());
                            npc.updateMovement();
                        }
                        else
                        {
                            stuckFrames++;
                        }
                        ticks = 0;
                    }
                    else
                    {
                        ticks++;
                    }
                }
                if (npc.getLocation().X <= path[state])
                {
                    stagnant = true;
                }
                break;

            case Direction.East:
                if (npc.getLocation().X < path[state])
                {
                    if (ticks >= SKIPPED_FRAMES)
                    {
                        npc.setDestination(new Vector2(npc.getLocation().X + npc.getVelocity(), npc.getLocation().Y));
                        if (collisionManager.isValid(npc, false))
                        {
                            stuckFrames = 0;
                            npc.deriveX(npc.getVelocity());
                            npc.updateMovement();
                        }
                        else
                        {
                            stuckFrames++;
                        }
                        ticks = 0;
                    }
                    else
                    {
                        ticks++;
                    }
                }
                if (npc.getLocation().X >= path[state])
                {
                    stagnant = true;
                }
                break;
            }
        }
Ejemplo n.º 4
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);
            }
        }