/// <summary> /// Detects if the objects have collided with each other and /// updates their status accordingly. Returns true if a /// collision was detected, false otherwise. /// </summary> /// <param name="player"></param> public bool Detect(Player player) { bool detection; detection = PlayerWallDetection(player); // detection = value of detection. if true, detection = true // if false check PlayerWallDetection and set detection to its value // detection = detection ? detection : PlayerWallDetection(player); return detection; }
private bool PlayerWallDetection(Player player) { // Dimensions of the border are (20, 20), (1900, 20) // (20, 980), and (1900, 980) Rectangle playerOutline = new Rectangle((int)player.Position.X, (int)player.Position.Y, player.Width, player.Height); // Checks for right wall collision if (player.Position.X > 1900 - (player.Width / 2)) { player.active = false; return true; } // Checks for left wall collision if (player.Position.X < 20 + (player.Width / 2)) { player.active = false; return true; } // Checks for top wall collision if (player.Position.Y < 20 + (player.Height / 2)) { player.active = false; return true; } // Checks for bottom wall collision if (player.Position.Y > 980 - (player.Height / 2)) { player.active = false; return true; } return false; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here settings = new Constants(); // Initialize player playerTextures = new List<Texture2D>(); player = new Player(); // Initialize walls walls = new List<Wall>(); currentWall = new Wall(); // Initialize collision detection collisions = new Collision(); base.Initialize(); }