Beispiel #1
0
        private InputComponent MakeInput(bool isKeyboard, int gamepadIndex)
        {
            return(new InputComponent(gamepadIndex,
                                      new InputMapping(f => (isKeyboard) ? InputFunctions.KeyboardMenuStart(f) : InputFunctions.MenuStart(f), f => StartIfReady()),
                                      new InputMapping(f => (isKeyboard) ? InputFunctions.KeyboardMenuSelect(f) : InputFunctions.MenuSelect(f), f =>
            {
                var player = players.FindPlayer(gamepadIndex, isKeyboard);

                if (player != null)
                {
                    PlayerIsReady(player);
                }
                else
                {
                    JoinPlayer(isKeyboard, gamepadIndex);
                }
            }), new InputMapping(f => (isKeyboard) ? InputFunctions.KeyboardMenuBack(f) : InputFunctions.MenuBack(f), f =>
            {
                var player = players.FindPlayer(gamepadIndex, isKeyboard);

                if (player != null)
                {
                    if (player.CurrentState == JoinState.State.Joined)
                    {
                        NonPositionalAudio.PlaySound("Audio/MenuActionSound");
                        Game.CurrentGameMode.RemovePlayer(gamepadIndex, isKeyboard);
                        RemoveEntity(player.HUD);
                        RemoveEntity(player.Player);
                        players.Remove(player);
                        numJoinedPlayer--;

                        if (numJoinedPlayer < 4)
                        {
                            Dispatcher.AddAnimation(Animation.Get(joinComponent.Opacity, 1, 0.2f, false, (val) =>
                            {
                                joinComponent.Opacity = val;
                                joinTextComponent.Opacity = val;
                            }, EasingFunctions.QuadIn));
                        }
                    }
                    else if (player.CurrentState == JoinState.State.Ready)
                    {
                        NonPositionalAudio.PlaySound("Audio/MenuActionSound");
                        player.Back();

                        // Animate text
                        var textChooser = player.HUD.GetComponentByName <HUDTextComponent>("nameTextchooser");
                        Dispatcher.AddAnimation(Animation.Get(textChooser.Opacity, 1f, 1f, false, (o) => textChooser.Opacity = o, EasingFunctions.QuadIn));
                        var boardChooser = player.HUD.GetComponentByName <HUDComponent>("namechooser");
                        Dispatcher.AddAnimation(Animation.Get(boardChooser.Opacity, 1f, 1f, false, (o) => boardChooser.Opacity = o, EasingFunctions.QuadIn));

                        var text = player.HUD.GetComponentByName <HUDTextComponent>("nameText");
                        Dispatcher.AddAnimation(Animation.Get(text.Opacity, 0f, 1f, false, (o) => text.Opacity = o, EasingFunctions.ToEaseOut(EasingFunctions.QuadIn)));
                        var board = player.HUD.GetComponentByName <HUDComponent>("name");
                        Dispatcher.AddAnimation(Animation.Get(board.Opacity, 0f, 1f, false, (o) => board.Opacity = o, EasingFunctions.ToEaseOut(EasingFunctions.QuadIn)));

                        player.Player.Freeze();

                        if (players.Count(j => j.CurrentState == JoinState.State.Ready) >= (Game.CurrentGameMode.PlayerMode == PlayerMode.TwoVsTwo ? 4 : 1))
                        {
                            pressStartToStartAnimation.IsRunning = false;
                            Dispatcher.AddAnimation(Animation.Get(pressStartToStart.Opacity, 0f, 0.3f, false, (o) => pressStartToStart.Opacity = o, EasingFunctions.ToEaseOut(EasingFunctions.QuadIn)));
                        }
                    }
                }
                else if (!players.Any())
                {
                    this.TransitionOutAndSwitchScene(new GameModeScene(Game));
                }
            }),
                                      new InputMapping(
                                          f => (isKeyboard)
                        ? InputFunctions.KeyboardMenuRandom(f)
                        : InputFunctions.MenuRandom(f), f =>
            {
                var player = players.FindPlayer(gamepadIndex, isKeyboard);
                if (player != null && player.CurrentState == JoinState.State.Joined)
                {
                    NonPositionalAudio.PlaySound("Audio/MenuActionSound");
                    SetRandomName(player);
                }
            }),
                                      new InputMapping(
                                          f => (isKeyboard)
                        ? InputFunctions.KeyboardMenuLeft(f) || InputFunctions.KeyboardMenuUp(f)
                        : InputFunctions.MenuLeft(f) || InputFunctions.MenuUp(f), f =>
            {
                var player = players.FindPlayer(gamepadIndex, isKeyboard);
                if (player != null && player.CurrentState == JoinState.State.Joined)
                {
                    NonPositionalAudio.PlaySound("Audio/MenuActionSound");
                    SetNextOrPreviousName(player, 1);
                }
            }),
                                      new InputMapping(
                                          f => (isKeyboard)
                        ? InputFunctions.KeyboardMenuRight(f) || InputFunctions.KeyboardMenuDown(f)
                        : InputFunctions.MenuRight(f) || InputFunctions.MenuDown(f), f =>
            {
                var player = players.FindPlayer(gamepadIndex, isKeyboard);
                if (player != null && player.CurrentState == JoinState.State.Joined)
                {
                    NonPositionalAudio.PlaySound("Audio/MenuActionSound");
                    SetNextOrPreviousName(player, -1);
                }
            })
                                      ));
        }
Beispiel #2
0
        public override void LoadContent()
        {
            base.LoadContent();

            Game.CurrentGameMode.ClearPlayers();

            var backgroundSize = new Vector2(6f / 3.508f * 1.1f * GameConstants.ScreenHeight, 1.1f * GameConstants.ScreenHeight);

            AddEntity(new Entity(this, EntityType.Game, new SpriteComponent("background", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: -1.0f)));
            AddEntity(new Entity(this, EntityType.Game, new SpriteComponent("trees_border", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f)));

            //// UI
            //var buttonBackground = new HUDComponent("button_bg", new Vector2(1.2f, 0.2f), offset: new Vector2(0.5f, 0f), origin: new Vector2(0.5f, 0f));

            //AddEntity(new Entity(this, EntityType.UI, buttonBackground,
            //    new HUDTextComponent(MainFont, 0.1f, "Vacamole",
            //        offset: buttonBackground.LocalPointToWorldPoint(new Vector2(0.5f, 0.5f)),
            //        origin: new Vector2(0.5f, 0.5f))
            //));

            HUDComponent vignetteComponent = new HUDComponent(Game.Debug.DebugRectangle, Vector2.One, layerDepth: -0.1f)
            {
                MaintainAspectRation = false,
                OnVirtualUIScreen    = false,
                Color = Color.FromNonPremultiplied(22, 59, 59, 163)
            };
            Vector2      logoSize      = new Vector2(1, 0.7684f);
            HUDComponent logoComponent = new HUDComponent("titleScreen", 0.8f * logoSize, offset: new Vector2(0.5f, 0.1f), origin: new Vector2(0.5f, 0f), layerDepth: -0.1f);

            AddEntity(new Entity(this, EntityType.UI, Vector2.Zero, vignetteComponent, logoComponent));

            mainMenuList = new HUDListEntity(this, new Vector2(0.5f, 0.8f), elementSize: 0.1f, allowAllControllers: true, isHorizontal: true, menuEntries: new[] {
                new HUDListEntity.ListEntry("New Game", OnNewGame),
                new HUDListEntity.ListEntry("Options", (i) => GoToMenuState(MenuState.Options)),
                new HUDListEntity.ListEntry("Controls", (i) => GoToMenuState(MenuState.Controls)),
                new HUDListEntity.ListEntry("Tutorial", OnGoToTutorial),
                new HUDListEntity.ListEntry("Credits", (i) => GoToMenuState(MenuState.Credits)),
                new HUDListEntity.ListEntry("Exit", OnExit)
            })
            {
                Enabled = false, Opacity = 0
            };

            optionsList = new HUDListEntity(this, new Vector2(0.5f, 0.8f), elementSize: 0.15f, allowAllControllers: true, isHorizontal: true, menuEntries: new[] {
                new HUDListEntity.ListEntry($"Master: {GetPercentage(Settings<GameSettings>.Value.MasterVolume)}%", OnMasterVolume),
                new HUDListEntity.ListEntry($"Sound: {GetPercentage(Settings<GameSettings>.Value.SoundVolume)}%", OnSoundVolume),
                new HUDListEntity.ListEntry($"Music: {GetPercentage(Settings<GameSettings>.Value.MusicVolume)}%", OnMusicVolume),
                new HUDListEntity.ListEntry("Back", SaveAndBack)
            })
            {
                Enabled = false, Opacity = 0
            };

            controlInstructionsBackground = new HUDComponent(Game.Debug.DebugRectangle, Vector2.One, origin: new Vector2(0.5f, 0.5f), layerDepth: -0.1f)
            {
                MaintainAspectRation = false,
                OnVirtualUIScreen    = false,
                Color   = Color.FromNonPremultiplied(0, 0, 0, 160),
                Opacity = 0
            };
            controlInstructions = new HUDComponent("controls", new Vector2(0.85f, 0.4f), origin: new Vector2(0.5f, 0.5f))
            {
                Opacity = 0, MaintainAspectRation = true
            };
            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.5f), controlInstructionsBackground, controlInstructions));
            AddEntity(mainMenuList);
            AddEntity(optionsList);

            GoToMenuState(MenuState.MainMenu);

            var layerIndependent = new Entity(this, EntityType.LayerIndependent, new CenterCameraComponent(Game.Camera));


            // Add controls to hide the controls overlay or the credits overlay (later version)
            for (int i = 0; i < 4; i++)
            {
                layerIndependent.AddComponent(new InputComponent(i, new InputMapping(f => InputFunctions.MenuSelect(f) || InputFunctions.MenuBack(f), HideControls)));
            }
            layerIndependent.AddComponent(new InputComponent(new InputMapping(f => InputFunctions.KeyboardMenuSelect(f) || InputFunctions.KeyboardMenuBack(f), HideControls)));


            AddEntity(layerIndependent);

            creditsScene = new[] {
                new HUDTextComponent(MainFont, 0.03f, "Credits",
                                     offset: new Vector2(0.5f, 0.1f),
                                     origin: new Vector2(0.5f, 0.5f))
                {
                    Opacity = 0
                },
                new HUDTextComponent(MainFont, 0.04f, "Programming",
                                     offset: new Vector2(0.5f, 0.25f),
                                     origin: new Vector2(0.5f, 0.5f))
                {
                    Opacity = 0
                },
                new HUDTextComponent(MainFont, 0.06f, "Alexander Kayed\nMoritz Zilian\nFlorian Zinggeler",
                                     offset: new Vector2(0.5f, 0.4f),
                                     origin: new Vector2(0.5f, 0.5f))
                {
                    Opacity = 0
                },
                new HUDTextComponent(MainFont, 0.04f, "Art",
                                     offset: new Vector2(0.5f, 0.6f),
                                     origin: new Vector2(0.5f, 0.5f))
                {
                    Opacity = 0
                },
                new HUDTextComponent(MainFont, 0.06f, "Sonja Böckler",
                                     offset: new Vector2(0.5f, 0.675f),
                                     origin: new Vector2(0.5f, 0.5f))
                {
                    Opacity = 0
                },
                new HUDTextComponent(MainFont, 0.035f, "This game was created during the\nETH Game Programming Laboratory course\nin collaboration with ZHdK",
                                     offset: new Vector2(0.5f, 0.85f),
                                     origin: new Vector2(0.5f, 0.5f))
                {
                    Opacity = 0
                },
            };
            AddEntity(new Entity(this, EntityType.UI, creditsScene));



            this.TransitionIn();
        }
Beispiel #3
0
        public override void LoadContent()
        {
            base.LoadContent();

            var backgroundSize = new Vector2(6f / 3.508f * 1.1f * GameConstants.ScreenHeight, 1.1f * GameConstants.ScreenHeight);

            AddEntity(new Entity(this, EntityType.Game, new SpriteComponent("background", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: -1.0f)));
            AddEntity(new Entity(this, EntityType.Game, new SpriteComponent("trees_border", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f)));

            // UI
            var buttonBackground = new HUDComponent("overlayInstructionBox", new Vector2(1.2f, 0.2f), offset: new Vector2(0.5f, 0.05f), origin: new Vector2(0.5f, 0.05f));

            AddEntity(new Entity(this, EntityType.UI, buttonBackground,
                                 new HUDTextComponent(MainFont, 0.1f, "Game mode",
                                                      offset: buttonBackground.LocalPointToWorldPoint(new Vector2(0.5f, 0.5f)),
                                                      origin: new Vector2(0.5f, 0.5f), layerDepth: 0.1f)
                                 ));

            // Player mode selection
            playerMode2vs2 = new HUDComponent("gameMode_2VS2_notselected", new Vector2(0.5f, 0.32f), origin: new Vector2(0.5f, 0.5f), offset: new Vector2(-0.16f, 0))
            {
                Opacity = 0f
            };
            playerMode2vs2Selected     = new HUDComponent("gameMode_2VS2_selected", new Vector2(0.5f, 0.32f), origin: new Vector2(0.5f, 0.5f), offset: new Vector2(-0.16f, 0));
            playerModeFree4All         = new HUDComponent("gameMode_freeForAll_notselected", new Vector2(0.5f, 0.32f), origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0.16f, 0));
            playerModeFree4AllSelected = new HUDComponent("gameMode_freeForAll_selected", new Vector2(0.5f, 0.32f), origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0.16f, 0))
            {
                Opacity = 0f
            };

            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.3f), playerMode2vs2, playerModeFree4All, playerMode2vs2Selected, playerModeFree4AllSelected));


            // Game mode selection
            gameModeWaves = new HUDTextComponent(MainFont, 0.05f, "WAVES", origin: new Vector2(0.5f, 0.5f), offset: new Vector2(-0.11f, 0), color: Color.Yellow)
            {
                Opacity = InActiveOpacity
            };
            gameModeBigHerd = new HUDTextComponent(MainFont, 0.05f, "BIG HERD", origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0.11f, 0))
            {
                Opacity = InActiveOpacity
            };

            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.55f), gameModeWaves, gameModeBigHerd));

            // Runtime mode selection
            runtimeModeOptions = Enumerable.Range(0, 4).Select(i => new HUDTextComponent(MainFont, 0.05f, "", origin: new Vector2(0.5f, 0.5f),
                                                                                         offset: new Vector2(-0.225f, 0) + new Vector2(0.15f, 0) * i)
            {
                Opacity = InActiveOpacity, Color = i == 0 ? Color.Yellow : Color.Wheat
            }).ToArray();
            UpdateRuntimeTexts();
            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.65f), runtimeModeOptions));

            // CONTINUE TEXT
            continueText = new HUDTextComponent(MainFont, 0.05f, "press A to continue", origin: new Vector2(0.5f, 0.5f))
            {
                Opacity = 0
            };
            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.8f), continueText));
            continueTextAnimation = Dispatcher.AddAnimation(Animation.Get(0, 1, 1.5f, true, val => continueText.Opacity = val, EasingFunctions.ToLoop(EasingFunctions.QuadIn))
                                                            .Set(a => a.IsRunning = false));


            // add controls
            var layerIndependent = new Entity(this, EntityType.LayerIndependent, new CenterCameraComponent(Game.Camera));

            for (int i = 0; i < 4; i++)
            {
                layerIndependent.AddComponent(new InputComponent(i,
                                                                 new InputMapping(f => InputFunctions.MenuSelect(f) || InputFunctions.MenuDown(f), OnNextPressed),
                                                                 new InputMapping(f => InputFunctions.MenuBack(f) || InputFunctions.MenuUp(f), OnBackPressed),
                                                                 new InputMapping(f => InputFunctions.MenuStart(f), OnStartPressed),
                                                                 new InputMapping(f => InputFunctions.MenuLeft(f), OnLeftPressed),
                                                                 new InputMapping(f => InputFunctions.MenuRight(f), OnRightPressed)));
            }


            layerIndependent.AddComponent(new InputComponent(
                                              new InputMapping(f => InputFunctions.KeyboardMenuSelect(f) || InputFunctions.KeyboardMenuDown(f), OnNextPressed),
                                              new InputMapping(f => InputFunctions.KeyboardMenuBack(f) || InputFunctions.KeyboardMenuUp(f), OnBackPressed),
                                              new InputMapping(f => InputFunctions.KeyboardMenuStart(f), OnStartPressed),
                                              new InputMapping(f => InputFunctions.KeyboardMenuLeft(f), OnLeftPressed),
                                              new InputMapping(f => InputFunctions.KeyboardMenuRight(f), OnRightPressed)));
            AddEntity(layerIndependent);

            GoToMenuState(MenuState.ChoosePlayerMode);


            this.TransitionIn();
        }