public override void LoadAssets() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(ScreenManager.GraphicsDeviceMgr.GraphicsDevice); //Add assets to respective dictionaries ScreenManager.AddTexture(@"Objects/ship"); ScreenManager.AddTexture(@"Backgrounds/GameScreenBackground"); ScreenManager.AddTexture(@"Objects/asteroid_pixelated"); ScreenManager.AddTexture(@"Objects/explosion"); ScreenManager.AddTexture(@"Objects/beamParticle"); ScreenManager.AddTexture(@"Objects/exhaust"); //Load Sound Effects shootSound = ScreenManager.ContentMgr.Load<SoundEffect>(@"Sounds/Laser_Shoot"); explosion = ScreenManager.ContentMgr.Load<SoundEffect>(@"Sounds/Explosion"); exhaustSound = ScreenManager.ContentMgr.Load<SoundEffect>(@"Sounds/Exhaust"); projectileSprite = ScreenManager.Textures["Objects/beamParticle"]; exhaustSprite = ScreenManager.Textures["Objects/exhaust"]; backgroundRectangle = new Rectangle(0, 0, GameConstants.VIEWPORT_WIDTH, GameConstants.VIEWPORT_HEIGHT); //Add initial game objects ship = new Ship(ScreenManager.ContentMgr, @"Objects/ship", GameConstants.VIEWPORT_WIDTH / 2, GameConstants.VIEWPORT_HEIGHT / 2, shootSound); ship.Rotation = 0; for (int i = 0; i < GameConstants.MAX_ASTEROIDS; i++) { CreateAsteroid(); } exhaust = new Exhaust(MainGameScreen.GetExhaustSprite(), ship.Position, ship.Velocity, exhaustSound); //Background music loop SoundEffect backgroundLoop = ScreenManager.ContentMgr.Load<SoundEffect>(@"Sounds/BackgroundMusic"); SoundEffectInstance bgSound = backgroundLoop.CreateInstance(); bgSound.IsLooped = true; bgSound.Play(); }
/// <summary> /// Checks collision between two rotated rectangles /// </summary> /// <param name="drawRectangle1">First rectangle</param> /// <param name="drawRectangle2">Second Rectangle</param> /// <returns>True or False</returns> public static bool CheckRotatedCollision(Ship ship, Asteroid asteroid) { float distance = 0.0f; Vector2 position1 = asteroid.Position; Vector2 position2 = ship.Position; float Cathetus1 = Math.Abs(position1.X - position2.X); float Cathetus2 = Math.Abs(position1.Y - position2.Y); Cathetus1 *= Cathetus1; Cathetus2 *= Cathetus2; distance = (float)Math.Sqrt(Cathetus1 + Cathetus2); if ((int)distance < ship.CollisionRectangle.Width) { return true; } return false; }