1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-07 05:13:38 +02: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:
Misa 2020-07-09 23:20:03 -07:00 committed by Ethan Lee
parent ca9e4c8f6e
commit 2506127a17
3 changed files with 23 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -105,7 +105,7 @@ public:
void settemprect(int t);
int checktrigger();
int checktrigger(int* block_idx);
int checkactivity();

View File

@ -2062,16 +2062,18 @@ void mapclass::twoframedelayfix()
// and when the script gets loaded script.run() has already ran for that frame, too.
// A bit kludge-y, but it's the least we can do without changing the frame ordering.
int block_idx = -1;
if (game.glitchrunnermode
|| game.deathseq != -1
// obj.checktrigger() sets obj.activetrigger
|| obj.checktrigger() <= -1
// obj.checktrigger() sets obj.activetrigger and block_idx
|| obj.checktrigger(&block_idx) <= -1
|| block_idx <= -1
|| obj.activetrigger < 300)
{
return;
}
game.newscript = "custom_" + game.customscript[obj.activetrigger - 300];
game.newscript = obj.blocks[block_idx].script;
obj.removetrigger(obj.activetrigger);
game.state = 0;
game.statedelay = 0;