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("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, "Select a game mode:", offset: buttonBackground.LocalPointToWorldPoint(new Vector2(0.5f, 0.5f)), origin: new Vector2(0.5f, 0.5f)) )); HUDListEntity levelList = new HUDListEntity(this, new Vector2(0.5f, 0.5f), menuEntries: levels.Select(l => new HUDListEntity.ListEntry(l.Item2, item => { selectedLevel = l.Item1; Dispatcher.NextFrame(StartLevel); })).ToArray()); AddEntity(levelList); AddEntity(new Entity(this, EntityType.LayerIndependent, new CenterCameraComponent(Game.Camera))); }
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(); }
public override void LoadContent() { base.LoadContent(); if (Game.CurrentGameMode.PlayerMode == PlayerMode.Free4All) { LoadContentFree4All(); } else { LoadContent2vs2(); } HUDComponent vignetteComponent = new HUDComponent(Game.Debug.DebugRectangle, Vector2.One, layerDepth: -0.8f) { MaintainAspectRation = false, OnVirtualUIScreen = false, Color = Color.FromNonPremultiplied(22, 59, 59, 163) }; AddEntity(new Entity(this, EntityType.UI, vignetteComponent)); 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))); var inputEntity = new Entity(this, EntityType.LayerIndependent); // [FOREACH PERFORMANCE] Should not allocate garbage foreach (var player in Game.CurrentGameMode.PlayerInfos) { if (player.IsKeyboardPlayer) { inputEntity.AddComponent(new InputComponent(player.GamepadIndex, new InputMapping(InputFunctions.KeyboardMenuStart, FadeInMenu) )); } else { inputEntity.AddComponent(new InputComponent(player.GamepadIndex, new InputMapping(InputFunctions.MenuStart, FadeInMenu) )); } } AddEntity(inputEntity); HUDTextComponent pressStartText = new HUDTextComponent(MainFont, 0.04f, "press start to continue", offset: new Vector2(0.5f, 0.9f), origin: new Vector2(0.5f, 0.5f), layerDepth: 0f) { Opacity = 0 }; Dispatcher.AddAnimation(Animation.Get(0, 1, 1.5f, true, val => pressStartText.Opacity = val, EasingFunctions.ToLoop(EasingFunctions.QuadIn), delay: 5f)); AddEntity(new Entity(this, EntityType.UI, pressStartText)); // Add continue overlay AddEntity(new Entity(this, EntityType.UI, continueBackground = new HUDComponent(Game.Debug.DebugRectangle, Vector2.One, layerDepth: 0.99f) { Color = Color.Black, Opacity = 0, MaintainAspectRation = false, OnVirtualUIScreen = false })); AddEntity(continueMenuList = new HUDListEntity(this, new Vector2(0.5f, 0.5f), layerDepth: 1f, menuEntries: new[] { new HUDListEntity.ListEntry("Rematch", Rematch), new HUDListEntity.ListEntry("Rejoin", Rejoin) , new HUDListEntity.ListEntry("Back to main menu", BackToMainMenu) }) { Enabled = false, Opacity = 0 }); AddEntity(new Entity(this, EntityType.LayerIndependent, new CenterCameraComponent(Game.Camera))); this.TransitionIn(); }
public override void LoadContent() { base.LoadContent(); Game.EngineComponents.Get <AudioManager>().PreloadSoundEffects("Audio/countDownLong", "Audio/countDownShort"); Game.CurrentGameMode.ClearScore(); AddPlayersWithBarns(locs, rotations); // Border trees Entity border; AddEntity(border = new Entity(this, EntityType.Game, new Vector2(0, 0), new SpriteComponent("joinscreen_outerBorder", new Vector2(screenWidth, screenWidth / 3.84f * 2.245f), new Vector2(0.5f, 0.5f), layerDepth: 0.9f) )); var triangulated = Triangulate.ConvexPartition(GameConstants.BoundingGameFieldTop, TriangulationAlgorithm.Earclip); triangulated.AddRange(Triangulate.ConvexPartition(GameConstants.BoundingGameFieldRight, TriangulationAlgorithm.Earclip)); triangulated.AddRange(Triangulate.ConvexPartition(GameConstants.BoundingGameFieldBottom, TriangulationAlgorithm.Earclip)); triangulated.AddRange(Triangulate.ConvexPartition(GameConstants.BoundingGameFieldLeft, TriangulationAlgorithm.Earclip)); var fixtureList = FixtureFactory.AttachCompoundPolygon(triangulated, 1, border.Body); border.AddComponent(new PhysicsComponent(fixtureList[0].Shape)); // Background AddEntity(new Entity(this, EntityType.Game, new Vector2(0, 0), // src image 6000x3508 new SpriteComponent("background", new Vector2(screenWidth, screenWidth / 3.84f * 2.245f), new Vector2(0.5f, 0.5f), layerDepth: -1.0f) )); // HUD // src image 1365x460 if (spawnAnyUI) { timeComponentBackground = new HUDComponent("timer_bg", new Vector2(1.365f / 0.46f * 0.1f, 1f * 0.1f), new Vector2(0.5f, 0f)); this.timeComponent100 = new HUDTextComponent(MainFont, 0.07f, "", color: countdownColor, offset: timeComponentBackground.LocalPointToWorldPoint(new Vector2(0.35f, 0.5f)), origin: new Vector2(0.5f, 0.5f) ); this.timeComponent10 = new HUDTextComponent(MainFont, 0.07f, "", color: countdownColor, offset: timeComponentBackground.LocalPointToWorldPoint(new Vector2(0.425f, 0.5f)), origin: new Vector2(0.5f, 0.5f) ); this.timeComponent1 = new HUDTextComponent(MainFont, 0.07f, "", color: countdownColor, offset: timeComponentBackground.LocalPointToWorldPoint(new Vector2(0.5f, 0.5f)), origin: new Vector2(0.5f, 0.5f) ); AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0f), timeComponentBackground, timeComponent100, timeComponent10, timeComponent1 )); if (!IsCountdownRunning) { timeComponentBackground.Opacity = timeComponent100.Opacity = timeComponent10.Opacity = timeComponent1.Opacity = 0f; } UpdateCountdown(0); // Add pause overlay AddEntity(new Entity(this, EntityType.UI, pauseOverlayComponents.AddAndReturn(new HUDComponent(Game.Debug.DebugRectangle, Vector2.One, layerDepth: 0.99f) { Color = Color.Black, MaintainAspectRation = false, OnVirtualUIScreen = false, }))); AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.25f), pauseTextOverlayComponents.AddAndReturn(new HUDTextComponent(MainFont, 0.2f, "Game Paused", origin: new Vector2(0.5f, 0.5f), layerDepth: 1f)))); pauseTextOverlayComponents.AddRange( AddEntity(pauseMenuList = new HUDListEntity(this, new Vector2(0.5f, 0.5f), layerDepth: 1f, menuEntries: new[] { new HUDListEntity.ListEntry("Resume", TogglePause), new HUDListEntity.ListEntry("Rejoin", BackToJoinScreen) , new HUDListEntity.ListEntry("Back to main menu", BackToMainMenu) }) { Enabled = false }) .GetAllComponents <HUDTextComponent>().ToList()); // make overlay invisible // [FOREACH PERFORMANCE] Should not allocate garbage pauseOverlayComponents.ForEach(c => c.Opacity = 0f); // [FOREACH PERFORMANCE] Should not allocate garbage pauseTextOverlayComponents.ForEach(c => c.Opacity = 0f); // Add pause controls // [FOREACH PERFORMANCE] Should not allocate garbage foreach (var playerInfo in Game.CurrentGameMode.PlayerInfos) { if (playerInfo.IsKeyboardPlayer) { AddEntity(new Entity(this, EntityType.LayerIndependent, new InputComponent(new InputMapping(i => InputFunctions.KeyboardPause(i), (f) => TogglePause(null))))); } else { AddEntity(new Entity(this, EntityType.LayerIndependent, new InputComponent(playerInfo.GamepadIndex, new InputMapping(i => InputFunctions.Pause(i), (f) => TogglePause(null)), new InputMapping(i => InputFunctions.StartCountdown(i), (f) => StartCountown()) ))); } } var playerInfos = Game.CurrentGameMode.PlayerInfos; var colors = ((PlayerColors[])Enum.GetValues(typeof(PlayerColors))); initialCountdownComponent = new HUDTextComponent(MainFont, 0.25f, Game.CurrentGameMode.PlayerMode == PlayerMode.TwoVsTwo ? "vs" : "free4all", origin: new Vector2(0.5f, 0.5f)); playerName1Component = new HUDTextComponent(MainFont, 0.15f, playerInfos[0].Name, color: colors[0].GetColor(), origin: new Vector2(0f, 0.5f), offset: new Vector2(-0.25f, -0.25f)); playerName2Component = new HUDTextComponent(MainFont, 0.15f, playerInfos.Count > 1 ? playerInfos[1].Name : "name2", color: colors[1].GetColor(), origin: new Vector2(0f, 0.5f), offset: new Vector2(-0.25f, 0.25f)); playerName3Component = new HUDTextComponent(MainFont, 0.15f, playerInfos.Count > 2 ? playerInfos[2].Name : "name3", color: colors[2].GetColor(), origin: new Vector2(1f, 0.5f), offset: new Vector2(0.25f, -0.25f)); playerName4Component = new HUDTextComponent(MainFont, 0.15f, playerInfos.Count > 3 ? playerInfos[3].Name : "name4", color: colors[3].GetColor(), origin: new Vector2(1f, 0.5f), offset: new Vector2(0.25f, 0.25f)); separatorTeam1Component = new HUDTextComponent(MainFont, 0.15f, "&", origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0f, -0.25f)); separatorTeam2Component = new HUDTextComponent(MainFont, 0.15f, "&", origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0f, 0.25f)); Entity countdownEntity; AddEntity(countdownEntity = new Entity(this, EntityType.UI, new Vector2(0.5f, 0.5f), initialCountdownComponent)); if (Game.CurrentGameMode.PlayerMode == PlayerMode.TwoVsTwo) { countdownEntity.AddComponent(playerName1Component); countdownEntity.AddComponent(playerName2Component); countdownEntity.AddComponent(playerName3Component); countdownEntity.AddComponent(playerName4Component); countdownEntity.AddComponent(separatorTeam1Component); countdownEntity.AddComponent(separatorTeam2Component); } } // Camera director AddEntity(new Entity(this, EntityType.LayerIndependent, new CameraDirectorComponent(playerEntities, Game.Camera))); }