1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00

Merge towerlogic() into gamelogic()

This doesn't change anything functionality-wise, but it does remove a
lot of duplicate code, which makes it easier to work on.
This commit is contained in:
Misa 2020-04-24 21:19:41 -07:00 committed by Ethan Lee
parent 841bfb7eae
commit c040ceda29
3 changed files with 296 additions and 399 deletions

View file

@ -115,12 +115,57 @@ void gamecompletelogic2()
} }
void towerlogic() void gamelogic()
{
//Misc
if (map.towermode)
{ {
//Logic for the tower level
map.updatetowerglow(); map.updatetowerglow();
}
help.updateglow(); help.updateglow();
if (game.alarmon)
{
game.alarmdelay--;
if (game.alarmdelay <= 0)
{
music.playef(19);
game.alarmdelay = 20;
}
}
if (obj.nearelephant)
{
obj.upset++;
if (obj.upset == 300)
{
obj.upsetmode = true;
//change player to sad
int i = obj.getplayer();
obj.entities[i].tile = 144;
music.playef(2);
}
if (obj.upset > 301) obj.upset = 301;
}
else if (obj.upsetmode)
{
obj.upset--;
if (obj.upset <= 0)
{
obj.upset = 0;
obj.upsetmode = false;
//change player to happy
int i = obj.getplayer();
obj.entities[i].tile = 0;
}
}
else
{
obj.upset = 0;
}
if (map.towermode)
{
if(!game.completestop) if(!game.completestop)
{ {
if (map.cameramode == 0) if (map.cameramode == 0)
@ -250,311 +295,21 @@ void towerlogic()
} }
} }
} }
}
else
{
game.lifesequence();
}
if (game.deathseq != -1) if (game.deathseq != -1)
{
if (map.towermode)
{ {
map.colsuperstate = 1; map.colsuperstate = 1;
map.cameramode = 2; map.cameramode = 2;
game.deathsequence();
game.deathseq--;
if (game.deathseq <= 0)
{
if (game.nodeathmode)
{
game.deathseq = 1;
game.gethardestroom();
//start depressing sequence here...
if (game.gameoverdelay <= -10 && graphics.fademode==0) graphics.fademode = 2;
if (graphics.fademode == 1) script.resetgametomenu();
}
else
{
if (game.currentroomdeaths > game.hardestroomdeaths)
{
game.hardestroomdeaths = game.currentroomdeaths;
game.hardestroom = map.roomname;
} }
game.gravitycontrol = game.savegc;
graphics.textboxremove();
map.resetplayer();
}
}
}
else
{
//State machine for game logic
game.updatestate();
//Time trial stuff
if (game.intimetrial)
{
if (game.timetrialcountdown > 0)
{
game.hascontrol = true;
game.timetrialcountdown--;
if (game.timetrialcountdown > 30)
{
game.hascontrol = false;
}
if(game.timetrialcountdown == 120) music.playef(21);
if(game.timetrialcountdown == 90) music.playef(21);
if(game.timetrialcountdown == 60) music.playef(21);
if (game.timetrialcountdown == 30)
{
switch(game.timetriallevel)
{
case 0:
music.play(1);
break;
case 1:
music.play(3);
break;
case 2:
music.play(2);
break;
case 3:
music.play(1);
break;
case 4:
music.play(12);
break;
case 5:
music.play(15);
break;
}
music.playef(22);
}
}
//Have we lost the par?
if (!game.timetrialparlost)
{
if ((game.minutes * 60) + game.seconds > game.timetrialpar)
{
game.timetrialparlost = true;
int i = obj.getplayer();
if (i > -1)
{
obj.entities[i].tile = 144;
}
music.playef(2);
}
}
}
//Update entities
if(!game.completestop)
{
for (int i = obj.entities.size() - 1; i >= 0; i--)
{
obj.updateentities(i); // Behavioral logic
obj.updateentitylogic(i); // Basic Physics
obj.entitymapcollision(i); // Collisions with walls
}
obj.entitycollisioncheck(); // Check ent v ent collisions, update states
//special for tower: is the player touching any spike blocks?
int player = obj.getplayer();
if(obj.checktowerspikes(player) && graphics.fademode==0)
{
game.deathseq = 30;
}
//Right so! Screenwraping for tower:
if (map.minitowermode)
{
if (map.scrolldir == 1)
{
//This is minitower 1!
player = obj.getplayer();
if (game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
map.gotoroom(48, 52);
}
if (game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
obj.entities[player].yp -= (71*8);
map.gotoroom(game.roomx + 1, game.roomy+1);
}
}
else
{
//This is minitower 2!
player = obj.getplayer();
if (game.door_left > -2 && obj.entities[player].xp < -14)
{
if (obj.entities[player].yp > 300)
{
obj.entities[player].xp += 320;
obj.entities[player].yp -= (71 * 8);
map.gotoroom(50, 54);
}
else
{
obj.entities[player].xp += 320;
map.gotoroom(50, 53);
}
}
if (game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(52, 53);
}
}
}
else
{
//Always wrap except for the very top and very bottom of the tower
if(map.ypos>=500 && map.ypos <=5000)
{
for (size_t i = 0; i < obj.entities.size(); i++)
{
if (obj.entities[i].xp <= -10)
{
obj.entities[i].xp += 320;
}
else
{
if (obj.entities[i].xp > 310)
{
obj.entities[i].xp -= 320;
}
}
}
}
else
{
//Do not wrap! Instead, go to the correct room
player = obj.getplayer();
if (game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
obj.entities[player].yp -= (671 * 8);
map.gotoroom(108, 109);
}
if (game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(110, 104);
}
}
}
if(game.lifeseq==0)
{
int player = obj.getplayer();
if(!map.invincibility)
{
if (obj.entities[player].yp-map.ypos <= 0)
{
game.deathseq = 30;
}
else if (obj.entities[player].yp-map.ypos >= 208)
{
game.deathseq = 30;
}
}
else
{
if (obj.entities[player].yp-map.ypos <= 0)
{
map.ypos-=10;
map.bypos = map.ypos / 2;
map.bscroll = 0;
}
else if (obj.entities[player].yp-map.ypos >= 208)
{
map.ypos+=2;
map.bypos = map.ypos / 2;
map.bscroll = 0;
}
}
if (obj.entities[player].yp - map.ypos <= 40)
{
map.spikeleveltop++;
if (map.spikeleveltop >= 8) map.spikeleveltop = 8;
}
else
{
if (map.spikeleveltop > 0) map.spikeleveltop--;
}
if (obj.entities[player].yp - map.ypos >= 164)
{
map.spikelevelbottom++;
if (map.spikelevelbottom >= 8) map.spikelevelbottom = 8;
}
else
{
if (map.spikelevelbottom > 0) map.spikelevelbottom--;
}
}
}
//Looping around, room change conditions!
}
if (game.teleport_to_new_area) script.teleport();
}
void gamelogic()
{
//Misc
help.updateglow();
if (game.alarmon)
{
game.alarmdelay--;
if (game.alarmdelay <= 0)
{
music.playef(19);
game.alarmdelay = 20;
}
}
if (obj.nearelephant)
{
obj.upset++;
if (obj.upset == 300)
{
obj.upsetmode = true;
//change player to sad
int i = obj.getplayer();
obj.entities[i].tile = 144;
music.playef(2);
}
if (obj.upset > 301) obj.upset = 301;
}
else if (obj.upsetmode)
{
obj.upset--;
if (obj.upset <= 0)
{
obj.upset = 0;
obj.upsetmode = false;
//change player to happy
int i = obj.getplayer();
obj.entities[i].tile = 0;
}
}
else
{
obj.upset = 0;
}
game.lifesequence();
if (game.deathseq != -1)
{
for (size_t i = 0; i < obj.entities.size(); i++) for (size_t i = 0; i < obj.entities.size(); i++)
{ {
if (game.roomx == 111 && game.roomy == 107 && !map.custommode) if (game.roomx == 111 && game.roomy == 107 && !map.custommode)
@ -1010,6 +765,68 @@ void gamelogic()
} }
obj.entitycollisioncheck(); // Check ent v ent collisions, update states obj.entitycollisioncheck(); // Check ent v ent collisions, update states
if (map.towermode)
{
//special for tower: is the player touching any spike blocks?
int player = obj.getplayer();
if(obj.checktowerspikes(player) && graphics.fademode==0)
{
game.deathseq = 30;
}
}
if(map.towermode && game.lifeseq==0)
{
int player = obj.getplayer();
if(!map.invincibility)
{
if (obj.entities[player].yp-map.ypos <= 0)
{
game.deathseq = 30;
}
else if (obj.entities[player].yp-map.ypos >= 208)
{
game.deathseq = 30;
}
}
else
{
if (obj.entities[player].yp-map.ypos <= 0)
{
map.ypos-=10;
map.bypos = map.ypos / 2;
map.bscroll = 0;
}
else if (obj.entities[player].yp-map.ypos >= 208)
{
map.ypos+=2;
map.bypos = map.ypos / 2;
map.bscroll = 0;
}
}
if (obj.entities[player].yp - map.ypos <= 40)
{
map.spikeleveltop++;
if (map.spikeleveltop >= 8) map.spikeleveltop = 8;
}
else
{
if (map.spikeleveltop > 0) map.spikeleveltop--;
}
if (obj.entities[player].yp - map.ypos >= 164)
{
map.spikelevelbottom++;
if (map.spikelevelbottom >= 8) map.spikelevelbottom = 8;
}
else
{
if (map.spikelevelbottom > 0) map.spikelevelbottom--;
}
}
} }
//Using warplines? //Using warplines?
@ -1033,7 +850,7 @@ void gamelogic()
} }
//Finally: Are we changing room? //Finally: Are we changing room?
if (map.warpx) if (map.warpx && !map.towermode)
{ {
for (size_t i = 0; i < obj.entities.size(); i++) for (size_t i = 0; i < obj.entities.size(); i++)
{ {
@ -1071,7 +888,7 @@ void gamelogic()
} }
} }
if (map.warpy) if (map.warpy && !map.towermode)
{ {
for (size_t i = 0; i < obj.entities.size(); i++) for (size_t i = 0; i < obj.entities.size(); i++)
{ {
@ -1090,7 +907,7 @@ void gamelogic()
} }
} }
if (map.warpy && !map.warpx) if (map.warpy && !map.warpx && !map.towermode)
{ {
for (size_t i = 0; i < obj.entities.size(); i++) for (size_t i = 0; i < obj.entities.size(); i++)
{ {
@ -1112,7 +929,7 @@ void gamelogic()
} }
} }
if (!map.warpy) if (!map.warpy && !map.towermode)
{ {
//Normal! Just change room //Normal! Just change room
int player = obj.getplayer(); int player = obj.getplayer();
@ -1128,7 +945,7 @@ void gamelogic()
} }
} }
if (!map.warpx) if (!map.warpx && !map.towermode)
{ {
//Normal! Just change room //Normal! Just change room
int player = obj.getplayer(); int player = obj.getplayer();
@ -1144,6 +961,88 @@ void gamelogic()
} }
} }
//Right so! Screenwraping for tower:
if (map.minitowermode)
{
if (map.scrolldir == 1)
{
//This is minitower 1!
int player = obj.getplayer();
if (game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
map.gotoroom(48, 52);
}
if (game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
obj.entities[player].yp -= (71*8);
map.gotoroom(game.roomx + 1, game.roomy+1);
}
}
else
{
//This is minitower 2!
int player = obj.getplayer();
if (game.door_left > -2 && obj.entities[player].xp < -14)
{
if (obj.entities[player].yp > 300)
{
obj.entities[player].xp += 320;
obj.entities[player].yp -= (71 * 8);
map.gotoroom(50, 54);
}
else
{
obj.entities[player].xp += 320;
map.gotoroom(50, 53);
}
}
if (game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(52, 53);
}
}
}
else if (map.towermode)
{
//Always wrap except for the very top and very bottom of the tower
if(map.ypos>=500 && map.ypos <=5000)
{
for (size_t i = 0; i < obj.entities.size(); i++)
{
if (obj.entities[i].xp <= -10)
{
obj.entities[i].xp += 320;
}
else
{
if (obj.entities[i].xp > 310)
{
obj.entities[i].xp -= 320;
}
}
}
}
else
{
//Do not wrap! Instead, go to the correct room
int player = obj.getplayer();
if (game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
obj.entities[player].yp -= (671 * 8);
map.gotoroom(108, 109);
}
if (game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(110, 104);
}
}
}
//Warp tokens //Warp tokens
if (map.custommode){ if (map.custommode){
if (game.teleport) if (game.teleport)

View file

@ -16,8 +16,6 @@ void gamecompletelogic();
void gamecompletelogic2(); void gamecompletelogic2();
void towerlogic();
void gamelogic(); void gamelogic();
#endif /* LOGIC_H */ #endif /* LOGIC_H */

View file

@ -426,7 +426,7 @@ int main(int argc, char *argv[])
{ {
gameinput(); gameinput();
towerrender(); towerrender();
towerlogic(); gamelogic();
} }
else else