Ejemplo n.º 1
0
 /// <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;
     }
 }
Ejemplo n.º 2
0
        /// <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());
        }
Ejemplo n.º 3
0
 /// <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;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// A callback function for Level to notify that the bike has contacted with a spike mat
 /// </summary>
 /// <param name="level">the caller of this function</param>
 public void TireFail(Level level)
 {
     Failed(true);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Starts a new game using a user defined custom level
 /// </summary>
 /// <param name="levelName">the name of the level </param>
 public void NewGame(String levelName)
 {
     level = new Level(levelName.Replace(' ', '_') + ".lvl", audioPlayer, Content);
     currentLevelName = levelName;
     NewGame();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts a new game using a predefined level
 /// </summary>
 /// <param name="levelNumber">the number of the predefiner level (1, 2 or 3)</param>
 public void NewGame(int levelNumber)
 {
     level = new Level(levelNumber, audioPlayer, Content);
     currentLevelName = "level" + levelNumber;
     NewGame();
 }
Ejemplo n.º 7
0
 /// <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);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// A callback function for Level to notify that the driver has hit his head
 /// </summary>
 /// <param name="level">the caller of this function</param>
 public void HeadFail(Level level)
 {
     Failed(false);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// A callback funtion to stop the testing of the level and return to the modifying view
 /// </summary>
 /// <param name="level">The caller of this function</param>
 public void CloseTesting(Level level)
 {
     if (!isReady)
     {
         testing = false;
         audioPlayer.StopMotor();
     }
 }