/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { TimeOnRound += gameTime.ElapsedGameTime.Milliseconds; if (RemainingParticipants > 0) { NextWaveTimer += gameTime.ElapsedGameTime.Milliseconds; if ((NextWaveTimer / 1000f) >= Current.WaveInterval) { Escapee e; foreach (Vector2 spawn in spawnLocations) { e = new Escapee { Position = spawn, Alive = true, Free = false, Tint = Escapee.Tints[rand.Next(0, 3)] }; escapeeManager.AddEscapee(e); currentEscapees.Add(e); RemainingParticipants--; if (RemainingParticipants == 0) break; } NextWaveTimer = 0; } } currentEscapees.RemoveAll(new Predicate<Escapee>((x) => !x.InPlay)); if (ParticipantsInPlay == 0 && RemainingParticipants == 0 && Next != null) { Current = Next; next = null; NextWaveTimer = 0; RemainingParticipants = Current.ParticipantCount; if (RoundChanged != null) RoundChanged(this, null); } base.Update(gameTime); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); Services.AddService(typeof(SpriteBatch), spriteBatch); score = new ScoreData(); Services.AddService(typeof(ScoreData), score); camera = new GameCamera { X = 0, Y = 0, Width = Window.ClientBounds.Width, Height = Window.ClientBounds.Height }; Services.AddService(typeof(GameCamera), camera); collisionManager = new CollisionManager(this,24,24); Components.Add(collisionManager); tmapRenderer = new TilemapRenderer(this); Components.Add(tmapRenderer); map = Tilemap.Load("testmap.tmx"); tmapRenderer.Map = map; playerManager = new PlayerManager(this); Components.Add(playerManager); player = new Player(); playerManager.Player = player; escapeeManager = new EscapeeManager(this); Components.Add(escapeeManager); sfx = new Dictionary<string, SoundEffect>(); Services.AddService(typeof(Dictionary<string, SoundEffect>), sfx); round = new Round { ParticipantCount = 9, WaveInterval = 10 }; uiManager = new UIManager(this); Components.Add(uiManager); base.Initialize(); }