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); }
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); } }
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); }
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(); }
public static void Reset() { elapsed = 0; scored = 0; Caterpillar.Reset(new Vector2(400, 300)); }