public void Update(GameTime gameTime) { if (this.enemiesSpawned == this.enemyCount) { this.enemiesSpawning = false; } if (this.enemiesSpawning) { this.spawnTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (this.spawnTimer > this.spawnDelay) { this.AddEnemy(this.hp, this.speed, this.coins); } } for (int i = 0; i < this.enemies.Count; ++i) { Enemy enemy = this.enemies[i]; enemy.Update(gameTime); if (enemy.isDead) { if (enemy.Health > 0) { enemy.SetWayPoints(this.map.WayPoints); this.EnemySuccess = true; this.player.Lives -= 1; this.player.Coins -= this.player.Coins > 0 ? 1 : 0; this.enemyCount += 1; if (this.player.Lives == 0) { this.enemies.Clear(); break; } } else { this.player.Coins += enemy.Coins; this.enemies.Remove(enemy); } if (this.enemiesSpawned >= this.enemyCount) { this.enemiesSpawning = false; this.enemiesSpawned = this.enemyCount; break; } --i; } } }
private void AddEnemy(int Health, float Speed, int Coins) { Enemy enemy = this.AnimationFrameCount > 0 ? new AnimatedEnemy(this.HealthBarTexture, this.HealthBarBackground, this.enemy, this.map.WayPoints.Peek(), Health, Speed, Coins) : new Enemy(this.HealthBarTexture, this.HealthBarBackground, this.enemy, this.map.WayPoints.Peek(), Health, Speed, Coins); if (AnimationFrameCount > 0) { ((AnimatedEnemy)enemy).SetFrameInfo(this.AnimationFrameCount, this.AnimationWidth, this.AnimationHeight, this.AnimationDelay); } enemy.SetWayPoints(this.map.WayPoints); this.enemies.Add(enemy); this.spawnTimer = 0; ++this.enemiesSpawned; }