// Load graphics content for the game public override void Activate() { if (_content == null) { _content = new ContentManager(ScreenManager.Game.Services, "Content"); } _spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice); _timerGoing = true; slime = new SlimeSprite(); System.Random rand = new System.Random(); foods = new FoodSprite[] { new FoodSprite(new Vector2((float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Width, (float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Height)), new FoodSprite(new Vector2((float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Width, (float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Height)), new FoodSprite(new Vector2((float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Width, (float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Height)), new FoodSprite(new Vector2((float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Width, (float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Height)), new FoodSprite(new Vector2((float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Width, (float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Height)), new FoodSprite(new Vector2((float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Width, (float)rand.NextDouble() * ScreenManager.GraphicsDevice.Viewport.Height)), }; // TODO: use this.Content to load your game content here foreach (var food in foods) { food.LoadContent(_content); } slime.LoadContent(_content); spriteFont = _content.Load <SpriteFont>("Impact"); backgroundMusic = _content.Load <Song>("newer-wave-by-kevin-macleod-from-filmmusic-io"); MediaPlayer.IsRepeating = true; MediaPlayer.Play(backgroundMusic); MediaPlayer.Volume = .5f; eatSound = _content.Load <SoundEffect>("Eating"); }
// Load graphics content for the game public override void Activate() { if (_content == null) { _content = new ContentManager(ScreenManager.Game.Services, "Content"); } _spriteBatch = ScreenManager.SpriteBatch; if (coinsList.Count == 0) { CoinSprite temp = new CoinSprite(_coinPosition); coinsList.Add(temp); } coinsCount = 0; slimeSprite = new SlimeSprite(); // Loads content for gameplay elements foreach (var coin in coinsList) { coin.LoadContent(_content); } slimeSprite.LoadContent(_content); coinPickup = _content.Load <SoundEffect>(coinSoundName); gameMusic = _content.Load <Song>(gameMusicName); MediaPlayer.IsRepeating = true; float roundedMusicVolume = (float)(MediaPlayer.Volume / 4.0); MediaPlayer.Volume = roundedMusicVolume; MediaPlayer.Play(gameMusic); _gameFont = _content.Load <SpriteFont>("gamefont"); // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. //ScreenManager.Game.ResetElapsedTime(); }