private void Failed(bool tireFailed) { if (view == null) { if (!failed) { failed = true; if (tireFailed) audioPlayer.PlayBlast(); else audioPlayer.PlayOuch(); // head failed audioPlayer.StopMotor(); view = new Menu(this); audioPlayer.PlayMusic(); } } }
/// <summary> /// Starts a new game after the level has been loaded. /// For internl use. /// </summary> private void NewGame() { level.HeadFail += new Action<Level>(HeadFail); level.TireFail += new Action<Level>(TireFail); level.Win += new Action<Level>(Win); level.EnableControl(); level.StopBikeMotor(); failed = false; level.ResetBike(); paused = false; won = false; audioPlayer.StopMusic(); audioPlayer.PlayMotor(); view = null; stopwatch.Reset(); stopwatch.Start(); }
/// <summary> /// A callback function for Level to notify that the player has got to the finish /// </summary> /// <param name="level">the caller of this function</param> public void Win(Level level) { if (view == null) { paused = true; stopwatch.Stop(); finishTime = stopwatch.Elapsed; audioPlayer.PlayFanfare(); audioPlayer.StopMotor(); view = new WinView(this); won = true; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); audioPlayer = new AudioPlayer(Content); level = new Level(1, audioPlayer, this.Content); level.HeadFail += new Action<Level>(HeadFail); level.TireFail += new Action<Level>(TireFail); level.Win += new Action<Level>(Win); background = this.Content.Load<Texture2D>("Images/sky"); font = this.Content.Load<SpriteFont>("SpriteFont3"); view = new SplashScreen(this); optionsButton = new Button("options", new Vector2(getWidth() * 0.015f, getHeight() * 0.89f), this.Content); optionsButton.ButtonPressed += (sender => Pause()); float aspect = (float)optionsButton.Width / (float)optionsButton.Height; optionsButton.Height = (int)(0.1f * getHeight()); optionsButton.Width = (int)(aspect * optionsButton.Height); exitButton = new Button("exit", new Vector2(getWidth() * 0.89f, getHeight() * 0.88f), this.Content); exitButton.ButtonPressed += (sender => Exit()); aspect = (float)exitButton.Width / (float)exitButton.Height; exitButton.Height = (int)(0.1f * (float)getHeight()); exitButton.Width = (int)(aspect * (float)exitButton.Height); leftButton = new Button("left", new Vector2(10, 20), this.Content, true); leftButton.ButtonPressed += (sender => level.leanBikeBackwards()); leftButton.Height = 70; rightButton = new Button("right", new Vector2(relativeX(735), relativeY(20)), this.Content, true); rightButton.Height = 70; rightButton.ButtonPressed += (sender => level.leanBikeForwards()); clockPos = new Vector2(0.45f * getWidth(), 0.89f * getHeight()); }
/// <summary> /// Shows LevelSelector on users custom level page /// </summary> /// <param name="newGame">for telling if we want to select the level for /// starting a new game or showing the high scores</param> public void ShowMyLevelsSelector(bool newGame) { view = new LevelSelector(this, newGame, true); }
/// <summary> /// Opens the level editor /// </summary> public void StartLevelEditor() { audioPlayer.StopMusic(); view = null; stopwatch.Reset(); paused = false; editorOpen = true; level = new LevelEditor(audioPlayer, this.Content); ((LevelEditor)level).Ready += LevelCreated; }
/// <summary> /// Shows InfoView /// </summary> public void ShowInfo() { view = new InfoView(this); }
/// <summary> /// Shows LevelSelector on predefined level page /// </summary> /// <param name="newGame">for telling if we want to select the level bacause of /// starting a new game or showing the high scores</param> public void ShowLevelSelector(bool newGame) { view = new LevelSelector(this, newGame, false); }
/// <summary> /// Shows the high scores for the selected level /// </summary> /// <param name="levelName">the name of the level which high scores we want to show</param> public void ShowHighScores(String levelName) { view = new HighScores(this, levelName); }
/// <summary> /// Resumes to the game if it has been paused /// </summary> public void Resume() { paused = false; audioPlayer.StopMusic(); audioPlayer.PlayMotor(); view = null; stopwatch.Start(); }
/// <summary> /// Open the main menu /// </summary> public void OpenMenu() { view = new Menu(this); audioPlayer.StopMotor(); audioPlayer.StopFanfare(); audioPlayer.PlayMusic(); }
/// <summary> /// A callback function for LevelEditor to notify that the editor should be closed /// </summary> /// <param name="sender">the caller of this function</param> /// <param name="args">for telling if the created level is wanted to be saved or /// not</param> public void LevelCreated(bool save) { editorOpen = false; editorOpen = false; if (save) view = new LevelSaver(this); else { level = new Level(1, audioPlayer, this.Content); view = new Menu(this); } }
/// <summary> /// Closes views on top the game world /// </summary> public void CloseView() { view = null; }