//Checks for collision between two animations, either by hitbox or pixel alpha values (EXAMPLE OF POLYMOPHISM) public static bool CollidesWith(Animation objectA, Animation objectB, bool calcPerPixel) { //Calculates current smallest rectangle around animation, based on animations transformation matrix Rectangle objectARectangle = CalculateBoundingRectangle( new Rectangle(0, 0, objectA.frameWidth, objectA.frameHeight), objectA.transformation); //Calculates current smallest rectangle around animation, based on animations transformation matrix Rectangle objectBRectangle = CalculateBoundingRectangle( new Rectangle(0, 0, objectB.frameWidth, objectB.frameHeight), objectB.transformation); //Checks hitbox collision of animations if (objectBRectangle.Intersects(objectARectangle)) { //Checks if any animation pixels overlap, based on alpha values if (IntersectPixels(objectA.transformation, objectA.frameWidth, objectA.frameHeight, objectA.ColorData, objectB.transformation, objectB.frameWidth, objectB.frameHeight, objectB.ColorData)) { return true; } } return false; }
//Creates explosion at correct position and size public void AddExplosion(Vector2 position, float scale) { //Creates explosion animation Animation explosion = new Animation(explosionTexture, 10, 0.25f, position, 0f, Color.White); explosion.scale = scale; //Disables explosion after one play explosion.runOnce = true; explosions.Add(explosion); }
//Checks for collision between two animations, by pixel alpha values (EXAMPLE OF POLYMOPHISM) public static bool CollidesWith(Animation objectA, Animation objectB) { return CollidesWith(objectA, objectB, true); }