Started working on *simple* axis aligned collisions

This commit is contained in:
sam-astro 2022-01-13 22:19:11 -05:00
parent 71ba1d608e
commit 4546c8e2a2
2 changed files with 18 additions and 3 deletions

View File

@ -18,7 +18,7 @@
using namespace std; using namespace std;
using namespace boost; using namespace boost;
vector<string> types = { "int", "float", "string", "bool", "void", "null", "Sprite", "Vec2"}; vector<string> types = { "int", "float", "string", "bool", "void", "null", "Sprite", "Vec2" };
unordered_map<string, vector<vector<string>>> builtinFunctionValues; unordered_map<string, vector<vector<string>>> builtinFunctionValues;
unordered_map<string, boost::any> builtinVarVals; unordered_map<string, boost::any> builtinVarVals;
@ -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;

View File

@ -140,3 +140,9 @@ func HandleBallBounce()
} }
} }
} }
func Colliding(a, b)
{
bool b = CPP.Physics.AxisAlignedCollision(a, b)
return b
}