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

            for (int i = 0; i < 3; i++)
            {
                Entity ent = EntityFinder.GetEnt(new Vector2f(Position.X, Position.Y - 14 - i * 16));

                if (ent is Player)
                {
                    Player player;
                    player = (Player)ent;

                    player.OnLadder = true;
                }
            }

            Entity ent2 = EntityFinder.GetEnt(new Vector2f(Position.X, Position.Y - 16 - 34));
            {
                if (ent2 is Player)
                {
                    Player player;
                    player = (Player)ent2;

                    player.OnLadder = true;

                    if (player.Position.Y <= Position.Y - 16 - 48)
                    {
                        player.OnTopOfLadder = true;
                    }
                }
            }
        }
Esempio n. 2
0
        public void PickUp()
        {
            if (pickUp == null)
            {
                pickUp = EntityFinder.GetEnt(Position + EntityFinder.GetDir(Flipped, 16, 0));

                if (pickUp != null && !pickUp.Movable)
                {
                    pickUp = null;
                }

                if (pickUp != null)
                {
                    pickUp.BounceC = 5;

                    SoundMan.PlaySound("pickup", Position);
                    pickUp.Carried = true;
                }
            }
            else
            {
                if (EntityFinder.GetEnt(Position + EntityFinder.GetDir(Flipped, 16, 0)) == null)
                {
                    pickUp.Position = Position + EntityFinder.GetDir(Flipped, 16, 0);
                    pickUp.Carried  = false;
                    pickUp          = null;
                }
            }
        }
Esempio n. 3
0
        public void BlowUp()
        {
            ScreenShake = true;

            Entity a = EntityFinder.GetEnt(new Vector2f(Position.X - 16, Position.Y));

            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X + 16, Position.Y));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X, Position.Y - 16));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X, Position.Y + 16));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X - 16, Position.Y + 16));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X - 16, Position.Y - 16));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X + 16, Position.Y - 16));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }

            a = EntityFinder.GetEnt(new Vector2f(Position.X + 16, Position.Y + 16));
            if (a != null && !(a is Dynamite))
            {
                a.Destroyed = true;
            }


            Destroyed = true;
        }
Esempio n. 4
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. 5
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. 6
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);
        }
Esempio n. 7
0
        public override void Act()
        {
            if (entToLift != null && Pushed != 0 && state != State.Off && state != State.Lowering)
            {
                Push(entToLift, PushedDir, Pushed);
            }

            base.Act();

            counter++;



            if ((Carried || Hooked) && entToLift != null)
            {
                entToLift.Hooked = false;
                entToLift        = null;
                state            = State.Off;
            }

            Vector2f soundPos = new Vector2f(Position.X + 32 + hookPosX, Position.Y - 64 + hookPosY);

            if (!Carried && !Hooked)
            {
                if (state == State.Off)
                {
                    if (hookPosX > 0)
                    {
                        hookPosX--;
                    }
                    if (hookPosY > 0)
                    {
                        hookPosY--;
                    }

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

                    warmUp++;

                    entToLift = EntityFinder.FindEnt(this, EntityFinder.Dir.Down, 112, hookPosX + 32, -48);

                    if (entToLift != null)
                    {
                        if (coolOff == 0 && warmUp > 80)
                        {
                            state = State.Lowering;
                        }
                    }
                }

                if (state == State.Lowering)
                {
                    if (counter % 10 == 0)
                    {
                        SoundMan.PlaySound("drop", Position);
                    }

                    entToLift = EntityFinder.FindEnt(this, EntityFinder.Dir.Down, 112, hookPosX + 32, -48);
                    if (entToLift == null)
                    {
                        state = State.Off;
                    }

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

                    if (entToLift != null && hookPosY + Position.Y - 48 <= entToLift.Position.Y)
                    {
                        hookPosY += 0.25f;
                    }
                    else
                    {
                        if (entToLift != null)
                        {
                            SoundMan.PlaySound("pickup", soundPos);
                            BounceC           = 5;
                            entToLift.BounceC = 5;
                        }
                        state = State.LiftingUp;
                    }
                }

                if (state == State.LiftingUp)
                {
                    if (counter % 5 == 0)
                    {
                        SoundMan.PlaySound("drop", soundPos);
                    }

                    warmUp  = 0;
                    coolOff = 100;

                    if (hookPosY > 0)
                    {
                        hookPosY -= 0.5f;
                    }
                    else
                    {
                        state = State.MovingRight;
                    }

                    if (entToLift != null)
                    {
                        entToLift.Hooked = true;
                    }
                    else
                    {
                        state = State.Off;
                    }
                }

                {
                    if (entToLift != null && entToLift.Hooked)
                    {
                        if (state == State.LiftingUp)
                        {
                            if (entToLift.Carried)
                            {
                                entToLift.Hooked = false;
                                state            = State.Off;
                            }



                            if (entToLift.Position.Y > Position.Y - 54 + hookPosY)
                            {
                                if (!Push(entToLift, EntityFinder.Dir.Up, 1f))
                                {
                                    entToLift.Hooked = false;
                                    state            = State.Off;
                                }
                            }

                            if (entToLift.Position.Y < Position.Y - 54 + hookPosY)
                            {
                                if (!Push(entToLift, EntityFinder.Dir.Down, 1f))
                                {
                                    entToLift.Hooked = false;
                                    state            = State.Off;
                                }
                            }
                        }

                        if (state == State.MovingRight)
                        {
                            if (entToLift.Position.X > Position.X + 32 + hookPosX)
                            {
                                if (!Push(entToLift, EntityFinder.Dir.Left, 1f))
                                {
                                    entToLift.Hooked = false;
                                    state            = State.Off;
                                }
                            }

                            if (entToLift.Position.X < Position.X + 32 + hookPosX)
                            {
                                if (!Push(entToLift, EntityFinder.Dir.Right, 1f))
                                {
                                    entToLift.Hooked = false;
                                    state            = State.Off;
                                }
                            }
                        }

                        if (entToLift.Hooked == false)
                        {
                            entToLift = null;
                            state     = State.Off;
                            coolOff   = 100;
                        }
                    }
                }

                if (state == State.MovingRight)
                {
                    if (counter % 5 == 0)
                    {
                        SoundMan.PlaySound("drop", soundPos);
                    }

                    if (hookPosX < 64)
                    {
                        hookPosX += 0.5f;
                    }
                    else
                    {
                        SoundMan.PlaySound("pickup", soundPos);

                        coolOff          = 100;
                        entToLift.Hooked = false;
                        state            = State.Off;
                        entToLift        = null;
                    }
                }
            }
        }
Esempio n. 8
0
        public void Loop(RenderWindow window)
        {
            counter++;

            CursorPosF = new Vector2f(CursorPos.X * 16, CursorPos.Y * 16 + 8);

            Level.ScrollTo(CursorPosF, false);
            Level.GetEntities().RemoveAll(a => a.Destroyed);

            Type entType = Level.EntityTypes[currentEnt];

            cursorEnt = (Entity)Activator.CreateInstance(entType, CursorPos);

            if (buttonDelay == 0)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.F3) || Keyboard.IsKeyPressed(Keyboard.Key.F5) ||
                    Keyboard.IsKeyPressed(Keyboard.Key.F1)
                    )
                {
                    showTextWindow = !showTextWindow;

                    if (Keyboard.IsKeyPressed(Keyboard.Key.F3))
                    {
                        textInputOperation = TextInputOperation.Save;
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.F5))
                    {
                        textInputOperation = TextInputOperation.Load;
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.F1))
                    {
                        textInputOperation = TextInputOperation.InfoBox;
                    }

                    if (textInputOperation == TextInputOperation.Save || textInputOperation == TextInputOperation.Load)
                    {
                        textInputString = LevelName;
                    }

                    bool addEvent = true;

                    if (textInputOperation == TextInputOperation.InfoBox)
                    {
                        Entity ent = EntityFinder.GetEnt(new Vector2f(CursorPosF.X + 8, CursorPosF.Y - 8));

                        if (ent != null && ent is InfoBox)
                        {
                            InfoBox infoBox = (InfoBox)ent;
                            textInputString = infoBox.InfoString;
                        }
                        else
                        {
                            showTextWindow = false;
                            addEvent       = false;
                        }
                    }

                    if (addEvent)
                    {
                        if (showTextWindow)
                        {
                            window.TextEntered += TextEntered;
                        }
                        else
                        {
                            window.TextEntered -= TextEntered;
                        }
                    }

                    buttonDelay = 20;
                }

                if (showTextWindow)
                {
                    if (Keyboard.IsKeyPressed(Keyboard.Key.Return))
                    {
                        if (textInputOperation == TextInputOperation.Save)
                        {
                            LevelName = textInputString;
                            Level.SaveLevel(LevelName);
                        }
                        if (textInputOperation == TextInputOperation.Load)
                        {
                            LevelName = textInputString;

                            Level.LoadLevel(LevelName, true);

                            CollisionMan.Entities = Level.GetEntities();
                            EntityFinder.Entities = Level.GetEntities();
                        }
                        if (textInputOperation == TextInputOperation.InfoBox)
                        {
                            Entity ent = EntityFinder.GetEnt(new Vector2f(CursorPosF.X + 8, CursorPosF.Y - 8));

                            if (ent != null && ent is InfoBox)
                            {
                                InfoBox infoBox = (InfoBox)ent;
                                infoBox.InfoString = textInputString;
                            }
                        }

                        showTextWindow      = false;
                        window.TextEntered -= TextEntered;
                    }

                    if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                    {
                        showTextWindow      = false;
                        window.TextEntered -= TextEntered;
                    }
                }
            }

            if (buttonDelay == 0 && !showTextWindow)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Z))
                {
                    if (currentEnt > 0)
                    {
                        currentEnt--;
                    }
                    buttonDelay = 10;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.X))
                {
                    if (currentEnt < Level.EntityTypes.Count - 1)
                    {
                        currentEnt++;
                    }
                    buttonDelay = 10;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.F12))
                {
                    Level.GetEntities().Clear();

                    buttonDelay = 10;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.Delete))
                {
                    Entity ent = EntityFinder.GetEnt(new Vector2f(CursorPosF.X + 8, CursorPosF.Y - 8));

                    if (ent != null)
                    {
                        ent.Destroyed = true;
                    }

                    buttonDelay = 10;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.F))
                {
                    Entity ent = EntityFinder.GetEnt(new Vector2f(CursorPosF.X + 8, CursorPosF.Y - 8));

                    if (ent != null)
                    {
                        ent.Flipped = !ent.Flipped;
                    }

                    buttonDelay = 10;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.Space))
                {
                    Entity ent = EntityFinder.GetEnt(new Vector2f(CursorPosF.X + 8, CursorPosF.Y - 8));

                    if (ent != null)
                    {
                        ent.Destroyed = true;
                    }

                    Entity newEnt = (Entity)Activator.CreateInstance(entType, CursorPos);
                    Level.GetEntities().Add(newEnt);


                    buttonDelay = 10;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    CursorPos   = new Vector2i(CursorPos.X + 1, CursorPos.Y);
                    buttonDelay = 10;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
                {
                    CursorPos   = new Vector2i(CursorPos.X - 1, CursorPos.Y);
                    buttonDelay = 10;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Up))
                {
                    CursorPos   = new Vector2i(CursorPos.X, CursorPos.Y - 1);
                    buttonDelay = 10;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down))
                {
                    CursorPos   = new Vector2i(CursorPos.X, CursorPos.Y + 1);
                    buttonDelay = 10;
                }
            }
            if (buttonDelay > 0)
            {
                buttonDelay--;
            }
        }
Esempio n. 9
0
        protected bool Push(Entity ent, EntityFinder.Dir dir, float speed = 1)
        {
            if (ent.Movable == false)
            {
                return false;
            }
            else
            {
                if (dir == EntityFinder.Dir.Right && ent.BlockedRightEnt == null)
                {
                    ent.Position = new Vector2f(ent.Position.X + speed, ent.Position.Y);
                    ent.Pushed = speed;
                    ent.PushedDir = dir;

                    if (ent.CeilingEnt != null) Push(ent.CeilingEnt, dir, speed);
                    return true;
                }

                if (dir == EntityFinder.Dir.Left && ent.BlockedLeftEnt == null)
                {
                    ent.Position = new Vector2f(ent.Position.X - speed, ent.Position.Y);
                    ent.Pushed = speed;
                    ent.PushedDir = dir;

                    if (ent.CeilingEnt != null) Push(ent.CeilingEnt, dir, speed);
                    return true;
                }
                if (dir == EntityFinder.Dir.Up)
                {
                    bool doPush = true;

                    if (ent.CeilingEnt != null)
                        if (!ent.CeilingEnt.Movable) doPush = false;

                    if (doPush)
                    {
                        ent.Speed = new Vector2f(ent.Speed.X, 0);
                        ent.Position = new Vector2f(ent.Position.X, ent.Position.Y - speed);
                        ent.Pushed = speed;
                        ent.PushedDir = dir;

                        if (ent.CeilingEnt != null) if (!Push(ent.CeilingEnt, dir, speed)) return false;
                        return true;
                    }
                    else return false;
                    
                }
                if (dir == EntityFinder.Dir.Down)
                {
                    bool doPush = true;

                    if (ent.GroundEnt != null)
                        if (!ent.GroundEnt.Movable) doPush = false;

                    if (doPush)
                    {
                        ent.Speed = new Vector2f(ent.Speed.X, 0);
                        ent.Position = new Vector2f(ent.Position.X, ent.Position.Y + speed);
                        ent.Pushed = speed;
                        ent.PushedDir = dir;

                        if (ent.GroundEnt != null) if (!Push(ent.GroundEnt, dir, speed)) return false;
                        return true;
                    }
                    else return false;
                }
       
            }

            return false;
        }