public void CheckCollision(List <Enemy> enemies, List <Laser> lasers, ExplosionManager explosionManager) { Rectangle rectangle2; Rectangle laserRectangle; // detect collisions between the player and all enemies. enemies.ForEach(e => { //create a retangle for the enemy rectangle2 = new Rectangle( (int)e.CentrePosition.X, (int)e.CentrePosition.Y, e.Width, e.Height); // now see if this enemy collide with any laser shots lasers.ForEach(lb => { // create a rectangle for this laserbeam laserRectangle = new Rectangle( (int)lb.Position.X, (int)lb.Position.Y, lb.Width, lb.Height); // test the bounds of the laer and enemy if (laserRectangle.Intersects(rectangle2)) { // play the sound of explosion. //var explosion = explosionSound.CreateInstance(); //explosion.Play(); explosionManager.AddExplosion(lb.Position); // kill off the enemy e.Health = 0; //record the kill //myGame.Stage.EnemiesKilled++; // kill off the laserbeam lb.Active = false; // record your score //myGame.Score += e.Value; } }); }); }
public GameScene(int width, int height, int playerCount, string[] playerIDs, string[] playerNames, PlayerColour[] playerColours, string localClientID, Client client) { _players = new Dictionary <string, Player>(); _playerColours = new Dictionary <string, PlayerColour>(); _remotePlayers = new List <RemotePlayer>(); Client = client; for (int i = 0; i < playerCount; i++) { Player player; if (playerIDs[i] == localClientID) { var locPlay = new LocalPlayer(); _localPlayer = locPlay; player = locPlay; } else { var remPlay = new RemotePlayer(); _remotePlayers.Add(remPlay); player = remPlay; } player.NetworkID = playerIDs[i]; _playerColours.Add(playerIDs[i], playerColours[i]); _players.Add(player.NetworkID, player); } _GUI = new GameSceneGUI(width, height, playerIDs, playerNames, playerColours); _updatePackets = new Queue <PlayerUpdatePacket>(); _enemyManager = new EnemyManager(); _laserManager = new LaserManager(); _backgroundManager = new BackgroundManager(); _explosionManager = new ExplosionManager(); }