private void processEnemies(GameTime gameTime) { for (int i = enemyList.Count - 1; i >= 0; i--) { if (enemyList[i].health <= 0) { fastMessage enemyDeathFastMessage = new fastMessage(); enemyDeathFastMessage.Message = "boom!"; enemyDeathFastMessage.Color = Color.OrangeRed; enemyDeathFastMessage.Position = enemyList[i].position - (enemyList[i].origin / 2); enemyDeathFastMessage.Duration = TimeSpan.FromSeconds(1); enemyDeathFastMessage.GameTime = gameTime.TotalGameTime; fastMessages.Add(enemyDeathFastMessage); foreach (Special special in player.Specials) { if (random.Next(0, 100) <= special.dropRate) { specialDropsList.Add(new SpecialDrop(player.Specials.IndexOf(special), special.texture, gameTime, enemyList[i].position)); break; } } enemyList.RemoveAt(i); player.killCount++; return; } if ((gameTime.TotalGameTime - enemyList[i].lastAction) > TimeSpan.FromSeconds(1.5f)) { Vector2 newProjDirection = new Vector2(player.Position.X + random.Next(-20, 20), player.Position.Y + random.Next(-20, 20)); enemyProjectileList.Add(new Projectile(enemyList[i].position, newProjDirection, textureCache[3], false)); enemyList[i].lastAction = gameTime.TotalGameTime; } Vector2 direction = (player.Position - enemyList[i].position); direction.Normalize(); enemyList[i].position += direction; enemyList[i].rotation = (float)(Math.Atan2(direction.Y, direction.X)); } }
private void processDamage(GameTime gameTime) { if (!debugMode) { for (int i = enemyProjectileList.Count - 1; i >= 0; i--) { if (!enemyProjectileList[i].hasHit) { Vector2 diff = player.Position - enemyProjectileList[i].position; if (diff.Length() < 14) { enemyProjectileList[i].hasHit = true; player.Health -= 10; fastMessage playerHitFastMessage = new fastMessage(); playerHitFastMessage.Message = "-10"; playerHitFastMessage.Color = Color.Red; playerHitFastMessage.Position = player.Position; playerHitFastMessage.Duration = TimeSpan.FromSeconds(0.33); playerHitFastMessage.GameTime = gameTime.TotalGameTime; fastMessages.Add(playerHitFastMessage); } } else enemyProjectileList.RemoveAt(i); } } for (int i = playerProjectileList.Count - 1; i >= 0; i--) { if (!playerProjectileList[i].hasHit) { foreach (BasicEnemy enemy in enemyList) { Vector2 diff = enemy.position - playerProjectileList[i].position; if (diff.Length() < 14) { playerProjectileList[i].hasHit = true; enemy.health -= 10; } } } else playerProjectileList.RemoveAt(i); } }