Changed collision

This commit is contained in:
sam-astro 2022-01-14 07:35:02 -05:00 committed by GitHub
parent 4546c8e2a2
commit 735a20c224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,17 +129,17 @@ boost::any EditClassSubComponent(boost::any value, string oper, boost::any other
return nullType; return nullType;
} }
bool AxisAlignedCollision(const Sprite& a, const Sprite& b) bool AxisAlignedCollision(const Sprite& a, const Sprite& b) // AABB - AABB collision
{ {
bool colX = false; // collision x-axis?
if ((a.position.x + (a.scale.x / 2) <= b.position.x + (b.scale.x / 2)) && (a.position.x - (a.scale.x / 2) >= b.position.x - (b.scale.x / 2))) bool collisionX = a.position.x + a.scale.x >= b.position.x &&
colX = true; b.position.x + b.scale.x >= a.position.x;
bool colY = false; // collision y-axis?
if ((a.position.y + (a.scale.y / 2) <= b.position.y + (b.scale.y / 2)) && (a.position.y - (a.scale.y / 2) >= b.position.y - (b.scale.y / 2))) bool collisionY = a.position.y + a.scale.y >= b.position.y &&
colY = true; b.position.y + b.scale.y >= b.position.y;
// collision only if on both axes
return colX && colY; return collisionX && collisionY;
} }
// Initial script processing, which loads variables and functions from builtin // Initial script processing, which loads variables and functions from builtin
int GetBuiltins(const string& s) int GetBuiltins(const string& s)