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

Factor out entity drawing to separate function

This makes it easy to re-use without duplicating code.
This commit is contained in:
Misa 2020-10-31 21:38:15 -07:00 committed by Ethan Lee
parent fd53278163
commit e809cc0615
2 changed files with 30 additions and 17 deletions

View file

@ -1593,6 +1593,27 @@ void Graphics::drawtrophytext()
void Graphics::drawentities() void Graphics::drawentities()
{ {
const int yoff = map.towermode ? lerp(map.oldypos, map.ypos) : 0;
for (int i = obj.entities.size() - 1; i >= 0; i--)
{
drawentity(i, yoff);
}
}
void Graphics::drawentity(const int i, const int yoff)
{
if (!INBOUNDS_VEC(i, obj.entities))
{
WHINE_ONCE("drawentity() out-of-bounds!");
return;
}
if (obj.entities[i].invis)
{
return;
}
point tpoint; point tpoint;
SDL_Rect drawRect; SDL_Rect drawRect;
@ -1610,15 +1631,6 @@ void Graphics::drawentities()
std::vector<SDL_Surface*>& spritesvec = flipmode ? flipsprites : sprites; std::vector<SDL_Surface*>& spritesvec = flipmode ? flipsprites : sprites;
const int yoff = map.towermode ? lerp(map.oldypos, map.ypos) : 0;
for (int i = obj.entities.size() - 1; i >= 0; i--)
{
if (obj.entities[i].invis)
{
continue;
}
const int xp = lerp(obj.entities[i].lerpoldxp, obj.entities[i].xp); const int xp = lerp(obj.entities[i].lerpoldxp, obj.entities[i].xp);
const int yp = lerp(obj.entities[i].lerpoldyp, obj.entities[i].yp); const int yp = lerp(obj.entities[i].lerpoldyp, obj.entities[i].yp);
@ -1629,7 +1641,7 @@ void Graphics::drawentities()
// Sprites // Sprites
if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec))
{ {
continue; return;
} }
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
@ -1697,7 +1709,7 @@ void Graphics::drawentities()
// Tiles // Tiles
if (!INBOUNDS_VEC(obj.entities[i].drawframe, tiles)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, tiles))
{ {
continue; return;
} }
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
@ -1712,7 +1724,7 @@ void Graphics::drawentities()
// Special: Moving platform, 4 tiles or 8 tiles // Special: Moving platform, 4 tiles or 8 tiles
if (!INBOUNDS_VEC(obj.entities[i].drawframe, tilesvec)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, tilesvec))
{ {
continue; return;
} }
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
@ -1779,7 +1791,7 @@ void Graphics::drawentities()
case 9: // Really Big Sprite! (2x2) case 9: // Really Big Sprite! (2x2)
if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec))
{ {
continue; return;
} }
setcolreal(obj.entities[i].realcol); setcolreal(obj.entities[i].realcol);
@ -1818,7 +1830,7 @@ void Graphics::drawentities()
case 10: // 2x1 Sprite case 10: // 2x1 Sprite
if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec))
{ {
continue; return;
} }
setcolreal(obj.entities[i].realcol); setcolreal(obj.entities[i].realcol);
@ -1845,7 +1857,7 @@ void Graphics::drawentities()
case 12: // Regular sprites that don't wrap case 12: // Regular sprites that don't wrap
if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec))
{ {
continue; return;
} }
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
@ -1904,7 +1916,7 @@ void Graphics::drawentities()
//Special for epilogue: huge hero! //Special for epilogue: huge hero!
if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec))
{ {
continue; return;
} }
tpoint.x = xp; tpoint.y = yp - yoff; tpoint.x = xp; tpoint.y = yp - yoff;
@ -1920,7 +1932,6 @@ void Graphics::drawentities()
} }
} }
} }
}
void Graphics::drawbackground( int t ) void Graphics::drawbackground( int t )
{ {

View file

@ -140,6 +140,8 @@ public:
void drawentities(); void drawentities();
void drawentity(const int i, const int yoff);
void drawtrophytext(); void drawtrophytext();
void bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2); void bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2);