コード例 #1
0
        // Specify what you want to happen when the event is raised.
        private void FlipDisplay(object source, ElapsedEventArgs e)
        {
            // Draw the next screen
            screenCanvas.Clear();

            switch (gameStatus)
            {
            case Modes.TITLE:
                TitleScreen(currTitle);
                break;

            case Modes.GAME:
                if (!PlayGame(currGame))
                {
                    currTitle = new TitleScreen();
                    currTitle.InitTitleScreen();
                }
                break;
            }

            // Flip the screen to show the updated image
            bLastDrawn = false;
            PictureBox frame = this.frames[iShowFrame];

            if (frame.InvokeRequired)
            {
                frame.Invoke(new MethodInvoker(delegate
                {
                    frame.BringToFront();
                    frame.Visible = true;
                    iShowFrame    = 1 - iShowFrame;
                    frames[iShowFrame].Visible = false;
                }));
            }
            else
            {
                frame.BringToFront();
                frame.Visible = true;
                iShowFrame    = 1 - iShowFrame;
                frames[iShowFrame].Visible = false;
            }

            // Set another timer...
            if (gameStatus != Modes.EXIT)
            {
                SetFlipTimer();
            }
        }
コード例 #2
0
        private void frmAsteroids_Activated(object sender, EventArgs e)
        {
            if (gameStatus == Modes.PREP)
            {
                screenCanvas = new ScreenCanvas();
                score        = new Score();
                gameStatus   = Modes.TITLE;
                currTitle    = new TitleScreen();
                currTitle.InitTitleScreen();

                // Timers for flipping display and playing sounds
                SetFlipTimer();
                SetSoundsTimer();

                // Handle the game
                do
                {
                    Application.DoEvents();
                    Thread.Sleep(0);
                } while (gameStatus != Modes.EXIT);
            }
        }
コード例 #3
0
        private void frmAsteroids_KeyDown(object sender, KeyEventArgs e)
        {
            // Check escape key
            if (e.KeyData == Keys.Escape) // Escape
            {
                // Escape during a title screen exits the game
                if (gameStatus == Modes.TITLE)
                {
                    gameStatus = Modes.EXIT;
                    Application.Exit();
                }

                // Escape in game goes back to Title Screen
                if (gameStatus == Modes.GAME)
                {
                    score.CancelGame();
                    currTitle  = new TitleScreen();
                    gameStatus = Modes.TITLE;
                }
            }
            else // Not Escape
            {
                // If we are in tht Title Screen, Start a game
                if (gameStatus == Modes.TITLE)
                {
                    score.ResetGame();
                    currGame               = new Game();
                    gameStatus             = Modes.GAME;
                    bLeftPressed           = false;
                    bRightPressed          = false;
                    bUpPressed             = false;
                    bHyperspaceLastPressed = false;
                    bShootingLastPressed   = false;
                    bPauseLastPressed      = false;
                }
                else // In Game
                {
                    // Keydown handled in game

                    // Rotate Left
                    if (e.KeyData == Keys.Left)
                    {
                        bLeftPressed = true;
                    }

                    // Rotate Right
                    if (e.KeyData == Keys.Right)
                    {
                        bRightPressed = true;
                    }

                    // Thrust
                    if (e.KeyData == Keys.Up)
                    {
                        bUpPressed = true;
                    }

                    // Hyperspace (can't be held down)
                    if (!bHyperspaceLastPressed && (e.KeyData == Keys.Down))
                    {
                        bHyperspaceLastPressed = true;
                        currGame.Hyperspace();
                    }

                    // Shooting (can't be held down)
                    if (!bShootingLastPressed && (e.KeyData == Keys.Space))
                    {
                        bShootingLastPressed = true;
                        currGame.Shoot();
                    }

                    // Pause can't be held down)
                    if (!bPauseLastPressed && (e.KeyData == Keys.P))
                    {
                        bPauseLastPressed = true;
                        currGame.Pause();
                    }
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Sixtten610/AsteroidsX
        static void Main(string[] args)
        {
            // skapar en 1000x1000 pixel ruta
            Raylib.InitWindow(1000, 1000, "Asteroids");
            Raylib.SetTargetFPS(60);

            // enum för gamestates
            GameState screen = GameState.title;

            // de olika skärmarna som man kan navigera
            TitleScreen titleScreen = new TitleScreen();

            PauseScreen pauseScreen = new PauseScreen();

            DifficultyScreen difficultyScreen = new DifficultyScreen();

            SettingScreen settingScreen = new SettingScreen();

            SinglePlayerScreen singlePlayerScreen = new SinglePlayerScreen();

            EndScreen endScreen = new EndScreen();

            MultiPlayerScreen multiPlayer = new MultiPlayerScreen();

            // single-player spel
            SinglePlayerGame singlePlayerGame = new SinglePlayerGame();

            bool restartGames = false;

            // spel loop
            while (!Raylib.WindowShouldClose())
            {
                Raylib.BeginDrawing();
                Raylib.ClearBackground(Color.BLACK);

                // if [..] if else för vilken spelskärm som ska visas
                // skärmarna har Uppdate och Draw metoder, samt knappar för att
                // reagera med annat UI i prog.cs
                if (screen == GameState.title)
                {
                    titleScreen.Update();
                    titleScreen.Draw();

                    if (titleScreen.isSinglePlayerPressed)
                    {
                        screen = GameState.singlePlayer;
                    }
                    else if (titleScreen.isMultiPlayerPressed)
                    {
                        screen = GameState.multiPlayer;
                    }
                    else if (titleScreen.isDifficultyPressed)
                    {
                        screen = GameState.difficulty;
                    }
                    else if (titleScreen.isSettingsPressed)
                    {
                        screen = GameState.settings;
                    }
                }
                else if (screen == GameState.difficulty)
                {
                    difficultyScreen.Update();
                    difficultyScreen.Draw();

                    if (difficultyScreen.isBackPressed)
                    {
                        screen = GameState.title;
                    }
                }
                else if (screen == GameState.singlePlayer)
                {
                    singlePlayerScreen.Update();
                    singlePlayerScreen.Draw();

                    if (singlePlayerScreen.isBackPressed)
                    {
                        screen = GameState.title;
                    }
                    else if (singlePlayerScreen.isPlayPressed)
                    {
                        screen = GameState.singlePlayerGame;
                    }
                }
                else if (screen == GameState.singlePlayerGame)
                {
                    pauseScreen.isPaused();

                    if (pauseScreen.GetIfPaused)
                    {
                        pauseScreen.Update();
                        pauseScreen.Draw();

                        if (pauseScreen.isMainMenuPressed())
                        {
                            screen       = GameState.title;
                            restartGames = true;
                        }
                    }
                    else
                    {
                        singlePlayerGame.CreateSinglePlayerShip();
                        singlePlayerGame.Update();
                        singlePlayerGame.Draw();

                        if (!singlePlayerGame.ContinueGame)
                        {
                            screen = GameState.end;
                        }
                    }
                }
                else if (screen == GameState.multiPlayer)
                {
                    multiPlayer.Update();
                    multiPlayer.Draw();

                    if (multiPlayer.isBackPressed)
                    {
                        screen = GameState.title;
                    }
                    else if (multiPlayer.isPlayPressed)
                    {
                        screen = GameState.multiPlayerGame;
                    }
                }
                else if (screen == GameState.settings)
                {
                    settingScreen.Update();
                    settingScreen.Draw();

                    if (singlePlayerScreen.isBackPressed)
                    {
                        screen = GameState.title;
                    }
                }
                else if (screen == GameState.end)
                {
                    endScreen.Update();
                    endScreen.Draw();

                    if (endScreen.isMainMenuPressed)
                    {
                        screen       = GameState.title;
                        restartGames = true;
                    }
                }

                // skapar nytt spel om metoden kallas
                if (restartGames)
                {
                    ObjectGame.Clear();
                    singlePlayerGame = new SinglePlayerGame();
                    restartGames     = false;
                }

                Raylib.EndDrawing();
            }
        }