mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
Started working on *simple* axis aligned collisions
This commit is contained in:
parent
71ba1d608e
commit
4546c8e2a2
@ -131,7 +131,14 @@ boost::any EditClassSubComponent(boost::any value, string oper, boost::any other
|
|||||||
|
|
||||||
bool AxisAlignedCollision(const Sprite& a, const Sprite& b)
|
bool AxisAlignedCollision(const Sprite& a, const Sprite& b)
|
||||||
{
|
{
|
||||||
|
bool colX = false;
|
||||||
|
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)))
|
||||||
|
colX = true;
|
||||||
|
bool colY = false;
|
||||||
|
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)))
|
||||||
|
colY = true;
|
||||||
|
|
||||||
|
return colX && colY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial script processing, which loads variables and functions from builtin
|
// Initial script processing, which loads variables and functions from builtin
|
||||||
@ -235,8 +242,10 @@ boost::any CPPFunction(const string& name, const vector<boost::any>& args)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
else if (name == "CPP.Graphics.Draw")
|
else if (name == "CPP.Graphics.Draw")
|
||||||
{
|
|
||||||
any_cast<Sprite>(args[0]).Draw();
|
any_cast<Sprite>(args[0]).Draw();
|
||||||
|
else if (name == "CPP.Physics.AxisAlignedCollision")
|
||||||
|
{
|
||||||
|
return AxisAlignedCollision(any_cast<Sprite>(args[0]), any_cast<Sprite>(args[1]));
|
||||||
}
|
}
|
||||||
else if (name == "CPP.Input.GetKey")
|
else if (name == "CPP.Input.GetKey")
|
||||||
return KEYS[StringRaw(any_cast<string>(args[0]))] == 1;
|
return KEYS[StringRaw(any_cast<string>(args[0]))] == 1;
|
||||||
|
|||||||
@ -140,3 +140,9 @@ func HandleBallBounce()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Colliding(a, b)
|
||||||
|
{
|
||||||
|
bool b = CPP.Physics.AxisAlignedCollision(a, b)
|
||||||
|
return b
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user