1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-04 18:29:41 +01:00

Consolidate tower BG bypos and bscroll assignments

Tower backgrounds have a bypos and bscroll. bypos is just the y-position
of the background, and bscroll is the amount of pixels to scroll the
background by on each frame, which is used to scroll it (if it's not
being redrawn) and for linear interpolation.

For the tower background (and not the title background), bypos is
map.ypos / 2, and bscroll is (map.ypos - map.oldypos) / 2. However,
usually bscroll gets assigned at the same time bypos is incremented or
decremented, so you never see that calculation explicitly - except in
the previous commit, where I worked out the calculation because the
change in y-position isn't a known constant.

Having to do all these calculations every time introduces the
possibility of errors where you forget to do it, or you do it wrongly.
But that's not even the worst; you could cause a linear interpolation
glitch if you decide to overwrite bscroll without taking into account
map.oldypos and map.ypos.

So that's why I'm adding a function that automatically updates the tower
background, using the values of map.oldypos and map.ypos, that is used
every time map.ypos is assigned. That way, we have to write less code,
you can be sure that there's no place where we forget to do the
calculations (or at least it will be glaringly obvious) or we do it
wrongly, and it plays nicely with linear interpolation. This also
replaces every instance where the manual calculations are done with the
new function.
This commit is contained in:
Misa 2021-04-22 18:47:07 -07:00 committed by Ethan Lee
parent 5c3fbd0022
commit 9f603ea3fe
5 changed files with 28 additions and 38 deletions

View file

@ -222,7 +222,6 @@ void gamelogic(void)
//do nothing! //do nothing!
//a trigger will set this off in the game //a trigger will set this off in the game
map.cameramode = 1; map.cameramode = 1;
graphics.towerbg.bscroll = 0;
} }
else if (map.cameramode == 1) else if (map.cameramode == 1)
{ {
@ -230,20 +229,15 @@ void gamelogic(void)
if(graphics.towerbg.scrolldir==0) if(graphics.towerbg.scrolldir==0)
{ {
map.ypos -= 2; map.ypos -= 2;
graphics.towerbg.bypos -= 1;
graphics.towerbg.bscroll = -1;
} }
else else
{ {
map.ypos += 2; map.ypos += 2;
graphics.towerbg.bypos += 1;
graphics.towerbg.bscroll = 1;
} }
} }
else if (map.cameramode == 2) else if (map.cameramode == 2)
{ {
//do nothing, but cycle colours (for taking damage) //do nothing, but cycle colours (for taking damage)
graphics.towerbg.bscroll = 0;
} }
else if (map.cameramode == 4) else if (map.cameramode == 4)
{ {
@ -257,8 +251,6 @@ void gamelogic(void)
map.cameraseekframe = 10; map.cameraseekframe = 10;
map.cameramode = 5; map.cameramode = 5;
graphics.towerbg.bscroll = map.cameraseek/2;
} }
else if (map.cameramode == 5) else if (map.cameramode == 5)
{ {
@ -284,7 +276,6 @@ void gamelogic(void)
} }
} }
map.cameraseekframe--; map.cameraseekframe--;
graphics.towerbg.bypos = map.ypos / 2;
} }
else else
{ {
@ -293,30 +284,21 @@ void gamelogic(void)
{ {
map.ypos = obj.entities[i].yp - 120; map.ypos = obj.entities[i].yp - 120;
} }
graphics.towerbg.bypos = map.ypos / 2;
map.cameramode = 0; map.cameramode = 0;
map.colsuperstate = 0; map.colsuperstate = 0;
} }
} }
} }
else
{
graphics.towerbg.bscroll = 0;
}
if (map.ypos <= 0) if (map.ypos <= 0)
{ {
map.ypos = 0; map.ypos = 0;
graphics.towerbg.bypos = 0;
graphics.towerbg.bscroll = 0;
} }
if (map.towermode && map.minitowermode) if (map.towermode && map.minitowermode)
{ {
if (map.ypos >= 568) if (map.ypos >= 568)
{ {
map.ypos = 568; map.ypos = 568;
graphics.towerbg.bypos = map.ypos / 2;
graphics.towerbg.bscroll = 0;
} //100-29 * 8 = 568 } //100-29 * 8 = 568
} }
else else
@ -324,7 +306,6 @@ void gamelogic(void)
if (map.ypos >= 5368) if (map.ypos >= 5368)
{ {
map.ypos = 5368; //700-29 * 8 = 5368 map.ypos = 5368; //700-29 * 8 = 5368
graphics.towerbg.bypos = map.ypos / 2.0;
} }
} }
@ -910,9 +891,6 @@ void gamelogic(void)
if (above_screen || below_screen) if (above_screen || below_screen)
{ {
graphics.towerbg.bypos = map.ypos / 2;
graphics.towerbg.bscroll = (map.ypos - map.oldypos) / 2;
/* The buffer isn't big enough; we have to redraw */ /* The buffer isn't big enough; we have to redraw */
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
} }
@ -1347,6 +1325,11 @@ void gamelogic(void)
} }
} }
if (map.towermode)
{
map.setbgobjlerp(graphics.towerbg);
}
//Update colour cycling for final level //Update colour cycling for final level
if (map.finalmode && map.final_colormode) if (map.finalmode && map.final_colormode)
{ {

View file

@ -595,6 +595,12 @@ void mapclass::updatebgobj(TowerBG& bg_obj)
bg_obj.tdrawback = true; bg_obj.tdrawback = true;
} }
void mapclass::setbgobjlerp(TowerBG& bg_obj)
{
bg_obj.bypos = ypos / 2;
bg_obj.bscroll = (ypos - oldypos) / 2;
}
void mapclass::updatetowerglow(TowerBG& bg_obj) void mapclass::updatetowerglow(TowerBG& bg_obj)
{ {
if (colstatedelay <= 0 || colsuperstate > 0) if (colstatedelay <= 0 || colsuperstate > 0)
@ -827,7 +833,7 @@ void mapclass::resetplayer(const bool player_died)
ypos = 0; ypos = 0;
} }
oldypos = ypos; oldypos = ypos;
graphics.towerbg.bypos = ypos / 2; setbgobjlerp(graphics.towerbg);
} }
} }
@ -1249,7 +1255,7 @@ void mapclass::loadlevel(int rx, int ry)
ypos = (700-29) * 8; ypos = (700-29) * 8;
oldypos = ypos; oldypos = ypos;
graphics.towerbg.bypos = ypos / 2; setbgobjlerp(graphics.towerbg);
cameramode = 0; cameramode = 0;
graphics.towerbg.colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
@ -1259,7 +1265,7 @@ void mapclass::loadlevel(int rx, int ry)
//you've entered from the top floor //you've entered from the top floor
ypos = 0; ypos = 0;
oldypos = ypos; oldypos = ypos;
graphics.towerbg.bypos = 0; setbgobjlerp(graphics.towerbg);
cameramode = 0; cameramode = 0;
graphics.towerbg.colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
@ -1342,14 +1348,13 @@ void mapclass::loadlevel(int rx, int ry)
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = false; minitowermode = false;
tower.minitowermode = false; tower.minitowermode = false;
graphics.towerbg.bscroll = 0;
graphics.towerbg.scrolldir = 0; graphics.towerbg.scrolldir = 0;
setbgobjlerp(graphics.towerbg);
roomname = "The Tower"; roomname = "The Tower";
tileset = 1; tileset = 1;
background = 3; background = 3;
towermode = true; towermode = true;
//graphics.towerbg.bypos = 0; ypos = 0; cameramode = 0;
//All the entities for here are just loaded here; it's essentially one room after all //All the entities for here are just loaded here; it's essentially one room after all
@ -1433,8 +1438,8 @@ void mapclass::loadlevel(int rx, int ry)
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
graphics.towerbg.bscroll = 0;
graphics.towerbg.scrolldir = 1; graphics.towerbg.scrolldir = 1;
setbgobjlerp(graphics.towerbg);
roomname = "Panic Room"; roomname = "Panic Room";
tileset = 1; tileset = 1;
@ -1445,7 +1450,7 @@ void mapclass::loadlevel(int rx, int ry)
ypos = 0; ypos = 0;
oldypos = 0; oldypos = 0;
graphics.towerbg.bypos = 0; setbgobjlerp(graphics.towerbg);
cameramode = 0; cameramode = 0;
graphics.towerbg.colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
@ -1455,8 +1460,8 @@ void mapclass::loadlevel(int rx, int ry)
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
graphics.towerbg.bscroll = 0;
graphics.towerbg.scrolldir = 1; graphics.towerbg.scrolldir = 1;
setbgobjlerp(graphics.towerbg);
roomname = "Panic Room"; roomname = "Panic Room";
tileset = 1; tileset = 1;
@ -1474,7 +1479,7 @@ void mapclass::loadlevel(int rx, int ry)
ypos = (100-29) * 8; ypos = (100-29) * 8;
oldypos = ypos; oldypos = ypos;
graphics.towerbg.bypos = ypos/2; setbgobjlerp(graphics.towerbg);
cameramode = 0; cameramode = 0;
graphics.towerbg.colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0;} colsuperstate = 0;}
@ -1484,8 +1489,8 @@ void mapclass::loadlevel(int rx, int ry)
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
graphics.towerbg.bscroll = 0;
graphics.towerbg.scrolldir = 0; graphics.towerbg.scrolldir = 0;
setbgobjlerp(graphics.towerbg);
final_colorframe = 2; final_colorframe = 2;
roomname = "The Final Challenge"; roomname = "The Final Challenge";
@ -1518,7 +1523,7 @@ void mapclass::loadlevel(int rx, int ry)
ypos = (100-29) * 8; ypos = (100-29) * 8;
oldypos = ypos; oldypos = ypos;
graphics.towerbg.bypos = ypos/2; setbgobjlerp(graphics.towerbg);
cameramode = 0; cameramode = 0;
graphics.towerbg.colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
@ -1530,8 +1535,8 @@ void mapclass::loadlevel(int rx, int ry)
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
graphics.towerbg.bscroll = 0;
graphics.towerbg.scrolldir = 0; graphics.towerbg.scrolldir = 0;
setbgobjlerp(graphics.towerbg);
final_colorframe = 2; final_colorframe = 2;
roomname = "The Final Challenge"; roomname = "The Final Challenge";
@ -1557,7 +1562,7 @@ void mapclass::loadlevel(int rx, int ry)
ypos = 0; ypos = 0;
oldypos = 0; oldypos = 0;
graphics.towerbg.bypos = 0; setbgobjlerp(graphics.towerbg);
cameramode = 0; cameramode = 0;
graphics.towerbg.colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;

View file

@ -50,6 +50,8 @@ public:
void updatebgobj(TowerBG& bg_obj); void updatebgobj(TowerBG& bg_obj);
void setbgobjlerp(TowerBG& bg_obj);
void updatetowerglow(TowerBG& bg_obj); void updatetowerglow(TowerBG& bg_obj);
void nexttowercolour(void); void nexttowercolour(void);

View file

@ -2707,7 +2707,7 @@ void scriptclass::startgamemode( int t )
map.ypos = obj.entities[i].yp - 120; map.ypos = obj.entities[i].yp - 120;
map.oldypos = map.ypos; map.oldypos = map.ypos;
} }
graphics.towerbg.bypos = map.ypos / 2; map.setbgobjlerp(graphics.towerbg);
map.cameramode = 0; map.cameramode = 0;
map.colsuperstate = 0; map.colsuperstate = 0;
} }

View file

@ -495,8 +495,8 @@ int main(int argc, char *argv[])
map.ypos = (700-29) * 8; map.ypos = (700-29) * 8;
map.oldypos = map.ypos; map.oldypos = map.ypos;
graphics.towerbg.bypos = map.ypos / 2; map.setbgobjlerp(graphics.towerbg);
graphics.titlebg.bypos = map.ypos / 2; map.setbgobjlerp(graphics.titlebg);
{ {
// Prioritize unlock.vvv first (2.2 and below), // Prioritize unlock.vvv first (2.2 and below),