/// <summary> /// Initializes the screen /// </summary> public override void Initialize() { // Add background _background = new Sprite(this.Game, "Graphics/Backgrounds/spr_title"); this.Background.Add(_background); // Add buttons _playButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_play"); _helpButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_help"); _quitButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_quit"); this.Foreground.Add(_playButton); this.Foreground.Add(_helpButton); this.Foreground.Add(_quitButton); // Initialize sprites and load their textures base.Initialize(); // Set the positions _background.Position = Vector2.UnitY * 0/*-80*/ + Vector2.UnitX * (this.ScreenManager.ScreenWidth - _background.Texture.Width) / 2; _playButton.Position = new Vector2((this.ScreenManager.ScreenWidth - _playButton.Texture.Width) / 2, 500/*440*/); _helpButton.Position = new Vector2((this.ScreenManager.ScreenWidth - _helpButton.Texture.Width) / 2, 560/*500*/); _quitButton.Position = new Vector2((this.ScreenManager.ScreenWidth - _quitButton.Texture.Width) / 2, 620/*560*/); // Set on click actions _playButton.OnClicked += new ButtonClickDelegate(_playButton_OnClicked); _helpButton.OnClicked += new ButtonClickDelegate(_helpButton_OnClicked); _quitButton.OnClicked += new ButtonClickDelegate(_quitButton_OnClicked); }
/// <summary> /// Initializes the screen /// </summary> public override void Initialize() { // Create sprites _background = new Sprite(this.Game, "Graphics/Backgrounds/spr_help"); this.Background.Add(_background); _backButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_back"); this.Foreground.Add(_backButton); // Initalize sprites and load their textures base.Initialize(); // Set the positions _background.Position = /*Vector2.UnitY * -50 +*/ Vector2.UnitX * (this.ScreenManager.ScreenWidth - _background.Texture.Width) / 2; _backButton.Position = new Vector2((this.ScreenManager.ScreenWidth - _backButton.Texture.Width) / 2, 720/*650*/); _backButton.OnClicked += new ButtonClickDelegate(_backButton_OnClicked); }
/// <summary> /// Initialiazes the screen /// </summary> public override void Initialize() { _background = new Sprite(this.Game, "Graphics/Backgrounds/spr_levelselect"); this.Background.Add(_background); // add the level buttons var levelUnlocks = TickTick.Data.Level.ReadLevelUnlocks("Levels/progress.txt"); _levelButtons = new Button[Levels]; for (Int32 i = 0; i < Levels; i++) { var assetName = String.Format("Graphics/Sprites/spr_level_{0}", levelUnlocks[i].Solved ? "solved" : (levelUnlocks[i].Unlocked ? "unsolved" : "locked") ); _levelButtons[i] = new LevelButton(this.Game, this.InputManager, assetName, String.Format("Content/Levels/{0}.txt", i+1)); _levelButtons[i].Enabled = levelUnlocks[i].Unlocked; this.Foreground.Add(_levelButtons[i]); } _backButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_back"); this.Foreground.Add(_backButton); // Initialize and load all the sprites base.Initialize(); // Set positions and actions for the levelbuttons for (Int32 i = 0; i < Levels; i++) { int row = i / 4; int column = i % 4; _levelButtons[i].Position = new Vector2(column * (_levelButtons[i].Texture.Width + 20), row * (_levelButtons[i].Texture.Height + 20)) + new Vector2(390 /*310*/, 180/*120*/); _levelButtons[i].OnClicked += new ButtonClickDelegate(LevelSelectScreen_OnClicked); } _background.Position = /*Vector2.UnitY * -50 +*/ Vector2.UnitX * (this.ScreenManager.ScreenWidth - _background.Texture.Width) / 2; _backButton.Position = new Vector2((this.ScreenManager.ScreenWidth - _backButton.Texture.Width) / 2, 680/*650*/); _backButton.OnClicked += new ButtonClickDelegate(_backButton_OnClicked); }
/// <summary> /// /// </summary> /// <param name="button"></param> /// <param name="relativePosition"></param> protected void _backButton_OnClicked(Button button, Vector2 relativePosition) { this.ScreenManager.AddScreen(new TitleScreen(this.Game)); this.ExitScreen(); }
/// <summary> /// Initializes the screen /// </summary> public override void Initialize() { _keyboardController = new KeyboardController(this.Game, Keys.W, Keys.A, Keys.D); _keyboardController.Initialize(); ///////////////////////////////////// // Build the layers ///////////////////////////////////// // Add the sky var _backgroundSky = new Sprite(this.Game, "Graphics/Backgrounds/spr_sky"); _background.Add(_backgroundSky); // Add a few random mountains var _mountains = new Sprite[5]; for (int i = 0; i < 5; i++) { _mountains[i] = new Sprite(this.Game, String.Format("Graphics/Backgrounds/spr_mountain_{0}", (this.ScreenManager.Random.Next(2) + 1))); _background.Add(_mountains[i]); } // Add the clouds _background.Add(new Clouds(this.Game, 2)); // Get the tiles var tiles = _levelData.GenerateComponents(this.Game, _foreground, out _levelState); foreach (var tile in tiles) { _foreground.Add(tile); if (tile.GetType() == typeof(Player)) { _player = tile as Player; _playerController = new PlayerController(Game, _keyboardController, _player); _playerController.Initialize(); _camera.FocusOn(_player); } } // Add the time _overlay.Add(new Sprite(this.Game, "Graphics/Sprites/spr_timer") { Position = Vector2.One * 10 }); _overlay.Add(new TimerDisplay(this.Game, _levelState) { Position = new Vector2(31, 36) }); // Add the quit button var quitButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_quit"); _overlay.Add(quitButton); ///////////////////////////////////// // Initialize the screen components ///////////////////////////////////// base.Initialize(); _camera.Initialize(); _background.Initialize(); _foreground.Initialize(); _overlay.Initialize(); _backgroundSky.Position = Vector2.UnitY * (this.ScreenManager.ScreenHeight - _backgroundSky.Texture.Height); foreach (var mountain in _mountains) mountain.Position = Vector2.UnitX * (Single)(this.ScreenManager.Random.NextDouble() * this.ScreenManager.ScreenWidth - mountain.Texture.Width / 2) + Vector2.UnitY * (this.ScreenManager.ScreenHeight - mountain.Texture.Height); quitButton.Position = new Vector2(this.ScreenManager.ScreenWidth - quitButton.Texture.Width - 10, 10); ///////////////////////////////////// // Action handlers ///////////////////////////////////// quitButton.OnClicked += new ButtonClickDelegate(quitButton_OnClicked); _levelState.OnCompleted += new EventHandler(_levelState_OnCompleted); _levelState.OnLost += new EventHandler(_levelState_OnLost); System.Diagnostics.Debug.WriteLine("Called init"); }
/// <summary> /// On quit button clicked /// </summary> /// <param name="button"></param> /// <param name="relativePosition"></param> protected void quitButton_OnClicked(Button button, Vector2 relativePosition) { this.ExitScreen(); this.ScreenManager.AddScreen(new LevelSelectScreen(this.Game)); System.Diagnostics.Debug.WriteLine("Call exit"); }
/// <summary> /// Is called when the quit button is clicked /// </summary> /// <param name="button">Reference to the clicked button</param> /// <param name="relativePosition">Position on the button clicked</param> protected void _quitButton_OnClicked(Button button, Vector2 relativePosition) { this.ExitScreen(); }
/// <summary> /// Is called when the play button is clicked /// </summary> /// <param name="button">Reference to the clicked button</param> /// <param name="relativePosition">Position on the button clicked</param> protected void _playButton_OnClicked(Button button, Vector2 relativePosition) { this.ScreenManager.AddScreen(new LevelSelectScreen(this.Game)); this.ExitScreen(); }
/// <summary> /// /// </summary> /// <param name="button"></param> /// <param name="relativePosition"></param> protected void LevelSelectScreen_OnClicked(Button button, Vector2 relativePosition) { var levelButton = button as LevelButton; this.ScreenManager.AddScreen(new LevelScreen(this.Game, levelButton.Level)); this.ExitScreen(); }