public AdjacentAgentSensor(Tower owner, float range) : base(owner, range) { AgentsInRange = new Dictionary <Unit, Tuple <float, float> >(); }
public override void Update(GameTime gameTime) { previousKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); if (currentKeyboardState.IsKeyDown(Keys.M)) { Game1.Instance.UpdateGameState(GameState.MainMenu); Console.WriteLine("Switch to menu screen"); return; } if (currentKeyboardState.IsKeyDown(Keys.W) && previousKeyboardState.IsKeyUp(Keys.W)) { wallPlacementMode = !wallPlacementMode; towerPlacementMode = false; Console.WriteLine("Placement Mode: " + wallPlacementMode); } if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) { SpawnNewWave(gameTime); } if (currentKeyboardState.IsKeyDown(Keys.T) && previousKeyboardState.IsKeyUp(Keys.T)) { towerPlacementMode = !towerPlacementMode; wallPlacementMode = false; } if (playerLives <= 0) { Game1.Instance.UpdateGameState(GameState.EndOfGame); return; } if (mouseState.LeftButton == ButtonState.Pressed) { if (wallPlacementMode && playerResources >= Game1.Instance.GameSettings.WallCost) { Tile t = mapGrid.GetTileAtPosition(mouseState.Position); Wall w = new Wall(t.Position); w.AgentTexture = wallTexture; walls.Add(w); mapGrid.Update(); path = mapGrid.FindPath(startTile.Position.ToPoint(), endTile.Position.ToPoint()); if (path == null) { walls.Clear(); towers.Clear(); badPlayer = true; mapGrid.Reset(); path = mapGrid.FindPath(startTile.Position.ToPoint(), endTile.Position.ToPoint()); } List <int> indicesToRemove = new List <int> (); for (int i = 0; i < Units.Count; i++) { Units [i].ChangePath(path); if (Units [i].HitPoints == 0) { indicesToRemove.Add(i); } } for (int i = Units.Count; i >= 0; i--) { if (indicesToRemove.Contains(i)) { Units.RemoveAt(i); } } playerResources -= Game1.Instance.GameSettings.WallCost; } if (towerPlacementMode && playerResources >= Game1.Instance.GameSettings.TowerCost) { bool towerPresent = false; foreach (Wall w in walls) { if (w.BoundingBox.Contains(mouseState.Position)) { foreach (Tower t in towers) { if (t.BoundingBox.Contains(mouseState.Position)) { towerPresent = true; } } if (!towerPresent) { Tower t = new Tower(w.Center, 10, 100); t.AgentTexture = towerTexture; towers.Add(t); playerResources -= Game1.Instance.GameSettings.TowerCost; break; } } } } wallPlacementMode = false; towerPlacementMode = false; } for (int i = towers.Count - 1; i >= 0; i--) { if (towers [i].ShotsLeft <= 0) { towers.RemoveAt(i); } } toDelete.Clear(); for (int i = 0; i < units.Count; i++) { units[i].Update(); if (endTile.RealBoundary.Contains(units[i].Position + units[i].Center)) { playerLives--; toDelete.Add(i); } } foreach (int i in toDelete) { units.RemoveAt(i); } foreach (Tower t in towers) { t.Update(gameTime); } if (newWaveStarted == true) { SpawnNewWave(gameTime); } if (units.Count <= 0 && newWaveStarted == false) { waveTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; while (waveTimer >= Game1.Instance.GameSettings.WaveDelay) { currentWave++; if (currentWave > 1) { currentNumUnits += Game1.Instance.GameSettings.UnitsPerWave; currentUnitHP = (int)(currentUnitHP * Game1.Instance.GameSettings.UnitWaveHPMult); playerResources += Game1.Instance.GameSettings.WaveReward; } newWaveStarted = true; waveTimer = 0; } } }