예제 #1
0
        public static void Prepare(SplashImage[] images, OnFinish action)
        {
            for (int i = 0; i < images.Length; i++)
            {
                if (i > 0)
                {
                    images[i].IsActive = false;
                }

                if (i == images.Length - 1)
                {
                    images[i].Finish += action;
                }
                else
                {
                    images[i].Next = images[i + 1];
                }
            }
        }
예제 #2
0
파일: Game.cs 프로젝트: Wezthal/GameProject
        private void Init()
        {
            Music = new MusicPlayer();
            Sounds = new SoundManager();
            Assets = new Assets();
            Assets.Load();

            var vm = new SFML.Window.VideoMode(1000, 750, 32);
            var style = Styles.Close;
            var settings = new ContextSettings(0, 0, 8);

            Window = new SFML.Graphics.RenderWindow(vm, "", style, settings);
            Window.SetView(View);
            Window.SetVerticalSyncEnabled(true);
            Window.Closed += (sender, e) => { IsAppExited = true; };
            Window.LostFocus += (sender, e) => { IsPaused = true; };
            Window.GainedFocus += (sender, e) => { IsPaused = false; };
            Window.SetMouseCursorVisible(true);

            var splash = new Space("Splash", true);
            var menu = new Space("Menu");
            var inGame = new Space("InGame");
            var gameOver = new Space("GameOver");

            //  ----- ----- ----- Splash ----- ----- -----

            var images = new SplashImage[]
            {
                new SplashImage(Assets.Textures["sfml"], 3, 1, 1),
                new SplashImage(Assets.Textures["rsas"], 5, 1, 1)
            };

            SplashImage.Prepare(images, e =>
            {
                splash.IsActive = false;
                menu.IsActive = true;
            });

            foreach(var image in images)
                splash.Add(image);

            //  ----- ----- ----- Menu ----- ----- -----
            var btnStart = new MenuButton("Play", 40, new Vector(100, 100));
            var btnQuit = new MenuButton("Quit", 40, new Vector(100, 200));

            var btnDiffEasy = new MenuButton("Easy", 30, new Vector(250, 100));
            var btnDiffMedium = new MenuButton("Medium", 30, new Vector(250, 150));
            var btnDiffHard = new MenuButton("Hard", 30, new Vector(250, 200));

            var infoText =
                "- Instructions -\n" +
                "- Run, shoot and survive as long as possible.\n" +
                "- Collect white powersups to recover health.\n" +
                "- New weapons are unlocked after each 1000 kills.\n" +
                "\n" +
                "- Use WASD keys to move, and mouse to aim and shoot.\n" +
                "- Use the numbers keys to change weapons.\n" +
                "- During gameplay, press ESC to pause or F1 to give up.";
            var btnInfoText = new MenuButton(infoText, 20, new Vector(450, 125));

            var highscoreList = new HighscoreList(new Vector2f(50, 300));

            Difficulty = RSaS.Difficulty.Medium;
            btnDiffMedium.Text.Color = Color.Red;

            btnStart.Click += e =>
            {
                if (IsGameOver)
                {
                    IsGameOver = false;
                    InitInGame(inGame);
                }

                Music.Play("music");
                menu.IsActive = false;
                inGame.IsActive = true;
                IsOSCursorVisible = false;
            };

            btnQuit.Click += e =>
            {
                IsAppExited = true;
            };

            btnDiffEasy.Click += e =>
            {
                if (!IsGameOver)
                    return;

                Difficulty = RSaS.Difficulty.Easy;
                btnDiffEasy.Text.Color = Color.Red;
                btnDiffMedium.Text.Color = Color.White;
                btnDiffHard.Text.Color = Color.White;
            };

            btnDiffMedium.Click += e =>
            {
                if (!IsGameOver)
                    return;

                Difficulty = RSaS.Difficulty.Medium;
                btnDiffEasy.Text.Color = Color.White;
                btnDiffMedium.Text.Color = Color.Red;
                btnDiffHard.Text.Color = Color.White;
            };

            btnDiffHard.Click += e =>
            {
                if (!IsGameOver)
                    return;

                Difficulty = RSaS.Difficulty.Hard;
                btnDiffEasy.Text.Color = Color.White;
                btnDiffMedium.Text.Color = Color.White;
                btnDiffHard.Text.Color = Color.Red;
            };

            menu.Add(btnStart);
            menu.Add(btnQuit);
            menu.Add(btnDiffEasy);
            menu.Add(btnDiffMedium);
            menu.Add(btnDiffHard);
            menu.Add(btnInfoText);
            menu.Add(highscoreList);
        }