예제 #1
0
        //Update input handler, then the current state, and then check if new state should be loaded
        private void windowUpdateFrame(object sender, FrameEventArgs e)
        {
            InputHandler.updateState();

            if (InputHandler.fullScreen())
            {
                if (window.WindowState == WindowState.Fullscreen)
                {
                    window.WindowState = WindowState.Normal;
                }
                else
                {
                    window.WindowState = WindowState.Fullscreen;
                }
            }

            current.Update();

            if (current.switchTo() != null)
            {
                current = current.switchTo();
                current.Load();
                if (current is ExitState)
                {
                    window.Close();
                }
            }
        }
예제 #2
0
        //Link render and update functions and create the main menu
        public Game(GameWindow window)
        {
            ConfigSettings.loadConfig();

            this.window         = window;
            window.Load        += windowLoad;
            window.UpdateFrame += windowUpdateFrame;
            window.RenderFrame += windowRenderFrame;

            window.VSync = OpenTK.VSyncMode.On;

            current = new MainMenu();
        }
예제 #3
0
        public void selectOption()
        {
            switch (selected)
            {
            case 0:
                nextScene = new RoomViewer();
                break;

            case 1:
                nextScene = new ExitState();
                break;

            default:
                nextScene = null;
                break;
            }
        }
예제 #4
0
        public override void Update()
        {
            //Collect the tiles that are currently around the player
            around = new Tiles[3, 3];
            for (int y = 0; y < around.GetLength(1); y++)
            {
                for (int x = 0; x < around.GetLength(0); x++)
                {
                    try
                    {
                        around[x, y] = grid[p1.getMazeX() - (1 - x), p1.getMazeY() - (1 - y)];
                    }
                    catch (Exception)
                    {
                        around[x, y] = Tiles.FLOOR;
                    }
                }
            }

            //update player and return the amount of damage the player is dealing
            int damage = p1.Update(around);

            //pick up any money the player is standing on
            p1.pickUpMoney(room.isTreasureAt(p1.getMazeX(), p1.getMazeY()));

            //damage = -1 means the player wants to drop a red coin
            if (damage == -1)
            {
                room.dropCoin(p1.x, p1.y);
            }
            else
            {
                //damage enemies based on damage and where the player is looking
                room.HitEnemies(damage, p1.lookingAt());
            }

            //delete killed enemies or picked up treasures
            room.ClearEnemies();
            room.clearTreasures();



            //if player is standing on a passage send him to the new room
            Tiles     playerPos = grid[p1.getMazeX(), p1.getMazeY()];
            Direction d         = p1.getDirection();

            if (playerPos == Tiles.PASSAGE)
            {
                if (room.getPassage(d).isExit)
                {
                    //if the passage is marked as isExit, load the end of the game state
                    nextScene = new FinishState(p1.wealth);
                }
                else
                {
                    switchRoom(maze.getRoom(room.getPassage(d).getConnection()), room.getPassage(d).getExitDirection());
                }
            }

            if (!p1.moving)
            {
                p1.Hit(room.UpdateEnemies(p1.getMazeX(), p1.getMazeY()));
                p1.setMoving();
            }

            if (p1.wealth < 0)
            {
                nextScene = new FinishState(p1.wealth);
            }


            if (InputHandler.isZoomIn())
            {
                zoom += 0.1f;
            }

            if (InputHandler.isZoomOut())
            {
                zoom -= 0.1f;
            }

            cam.Update(p1.getCameraTransform(zoom), zoom);
        }