public void Collision() { // Check for collisions with player PlayerComponent player = Game.Services.GetService <PlayerComponent>(); TRender trender = Game.Services.GetService <TRender>(); foreach (EnemyComponent enemies in trender.enemies) { if (player.Bounds.Intersects(boundingRect)) { EnemyOof.Play(); player.ResetPlayer(); Visible = false; Enabled = false; } } }
public void Collision() { // Check for collisions with player PlayerComponent player = Game.Services.GetService <PlayerComponent>(); TRender trender = Game.Services.GetService <TRender>(); switch (trender._current) { case TRender.LevelStates.LevelOne: //check if the player has all gems to pass through the portal if (player.Collectables == 5) { //check if the player intersects with the open portal if (boundingRect.Intersects(player.Bounds) && PortalOpen) { PortalWhoosh.Play(); Visible = false; Enabled = false; player.Collectables = 0; //change the level state trender._current = TRender.LevelStates.LevelTwo; trender.tileManager.ActiveLayer = trender.tileManager.GetLayer("LevelTwo"); trender.hasLevelChanged = true; //clear all the variable lists trender.Collectables.Clear(); trender.Portal.Clear(); player.ResetPlayer(); trender.enemies.Clear(); // Creates a set of impassable tiles trender.collisons.Clear(); // Important for removing colliders from screen trender.tileManager.ActiveLayer.makeImpassable(trender.impassableTiles); trender.SetupCollison(); trender.SetupComponents(); } } break; case TRender.LevelStates.LevelTwo: if (player.Collectables == 5) { if (boundingRect.Intersects(player.Bounds) && PortalOpen) { Visible = false; Enabled = false; player.Collectables = 0; trender._current = TRender.LevelStates.LevelThree; trender.tileManager.ActiveLayer = trender.tileManager.GetLayer("LevelThree"); trender.hasLevelChanged = true; trender.collisons.Clear(); trender.Collectables.Clear(); trender.Portal.Clear(); trender.enemies.Clear(); player.ResetPlayer(); trender.tileManager.ActiveLayer.makeImpassable(trender.impassableTiles); trender.SetupCollison(); trender.SetupComponents(); } } break; case TRender.LevelStates.LevelThree: if (player.Collectables == 5) { if (boundingRect.Intersects(player.Bounds) && PortalOpen) { Visible = false; Enabled = false; player.Collectables = 0; trender._current = TRender.LevelStates.LevelFour; trender.tileManager.ActiveLayer = trender.tileManager.GetLayer("LevelFour"); trender.hasLevelChanged = true; trender.collisons.Clear(); trender.Collectables.Clear(); player.ResetPlayer(); trender.Portal.Clear(); trender.tileManager.ActiveLayer.makeImpassable(trender.impassableTiles); trender.SetupCollison(); trender.SetupComponents(); } } break; case TRender.LevelStates.LevelFour: if (player.Collectables == 5) { if (boundingRect.Intersects(player.Bounds) && PortalOpen) { Visible = false; Enabled = false; player.Collectables = 0; trender._current = TRender.LevelStates.LevelOne; trender.tileManager.ActiveLayer = trender.tileManager.GetLayer("LevelOne"); trender.hasLevelChanged = true; trender.collisons.Clear(); trender.Collectables.Clear(); player.ResetPlayer(); trender.Portal.Clear(); trender.tileManager.ActiveLayer.makeImpassable(trender.impassableTiles); trender.SetupCollison(); trender.SetupComponents(); } } break; } }