mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Clean up background drawing code
As #974 states, the lab background only ever uses the first generated value from `backboxint`, so let's change it to a normal variable instead of an array. Also, stars don't need their width/height set to 2 constantly... they never change in the first place, Terry!
This commit is contained in:
parent
5089bc373e
commit
81ad7ed9d6
2 changed files with 48 additions and 58 deletions
|
@ -46,13 +46,11 @@ void Graphics::init(void)
|
||||||
flipmode = false;
|
flipmode = false;
|
||||||
setflipmode = false;
|
setflipmode = false;
|
||||||
|
|
||||||
//Background inits
|
// Initialize backgrounds
|
||||||
for (int i = 0; i < numstars; i++)
|
for (int i = 0; i < numstars; i++)
|
||||||
{
|
{
|
||||||
SDL_Rect s = {(int) (fRandom() * 320), (int) (fRandom() * 240), 2, 2};
|
stars[i] = {(int) (fRandom() * 320), (int) (fRandom() * 240), 2, 2};
|
||||||
int s2 = 4+(fRandom()*4);
|
starsspeed[i] = 4 + (fRandom() * 4);
|
||||||
stars[i] = s;
|
|
||||||
starsspeed[i] = s2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numbackboxes; i++)
|
for (int i = 0; i < numbackboxes; i++)
|
||||||
|
@ -60,7 +58,7 @@ void Graphics::init(void)
|
||||||
SDL_Rect bb;
|
SDL_Rect bb;
|
||||||
int bvx = 0;
|
int bvx = 0;
|
||||||
int bvy = 0;
|
int bvy = 0;
|
||||||
if(fRandom()*100 > 50)
|
if (fRandom() * 100 > 50)
|
||||||
{
|
{
|
||||||
bvx = 9 - (fRandom() * 19);
|
bvx = 9 - (fRandom() * 19);
|
||||||
if (bvx > -6 && bvx < 6) bvx = 6;
|
if (bvx > -6 && bvx < 6) bvx = 6;
|
||||||
|
@ -72,14 +70,15 @@ void Graphics::init(void)
|
||||||
bvy = 9 - (fRandom() * 19);
|
bvy = 9 - (fRandom() * 19);
|
||||||
if (bvy > -6 && bvy < 6) bvy = 6;
|
if (bvy > -6 && bvy < 6) bvy = 6;
|
||||||
bvy = bvy * 1.5;
|
bvy = bvy * 1.5;
|
||||||
setRect(bb, fRandom() * 320, fRandom() * 240, 12, 32) ;
|
setRect(bb, fRandom() * 320, fRandom() * 240, 12, 32);
|
||||||
}
|
}
|
||||||
float bint = 0.5 + ((fRandom() * 100) / 200);
|
|
||||||
backboxes[i] = bb;
|
backboxes[i] = bb;
|
||||||
backboxvx[i] = bvx;
|
backboxvx[i] = bvx;
|
||||||
backboxvy[i] = bvy;
|
backboxvy[i] = bvy;
|
||||||
backboxint[i] = bint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backboxmult = 0.5 + ((fRandom() * 100) / 200);
|
||||||
|
|
||||||
backoffset = 0;
|
backoffset = 0;
|
||||||
foregrounddrawn = false;
|
foregrounddrawn = false;
|
||||||
backgrounddrawn = false;
|
backgrounddrawn = false;
|
||||||
|
@ -2323,8 +2322,6 @@ void Graphics::drawbackground( int t )
|
||||||
fill_rect(0, 0, 0);
|
fill_rect(0, 0, 0);
|
||||||
for (int i = 0; i < numstars; i++)
|
for (int i = 0; i < numstars; i++)
|
||||||
{
|
{
|
||||||
stars[i].w = 2;
|
|
||||||
stars[i].h = 2;
|
|
||||||
SDL_Rect star_rect = stars[i];
|
SDL_Rect star_rect = stars[i];
|
||||||
star_rect.x = lerp(star_rect.x + starsspeed[i], star_rect.x);
|
star_rect.x = lerp(star_rect.x + starsspeed[i], star_rect.x);
|
||||||
if (starsspeed[i] <= 6)
|
if (starsspeed[i] <= 6)
|
||||||
|
@ -2349,62 +2346,62 @@ void Graphics::drawbackground( int t )
|
||||||
{
|
{
|
||||||
//Akward ordering to match tileset
|
//Akward ordering to match tileset
|
||||||
case 0:
|
case 0:
|
||||||
bcol2 = getRGB(0, 16*backboxint[0], 16*backboxint[0]);
|
bcol2 = getRGB(0, 16*backboxmult, 16*backboxmult);
|
||||||
break; //Cyan
|
break; //Cyan
|
||||||
case 1:
|
case 1:
|
||||||
bcol2 = getRGB(16*backboxint[0], 0, 0);
|
bcol2 = getRGB(16*backboxmult, 0, 0);
|
||||||
break; //Red
|
break; //Red
|
||||||
case 2:
|
case 2:
|
||||||
bcol2 = getRGB(16*backboxint[0], 0, 16*backboxint[0]);
|
bcol2 = getRGB(16*backboxmult, 0, 16*backboxmult);
|
||||||
break; //Purple
|
break; //Purple
|
||||||
case 3:
|
case 3:
|
||||||
bcol2 = getRGB(0, 0, 16*backboxint[0]);
|
bcol2 = getRGB(0, 0, 16*backboxmult);
|
||||||
break; //Blue
|
break; //Blue
|
||||||
case 4:
|
case 4:
|
||||||
bcol2 = getRGB(16*backboxint[0], 16*backboxint[0], 0);
|
bcol2 = getRGB(16*backboxmult, 16*backboxmult, 0);
|
||||||
break; //Yellow
|
break; //Yellow
|
||||||
case 5:
|
case 5:
|
||||||
bcol2 = getRGB(0, 16 * backboxint[0], 0);
|
bcol2 = getRGB(0, 16 * backboxmult, 0);
|
||||||
break; //Green
|
break; //Green
|
||||||
case 6:
|
case 6:
|
||||||
//crazy case
|
//crazy case
|
||||||
switch(spcol)
|
switch(spcol)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
bcol2 = getRGB(0, 16*backboxint[0], 16*backboxint[0]);
|
bcol2 = getRGB(0, 16*backboxmult, 16*backboxmult);
|
||||||
break; //Cyan
|
break; //Cyan
|
||||||
case 1:
|
case 1:
|
||||||
bcol2 = getRGB(0, (spcoldel+1)*backboxint[0], 16*backboxint[0]);
|
bcol2 = getRGB(0, (spcoldel+1)*backboxmult, 16*backboxmult);
|
||||||
break; //Cyan
|
break; //Cyan
|
||||||
case 2:
|
case 2:
|
||||||
bcol2 = getRGB(0, 0, 16*backboxint[0]);
|
bcol2 = getRGB(0, 0, 16*backboxmult);
|
||||||
break; //Blue
|
break; //Blue
|
||||||
case 3:
|
case 3:
|
||||||
bcol2 = getRGB((16-spcoldel)*backboxint[0], 0, 16*backboxint[0]);
|
bcol2 = getRGB((16-spcoldel)*backboxmult, 0, 16*backboxmult);
|
||||||
break; //Blue
|
break; //Blue
|
||||||
case 4:
|
case 4:
|
||||||
bcol2 = getRGB(16*backboxint[0], 0, 16*backboxint[0]);
|
bcol2 = getRGB(16*backboxmult, 0, 16*backboxmult);
|
||||||
break; //Purple
|
break; //Purple
|
||||||
case 5:
|
case 5:
|
||||||
bcol2 = getRGB(16*backboxint[0], 0, (spcoldel+1)*backboxint[0]);
|
bcol2 = getRGB(16*backboxmult, 0, (spcoldel+1)*backboxmult);
|
||||||
break; //Purple
|
break; //Purple
|
||||||
case 6:
|
case 6:
|
||||||
bcol2 = getRGB(16*backboxint[0], 0, 0);
|
bcol2 = getRGB(16*backboxmult, 0, 0);
|
||||||
break; //Red
|
break; //Red
|
||||||
case 7:
|
case 7:
|
||||||
bcol2 = getRGB(16*backboxint[0], (16-spcoldel)*backboxint[0], 0);
|
bcol2 = getRGB(16*backboxmult, (16-spcoldel)*backboxmult, 0);
|
||||||
break; //Red
|
break; //Red
|
||||||
case 8:
|
case 8:
|
||||||
bcol2 = getRGB(16*backboxint[0], 16*backboxint[0], 0);
|
bcol2 = getRGB(16*backboxmult, 16*backboxmult, 0);
|
||||||
break; //Yellow
|
break; //Yellow
|
||||||
case 9:
|
case 9:
|
||||||
bcol2 = getRGB((spcoldel+1)*backboxint[0], 16*backboxint[0], 0);
|
bcol2 = getRGB((spcoldel+1)*backboxmult, 16*backboxmult, 0);
|
||||||
break; //Yellow
|
break; //Yellow
|
||||||
case 10:
|
case 10:
|
||||||
bcol2 = getRGB(0, 16 * backboxint[0], 0);
|
bcol2 = getRGB(0, 16 * backboxmult, 0);
|
||||||
break; //Green
|
break; //Green
|
||||||
case 11:
|
case 11:
|
||||||
bcol2 = getRGB(0, 16 * backboxint[0], (16-spcoldel)*backboxint[0]);
|
bcol2 = getRGB(0, 16 * backboxmult, (16-spcoldel)*backboxmult);
|
||||||
break; //Green
|
break; //Green
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2417,62 +2414,62 @@ void Graphics::drawbackground( int t )
|
||||||
{
|
{
|
||||||
//Akward ordering to match tileset
|
//Akward ordering to match tileset
|
||||||
case 0:
|
case 0:
|
||||||
bcol = getRGB(16, 128*backboxint[0], 128*backboxint[0]);
|
bcol = getRGB(16, 128*backboxmult, 128*backboxmult);
|
||||||
break; //Cyan
|
break; //Cyan
|
||||||
case 1:
|
case 1:
|
||||||
bcol = getRGB(128*backboxint[0], 16, 16);
|
bcol = getRGB(128*backboxmult, 16, 16);
|
||||||
break; //Red
|
break; //Red
|
||||||
case 2:
|
case 2:
|
||||||
bcol = getRGB(128*backboxint[0], 16, 128*backboxint[0]);
|
bcol = getRGB(128*backboxmult, 16, 128*backboxmult);
|
||||||
break; //Purple
|
break; //Purple
|
||||||
case 3:
|
case 3:
|
||||||
bcol = getRGB(16, 16, 128*backboxint[0]);
|
bcol = getRGB(16, 16, 128*backboxmult);
|
||||||
break; //Blue
|
break; //Blue
|
||||||
case 4:
|
case 4:
|
||||||
bcol = getRGB(128*backboxint[0], 128*backboxint[0], 16);
|
bcol = getRGB(128*backboxmult, 128*backboxmult, 16);
|
||||||
break; //Yellow
|
break; //Yellow
|
||||||
case 5:
|
case 5:
|
||||||
bcol = getRGB(16, 128 * backboxint[0], 16);
|
bcol = getRGB(16, 128 * backboxmult, 16);
|
||||||
break; //Green
|
break; //Green
|
||||||
case 6:
|
case 6:
|
||||||
//crazy case
|
//crazy case
|
||||||
switch(spcol)
|
switch(spcol)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
bcol = getRGB(16, 128*backboxint[0], 128*backboxint[0]);
|
bcol = getRGB(16, 128*backboxmult, 128*backboxmult);
|
||||||
break; //Cyan
|
break; //Cyan
|
||||||
case 1:
|
case 1:
|
||||||
bcol = getRGB(16, ((spcoldel+1)*8)*backboxint[0], 128*backboxint[0]);
|
bcol = getRGB(16, ((spcoldel+1)*8)*backboxmult, 128*backboxmult);
|
||||||
break; //Cyan
|
break; //Cyan
|
||||||
case 2:
|
case 2:
|
||||||
bcol = getRGB(16, 16, 128*backboxint[0]);
|
bcol = getRGB(16, 16, 128*backboxmult);
|
||||||
break; //Blue
|
break; //Blue
|
||||||
case 3:
|
case 3:
|
||||||
bcol = getRGB((128-(spcoldel*8))*backboxint[0], 16, 128*backboxint[0]);
|
bcol = getRGB((128-(spcoldel*8))*backboxmult, 16, 128*backboxmult);
|
||||||
break; //Blue
|
break; //Blue
|
||||||
case 4:
|
case 4:
|
||||||
bcol = getRGB(128*backboxint[0], 16, 128*backboxint[0]);
|
bcol = getRGB(128*backboxmult, 16, 128*backboxmult);
|
||||||
break; //Purple
|
break; //Purple
|
||||||
case 5:
|
case 5:
|
||||||
bcol = getRGB(128*backboxint[0], 16, ((spcoldel+1)*8)*backboxint[0]);
|
bcol = getRGB(128*backboxmult, 16, ((spcoldel+1)*8)*backboxmult);
|
||||||
break; //Purple
|
break; //Purple
|
||||||
case 6:
|
case 6:
|
||||||
bcol = getRGB(128*backboxint[0], 16, 16);
|
bcol = getRGB(128*backboxmult, 16, 16);
|
||||||
break; //Red
|
break; //Red
|
||||||
case 7:
|
case 7:
|
||||||
bcol = getRGB(128*backboxint[0], (128-(spcoldel*8))*backboxint[0], 16);
|
bcol = getRGB(128*backboxmult, (128-(spcoldel*8))*backboxmult, 16);
|
||||||
break; //Red
|
break; //Red
|
||||||
case 8:
|
case 8:
|
||||||
bcol = getRGB(128*backboxint[0], 128*backboxint[0], 16);
|
bcol = getRGB(128*backboxmult, 128*backboxmult, 16);
|
||||||
break; //Yellow
|
break; //Yellow
|
||||||
case 9:
|
case 9:
|
||||||
bcol = getRGB(((spcoldel+1)*8)*backboxint[0], 128*backboxint[0], 16);
|
bcol = getRGB(((spcoldel+1)*8)*backboxmult, 128*backboxmult, 16);
|
||||||
break; //Yellow
|
break; //Yellow
|
||||||
case 10:
|
case 10:
|
||||||
bcol = getRGB(16, 128 * backboxint[0], 16);
|
bcol = getRGB(16, 128 * backboxmult, 16);
|
||||||
break; //Green
|
break; //Green
|
||||||
case 11:
|
case 11:
|
||||||
bcol = getRGB(16, 128 * backboxint[0], (128-(spcoldel*8))*backboxint[0]);
|
bcol = getRGB(16, 128 * backboxmult, (128-(spcoldel*8))*backboxmult);
|
||||||
break; //Green
|
break; //Green
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2573,8 +2570,6 @@ void Graphics::drawbackground( int t )
|
||||||
fill_rect(0, 0, 0);
|
fill_rect(0, 0, 0);
|
||||||
for (int i = 0; i < numstars; i++)
|
for (int i = 0; i < numstars; i++)
|
||||||
{
|
{
|
||||||
stars[i].w = 2;
|
|
||||||
stars[i].h = 2;
|
|
||||||
SDL_Rect star_rect = stars[i];
|
SDL_Rect star_rect = stars[i];
|
||||||
star_rect.y = lerp(star_rect.y + starsspeed[i], star_rect.y);
|
star_rect.y = lerp(star_rect.y + starsspeed[i], star_rect.y);
|
||||||
if (starsspeed[i] <= 8)
|
if (starsspeed[i] <= 8)
|
||||||
|
@ -2632,15 +2627,12 @@ void Graphics::updatebackground(int t)
|
||||||
//Starfield
|
//Starfield
|
||||||
for (int i = 0; i < numstars; i++)
|
for (int i = 0; i < numstars; i++)
|
||||||
{
|
{
|
||||||
stars[i].w = 2;
|
|
||||||
stars[i].h = 2;
|
|
||||||
stars[i].x -= starsspeed[i];
|
stars[i].x -= starsspeed[i];
|
||||||
if (stars[i].x < -10)
|
if (stars[i].x < -10)
|
||||||
{
|
{
|
||||||
stars[i].x += 340;
|
stars[i].x += 340;
|
||||||
stars[i].y = int(fRandom() * 240);
|
stars[i].y = (int) fRandom() * 240;
|
||||||
stars[i].w = 2;
|
starsspeed[i] = 4 + (int) (fRandom() * 4);
|
||||||
starsspeed[i] = 4+int(fRandom()*4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2783,14 +2775,12 @@ void Graphics::updatebackground(int t)
|
||||||
//Final Starfield
|
//Final Starfield
|
||||||
for (int i = 0; i < numstars; i++)
|
for (int i = 0; i < numstars; i++)
|
||||||
{
|
{
|
||||||
stars[i].w = 2;
|
|
||||||
stars[i].h = 2;
|
|
||||||
stars[i].y -= starsspeed[i];
|
stars[i].y -= starsspeed[i];
|
||||||
if (stars[i].y < -10)
|
if (stars[i].y < -10)
|
||||||
{
|
{
|
||||||
stars[i].y += 260;
|
stars[i].y += 260;
|
||||||
stars[i].x = fRandom() * 320;
|
stars[i].x = fRandom() * 320;
|
||||||
starsspeed[i] = 5+(fRandom()*5);
|
starsspeed[i] = 5 + (fRandom() * 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -399,7 +399,7 @@ public:
|
||||||
SDL_Rect backboxes[numbackboxes];
|
SDL_Rect backboxes[numbackboxes];
|
||||||
int backboxvx[numbackboxes];
|
int backboxvx[numbackboxes];
|
||||||
int backboxvy[numbackboxes];
|
int backboxvy[numbackboxes];
|
||||||
float backboxint[numbackboxes];
|
float backboxmult;
|
||||||
|
|
||||||
int warpskip;
|
int warpskip;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue