Пример #1
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;
                }
            }
        }
Пример #2
0
        static void StartApp()
        {
            SoundMan.LoadSounds();



            TrainBoxApp app = new TrainBoxApp();

            app.StartTrainBoxApp();
        }
Пример #3
0
        public override void Act()
        {
            base.Act();

            counter++;

            //Entity ent = GetEnt(entities, new Vector2f(Position.X, Position.Y - 16));
            Entity ent = CeilingEnt;

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

            if (ent != null && !Flipped && BlockedRightEnt == null)
            {
                activated = true;
            }
            if (ent != null && Flipped && BlockedLeftEnt == null)
            {
                activated = true;
            }

            if (ent == null && ((BlockedLeftEnt != null && Flipped) ||
                                (BlockedRightEnt != null && !Flipped)))
            {
                activated = false;
            }

            if (Carried || Hooked)
            {
                activated = false;
            }

            if (activated)
            {
                if (counter % 7 == 0)
                {
                    SoundMan.PlaySound("drop", Position);
                }

                if (!Flipped)
                {
                    Push(this, EntityFinder.Dir.Right, 0.4f);
                }
                if (Flipped)
                {
                    Push(this, EntityFinder.Dir.Left, 0.4f);
                }
            }
        }
Пример #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;
            }
        }
Пример #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;
                    }
                }
            }
        }
Пример #6
0
        void GameWonLogic()
        {
            if (Keyboard.IsKeyPressed(Keyboard.Key.Return) || Keyboard.IsKeyPressed(Keyboard.Key.Space) ||
                Keyboard.IsKeyPressed(Keyboard.Key.Escape))
            {
                if (menuC > 100 && !keypressTrigger)
                {
                    State = MenuState.PlayMenu;

                    menuC = 0;
                }
                keypressTrigger = true;
            }


            if (menuC == 2)
            {
                SoundMan.PlayMusic(2);

                for (int i = 0; i < starField.Count(); i++)
                {
                    starField[i] = new Vector2f(r.Next(0, 320), r.Next(0, 120));
                    Console.WriteLine(starField[i].X);
                }
            }

            if (menuC > 2)
            {
                for (int i = 0; i < starField.Count(); i++)
                {
                    starField[i] = new Vector2f(starField[i].X, starField[i].Y + 1 + (i / 10f));
                    if (starField[i].Y > 130)
                    {
                        starField[i] = new Vector2f(r.Next(0, 320), -16);
                    }
                }
            }
        }
Пример #7
0
        public void StartTrainBoxApp()
        {
            Level.PrepareEntityTypes();

            bool quit = false;

            TextureMan.LoadTextures();
            TextureMan.CreateShadows();

            bufferSpr = new Sprite();

            buffer = new RenderTexture(320, 120);
            buffer.Clear(Color.Black);

            menu.Active = true;
            menu.State  = Menu.MenuState.Intro;
            menu.CounterReset();
            menu.LoadLevelInfo();

            while (true)
            {
                if (fullScreen)
                {
                    screenSizeX = 1366;
                    screenSizeY = 768;
                }
                else
                {
                    screenSizeX = 960;
                    screenSizeY = 540;
                }

                if (fullScreen)
                {
                    window = new RenderWindow(new VideoMode(screenSizeX, screenSizeY),
                                              "Super Starbox", Styles.Fullscreen);
                }
                else
                {
                    window = new RenderWindow(new VideoMode(screenSizeX, screenSizeY),
                                              "Super Starbox", Styles.Titlebar);
                }

                window.SetMouseCursorVisible(!fullScreen);

                window.SetVisible(true);
                window.Closed += new EventHandler(OnClosed);
                window.SetFramerateLimit(60);

                window.LostFocus   += new EventHandler(OnLostFocus);
                window.GainedFocus += new EventHandler(OnGainedFocus);

                bool editorButtonTrigger = false;

                SoundMan.PlayMusic();

                while (true)
                {
                    buffer.Clear(Color.Black);

                    if (!menu.Active)
                    {
                        level.DrawLevel(buffer);
                    }


                    if (fadeOut != 0)
                    {
                        RectangleShape rect = new RectangleShape();

                        rect.Position  = new Vector2f(0, 0);
                        rect.Size      = new Vector2f(320, 120);
                        rect.FillColor = new Color(0, 0, 0, (byte)fadeOut);

                        buffer.Draw(rect);
                    }

                    if (menu.Active)
                    {
                        menu.Draw(buffer);
                    }
                    if (editor.Active)
                    {
                        editor.Draw(buffer);
                    }

                    buffer.Display();

                    bufferSpr.Texture = buffer.Texture;
                    bufferSpr.Scale   = new Vector2f((screenSizeX / 320f) * screenScale, (screenSizeY / 120f) * screenScale);

                    bufferSpr.Origin   = new Vector2f(160, 60);
                    bufferSpr.Position = new Vector2f(screenSizeX / 2, screenSizeY / 2);

                    if (screenShake > 0)
                    {
                        bufferSpr.Position = new Vector2f(bufferSpr.Position.X + (float)new Random().Next(-200, 200) / 75,
                                                          bufferSpr.Position.Y + (float)new Random().Next(-200, 200) / 75);
                    }

                    if (gameState == GameState.ResetFadeOut)
                    {
                        bufferSpr.Rotation = gameStateC / 2;

                        screenScale = 1f + (float)gameStateC / 50f;
                    }

                    if (gameState == GameState.LevelFinished)
                    {
                        bufferSpr.Rotation = gameStateC / 2;

                        screenScale = 1f + (float)gameStateC / 25f;
                    }

                    if (gameState == GameState.ResetFadeIn)
                    {
                        bufferSpr.Rotation = (50 - gameStateC) / 2;

                        screenScale = 1f + (float)(50 - gameStateC) / 50f;
                    }

                    if (gameState == GameState.GamePlay || menu.Active)
                    {
                        screenScale        = 1;
                        bufferSpr.Rotation = 0;
                    }

                    window.DispatchEvents();
                    window.Clear(Color.Black);
                    window.Draw(bufferSpr);
                    window.Display();


                    if (Keyboard.IsKeyPressed(Keyboard.Key.F4))
                    {
                        fullScreen = !fullScreen;
                        break;
                    }

                    if (Keyboard.IsKeyPressed(Keyboard.Key.F10) && false)
                    {
                        if (!menu.Active)
                        {
                            if (!editorButtonTrigger)
                            {
                                editor.Active = !editor.Active;
                                if (editor.Active)
                                {
                                    editor.LevelName = levelName;
                                    level.ResetLevel();
                                    level.ResetScrollBounds();
                                    CollisionMan.Entities = level.GetEntities();
                                    EntityFinder.Entities = level.GetEntities();
                                    editor.Level          = level;
                                }
                                else
                                {
                                    levelName = editor.LevelName;
                                    level     = editor.Level;
                                    level.FindScrollBounds();
                                    gameState = GameState.StartLevel;
                                }
                            }
                        }
                        editorButtonTrigger = true;
                    }
                    else
                    {
                        editorButtonTrigger = false;
                    }

                    if (!editor.Active && !menu.Active)
                    {
                        GameLoop();
                    }

                    if (editor.Active)
                    {
                        if (windowHasFocus)
                        {
                            editor.Loop(window);
                        }
                    }
                    if (menu.Active)
                    {
                        if (windowHasFocus)
                        {
                            menu.Loop(window);
                        }

                        if (menu.State == Menu.MenuState.Quit)
                        {
                            quit = true;
                            break;
                        }

                        if (menu.State == Menu.MenuState.StartLevel)
                        {
                            levelName = menu.LevelName;

                            menu.Active = false;
                            level.LoadLevel(levelName);

                            gameStateC = 0;
                            gameState  = GameState.ResetFadeIn;
                            fadeOut    = 255;

                            CollisionMan.Entities = level.GetEntities();
                            EntityFinder.Entities = level.GetEntities();
                        }
                    }
                }

                window.Dispose();
                if (quit)
                {
                    break;
                }
            }

            menu.SaveLevelInfo();
        }
Пример #8
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);
        }
Пример #9
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;
                    }
                }
            }
        }
Пример #10
0
        public override void Act()
        {
            counter++;

            CurrentTex = "player";

            if (Walking && GroundEnt != null && (counter % 20 < 5))
            {
                CurrentTex = "playerwalk1";
            }
            if (Walking && GroundEnt != null && (counter % 20 >= 5 && counter % 20 < 10))
            {
                CurrentTex = "player";
            }
            if (Walking && GroundEnt != null && (counter % 20 >= 10 && counter % 20 < 15))
            {
                CurrentTex = "playerwalk2";
            }
            if (Walking && GroundEnt != null && (counter % 20 >= 15 && counter % 20 < 20))
            {
                CurrentTex = "player";
            }


            if (Climbing)
            {
                Speed = new Vector2f(Speed.X, 0);
            }

            base.Act();

            if (Climbing && !DoJump)
            {
                Position = new Vector2f(Position.X, Position.Y - Speed.Y);
                if (!OnLadder)
                {
                    Climbing = false;
                }
            }

            OnLadder      = false;
            OnTopOfLadder = false;

            if (GroundEnt is Ladder)
            {
                Position = new Vector2f(Position.X, Position.Y);
            }

            if (GroundEnt != null || Climbing)
            {
                if (DoJump)
                {
                    BounceC = 10;

                    SoundMan.PlaySound("jump", Position);

                    Position = new Vector2f(Position.X, Position.Y - 0.5f);
                    Speed    = new Vector2f(Speed.X, -2f);
                    DoJump   = false;
                    Climbing = false;
                }
            }


            if (pickUp != null)
            {
                pickUp.Speed = new Vector2f(0, 0);
                if (!Flipped)
                {
                    pickUp.Position = new Vector2f(Position.X + 6, Position.Y - 6);
                }
                else
                {
                    pickUp.Position = new Vector2f(Position.X - 6, Position.Y - 6);
                }

                if (pickUp.Destroyed)
                {
                    pickUp = null;
                }
            }
        }
Пример #11
0
        public virtual void Act()
        {
            Pushed = 0;

            if (bounceC > 0)
            {
                bounceC--;

                scaleX = 1 + (float)bounceC / 30f;
                scaleY = 1 - (float)bounceC / 50f;
            }

            if (bounceC == 0)
            {
                scaleX = 1;
                scaleY = 1;
            }

            if (BlockedRightEnt != null && Movable)
            {
                Position = new Vector2f((int)Position.X, Position.Y);

                if (Speed.X > 0)
                {
                    if (BlockedRightEnt.Hooked || !Push(BlockedRightEnt, EntityFinder.Dir.Right, 1))
                    {
                        Speed = new Vector2f(0, Speed.Y);
                    }
                }
            }

            if (BlockedLeftEnt != null && Movable)
            {
                Position = new Vector2f((int)(Position.X + 0.9f), Position.Y);

                if (Speed.X < 0)
                {
                    if (BlockedLeftEnt.Hooked || !Push(BlockedLeftEnt, EntityFinder.Dir.Left, 1))
                    {
                        Speed = new Vector2f(0, Speed.Y);
                    }
                }
            }

            if (GroundEnt == null && Movable)
            {
                Speed += new Vector2f(0, 0.1f);

                if (!Walking)
                {
                    Speed = new Vector2f(Speed.X * 0.9f, Speed.Y);
                    if (Math.Abs(Speed.X) < 0.1)
                    {
                        Speed = new Vector2f(0, Speed.Y);
                    }
                }
            }

            if (GroundEnt != null && Movable && !GroundEnt.Carried)
            {
                if (Speed.Y > 0)
                {
                    if (GroundEnt.Hooked == false)
                    {
                        SoundMan.PlaySound("drop", Position);

                        bounceC = 10;
                        if (!GroundEnt.Movable)
                        {
                            GroundEnt.BounceC = 3;
                        }
                        else
                        {
                            GroundEnt.BounceC = 7;

                            if (GroundEnt.GroundEnt != null && GroundEnt.GroundEnt.Movable)
                            {
                                GroundEnt.GroundEnt.BounceC = 3;
                            }
                        }
                    }
                    if (!Hooked)
                    {
                        Position = new Vector2f(Position.X, GroundEnt.Position.Y - 16);
                    }
                }



                if (!Walking)
                {
                    if (!Carried && !Hooked)
                    {
                        Position = new Vector2f(Position.X, GroundEnt.Position.Y - 16);
                    }

                    Speed = new Vector2f(Speed.X * 0.5f, Speed.Y);
                    if (Math.Abs(Speed.X) < 0.1)
                    {
                        Speed = new Vector2f(0, Speed.Y);
                    }
                }

                Speed = new Vector2f(Speed.X, 0);
            }

            if (CeilingEnt != null && Movable)
            {
                //Position = new Vector2f(Position.X, CeilingEnt.Position.Y+15);

                if (Speed.Y < 0)
                {
                    Speed = new Vector2f(Speed.X, 0);
                    if (!CeilingEnt.Movable)
                    {
                        CeilingEnt.BounceC = 3;
                    }
                    else
                    {
                        CeilingEnt.BounceC = 7;
                    }
                    bounceC = 10;
                }
            }

            if (Speed.Y > 1)
            {
                Speed = new Vector2f(Speed.X, 1f);
            }


            if (!Hooked)
            {
                Position += Speed;
            }
            else
            {
                Speed = new Vector2f(Speed.X, 0);
            }
        }