Exemplo n.º 1
0
 public override void Draw(GameTime gameTime)
 {
     if (Game1.CurrentGameState == GameState.Play)
     {
         SpriteBatch spriteBatch = Game.Services.GetService(typeof(SpriteBatch)) as SpriteBatch;
         Wall.Draw(spriteBatch);
         Food.Draw(spriteBatch);
         Caterpillar.Draw(spriteBatch);
     }
     base.Draw(gameTime);
 }
Exemplo n.º 2
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     Services.AddService(typeof(SpriteBatch), spriteBatch);
     Font1 = Content.Load <SpriteFont>("Font/Font1");
     Food.LoadContent(this.Content);
     Caterpillar.LoadContent(this.Content);
     SoundManager.LoadContent(this.Content);
     this.MainMenuButton();
     this.GameOverMenuButton();
     if (SoundManager.IsEnabled)
     {
         MediaPlayer.Play(SoundManager.MainMenu);
     }
 }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            if (Game1.CurrentGameState == GameState.Play)
            {
                KeyboardState keyboardState = Keyboard.GetState();
                Food.Update(gameTime);
                Caterpillar.Update(gameTime, keyboardState);

                if (Caterpillar.Head.Path.Intersects(Food.Path))
                {
                    IncreaseScore(1);
                    Food.ChangePosition(Wall.ListWall);
                }

                if (Caterpillar.IsHurted(Wall.ListWall))
                {
                    Game1.CurrentGameState = GameState.GameOver;
                    Score = scored;
                    SoundManager.SoundEffectPause();
                    MediaPlayer.Play(SoundManager.GameOver);
                    if (scored > Game1.HighScore)
                    {
                        Game1.HighScore = scored;
                    }
                }
            }
            if (scored > Score)
            {
                elapsed += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (elapsed > 10)
                {
                    Score++;
                    elapsed = 0;
                }
            }
            else if (scored < Score)
            {
                Score = 0;
            }
            base.Update(gameTime);
        }
Exemplo n.º 4
0
 private static void IncreaseScore(int score)
 {
     SoundManager.Scored.Play();
     while (score > 0)
     {
         scored++;
         if (scored < 31)
         {
             if (scored % 3 == 0)
             {
                 Caterpillar.IncreaseSpeed();
             }
         }
         else
         {
             Caterpillar.MaxSpeed();
         }
         score--;
     }
     Caterpillar.AddTail();
 }
Exemplo n.º 5
0
 public static void Reset()
 {
     elapsed = 0;
     scored  = 0;
     Caterpillar.Reset(new Vector2(400, 300));
 }