public MainMenu(Game game, EffectRenderer renderer, StateManager parent) : base(game, renderer, parent) { titlePic = new Picture(game, guiManager, gameRef.Content.Load<Texture2D>("Gui/button-up")); characterPic = new Picture(game, guiManager, gameRef.Content.Load<Texture2D>("Freezling")); guiManager.AddPicture("titlePic", gameRef.Content.Load<Texture2D>("Gui/button-up")); guiManager["titlePic"].Position = new Vector2(400, 40.0f); guiManager["titlePic"].Size = new Vector2(400, 100); guiManager.AddButton("btnPlay", "Play", 60, guiManager["titlePic"].Position.Y + 100, 300, 75); guiManager.AddButton("btnSurvival", "Survival", 60, guiManager["btnPlay"].Position.Y + 100, 300, 75); guiManager.AddButton("btnRules", "Rules", 60, guiManager["btnSurvival"].Position.Y + 100, 300, 75); guiManager.AddButton("btnOptions", "Options", 60, guiManager["btnRules"].Position.Y + 100, 300, 75); guiManager.AddButton("btnExit", "Exit", 60, guiManager["btnOptions"].Position.Y + 100, 300, 75); guiManager.AddPicture("characterPic", gameRef.Content.Load<Texture2D>("Freezling")); guiManager["characterPic"].Position = new Vector2(guiManager["titlePic"].Position.X + 75, guiManager["titlePic"].Position.Y + 225); guiManager["characterPic"].Size = new Vector2(450, 450); btnPlay = guiManager["btnPlay"] as Button; btnPlay.Click += (control, button) => { GameState Play = this.parent[GameStateType.Playing]; if (Play != null) { this.parent.PushState(Play); Play playState = new Play(this.gameRef, this.renderer, this.parent); playState.Initialize(); this.parent.PushState(playState); } }; btnOptions = guiManager["btnOptions"] as Button; btnOptions.Click += (control, button) => { GameState Options = this.parent[GameStateType.OptionsMenu]; if (Options != null) { this.parent.PushState(Options); EndState endState = new EndState(this.gameRef, this.renderer, this.parent); endState.Initialize(); this.parent.PushState(endState); } }; btnExit = guiManager["btnExit"] as Button; btnExit.Click += (control, button) => { gameRef.Exit(); }; }
public override void Initialize() { childComponents = new List<GameObject>(); ioManager = new IOManager(); font = gameRef.Content.Load<SpriteFont>("SpriteFont1"); platform = new Platform(new Rectangle(18, 40, 445, 650), gameRef.Content); guage = new Guage(new Rectangle(platform.Position.X + platform.Position.Width + 2, 40, 100, 650), gameRef.Content); Vector2 startingPos = platform.getMidPoint(); player = new Munchlit(new Rectangle((int)startingPos.X, (int)startingPos.Y, 20, 20), gameRef.Content); childComponents.Add(platform); childComponents.Add(guage); childComponents.Add(player); for (int i = platform.Position.X + 12; i <= platform.Position.X + platform.Position.Width - 24; i += 30) { childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 45, 30, 30), gameRef.Content, 0)); childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 75, 30, 30), gameRef.Content, 0)); childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 105, 30, 30), gameRef.Content, 0)); } guiManager.AddLabel("HighScore", font, "Highscore: " + 0); guiManager["HighScore"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 40.0f); guiManager["HighScore"].Size = new Vector2(200.0f, 75.0f); guiManager["HighScore"].Color = Color.Black; guiManager.AddLabel("level", font, "Level: " + level); guiManager["level"].Position = new Vector2(platform.Position.X + platform.Position.Width / 3 + 20, 10.0f); guiManager["level"].Size = new Vector2(150, 20.0f); guiManager["level"].Color = Color.Black; guiManager.AddLabel("time", font, "Timer: " + timer); guiManager["time"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 70.0f); guiManager["time"].Size = new Vector2(200.0f, 75.0f); guiManager["time"].Color = Color.Black; guiManager.AddLabel("lives", font, "Lives: " + player.Lives); guiManager["lives"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 100.0f); guiManager["lives"].Size = new Vector2(150.0f, 20.0f); guiManager["lives"].Color = Color.Black; guiManager.AddLabel("points", font, "Points: " + player.Point); guiManager["points"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 130.0f); guiManager["points"].Size = new Vector2(150.0f, 20.0f); guiManager["points"].Color = Color.Black; guiManager.AddPicture("tmp", gameRef.Content.Load<Texture2D>("Freezling")); guiManager["tmp"].Position = new Vector2(guage.Position.X + guage.Position.Width + 30, 200.0f); guiManager["tmp"].Size = new Vector2(200.0f, 200.0f); guiManager.AddButton("pause", "PAUSE", guage.Position.X + guage.Position.Width + 10, 400, 200.0f, 75.0f); guiManager.AddButton("btnMainMenu", "Menu", guage.Position.X + guage.Position.Width + 10, 500, 200.0f, 75.0f); guiManager.AddButton("btnExit", "Exit", guage.Position.X + guage.Position.Width + 10, 600, 200.0f, 75.0f); btnMainMenu = guiManager["btnMainMenu"] as Button; btnMainMenu.Click += (control, button) => { GameState MainMenu = this.parent[GameStateType.Playing]; if (MainMenu != null) { this.parent.PushState(MainMenu); MainMenu MainMenuState = new MainMenu(this.gameRef, this.renderer, this.parent); MainMenu.Initialize(); this.parent.PushState(MainMenuState); } }; btnExit = guiManager["btnExit"] as Button; btnExit.Click += (control, button) => { gameRef.Exit(); }; try { highScore = ioManager.LoadHighScore(); } catch (Exception) { ioManager.SaveHighScore(0); highScore = 0; } }
/// <summary> /// Adds a button to this GUI manager. /// </summary> /// <param name="name">The name of the button control.</param> /// <param name="group">The button group.</param> /// <param name="x">The X coordinate of the button.</param> /// <param name="y">The Y coordinate of the button.</param> /// <param name="width">The width of the button.</param> /// <param name="height">The height of the button.</param> public void AddButton(string name, string text, float x, float y, float width, float height) { Button button = new Button(game, this, text, x, y, width, height); button.Name = name; controls[name] = button; }