private void CheckForCollision() { var listOfEnemies = EnemySpawner.GetListOfEnemies(); var listOfPlayers = PlayerSprite.GetPlayerSprites(); var player = listOfPlayers.First <PlayerSprite>(); foreach (var enemyPicture in listOfEnemies) { if (enemyPicture.Bounds.IntersectsWith(player.Bounds) && enemyPicture.Visible) { enemyPicture.Dispose(); Player.Health = Player.Health - 1; } } }
public GameWindow() { InitializeComponent(); var enemy = new Enemy(this); var player = new Player(); var gold = new Gold(this); var goldSpawner = new GoldSpawner(this, gold); this.MaximumSize = new Size(900, 900); masterTimer.Interval = 1; masterTimer.Enabled = true; var playerSprite = new PlayerSprite(); Controls.Add(playerSprite); var PlayerController = new PlayerContoller(this, playerSprite); var enemyPicture = new EnemyPicture(this); var enemySpawner = new EnemySpawner(this, enemyPicture); var enemyController = new EnemyController(this); masterTimer.Tick += (sender, e) => SetRandomNumberEveryTick(); masterTimer.Tick += (sender, e) => CheckIfGameShouldRun(); }