Esempio n. 1
0
        public override void Act()
        {
            base.Act();

            if (BlockedLeftEnt is KeyLock ||
                BlockedRightEnt is KeyLock ||
                GroundEnt is KeyLock ||
                CeilingEnt is KeyLock)
            {
                SoundMan.PlaySound("open", Position);

                if (BlockedLeftEnt is KeyLock)
                {
                    BlockedLeftEnt.Destroyed = true;
                }
                if (BlockedRightEnt is KeyLock)
                {
                    BlockedRightEnt.Destroyed = true;
                }
                if (GroundEnt is KeyLock)
                {
                    GroundEnt.Destroyed = true;
                }
                if (CeilingEnt is KeyLock)
                {
                    CeilingEnt.Destroyed = true;
                }


                while (true)
                {
                    Entity a = EntityFinder.FindOfType(typeof(KeyBlock));

                    if (a != null)
                    {
                        a.Destroyed = true;
                    }
                    else
                    {
                        break;
                    }
                }

                Destroyed = true;
            }
        }
Esempio n. 2
0
        public override void Act()
        {
            base.Act();

            if (CeilingEnt != null && CeilingEnt.Movable && !activated && !Carried && !Hooked)
            {
                activated = true;

                SoundMan.PlaySound("pickup", Position);

                bool playSound = true;

                while (true)
                {
                    Entity a = EntityFinder.FindOfType(typeof(Dynamite));

                    if (a != null)
                    {
                        Dynamite d = (Dynamite)a;

                        BounceC = 20;

                        if (playSound)
                        {
                            SoundMan.PlaySound("explode", d.Position);
                        }
                        playSound = false;

                        d.BlowUp();
                        d.BlowUp();
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        bool GameLoop()
        {
            bool openDoor = true;

            CollisionMan.PopulateCells();
            CollisionMan.CheckCollisionCells();

            if (screenShake > 0)
            {
                screenShake--;
            }

            gameStateC++;

            if (gameState == GameState.StartLevel)
            {
                level.Timer.Reset();
                level.Timer.Start();

                gameState = GameState.GamePlay;
            }

            if (gameState == GameState.ResetFadeOut)
            {
                level.Timer.Stop();

                fadeOut = gameStateC * 10;

                if (gameStateC == 25)
                {
                    gameStateC = 0;
                    gameState  = GameState.ResetFadeIn;

                    level.ResetLevel();
                }
            }

            if (gameState == GameState.ResetFadeIn)
            {
                level.ScrollTo(EntityFinder.FindOfType(typeof(Player)).Position, true);

                if (gameStateC > 10)
                {
                    fadeOut = 255 - (int)((gameStateC - 10) * 6.3);
                }
                else
                {
                    fadeOut = 255;
                }

                if (gameStateC == 50)
                {
                    gameStateC = 0;
                    gameState  = GameState.StartLevel;
                }
            }

            if (gameState == GameState.LevelFinished)
            {
                level.Timer.Stop();

                if (gameStateC < 50)
                {
                    fadeOut = gameStateC * 5;
                }
                else
                {
                    fadeOut = 255;
                }

                if (gameStateC == 2)
                {
                    SoundMan.PlaySound("win", SoundMan.Center);
                }


                if (gameState == GameState.LevelFinished && gameStateC >= 70)
                {
                    menu.Active = true;
                    menu.State  = Menu.MenuState.LevelWon;
                    menu.CounterReset();
                    menu.LevelCompletiontime = level.Timer.Elapsed;
                    menu.LevelName           = levelName;

                    return(false);
                }
            }

            if (!Keyboard.IsKeyPressed(Keyboard.Key.P))
            {
                buttonTriggerP = false;
            }
            if (!buttonTriggerP && Keyboard.IsKeyPressed(Keyboard.Key.P))
            {
                if (gameState == GameState.GamePlay)
                {
                    gameState = GameState.Paused;
                    level.Timer.Stop();
                }
                else if (gameState == GameState.Paused)
                {
                    gameState = GameState.GamePlay;
                    level.Timer.Start();
                }

                buttonTriggerP = true;
            }

            if (gameState == GameState.Paused)
            {
                fadeOut = 128;
            }

            if (gameState == GameState.GamePlay)
            {
                fadeOut = 0;


                for (int i = 0; i < level.GetEntities().Count; i++)
                {
                    Entity ent = level.GetEntities()[i];

                    if (ent is StarBlock)
                    {
                        StarBlock starBlock = (StarBlock)ent;

                        if (!starBlock.StarOnTop)
                        {
                            openDoor = false;
                        }
                    }

                    if (windowHasFocus)
                    {
                        if (ent is Player)
                        {
                            Player player = (Player)ent;
                            level.ScrollTo(player.Position, false);
                            ControlPlayer(player);

                            if (player.Position.Y > 140)
                            {
                                gameState  = GameState.ResetFadeOut;
                                gameStateC = 0;
                            }
                        }

                        if (!ent.Destroyed)
                        {
                            ent.Act();
                        }
                        else
                        {
                            if (ent.ScreenShake)
                            {
                                screenShake     = 50;
                                ent.ScreenShake = false;
                            }
                        }
                    }
                }

                foreach (Entity ent in level.GetEntities())
                {
                    if (ent is Exit)
                    {
                        Exit exit = (Exit)ent;

                        if (!exit.Open && openDoor)
                        {
                            SoundMan.PlaySound("open", exit.Position);
                            exit.BounceC = 20;
                        }

                        exit.Open = openDoor;

                        if (openDoor)
                        {
                            Entity entp = EntityFinder.FindOfType(typeof(Player));
                            if (entp != null)
                            {
                                Player pl = (Player)entp;

                                if (pl.BlockedLeftEnt == exit || pl.BlockedRightEnt == exit || pl.CeilingEnt == exit || pl.GroundEnt == exit)
                                {
                                    gameState  = GameState.LevelFinished;
                                    gameStateC = 0;
                                }
                            }
                        }
                    }
                }
            }

            SoundMan.Center = new Vector2f(level.Scroll.X + 160, level.Scroll.Y + 60);

            //level.GetEntities().RemoveAll(a => a.Destroyed);

            if (Keyboard.IsKeyPressed(Keyboard.Key.Escape) && windowHasFocus)
            {
                menu.Active = true;
                menu.State  = Menu.MenuState.PlayMenu;
                menu.CounterReset();
            }

            return(true);
        }