コード例 #1
0
 // Internal method for checking rectangle to rectangle collisions.
 private static bool collisionCheckRectsDirected(Hitbox a, Hitbox b)
 {
     Vector2 center = new Vector2(b.hitbox.x, b.hitbox.y);
     b.rotate(-2*b.angle);
     Vector2 rotated_b1 = alignPoint(new Vector2(b.hitbox.x + b.halfSize.x, b.hitbox.y + b.halfSize.y), b);
     Vector2 rotated_b2 = alignPoint(new Vector2(b.hitbox.x - b.halfSize.x, b.hitbox.y + b.halfSize.y), b);
     b.rotate(-2*b.angle);
     Vector2 rotated_b3 = center - rotated_b1;
     rotated_b1 += center;
     Vector2 rotated_b4 = center - rotated_b2;
     rotated_b2 += center;
     return pointInRect(a, rotated_b1) || pointInRect(a, rotated_b2) || pointInRect(a, rotated_b3) ||
             pointInRect(a, rotated_b4);
 }