public void SpawnEnemy(int maxlevel) { PauseRendering = true; int r = Randomiser.Next(1, maxlevel+2); Enemy enemy; switch (r) { case 1: enemy = new Enemy(GameTypes.ENEMY_UNI);break; case 2: enemy = new Enemy(GameTypes.ENEMY_BIKE);break; case 3: enemy = new Enemy(GameTypes.ENEMY_TRIKE);break; case 4: enemy = new Enemy(GameTypes.ENEMY_QUAD);break; default: enemy = new Enemy(GameTypes.ENEMY_UNI); break; } LifeTimer.Stop(); enemy.BirthTime = (float)LifeTimer.Elapsed; GameEngine.Instance.Enemies.Add(enemy); // make sure his path is ok bool pathproven = false; bool pointclear = false; Stack<PathNode> testpath = new Stack<PathNode>(); Point start = Point.Empty; while (!pathproven) { start = new Point(Randomiser.Next(0, GameTypes.MAP_WIDTH), Randomiser.Next(0, GameTypes.MAP_HEIGHT)); bool mightbeclear = true; foreach(Enemy inner in Enemies) { if(enemy != inner) { if (inner.LastPoint == start || inner.NextPoint == start) { mightbeclear = false; break; } } } if(mightbeclear) { if (PathFinding.Instance.GetNode(start).Walkable) { PathFinding.Instance.GetPath(testpath, start, GameEngine.Instance.ThePlayer.CurrentPoint); pathproven = (testpath != null && testpath.Count > 2); } } } enemy.BeamTo(start); PauseRendering = false; }