private void GameLogic(Graphics g) { if (totalGhosts < maxGhosts) { //respawn Ghost ghost = new Ghost(backLayer.TileObject[spawningPlace.X, spawningPlace.Y].Sprite.Location.X, backLayer.TileObject[spawningPlace.X, spawningPlace.Y].Sprite.Location.Y); ghost.TileLocation = new Point(spawningPlace.X, spawningPlace.Y); ghost.Speed = ghostSpeed; //add ghosts to game objects GameObjects.Add(ghost); totalGhosts++; } for (int i = 0; i < GameObjects.Count; i++) { //collision if (pacMan.IsCollidingWith(GameObjects[i])) { //with ball if (GameObjects[i].GetType() == typeof(Ball)) { //remove ball Ball ball = (Ball)GameObjects[i]; ball.UnDraw(g); GameObjects.Remove(ball); foodLayer.Remove(ball.TileLocation.X, ball.TileLocation.Y); if (ball.Type == Ball.BallType.Power) { pacMan.HasPower = true; } totalBalls--; i--; //increment score totalScore += scoreIncrementRegular; continue; }//if //with ghost if (GameObjects[i].GetType() == typeof(Ghost)) { if (pacMan.HasPower == true) { //remove ghost Ghost ghost = (Ghost)GameObjects[i]; ghost.UnDraw(g); GameObjects.Remove(ghost); totalGhosts--; i--; //increment score totalScore += scoreIncrementGhost; continue; } else { //game over this.isRunning = false; this.isGameOver = true; this.isGameWon = false; } //if } //if } //if } //for if (totalBalls == 0) { this.isRunning = false; this.isGameOver = true; this.isGameWon = true; } }