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

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