/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // Get ControlManager from services _controlManager = (ControlManager)Game.Services.GetService(typeof(ControlManager)); // Add new control (title) Control title = new Control("Lost Gold", Control.TextSizeOptions.Large); title.offsetY = -150; _controlManager.Add(title); // Add new control (byline) Control byLine = new Control("by Lars Boldt", Control.TextSizeOptions.Small); byLine.offsetY = -120; _controlManager.Add(byLine); // Add new selectablecontrol (Start game) SelectableControl newGameLbl = new SelectableControl("Start new game", Control.TextSizeOptions.Medium); newGameLbl.OnSelect += new EventHandler(newGameLbl_onSelect); _controlManager.Add(newGameLbl); // Add new selectablecontrol (exit game) SelectableControl exitLbl = new SelectableControl("Exit", Control.TextSizeOptions.Medium); exitLbl.offsetY = 30; exitLbl.OnSelect += new EventHandler(exitLbl_onSelect); _controlManager.Add(exitLbl); base.Initialize(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Game over, you ran out of time if (engine.Enabled && engine.timeLeft <= 0) { Control loseText = new Control("You are out of time!", Control.TextSizeOptions.Large); loseText.Color = Color.Red; controlManager.Add(loseText); SelectableControl continueLbl = new SelectableControl("Press \"Enter\" or GamePad \"A\" to return to menu", Control.TextSizeOptions.Medium); continueLbl.offsetY = 50; continueLbl.OnSelect += new EventHandler(continueLbl_onSelect); controlManager.Add(continueLbl); engine.Enabled = false; } // Game won, you found the gold area if (engine.WinArea.Intersects(engine.Character.Rectangle()) && engine.Enabled) { Control winText = new Control("You found the gold!", Control.TextSizeOptions.Large); winText.Color = Color.Gold; controlManager.Add(winText); SelectableControl continueLbl = new SelectableControl("Press \"Enter\" or GamePad \"A\" to return to menu", Control.TextSizeOptions.Medium); continueLbl.offsetY = 50; continueLbl.OnSelect +=new EventHandler(continueLbl_onSelect); controlManager.Add(continueLbl); engine.Enabled = false; } // Game pause if (InputManager.KeyReleased(Keys.P) || InputManager.ButtonPressed(Buttons.Back, 0)) { // If game is running, pause it if (engine.Enabled) { engine.Enabled = false; controlManager.Add(new Control("Game paused", Control.TextSizeOptions.Large)); Control helpTxt = new Control("Press \"P\" or GamePad \"Back\" to unpause", Control.TextSizeOptions.Small); helpTxt.offsetY = 50; controlManager.Add(helpTxt); } // Game is paused, start it else { engine.Enabled = true; controlManager.Clear(); } } // Bring up Resume/exit menu during gameplay if ((InputManager.KeyReleased(Keys.Escape) || InputManager.ButtonPressed(Buttons.Start, 0)) && engine.Enabled) { engine.Enabled = false; Control menuTxt = new Control("Game menu", Control.TextSizeOptions.Large); menuTxt.offsetY = -40; controlManager.Add(menuTxt); SelectableControl resume = new SelectableControl("Resume", Control.TextSizeOptions.Medium); resume.OnSelect += new EventHandler(resume_OnSelect); controlManager.Add(resume); SelectableControl exit = new SelectableControl("Exit", Control.TextSizeOptions.Medium); exit.offsetY = 20; exit.OnSelect += new EventHandler(continueLbl_onSelect); controlManager.Add(exit); } base.Update(gameTime); }
/// <summary> /// Load content /// </summary> protected override void LoadContent() { base.LoadContent(); // SpriteBatch _spriteBatch = new SpriteBatch(Game.GraphicsDevice); // Character _character = new Character(Game); // Set character position _character.X = _startX; _character.Y = _startY; // Get starting animation frame art for character _characterFrameArt = _character.getCurrentFrame(0, new GameTime()); // Set character speed _characterSpeed = 2; // Camera2d _camera2d = new Camera2d(); // Center camera on player _camera2d.Pos = centerCameraOnCharacter(); // Camera zoom level _camera2d.Zoom = 1.5f; // Ambient sound - Load effect _ambientSound = Game.Content.Load<SoundEffect>(@"Sounds\AfternoonAmbienceSimple_01"); _ambientPlayer = _ambientSound.CreateInstance(); // Loop soundeffect _ambientPlayer.IsLooped = true; // Add each tile in each layer as a drawable foreach (Layer l in _layers) { foreach (LayerTile lt in l.LayerTiles) { AddDrawable( new DrawData(lt.TileSetTile.Art, new Rectangle( lt.X * _tileWidth, lt.Y * _tileHeight, lt.TileSetTile.Art.Width, lt.TileSetTile.Art.Height ) ) ); } } // Get Control Manager _controlManager = (ControlManager)Game.Services.GetService(typeof(ControlManager)); // Create timer control _timer = new Control(timeLeftToString(), Control.TextSizeOptions.Large); _timer.Id = "timer"; _timer.CenterText = false; _timer.Position = Vector2.Zero; _timer.Color = Color.Goldenrod; }