// Retrieves a new enemy from the pool. If the pool is empty, it creates one from scratch. public static Enemy1 getNewEnemy(IArtificialIntelligence ai) { Enemy1 enemy; // This must be called with an AI for the critter if (ai == null) return null; // if there are any enemies in the pool, use one of them if (zs_pool.Count > 0) { enemy = zs_pool[zs_pool.Count - 1]; enemy.setAI(ai); zs_pool.RemoveAt(zs_pool.Count - 1); } else enemy = new Enemy1(zs_image, ai); // pool was empty, so create a new enemy // reset the enemy before use enemy.setIsAlive(true); return enemy; }
private void AddAnEnemy(ref Enemy1 enemy) { this.z_enemyShips.Add(enemy); this.z_enemyShips[0].setIsAlive(true); }