public void Update(float delta) { if (AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(Game.MousePosition, _startBackground)) { ReadyToStart = true; } }
public override void Update(float delta) { Tower s = Game.PlayArea.CurrentlySelected; if (s != null && AKS.WasJustPressed(Mouse.Button.Left)) { // check if upgrade clicked // RectangleShape r = new RectangleShape(_upgradeBackground); r.Position += _renderSprite.Position; if (Utils.PointIsInRect(Game.MousePosition, r)) { Game.TryUpgradeTower(s); } // check if sell clicked // r = new RectangleShape(_sellBackground); r.Position += _renderSprite.Position; if (Utils.PointIsInRect(Game.MousePosition, r)) { Game.RemoveTower(s); Game.Money += s.Worth; Game.PlayArea.CurrentlySelected = null; } } }
public override void Update(float delta) { int i = 0; Vector2f mousePos = Utils.Snap2Grid(Game.MousePosition); CurrentlyHovered = null; foreach (Tower tower in Allowed) { float x = i % SizeTiles.X * Game.TileSize + Game.TileSize / 2; float y = (i / SizeTiles.X) * Game.TileSize + Game.TileSize / 2; Vector2f towerPos = Position + new Vector2f(x, y); if (mousePos == towerPos) { CurrentlyHovered = tower; if (AKS.WasJustPressed(Mouse.Button.Left)) { var toAdd = tower.CloneLevel0(); Game.Towers.Add(toAdd); Game.PlayArea.CurrentlyPlacing = toAdd; } break; } i++; } }
public void Update(float delta) { if (AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(Game.MousePosition, _retryLevelBackground)) { Choice = ChoiceOption.RetryLevel; } else if (AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(Game.MousePosition, _returnToTitleBackground)) { Choice = ChoiceOption.ReturnToTitle; } }
protected void Update(float delta) { if (AKS.WasJustPressed(Keyboard.Key.M)) { Music.Volume = Music.Volume == 0 ? DefaultMusicVolume : 0; } if (TitleScreen.ReadyToStart) { if (IsGameOver) { GameOverScreen.Update(delta); if (GameOverScreen.Choice == GameOverScreen.ChoiceOption.RetryLevel) { IsGameOver = false; GameOverScreen.IsWinScreen = false; ReloadLevel(); } else if (GameOverScreen.Choice == GameOverScreen.ChoiceOption.ReturnToTitle) { IsGameOver = false; GameOverScreen.IsWinScreen = false; ReturnToTitle(); } } else { if (TextQueue.Count > 0) { if (AKS.WasJustPressed(Mouse.Button.Left)) { TextQueue.RemoveAt(0); } } else { if (AKS.WasJustPressed(Keyboard.Key.R)) { Towers.Clear(); ReloadLevel(); } else { _inventory.Update(delta); _infoDisplay.Update(delta); _playArea.Update(delta); if (IsGameOver) { GameOverScreen.Choice = GameOverScreen.ChoiceOption.None; Towers.Clear(); return; } if (_playArea.IsFinished) { AdvanceLevel(); } if ((AKS.WasJustPressed(Mouse.Button.Left) && Utils.PointIsInRect(MousePosition, _startBackground)) || AKS.WasJustPressed(Keyboard.Key.P)) { if (_playArea.IsStarted) { _playArea.IsPaused = !_playArea.IsPaused; } else { _playArea.Start(); } } } } } } else { TitleScreen.Update(delta); } }
public override void Update(float delta) { bool didPlace = false; var snappedPos = Utils.Snap2Grid(Game.MousePosition); if (CurrentlyPlacing != null) { if (AKS.WasJustReleased(Mouse.Button.Left)) { if (CanPlaceTowerAt(snappedPos)) { CurrentlyPlacing.Position = snappedPos; Game.Money -= CurrentlyPlacing.Cost; CurrentlyPlacing.IsPlaced = true; CurrentlySelected = CurrentlyPlacing; CurrentlyPlacing = null; didPlace = true; } } else if (AKS.WasJustReleased(Mouse.Button.Right)) { Game.RemoveTower(CurrentlyPlacing); CurrentlyPlacing = null; } } bool newSelected = false; CurrentlyHovered = null; foreach (var tower in Game.PlacedTowers) { if (tower.Position == snappedPos) { if (AKS.WasJustPressed(Mouse.Button.Left)) { CurrentlySelected = tower; newSelected = true; } else { CurrentlyHovered = tower; } } } if (AKS.WasJustPressed(Mouse.Button.Left) && !newSelected) { Vector2i gridPos = Utils.Vf2Grid(Game.MousePositionf); if (gridPos.X < _widthTiles && gridPos.Y < _heightTiles) { CurrentlySelected = null; } } var upgradeCandidate = CurrentlyHovered ?? CurrentlySelected; if (upgradeCandidate != null && AKS.WasJustPressed(Keyboard.Key.U)) { Game.TryUpgradeTower(upgradeCandidate); } if (!IsStarted || IsPaused) { return; } for (int frame = 0; frame < (AKS.IsKeyDown(Keyboard.Key.LControl) ? 10 : 1); frame++) { foreach (var tower in Game.PlacedTowers) { tower.Update(delta); } foreach (var wave in Waves) { wave.Update(delta); Hp -= wave.FrameDamage; if (Hp <= 0) { Game.IsGameOver = true; return; } if (wave.IsFinishedSpawning && !_finishedWaves.Contains(wave)) { _finishedWaves.Add(wave); if (_finishedWaves.Count == _level.NumWaves) { _softFinished = true; } else { _waveCooldownTimer = 0; _waveCooldownGoal = wave.Cooldown; _waveToSpawn = _level.SpawnWave(); } } } if (_waveToSpawn != null) { _waveCooldownTimer += delta; if (_waveCooldownTimer >= _waveCooldownGoal) { Waves.Add(_waveToSpawn); _waveToSpawn = null; } } foreach (var bullet in Bullets) { if (bullet.ShouldBeCulled) { _bulletsToRemove.Add(bullet); } else { bullet.Update(delta); if (bullet.ShouldBeCulled) { _bulletsToRemove.Add(bullet); } if (bullet.IsCollidable) { foreach (var wave in Waves) { if (!wave.TryBullet(bullet)) { if (bullet.ShouldBeCulled) { _bulletsToRemove.Add(bullet); } continue; } } } } } foreach (var bullet in _bulletsToRemove) { Bullets.Remove(bullet); } _bulletsToRemove.Clear(); foreach (var wave in Waves) { wave.CullDeadCreeps(); } if (_softFinished) { if (!_awaitingCooldown) { int totalCreeps = 0; foreach (CreepWave wave in Waves) { totalCreeps += wave.Creeps.Count; } if (totalCreeps == 0) { _awaitingCooldown = true; } } if (_awaitingCooldown) { _cooldownTimer += delta; if (_cooldownTimer >= _cooldownGoal) { IsFinished = true; break; } } } } }