mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-31 02:14:09 +03:00
Directly execute scripts if script boxes have a non-empty script field
Instead of using gamestates, just directly use the 'script' attribute of a script box if it is non-empty. This is accomplished by having to return the index of the block that the player collides with, so callers can inspect the 'script' attribute of the block themselves, and do their logic accordingly.
This commit is contained in:
@@ -3876,9 +3876,11 @@ void entityclass::settemprect( int t )
|
||||
rectset(tempx, tempy, tempw, temph);
|
||||
}
|
||||
|
||||
int entityclass::checktrigger()
|
||||
int entityclass::checktrigger(int* block_idx)
|
||||
{
|
||||
//Returns an int player entity (rule 0) collides with a trigger
|
||||
//Also returns the index of the block
|
||||
*block_idx = -1;
|
||||
for(size_t i=0; i < entities.size(); i++)
|
||||
{
|
||||
if(entities[i].rule==0)
|
||||
@@ -3894,6 +3896,7 @@ int entityclass::checktrigger()
|
||||
if (blocks[j].type == TRIGGER && help.intersects(blocks[j].rect, temprect))
|
||||
{
|
||||
activetrigger = blocks[j].trigger;
|
||||
*block_idx = j;
|
||||
return blocks[j].trigger;
|
||||
}
|
||||
}
|
||||
@@ -4816,9 +4819,20 @@ void entityclass::entitycollisioncheck()
|
||||
|
||||
// WARNING: If updating this code, don't forget to update Map.cpp mapclass::twoframedelayfix()
|
||||
activetrigger = -1;
|
||||
if (checktrigger() > -1)
|
||||
int block_idx = -1;
|
||||
if (checktrigger(&block_idx) > -1 && block_idx > -1)
|
||||
{
|
||||
game.state = activetrigger;
|
||||
if (blocks[block_idx].script != "")
|
||||
{
|
||||
game.startscript = true;
|
||||
game.newscript = blocks[block_idx].script;
|
||||
removetrigger(activetrigger);
|
||||
game.state = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
game.state = activetrigger;
|
||||
}
|
||||
game.statedelay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user