Karts involved in collisions addressable by ID
This commit is contained in:
parent
31f7ea7c89
commit
8c5606be08
@ -3,5 +3,5 @@ void onCollision()
|
||||
/*
|
||||
Currently activates on Kart collisions
|
||||
*/
|
||||
displayMessage("Whoa! Road rage...");
|
||||
displayMessage("Whoa! Road rage... between Kart: " + getCollidingKart1() + " - " + getCollidingKart2());
|
||||
}
|
||||
|
@ -171,6 +171,9 @@ void Physics::update(float dt)
|
||||
p->getUserPointer(1)->getPointerKart(),
|
||||
p->getContactPointCS(1) );
|
||||
ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
int kartid1 = p->getUserPointer(0)->getPointerKart()->getWorldKartId();
|
||||
int kartid2 = p->getUserPointer(1)->getPointerKart()->getWorldKartId();
|
||||
script_engine->setCollision(kartid1,kartid2);
|
||||
script_engine->runScript("collisions");
|
||||
continue;
|
||||
} // if kart-kart collision
|
||||
|
@ -43,6 +43,9 @@ using namespace irr;
|
||||
void enableTrigger(asIScriptGeneric *gen);
|
||||
void disableTrigger(asIScriptGeneric *gen);
|
||||
|
||||
int m_collidingkartid1;
|
||||
int m_collidingkartid2;
|
||||
|
||||
ScriptEngine::ScriptEngine()
|
||||
{
|
||||
// Create the script engine
|
||||
@ -51,8 +54,8 @@ ScriptEngine::ScriptEngine()
|
||||
{
|
||||
std::cout << "Failed to create script engine." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
m_collidingkartid1 = 0;
|
||||
m_collidingkartid2 = 0;
|
||||
// Configure the script engine with all the functions,
|
||||
// and variables that the script should be able to use.
|
||||
configureEngine(m_engine);
|
||||
@ -102,7 +105,14 @@ void squashKart(asIScriptGeneric *gen)
|
||||
AbstractKart* kart = World::getWorld()->getKart(id);
|
||||
kart->setSquash(time,0.5); //0.5 * max speed is new max for squashed duration
|
||||
}
|
||||
|
||||
void getCollidingKart1(asIScriptGeneric *gen)
|
||||
{
|
||||
gen->SetReturnDWord(m_collidingkartid1);
|
||||
}
|
||||
void getCollidingKart2(asIScriptGeneric *gen)
|
||||
{
|
||||
gen->SetReturnDWord(m_collidingkartid2);
|
||||
}
|
||||
|
||||
std::string getScript(std::string scriptName)
|
||||
{
|
||||
@ -233,7 +243,11 @@ void ScriptEngine::runScript(std::string scriptName)
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ScriptEngine::setCollision(int collider1,int collider2)
|
||||
{
|
||||
m_collidingkartid1 = collider1;
|
||||
m_collidingkartid2 = collider2;
|
||||
}
|
||||
|
||||
|
||||
void ScriptEngine::configureEngine(asIScriptEngine *engine)
|
||||
@ -249,6 +263,8 @@ void ScriptEngine::configureEngine(asIScriptEngine *engine)
|
||||
r = engine->RegisterGlobalFunction("void squashKart(int id, float time)", asFUNCTION(squashKart), asCALL_GENERIC); assert(r>=0);
|
||||
r = engine->RegisterGlobalFunction("void enableTrigger(string &in)", asFUNCTION(enableTrigger), asCALL_GENERIC); assert(r>=0);
|
||||
r = engine->RegisterGlobalFunction("void disableTrigger(string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r>=0);
|
||||
r = engine->RegisterGlobalFunction("uint getCollidingKart1()", asFUNCTION(getCollidingKart1), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterGlobalFunction("uint getCollidingKart2()", asFUNCTION(getCollidingKart2), asCALL_GENERIC); assert( r >= 0 );
|
||||
|
||||
// It is possible to register the functions, properties, and types in
|
||||
// configuration groups as well. When compiling the scripts it can then
|
||||
|
@ -33,9 +33,12 @@ public:
|
||||
|
||||
void runScript(std::string scriptName);
|
||||
|
||||
void setCollision(int kartid1,int kartid2);
|
||||
|
||||
private:
|
||||
asIScriptEngine *m_engine;
|
||||
|
||||
|
||||
void configureEngine(asIScriptEngine *engine);
|
||||
int compileScript(asIScriptEngine *engine,std::string scriptName);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user