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

Fix colors updating too fast in TITLEMODE/MAPMODE/GAMECOMPLETEMODE

These colors were of the colors of each crewmate, the inactive crewmate
color, and the color of the trinket and clock on the quicksave/summary
screens.

These colors all used fRandom() and so kept updating too quickly because
they would be recalculated every time the delta-timestep render function
got called, which isn't ideal. Thus, I've had to add attributes onto the
Graphics class to store these colors and make sure they're only
recalculated in logic functions instead.

Thankfully, the color used for the sprites on the time trial results
screen doesn't use fRandom(), so I don't have to worry about those.

There's a new version of Graphics::drawsprite() that takes in a pre-made
color already, instead of a color ID. As well, I've also added
Graphics::updatetitlecolours() to update these colors on the title
screen.
This commit is contained in:
Misa 2020-05-01 16:40:35 -07:00 committed by Ethan Lee
parent 3699adec82
commit 11803b0229
4 changed files with 122 additions and 43 deletions

View file

@ -124,6 +124,19 @@ void Graphics::init()
screenshake_x = 0; screenshake_x = 0;
screenshake_y = 0; screenshake_y = 0;
col_crewred = 0x00000000;
col_crewyellow = 0x00000000;
col_crewgreen = 0x00000000;
col_crewcyan = 0x00000000;
col_crewblue = 0x00000000;
col_crewpurple = 0x00000000;
col_crewinactive = 0x00000000;
col_clock = 0x00000000;
col_trinket = 0x00000000;
col_tr = 0;
col_tg = 0;
col_tb = 0;
} }
int Graphics::font_idx(uint32_t ch) { int Graphics::font_idx(uint32_t ch) {
@ -160,6 +173,29 @@ void Graphics::drawspritesetcol(int x, int y, int t, int c)
BlitSurfaceColoured(sprites[t],NULL,backBuffer, &rect, ct); BlitSurfaceColoured(sprites[t],NULL,backBuffer, &rect, ct);
} }
void Graphics::updatetitlecolours()
{
setcol(15);
col_crewred = ct.colour;
setcol(14);
col_crewyellow = ct.colour;
setcol(13);
col_crewgreen = ct.colour;
setcol(0);
col_crewcyan = ct.colour;
setcol(16);
col_crewblue = ct.colour;
setcol(20);
col_crewpurple = ct.colour;
setcol(19);
col_crewinactive = ct.colour;
setcol(18);
col_clock = ct.colour;
setcol(18);
col_trinket = ct.colour;
}
void Graphics::Makebfont() void Graphics::Makebfont()
{ {
for (int j = 0; j < (grphx.im_bfont->h / 8); j++) for (int j = 0; j < (grphx.im_bfont->h / 8); j++)
@ -540,6 +576,13 @@ void Graphics::drawsprite( int x, int y, int t, int r, int g, int b )
BlitSurfaceColoured(sprites[t], NULL, backBuffer, &rect, ct); BlitSurfaceColoured(sprites[t], NULL, backBuffer, &rect, ct);
} }
void Graphics::drawsprite(int x, int y, int t, Uint32 c)
{
SDL_Rect rect = { Sint16(x), Sint16(y), sprites_rect.w, sprites_rect.h };
setcolreal(c);
BlitSurfaceColoured(sprites[t], NULL, backBuffer, &rect, ct);
}
void Graphics::drawtile( int x, int y, int t ) void Graphics::drawtile( int x, int y, int t )
{ {
if (!INBOUNDS(t, tiles)) if (!INBOUNDS(t, tiles))
@ -890,22 +933,22 @@ void Graphics::drawcrewman( int x, int y, int t, bool act, bool noshift /*=false
{ {
if (flipmode) if (flipmode)
{ {
drawspritesetcol(x, y, 14, 19); drawsprite(x, y, 14, col_crewinactive);
} }
else else
{ {
drawspritesetcol(x, y, 12, 19); drawsprite(x, y, 12, col_crewinactive);
} }
} }
else else
{ {
if (flipmode) if (flipmode)
{ {
drawspritesetcol(x - 8, y, 14, 19); drawsprite(x - 8, y, 14, col_crewinactive);
} }
else else
{ {
drawspritesetcol(x - 8, y, 12, 19); drawsprite(x - 8, y, 12, col_crewinactive);
} }
} }
} }
@ -916,22 +959,22 @@ void Graphics::drawcrewman( int x, int y, int t, bool act, bool noshift /*=false
switch(t) switch(t)
{ {
case 0: case 0:
drawspritesetcol(x, y, crewframe, 0); drawsprite(x, y, crewframe, col_crewcyan);
break; break;
case 1: case 1:
drawspritesetcol(x, y, crewframe, 20); drawsprite(x, y, crewframe, col_crewpurple);
break; break;
case 2: case 2:
drawspritesetcol(x, y, crewframe, 14); drawsprite(x, y, crewframe, col_crewyellow);
break; break;
case 3: case 3:
drawspritesetcol(x, y, crewframe, 15); drawsprite(x, y, crewframe, col_crewred);
break; break;
case 4: case 4:
drawspritesetcol(x, y, crewframe, 13); drawsprite(x, y, crewframe, col_crewgreen);
break; break;
case 5: case 5:
drawspritesetcol(x, y, crewframe, 16); drawsprite(x, y, crewframe, col_crewblue);
break; break;
} }

View file

@ -103,6 +103,7 @@ public:
void drawgui(); void drawgui();
void drawsprite(int x, int y, int t, int r, int g, int b); void drawsprite(int x, int y, int t, int r, int g, int b);
void drawsprite(int x, int y, int t, Uint32 c);
void printcrewname(int x, int y, int t); void printcrewname(int x, int y, int t);
@ -305,6 +306,20 @@ public:
return v0 + alpha * (v1 - v0); return v0 + alpha * (v1 - v0);
} }
float alpha; float alpha;
Uint32 col_crewred;
Uint32 col_crewyellow;
Uint32 col_crewgreen;
Uint32 col_crewcyan;
Uint32 col_crewblue;
Uint32 col_crewpurple; //actually pink
Uint32 col_crewinactive;
Uint32 col_clock;
Uint32 col_trinket;
int col_tr;
int col_tg;
int col_tb;
void updatetitlecolours();
}; };
extern Graphics graphics; extern Graphics graphics;

View file

@ -17,6 +17,27 @@ void titlelogic()
graphics.updatetowerbackground(); graphics.updatetowerbackground();
} }
if (!game.menustart)
{
graphics.col_tr = (int)(164 - (help.glow / 2) - int(fRandom() * 4));
graphics.col_tg = 164 - (help.glow / 2) - int(fRandom() * 4);
graphics.col_tb = 164 - (help.glow / 2) - int(fRandom() * 4);
}
else
{
graphics.col_tr = map.r - (help.glow / 4) - int(fRandom() * 4);
graphics.col_tg = map.g - (help.glow / 4) - int(fRandom() * 4);
graphics.col_tb = map.b - (help.glow / 4) - int(fRandom() * 4);
if (graphics.col_tr < 0) graphics.col_tr = 0;
if(graphics.col_tr>255) graphics.col_tr=255;
if (graphics.col_tg < 0) graphics.col_tg = 0;
if(graphics.col_tg>255) graphics.col_tg=255;
if (graphics.col_tb < 0) graphics.col_tb = 0;
if(graphics.col_tb>255) graphics.col_tb=255;
graphics.updatetitlecolours();
}
graphics.crewframedelay--; graphics.crewframedelay--;
if (graphics.crewframedelay <= 0) if (graphics.crewframedelay <= 0)
{ {
@ -51,6 +72,7 @@ void maplogic()
//Misc //Misc
help.updateglow(); help.updateglow();
graphics.updatetextboxes(); graphics.updatetextboxes();
graphics.updatetitlecolours();
graphics.crewframedelay--; graphics.crewframedelay--;
if (graphics.crewframedelay <= 0) if (graphics.crewframedelay <= 0)
@ -103,6 +125,17 @@ void gamecompletelogic()
help.updateglow(); help.updateglow();
graphics.crewframe = 0; graphics.crewframe = 0;
map.scrolldir = 1; map.scrolldir = 1;
graphics.updatetitlecolours();
graphics.col_tr = map.r - (help.glow / 4) - fRandom() * 4;
graphics.col_tg = map.g - (help.glow / 4) - fRandom() * 4;
graphics.col_tb = map.b - (help.glow / 4) - fRandom() * 4;
if (graphics.col_tr < 0) graphics.col_tr = 0;
if(graphics.col_tr>255) graphics.col_tr=255;
if (graphics.col_tg < 0) graphics.col_tg = 0;
if(graphics.col_tg>255) graphics.col_tg=255;
if (graphics.col_tb < 0) graphics.col_tb = 0;
if(graphics.col_tb>255) graphics.col_tb=255;
game.creditposition--; game.creditposition--;
if (game.creditposition <= -game.creditmaxposition) if (game.creditposition <= -game.creditmaxposition)

View file

@ -519,8 +519,8 @@ void menurender()
graphics.Print(160 - 84, 132-20, game.tele_gametime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 - 84, 132-20, game.tele_gametime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.Print(160 + 40, 132-20, help.number(game.tele_trinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 + 40, 132-20, help.number(game.tele_trinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.drawspritesetcol(50, 126-20, 50, 18); graphics.drawsprite(50, 126-20, 50, graphics.col_clock);
graphics.drawspritesetcol(175, 126-20, 22, 18); graphics.drawsprite(175, 126-20, 22, graphics.col_trinket);
break; break;
case 1: case 1:
//Show quick save info //Show quick save info
@ -535,8 +535,8 @@ void menurender()
graphics.Print(160 - 84, 132-20, game.quick_gametime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 - 84, 132-20, game.quick_gametime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.Print(160 + 40, 132-20, help.number(game.quick_trinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 + 40, 132-20, help.number(game.quick_trinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.drawspritesetcol(50, 126-20, 50, 18); graphics.drawsprite(50, 126-20, 50, graphics.col_clock);
graphics.drawspritesetcol(175, 126-20, 22, 18); graphics.drawsprite(175, 126-20, 22, graphics.col_trinket);
break; break;
} }
break; break;
@ -1029,9 +1029,9 @@ void titlerender()
if (!game.menustart) if (!game.menustart)
{ {
tr = (int)(164 - (help.glow / 2) - int(fRandom() * 4)); tr = graphics.col_tr;
tg = 164 - (help.glow / 2) - int(fRandom() * 4); tg = graphics.col_tg;
tb = 164 - (help.glow / 2) - int(fRandom() * 4); tb = graphics.col_tb;
int temp = 50; int temp = 50;
graphics.drawsprite((160 - 96) + 0 * 32, temp, 23, tr, tg, tb); graphics.drawsprite((160 - 96) + 0 * 32, temp, 23, tr, tg, tb);
@ -1051,15 +1051,9 @@ void titlerender()
{ {
if(!game.colourblindmode) graphics.drawtowerbackground(); if(!game.colourblindmode) graphics.drawtowerbackground();
tr = map.r - (help.glow / 4) - int(fRandom() * 4); tr = graphics.col_tr;
tg = map.g - (help.glow / 4) - int(fRandom() * 4); tg = graphics.col_tg;
tb = map.b - (help.glow / 4) - int(fRandom() * 4); tb = graphics.col_tb;
if (tr < 0) tr = 0;
if(tr>255) tr=255;
if (tg < 0) tg = 0;
if(tg>255) tg=255;
if (tb < 0) tb = 0;
if(tb>255) tb=255;
menurender(); menurender();
@ -1113,15 +1107,9 @@ void gamecompleterender()
if(!game.colourblindmode) graphics.drawtowerbackground(); if(!game.colourblindmode) graphics.drawtowerbackground();
tr = map.r - (help.glow / 4) - fRandom() * 4; tr = graphics.col_tr;
tg = map.g - (help.glow / 4) - fRandom() * 4; tg = graphics.col_tg;
tb = map.b - (help.glow / 4) - fRandom() * 4; tb = graphics.col_tb;
if (tr < 0) tr = 0;
if(tr>255) tr=255;
if (tg < 0) tg = 0;
if(tg>255) tg=255;
if (tb < 0) tb = 0;
if(tb>255) tb=255;
//rendering starts... here! //rendering starts... here!
@ -2193,8 +2181,8 @@ void maprender()
graphics.Print(160 - 84, 78, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 - 84, 78, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.Print(160 + 40, 78, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 + 40, 78, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.drawspritesetcol(50, 74, 50, 18); graphics.drawsprite(50, 74, 50, graphics.col_clock);
graphics.drawspritesetcol(175, 74, 22, 18); graphics.drawsprite(175, 74, 22, graphics.col_trinket);
} }
else else
{ {
@ -2202,8 +2190,8 @@ void maprender()
graphics.Print(160 - 84, 132, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 - 84, 132, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.Print(160 + 40, 132, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 + 40, 132, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.drawspritesetcol(50, 126, 50, 18); graphics.drawsprite(50, 126, 50, graphics.col_clock);
graphics.drawspritesetcol(175, 126, 22, 18); graphics.drawsprite(175, 126, 22, graphics.col_trinket);
} }
} }
else else
@ -2240,8 +2228,8 @@ void maprender()
graphics.Print(160 - 84, 78, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 - 84, 78, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.Print(160 + 40, 78, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 + 40, 78, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.drawspritesetcol(50, 74, 50, 18); graphics.drawsprite(50, 74, 50, graphics.col_clock);
graphics.drawspritesetcol(175, 74, 22, 18); graphics.drawsprite(175, 74, 22, graphics.col_trinket);
} }
else else
{ {
@ -2253,8 +2241,8 @@ void maprender()
graphics.Print(160 - 84, 132, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 - 84, 132, game.savetime, 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.Print(160 + 40, 132, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2)); graphics.Print(160 + 40, 132, help.number(game.savetrinkets), 255 - (help.glow / 2), 255 - (help.glow / 2), 255 - (help.glow / 2));
graphics.drawspritesetcol(50, 126, 50, 18); graphics.drawsprite(50, 126, 50, graphics.col_clock);
graphics.drawspritesetcol(175, 126, 22, 18); graphics.drawsprite(175, 126, 22, graphics.col_trinket);
} }
} }
else else