1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-05 10:49:41 +01:00

Refactor tower background to use a separate object instead

Previously, the tower background was controlled by a disparate set of
attributes on Graphics and mapclass, and wasn't really encapsulated. (If
that's what that word means, I don't particularly care about
object-oriented lingo.) But now, all relevant things that a tower
background has has been put into a TowerBG struct, so it will be easy to
make multiple copies without having to duplicate the code that handles
it.
This commit is contained in:
Misa 2020-11-02 15:05:24 -08:00 committed by Ethan Lee
parent 20207e2098
commit 72c048d71e
12 changed files with 198 additions and 185 deletions

View file

@ -1373,7 +1373,7 @@ void Game::updatestate()
gamestate = TITLEMODE; gamestate = TITLEMODE;
graphics.fademode = 4; graphics.fademode = 4;
graphics.backgrounddrawn = true; graphics.backgrounddrawn = true;
map.tdrawback = true; graphics.towerbg.tdrawback = true;
createmenu(Menu::timetrialcomplete); createmenu(Menu::timetrialcomplete);
state = 0; state = 0;
break; break;
@ -2942,7 +2942,7 @@ void Game::updatestate()
gamestate = TITLEMODE; gamestate = TITLEMODE;
graphics.fademode = 4; graphics.fademode = 4;
graphics.backgrounddrawn = true; graphics.backgrounddrawn = true;
map.tdrawback = true; graphics.towerbg.tdrawback = true;
music.play(6); music.play(6);
state = 0; state = 0;
break; break;
@ -3278,7 +3278,7 @@ void Game::updatestate()
gamestate = TITLEMODE; gamestate = TITLEMODE;
graphics.fademode = 4; graphics.fademode = 4;
graphics.backgrounddrawn = true; graphics.backgrounddrawn = true;
map.tdrawback = true; graphics.towerbg.tdrawback = true;
createmenu(Menu::nodeathmodecomplete); createmenu(Menu::nodeathmodecomplete);
state = 0; state = 0;
break; break;
@ -7129,7 +7129,7 @@ void Game::quittomenu()
FILESYSTEM_unmountassets(); // should be before music.play(6) FILESYSTEM_unmountassets(); // should be before music.play(6)
music.play(6); music.play(6);
graphics.backgrounddrawn = false; graphics.backgrounddrawn = false;
map.tdrawback = true; graphics.towerbg.tdrawback = true;
graphics.flipmode = false; graphics.flipmode = false;
//Don't be stuck on the summary screen, //Don't be stuck on the summary screen,
//or "who do you want to play the level with?" //or "who do you want to play the level with?"
@ -7223,7 +7223,7 @@ void Game::returntoeditor()
ed.level[i+(j*ed.maxwidth)].warpdir=ed.kludgewarpdir[i+(j*ed.maxwidth)]; ed.level[i+(j*ed.maxwidth)].warpdir=ed.kludgewarpdir[i+(j*ed.maxwidth)];
} }
} }
map.scrolldir = 0; graphics.towerbg.scrolldir = 0;
} }
#endif #endif
@ -7233,7 +7233,7 @@ void Game::returntopausemenu()
returntomenu(kludge_ingametemp); returntomenu(kludge_ingametemp);
gamestate = MAPMODE; gamestate = MAPMODE;
map.kludge_to_bg(); map.kludge_to_bg();
map.tdrawback = true; graphics.towerbg.tdrawback = true;
graphics.backgrounddrawn = false; graphics.backgrounddrawn = false;
mapheld = true; mapheld = true;
graphics.flipmode = graphics.setflipmode; graphics.flipmode = graphics.setflipmode;

View file

@ -115,10 +115,9 @@ void Graphics::init()
menubuffer = NULL; menubuffer = NULL;
screenbuffer = NULL; screenbuffer = NULL;
tempBuffer = NULL; tempBuffer = NULL;
towerbuffer = NULL;
towerbuffer_lerp = NULL;
footerbuffer = NULL; footerbuffer = NULL;
ghostbuffer = NULL; ghostbuffer = NULL;
towerbg = TowerBG();
trinketr = 0; trinketr = 0;
trinketg = 0; trinketg = 0;
trinketb = 0; trinketb = 0;
@ -736,13 +735,13 @@ void Graphics::drawtowertile( int x, int y, int t )
x += 8; x += 8;
y += 8; y += 8;
SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h }; SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
BlitSurfaceStandard(tiles2[t], NULL, towerbuffer, &rect); BlitSurfaceStandard(tiles2[t], NULL, towerbg.buffer, &rect);
} }
void Graphics::drawtowertile3( int x, int y, int t, int off ) void Graphics::drawtowertile3( int x, int y, int t, TowerBG& bg_obj )
{ {
t += off*30; t += bg_obj.colstate*30;
if (!INBOUNDS_VEC(t, tiles3)) if (!INBOUNDS_VEC(t, tiles3))
{ {
WHINE_ONCE("drawtowertile3() out-of-bounds!") WHINE_ONCE("drawtowertile3() out-of-bounds!")
@ -751,7 +750,7 @@ void Graphics::drawtowertile3( int x, int y, int t, int off )
x += 8; x += 8;
y += 8; y += 8;
SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h }; SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
BlitSurfaceStandard(tiles3[t], NULL, towerbuffer, &rect); BlitSurfaceStandard(tiles3[t], NULL, bg_obj.buffer, &rect);
} }
void Graphics::drawgui() void Graphics::drawgui()
@ -2116,15 +2115,15 @@ void Graphics::drawbackground( int t )
} }
case 3: //Warp zone (horizontal) case 3: //Warp zone (horizontal)
FillRect(backBuffer, 0x000000); FillRect(backBuffer, 0x000000);
BlitSurfaceStandard(towerbuffer, NULL, towerbuffer_lerp, NULL); BlitSurfaceStandard(towerbg.buffer, NULL, towerbg.buffer_lerp, NULL);
ScrollSurface(towerbuffer_lerp, lerp(0, -3), 0); ScrollSurface(towerbg.buffer_lerp, lerp(0, -3), 0);
BlitSurfaceStandard(towerbuffer_lerp, &towerbuffer_rect, backBuffer, NULL); BlitSurfaceStandard(towerbg.buffer_lerp, &towerbuffer_rect, backBuffer, NULL);
break; break;
case 4: //Warp zone (vertical) case 4: //Warp zone (vertical)
FillRect(backBuffer, 0x000000); FillRect(backBuffer, 0x000000);
SDL_BlitSurface(towerbuffer, NULL, towerbuffer_lerp, NULL); SDL_BlitSurface(towerbg.buffer, NULL, towerbg.buffer_lerp, NULL);
ScrollSurface(towerbuffer_lerp, 0, lerp(0, -3)); ScrollSurface(towerbg.buffer_lerp, 0, lerp(0, -3));
SDL_BlitSurface(towerbuffer_lerp, &towerbuffer_rect, backBuffer, NULL); SDL_BlitSurface(towerbg.buffer_lerp, &towerbuffer_rect, backBuffer, NULL);
break; break;
case 5: case 5:
//Warp zone, central //Warp zone, central
@ -2301,7 +2300,7 @@ void Graphics::updatebackground(int t)
if (backgrounddrawn) if (backgrounddrawn)
{ {
ScrollSurface(towerbuffer, -3, 0 ); ScrollSurface(towerbg.buffer, -3, 0 );
for (int j = 0; j < 15; j++) for (int j = 0; j < 15; j++)
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
@ -2317,7 +2316,7 @@ void Graphics::updatebackground(int t)
{ {
//draw the whole thing for the first time! //draw the whole thing for the first time!
backoffset = 0; backoffset = 0;
FillRect(towerbuffer, 0x000000); FillRect(towerbg.buffer, 0x000000);
for (int j = 0; j < 15; j++) for (int j = 0; j < 15; j++)
{ {
for (int i = 0; i < 21; i++) for (int i = 0; i < 21; i++)
@ -2340,7 +2339,7 @@ void Graphics::updatebackground(int t)
if (backgrounddrawn) if (backgrounddrawn)
{ {
ScrollSurface(towerbuffer,0,-3); ScrollSurface(towerbg.buffer,0,-3);
for (int j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
{ {
for (int i = 0; i < 21; i++) for (int i = 0; i < 21; i++)
@ -2356,7 +2355,7 @@ void Graphics::updatebackground(int t)
{ {
//draw the whole thing for the first time! //draw the whole thing for the first time!
backoffset = 0; backoffset = 0;
FillRect(towerbuffer,0x000000 ); FillRect(towerbg.buffer,0x000000 );
for (int j = 0; j < 16; j++) for (int j = 0; j < 16; j++)
{ {
for (int i = 0; i < 21; i++) for (int i = 0; i < 21; i++)
@ -2474,7 +2473,7 @@ void Graphics::drawtowermap()
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
{ {
temp = map.tower.at(i, j, yoff); temp = map.tower.at(i, j, yoff);
if (temp > 0) drawtile3(i * 8, (j * 8) - (yoff % 8), temp, map.colstate); if (temp > 0) drawtile3(i * 8, (j * 8) - (yoff % 8), temp, towerbg.colstate);
} }
} }
} }
@ -2485,66 +2484,66 @@ void Graphics::drawtowerspikes()
int spikelevelbottom = lerp(map.oldspikelevelbottom, map.spikelevelbottom); int spikelevelbottom = lerp(map.oldspikelevelbottom, map.spikelevelbottom);
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
{ {
drawtile3(i * 8, -8+spikeleveltop, 9, map.colstate); drawtile3(i * 8, -8+spikeleveltop, 9, towerbg.colstate);
drawtile3(i * 8, 230-spikelevelbottom, 8, map.colstate, 8 - spikelevelbottom); drawtile3(i * 8, 230-spikelevelbottom, 8, towerbg.colstate, 8 - spikelevelbottom);
} }
} }
void Graphics::drawtowerbackground() void Graphics::drawtowerbackground(const TowerBG& bg_obj)
{ {
FillRect(backBuffer, 0x000000); FillRect(backBuffer, 0x000000);
SDL_BlitSurface(towerbuffer, NULL, towerbuffer_lerp, NULL); SDL_BlitSurface(bg_obj.buffer, NULL, bg_obj.buffer_lerp, NULL);
ScrollSurface(towerbuffer_lerp, 0, lerp(0, -map.bscroll)); ScrollSurface(bg_obj.buffer_lerp, 0, lerp(0, -bg_obj.bscroll));
SDL_BlitSurface(towerbuffer_lerp, &towerbuffer_rect, backBuffer, NULL); SDL_BlitSurface(bg_obj.buffer_lerp, &towerbuffer_rect, backBuffer, NULL);
} }
void Graphics::updatetowerbackground() void Graphics::updatetowerbackground(TowerBG& bg_obj)
{ {
int temp; int temp;
if (map.bypos < 0) map.bypos += 120 * 8; if (bg_obj.bypos < 0) bg_obj.bypos += 120 * 8;
if (map.tdrawback) if (bg_obj.tdrawback)
{ {
int off = map.scrolldir == 0 ? 0 : map.bscroll; int off = bg_obj.scrolldir == 0 ? 0 : bg_obj.bscroll;
//Draw the whole thing; needed for every colour cycle! //Draw the whole thing; needed for every colour cycle!
for (int j = -1; j < 32; j++) for (int j = -1; j < 32; j++)
{ {
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
{ {
temp = map.tower.backat(i, j, map.bypos); temp = map.tower.backat(i, j, bg_obj.bypos);
drawtowertile3(i * 8, (j * 8) - (map.bypos % 8) - off, temp, map.colstate); drawtowertile3(i * 8, (j * 8) - (bg_obj.bypos % 8) - off, temp, bg_obj);
} }
} }
map.tdrawback = false; bg_obj.tdrawback = false;
} }
else else
{ {
//just update the bottom //just update the bottom
ScrollSurface(towerbuffer, 0, -map.bscroll); ScrollSurface(bg_obj.buffer, 0, -bg_obj.bscroll);
if (map.scrolldir == 0) if (bg_obj.scrolldir == 0)
{ {
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
{ {
temp = map.tower.backat(i, -1, map.bypos); temp = map.tower.backat(i, -1, bg_obj.bypos);
drawtowertile3(i * 8, -1*8 - (map.bypos % 8), temp, map.colstate); drawtowertile3(i * 8, -1*8 - (bg_obj.bypos % 8), temp, bg_obj);
temp = map.tower.backat(i, 0, map.bypos); temp = map.tower.backat(i, 0, bg_obj.bypos);
drawtowertile3(i * 8, -(map.bypos % 8), temp, map.colstate); drawtowertile3(i * 8, -(bg_obj.bypos % 8), temp, bg_obj);
} }
} }
else else
{ {
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
{ {
temp = map.tower.backat(i, 29, map.bypos); temp = map.tower.backat(i, 29, bg_obj.bypos);
drawtowertile3(i * 8, 29*8 - (map.bypos % 8) - map.bscroll, temp, map.colstate); drawtowertile3(i * 8, 29*8 - (bg_obj.bypos % 8) - bg_obj.bscroll, temp, bg_obj);
temp = map.tower.backat(i, 30, map.bypos); temp = map.tower.backat(i, 30, bg_obj.bypos);
drawtowertile3(i * 8, 30*8 - (map.bypos % 8) - map.bscroll, temp, map.colstate); drawtowertile3(i * 8, 30*8 - (bg_obj.bypos % 8) - bg_obj.bscroll, temp, bg_obj);
temp = map.tower.backat(i, 31, map.bypos); temp = map.tower.backat(i, 31, bg_obj.bypos);
drawtowertile3(i * 8, 31*8 - (map.bypos % 8) - map.bscroll, temp, map.colstate); drawtowertile3(i * 8, 31*8 - (bg_obj.bypos % 8) - bg_obj.bscroll, temp, bg_obj);
temp = map.tower.backat(i, 32, map.bypos); temp = map.tower.backat(i, 32, bg_obj.bypos);
drawtowertile3(i * 8, 32*8 - (map.bypos % 8) - map.bscroll, temp, map.colstate); drawtowertile3(i * 8, 32*8 - (bg_obj.bypos % 8) - bg_obj.bscroll, temp, bg_obj);
} }
} }
} }

View file

@ -11,6 +11,7 @@
#include "Maths.h" #include "Maths.h"
#include "Screen.h" #include "Screen.h"
#include "Textbox.h" #include "Textbox.h"
#include "TowerBG.h"
class Graphics class Graphics
{ {
@ -168,7 +169,7 @@ public:
void drawtile2( int x, int y, int t ); void drawtile2( int x, int y, int t );
void drawtile( int x, int y, int t ); void drawtile( int x, int y, int t );
void drawtowertile( int x, int y, int t ); void drawtowertile( int x, int y, int t );
void drawtowertile3( int x, int y, int t, int off ); void drawtowertile3( int x, int y, int t, TowerBG& bg_obj );
void drawmap(); void drawmap();
@ -192,8 +193,8 @@ public:
void menuoffrender(); void menuoffrender();
void drawtowerbackground(); void drawtowerbackground(const TowerBG& bg_obj);
void updatetowerbackground(); void updatetowerbackground(TowerBG& bg_obj);
void setcol(int t); void setcol(int t);
void drawfinalmap(); void drawfinalmap();
@ -225,11 +226,11 @@ public:
SDL_Surface* backBuffer; SDL_Surface* backBuffer;
Screen* screenbuffer; Screen* screenbuffer;
SDL_Surface* menubuffer; SDL_Surface* menubuffer;
SDL_Surface* towerbuffer;
SDL_Surface* towerbuffer_lerp;
SDL_Surface* foregroundBuffer; SDL_Surface* foregroundBuffer;
SDL_Surface* tempBuffer; SDL_Surface* tempBuffer;
TowerBG towerbg;
SDL_Rect bfont_rect; SDL_Rect bfont_rect;
SDL_Rect tiles_rect; SDL_Rect tiles_rect;
SDL_Rect sprites_rect; SDL_Rect sprites_rect;

View file

@ -579,7 +579,7 @@ void menuactionpress()
//disable animated backgrounds //disable animated backgrounds
game.colourblindmode = !game.colourblindmode; game.colourblindmode = !game.colourblindmode;
game.savestats(); game.savestats();
map.tdrawback = true; graphics.towerbg.tdrawback = true;
music.playef(11); music.playef(11);
break; break;
case 1: case 1:
@ -1683,7 +1683,7 @@ void titleinput()
music.playef(18); music.playef(18);
game.screenshake = 10; game.screenshake = 10;
game.flashlight = 5; game.flashlight = 5;
map.colstate = 10; graphics.towerbg.colstate = 10;
map.nexttowercolour(); map.nexttowercolour();
} }
else else
@ -2381,13 +2381,13 @@ void mapmenuactionpress()
map.bg_to_kludge(); map.bg_to_kludge();
game.kludge_ingametemp = game.currentmenuname; game.kludge_ingametemp = game.currentmenuname;
map.scrolldir = 0; graphics.towerbg.scrolldir = 0;
map.colstate = ((int) (map.colstate / 5)) * 5; graphics.towerbg.colstate = ((int) (graphics.towerbg.colstate / 5)) * 5;
map.bypos = 0; graphics.towerbg.bypos = 0;
map.nexttowercolour(); map.nexttowercolour();
// Fix delta rendering glitch // Fix delta rendering glitch
graphics.updatetowerbackground(); graphics.updatetowerbackground(graphics.towerbg);
titleupdatetextcol(); titleupdatetextcol();
break; break;
} }
@ -2536,11 +2536,11 @@ void gamecompleteinput()
//Do this before we update map.bypos //Do this before we update map.bypos
if (!game.colourblindmode) if (!game.colourblindmode)
{ {
graphics.updatetowerbackground(); graphics.updatetowerbackground(graphics.towerbg);
} }
//Do these here because input comes first //Do these here because input comes first
map.bypos += map.bscroll; graphics.towerbg.bypos += graphics.towerbg.bscroll;
game.oldcreditposition = game.creditposition; game.oldcreditposition = game.creditposition;
if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip)) if (key.isDown(KEYBOARD_z) || key.isDown(KEYBOARD_SPACE) || key.isDown(KEYBOARD_v) || key.isDown(game.controllerButton_flip))
@ -2556,7 +2556,7 @@ void gamecompleteinput()
} }
else else
{ {
map.bscroll = +7; graphics.towerbg.bscroll = +7;
} }
game.press_action = true; game.press_action = true;
} }

View file

@ -27,15 +27,15 @@ void titleupdatetextcol()
void titlelogic() void titlelogic()
{ {
//Misc //Misc
//map.updatetowerglow(); //map.updatetowerglow(graphics.towerbg);
help.updateglow(); help.updateglow();
map.bypos -= 2; graphics.towerbg.bypos -= 2;
map.bscroll = -2; graphics.towerbg.bscroll = -2;
if (!game.colourblindmode) if (!game.colourblindmode)
{ {
graphics.updatetowerbackground(); graphics.updatetowerbackground(graphics.towerbg);
} }
if (!game.menustart) if (!game.menustart)
@ -149,10 +149,10 @@ void maplogic()
void gamecompletelogic() void gamecompletelogic()
{ {
//Misc //Misc
map.updatetowerglow(); map.updatetowerglow(graphics.towerbg);
help.updateglow(); help.updateglow();
graphics.crewframe = 0; graphics.crewframe = 0;
map.scrolldir = 1; graphics.towerbg.scrolldir = 1;
graphics.updatetitlecolours(); graphics.updatetitlecolours();
graphics.col_tr = map.r - (help.glow / 4) - fRandom() * 4; graphics.col_tr = map.r - (help.glow / 4) - fRandom() * 4;
@ -169,11 +169,11 @@ void gamecompletelogic()
if (game.creditposition <= -Credits::creditmaxposition) if (game.creditposition <= -Credits::creditmaxposition)
{ {
game.creditposition = -Credits::creditmaxposition; game.creditposition = -Credits::creditmaxposition;
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} }
else if (!game.press_action) else if (!game.press_action)
{ {
map.bscroll = +1; graphics.towerbg.bscroll = +1;
} }
if (graphics.fademode == 1) if (graphics.fademode == 1)
@ -182,8 +182,8 @@ void gamecompletelogic()
graphics.showcutscenebars = false; graphics.showcutscenebars = false;
graphics.cutscenebarspos = 0; graphics.cutscenebarspos = 0;
graphics.oldcutscenebarspos = 0; graphics.oldcutscenebarspos = 0;
map.scrolldir = 0; graphics.towerbg.scrolldir = 0;
map.bypos = 0; graphics.towerbg.bypos = 0;
//Return to game //Return to game
game.gamestate = GAMECOMPLETE2; game.gamestate = GAMECOMPLETE2;
graphics.fademode = 4; graphics.fademode = 4;
@ -193,7 +193,7 @@ void gamecompletelogic()
void gamecompletelogic2() void gamecompletelogic2()
{ {
//Misc //Misc
map.updatetowerglow(); map.updatetowerglow(graphics.towerbg);
help.updateglow(); help.updateglow();
game.creditposdelay--; game.creditposdelay--;
@ -222,7 +222,7 @@ void gamecompletelogic2()
game.savetele(); game.savetele();
music.currentsong=tmp; music.currentsong=tmp;
//Return to game //Return to game
map.colstate = 10; graphics.towerbg.colstate = 10;
game.gamestate = TITLEMODE; game.gamestate = TITLEMODE;
graphics.fademode = 4; graphics.fademode = 4;
FILESYSTEM_unmountassets(); // should be before music.playef(18) FILESYSTEM_unmountassets(); // should be before music.playef(18)
@ -267,7 +267,7 @@ void gamelogic()
//Misc //Misc
if (map.towermode) if (map.towermode)
{ {
map.updatetowerglow(); map.updatetowerglow(graphics.towerbg);
} }
help.updateglow(); help.updateglow();
@ -331,28 +331,28 @@ void gamelogic()
//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;
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} }
else if (map.cameramode == 1) else if (map.cameramode == 1)
{ {
//move normally //move normally
if(map.scrolldir==0) if(graphics.towerbg.scrolldir==0)
{ {
map.ypos -= 2; map.ypos -= 2;
map.bypos -= 1; graphics.towerbg.bypos -= 1;
map.bscroll = -1; graphics.towerbg.bscroll = -1;
} }
else else
{ {
map.ypos += 2; map.ypos += 2;
map.bypos += 1; graphics.towerbg.bypos += 1;
map.bscroll = 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)
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} }
else if (map.cameramode == 4) else if (map.cameramode == 4)
{ {
@ -367,7 +367,7 @@ void gamelogic()
map.cameramode = 5; map.cameramode = 5;
map.bscroll = map.cameraseek/2; graphics.towerbg.bscroll = map.cameraseek/2;
} }
else if (map.cameramode == 5) else if (map.cameramode == 5)
{ {
@ -393,7 +393,7 @@ void gamelogic()
} }
} }
map.cameraseekframe--; map.cameraseekframe--;
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
} }
else else
{ {
@ -402,7 +402,7 @@ void gamelogic()
{ {
map.ypos = obj.entities[i].yp - 120; map.ypos = obj.entities[i].yp - 120;
} }
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
map.cameramode = 0; map.cameramode = 0;
map.colsuperstate = 0; map.colsuperstate = 0;
} }
@ -410,22 +410,22 @@ void gamelogic()
} }
else else
{ {
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} }
if (map.ypos <= 0) if (map.ypos <= 0)
{ {
map.ypos = 0; map.ypos = 0;
map.bypos = 0; graphics.towerbg.bypos = 0;
map.bscroll = 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;
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} //100-29 * 8 = 568 } //100-29 * 8 = 568
} }
else else
@ -433,7 +433,7 @@ void gamelogic()
if (map.ypos >= 5368) if (map.ypos >= 5368)
{ {
map.ypos = 5368; //700-29 * 8 = 5368 map.ypos = 5368; //700-29 * 8 = 5368
map.bypos = map.ypos / 2.0; graphics.towerbg.bypos = map.ypos / 2.0;
} }
} }
@ -998,14 +998,14 @@ void gamelogic()
if (obj.entities[player].yp-map.ypos <= 0) if (obj.entities[player].yp-map.ypos <= 0)
{ {
map.ypos-=10; map.ypos-=10;
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} }
else if (obj.entities[player].yp-map.ypos >= 208) else if (obj.entities[player].yp-map.ypos >= 208)
{ {
map.ypos+=2; map.ypos+=2;
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
map.bscroll = 0; graphics.towerbg.bscroll = 0;
} }
} }
@ -1207,7 +1207,7 @@ void gamelogic()
//Right so! Screenwraping for tower: //Right so! Screenwraping for tower:
if (map.towermode && map.minitowermode) if (map.towermode && map.minitowermode)
{ {
if (map.scrolldir == 1) if (graphics.towerbg.scrolldir == 1)
{ {
//This is minitower 1! //This is minitower 1!
int player = obj.getplayer(); int player = obj.getplayer();
@ -1712,7 +1712,7 @@ void gamelogic()
{ {
if (map.towermode) if (map.towermode)
{ {
graphics.updatetowerbackground(); graphics.updatetowerbackground(graphics.towerbg);
} }
else else
{ {

View file

@ -16,7 +16,6 @@ mapclass::mapclass()
r = 196; r = 196;
g = 196; g = 196;
b = 196; b = 196;
colstate = 0;
colstatedelay = 0; colstatedelay = 0;
colsuperstate = 0; colsuperstate = 0;
spikeleveltop = 0; spikeleveltop = 0;
@ -82,15 +81,11 @@ mapclass::mapclass()
ypos = 0; ypos = 0;
oldypos = 0; oldypos = 0;
bypos = 0;
background = 0; background = 0;
cameramode = 0; cameramode = 0;
cameraseek = 0; cameraseek = 0;
minitowermode = false; minitowermode = false;
scrolldir = 0;
tdrawback = false;
bscroll = 0;
roomtexton = false; roomtexton = false;
kludge_bypos = 0; kludge_bypos = 0;
kludge_colstate = 0; kludge_colstate = 0;
@ -581,15 +576,15 @@ void mapclass::setcol(const int r1, const int g1, const int b1 , const int r2, c
b = intpol(b1, b2, c / 5); b = intpol(b1, b2, c / 5);
} }
void mapclass::updatetowerglow() void mapclass::updatetowerglow(TowerBG& bg_obj)
{ {
if (colstatedelay <= 0 || colsuperstate > 0) if (colstatedelay <= 0 || colsuperstate > 0)
{ {
if (colsuperstate > 0) colstate--; if (colsuperstate > 0) bg_obj.colstate--;
colstate++; bg_obj.colstate++;
if (colstate >= 30) colstate = 0; if (bg_obj.colstate >= 30) bg_obj.colstate = 0;
int check = colstate % 5; //current state of phase int check = bg_obj.colstate % 5; //current state of phase
int cmode = (colstate - check) / 5; // current colour transition int cmode = (bg_obj.colstate - check) / 5; // current colour transition
switch(cmode) switch(cmode)
{ {
@ -623,7 +618,7 @@ void mapclass::updatetowerglow()
} }
if (colsuperstate > 0) colstatedelay = 0; if (colsuperstate > 0) colstatedelay = 0;
tdrawback = true; bg_obj.tdrawback = true;
} }
else else
{ {
@ -633,10 +628,10 @@ void mapclass::updatetowerglow()
void mapclass::nexttowercolour() void mapclass::nexttowercolour()
{ {
colstate+=5; graphics.towerbg.colstate+=5;
if (colstate >= 30) colstate = 0; if (graphics.towerbg.colstate >= 30) graphics.towerbg.colstate = 0;
int check = colstate % 5; //current state of phase int check = graphics.towerbg.colstate % 5; //current state of phase
int cmode = (colstate - check) / 5; // current colour transition int cmode = (graphics.towerbg.colstate - check) / 5; // current colour transition
switch(cmode) switch(cmode)
{ {
@ -660,15 +655,15 @@ void mapclass::nexttowercolour()
break; break;
} }
tdrawback = true; graphics.towerbg.tdrawback = true;
} }
void mapclass::settowercolour(int t) void mapclass::settowercolour(int t)
{ {
colstate=t*5; graphics.towerbg.colstate=t*5;
if (colstate >= 30) colstate = 0; if (graphics.towerbg.colstate >= 30) graphics.towerbg.colstate = 0;
int check = colstate % 5; //current state of phase int check = graphics.towerbg.colstate % 5; //current state of phase
int cmode = (colstate - check) / 5; // current colour transition int cmode = (graphics.towerbg.colstate - check) / 5; // current colour transition
switch(cmode) switch(cmode)
{ {
@ -692,7 +687,7 @@ void mapclass::settowercolour(int t)
break; break;
} }
tdrawback = true; graphics.towerbg.tdrawback = true;
} }
bool mapclass::spikecollide(int x, int y) bool mapclass::spikecollide(int x, int y)
@ -849,7 +844,7 @@ void mapclass::resetplayer()
ypos = 0; ypos = 0;
} }
oldypos = ypos; oldypos = ypos;
bypos = ypos / 2; graphics.towerbg.bypos = ypos / 2;
} }
} }
@ -1261,9 +1256,9 @@ void mapclass::loadlevel(int rx, int ry)
ypos = (700-29) * 8; ypos = (700-29) * 8;
oldypos = ypos; oldypos = ypos;
bypos = ypos / 2; graphics.towerbg.bypos = ypos / 2;
cameramode = 0; cameramode = 0;
colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
} }
else if (ry == 104) else if (ry == 104)
@ -1271,9 +1266,9 @@ 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;
bypos = 0; graphics.towerbg.bypos = 0;
cameramode = 0; cameramode = 0;
colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
} }
} }
@ -1351,17 +1346,17 @@ void mapclass::loadlevel(int rx, int ry)
break; break;
} }
case 3: //The Tower case 3: //The Tower
tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = false; minitowermode = false;
tower.minitowermode = false; tower.minitowermode = false;
bscroll = 0; graphics.towerbg.bscroll = 0;
scrolldir = 0; graphics.towerbg.scrolldir = 0;
roomname = "The Tower"; roomname = "The Tower";
tileset = 1; tileset = 1;
background = 3; background = 3;
towermode = true; towermode = true;
//bypos = 0; ypos = 0; cameramode = 0; //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
@ -1450,11 +1445,11 @@ void mapclass::loadlevel(int rx, int ry)
break; break;
} }
case 7: //Final Level, Tower 1 case 7: //Final Level, Tower 1
tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
bscroll = 0; graphics.towerbg.bscroll = 0;
scrolldir = 1; graphics.towerbg.scrolldir = 1;
roomname = "Panic Room"; roomname = "Panic Room";
tileset = 1; tileset = 1;
@ -1465,18 +1460,18 @@ void mapclass::loadlevel(int rx, int ry)
ypos = 0; ypos = 0;
oldypos = 0; oldypos = 0;
bypos = 0; graphics.towerbg.bypos = 0;
cameramode = 0; cameramode = 0;
colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
break; break;
case 8: //Final Level, Tower 1 (reentered from below) case 8: //Final Level, Tower 1 (reentered from below)
{ {
tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
bscroll = 0; graphics.towerbg.bscroll = 0;
scrolldir = 1; graphics.towerbg.scrolldir = 1;
roomname = "Panic Room"; roomname = "Panic Room";
tileset = 1; tileset = 1;
@ -1495,18 +1490,18 @@ void mapclass::loadlevel(int rx, int ry)
ypos = (100-29) * 8; ypos = (100-29) * 8;
oldypos = ypos; oldypos = ypos;
bypos = ypos/2; graphics.towerbg.bypos = ypos/2;
cameramode = 0; cameramode = 0;
colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0;} colsuperstate = 0;}
break; break;
case 9: //Final Level, Tower 2 case 9: //Final Level, Tower 2
{ {
tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
bscroll = 0; graphics.towerbg.bscroll = 0;
scrolldir = 0; graphics.towerbg.scrolldir = 0;
final_colorframe = 2; final_colorframe = 2;
roomname = "The Final Challenge"; roomname = "The Final Challenge";
@ -1540,20 +1535,20 @@ void mapclass::loadlevel(int rx, int ry)
ypos = (100-29) * 8; ypos = (100-29) * 8;
oldypos = ypos; oldypos = ypos;
bypos = ypos/2; graphics.towerbg.bypos = ypos/2;
cameramode = 0; cameramode = 0;
colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
break; break;
} }
case 10: //Final Level, Tower 2 case 10: //Final Level, Tower 2
{ {
tdrawback = true; graphics.towerbg.tdrawback = true;
minitowermode = true; minitowermode = true;
tower.minitowermode = true; tower.minitowermode = true;
bscroll = 0; graphics.towerbg.bscroll = 0;
scrolldir = 0; graphics.towerbg.scrolldir = 0;
final_colorframe = 2; final_colorframe = 2;
roomname = "The Final Challenge"; roomname = "The Final Challenge";
@ -1579,9 +1574,9 @@ void mapclass::loadlevel(int rx, int ry)
ypos = 0; ypos = 0;
oldypos = 0; oldypos = 0;
bypos = 0; graphics.towerbg.bypos = 0;
cameramode = 0; cameramode = 0;
colstate = 0; graphics.towerbg.colstate = 0;
colsuperstate = 0; colsuperstate = 0;
break; break;
} }
@ -2114,3 +2109,17 @@ void mapclass::twoframedelayfix()
script.dontrunnextframe = true; script.dontrunnextframe = true;
} }
} }
void mapclass::bg_to_kludge()
{
kludge_bypos = graphics.towerbg.bypos;
kludge_colstate = graphics.towerbg.colstate;
kludge_scrolldir = graphics.towerbg.scrolldir;
}
void mapclass::kludge_to_bg()
{
graphics.towerbg.bypos = kludge_bypos;
graphics.towerbg.colstate = kludge_colstate;
graphics.towerbg.scrolldir = kludge_scrolldir;
}

View file

@ -9,6 +9,7 @@
#include "Otherlevel.h" #include "Otherlevel.h"
#include "Spacestation2.h" #include "Spacestation2.h"
#include "Tower.h" #include "Tower.h"
#include "TowerBG.h"
#include "WarpClass.h" #include "WarpClass.h"
struct Roomtext struct Roomtext
@ -47,7 +48,7 @@ public:
void setcol(const int r1, const int g1, const int b1 , const int r2, const int g2, const int b2, const int c); void setcol(const int r1, const int g1, const int b1 , const int r2, const int g2, const int b2, const int c);
void updatetowerglow(); void updatetowerglow(TowerBG& bg_obj);
void nexttowercolour(); void nexttowercolour();
@ -102,21 +103,17 @@ public:
bool towermode; bool towermode;
float ypos; float ypos;
float oldypos; float oldypos;
int bypos;
int cameramode; int cameramode;
int cameraseek, cameraseekframe; int cameraseek, cameraseekframe;
int resumedelay; int resumedelay;
bool minitowermode; bool minitowermode;
int scrolldir;
//This is the old colour cycle //This is the old colour cycle
int r, g,b; int r, g,b;
int colstate, colstatedelay; int colstatedelay;
int colsuperstate; int colsuperstate;
int spikeleveltop, spikelevelbottom; int spikeleveltop, spikelevelbottom;
int oldspikeleveltop, oldspikelevelbottom; int oldspikeleveltop, oldspikelevelbottom;
bool tdrawback;
int bscroll;
//final level navigation //final level navigation
int finalx; int finalx;
int finaly; int finaly;
@ -172,18 +169,8 @@ public:
int kludge_bypos; int kludge_bypos;
int kludge_colstate; int kludge_colstate;
int kludge_scrolldir; int kludge_scrolldir;
void inline bg_to_kludge() void bg_to_kludge();
{ void kludge_to_bg();
kludge_bypos = bypos;
kludge_colstate = colstate;
kludge_scrolldir = scrolldir;
}
void inline kludge_to_bg()
{
bypos = kludge_bypos;
colstate = kludge_colstate;
scrolldir = kludge_scrolldir;
}
}; };
#ifndef MAP_DEFINITION #ifndef MAP_DEFINITION

View file

@ -1182,7 +1182,7 @@ void titlerender()
} }
else else
{ {
if(!game.colourblindmode) graphics.drawtowerbackground(); if(!game.colourblindmode) graphics.drawtowerbackground(graphics.towerbg);
tr = graphics.col_tr; tr = graphics.col_tr;
tg = graphics.col_tg; tg = graphics.col_tg;
@ -1211,7 +1211,7 @@ void gamecompleterender()
{ {
FillRect(graphics.backBuffer, 0x000000); FillRect(graphics.backBuffer, 0x000000);
if(!game.colourblindmode) graphics.drawtowerbackground(); if(!game.colourblindmode) graphics.drawtowerbackground(graphics.towerbg);
tr = graphics.col_tr; tr = graphics.col_tr;
tg = graphics.col_tg; tg = graphics.col_tg;
@ -1397,7 +1397,7 @@ void gamerender()
{ {
if (!game.colourblindmode) if (!game.colourblindmode)
{ {
graphics.drawtowerbackground(); graphics.drawtowerbackground(graphics.towerbg);
} }
else else
{ {

View file

@ -1537,7 +1537,7 @@ void scriptclass::run()
map.resetnames(); map.resetnames();
map.resetmap(); map.resetmap();
map.resetplayer(); map.resetplayer();
map.tdrawback = true; graphics.towerbg.tdrawback = true;
obj.resetallflags(); obj.resetallflags();
i = obj.getplayer(); i = obj.getplayer();
@ -2642,7 +2642,7 @@ void scriptclass::resetgametomenu()
graphics.flipmode = false; graphics.flipmode = false;
obj.entities.clear(); obj.entities.clear();
graphics.fademode = 4; graphics.fademode = 4;
map.tdrawback = true; graphics.towerbg.tdrawback = true;
game.createmenu(Menu::gameover); game.createmenu(Menu::gameover);
} }
@ -2732,7 +2732,7 @@ void scriptclass::startgamemode( int t )
{ {
map.ypos = obj.entities[i].yp - 120; map.ypos = obj.entities[i].yp - 120;
} }
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
map.cameramode = 0; map.cameramode = 0;
map.colsuperstate = 0; map.colsuperstate = 0;
} }
@ -3714,7 +3714,7 @@ void scriptclass::hardreset()
} }
map.cameraseekframe = 0; map.cameraseekframe = 0;
map.resumedelay = 0; map.resumedelay = 0;
map.scrolldir = 0; graphics.towerbg.scrolldir = 0;
map.customshowmm=true; map.customshowmm=true;
SDL_memset(map.roomdeaths, 0, sizeof(map.roomdeaths)); SDL_memset(map.roomdeaths, 0, sizeof(map.roomdeaths));

View file

@ -0,0 +1,17 @@
#ifndef TOWERBG_H
#define TOWERBG_H
#include <SDL.h>
struct TowerBG
{
SDL_Surface* buffer;
SDL_Surface* buffer_lerp;
bool tdrawback;
int bypos;
int bscroll;
int colstate;
int scrolldir;
};
#endif /* TOWERBG_H */

View file

@ -3292,7 +3292,7 @@ void editorrender()
{ {
if(!game.colourblindmode) if(!game.colourblindmode)
{ {
graphics.drawtowerbackground(); graphics.drawtowerbackground(graphics.towerbg);
} }
else else
{ {
@ -3679,8 +3679,8 @@ void editorlogic()
game.shouldreturntoeditor = false; game.shouldreturntoeditor = false;
} }
map.bypos -= 2; graphics.towerbg.bypos -= 2;
map.bscroll = -2; graphics.towerbg.bscroll = -2;
ed.entframedelay--; ed.entframedelay--;
if(ed.entframedelay<=0) if(ed.entframedelay<=0)
@ -3740,14 +3740,14 @@ void editorlogic()
} }
else if (!game.colourblindmode) else if (!game.colourblindmode)
{ {
graphics.updatetowerbackground(); graphics.updatetowerbackground(graphics.towerbg);
} }
if (graphics.fademode == 1) if (graphics.fademode == 1)
{ {
//Return to game //Return to game
map.nexttowercolour(); map.nexttowercolour();
map.colstate = 10; graphics.towerbg.colstate = 10;
game.gamestate = TITLEMODE; game.gamestate = TITLEMODE;
script.hardreset(); script.hardreset();
graphics.fademode = 4; graphics.fademode = 4;

View file

@ -210,7 +210,7 @@ int main(int argc, char *argv[])
game.mainmenu = 0; game.mainmenu = 0;
map.ypos = (700-29) * 8; map.ypos = (700-29) * 8;
map.bypos = map.ypos / 2; graphics.towerbg.bypos = map.ypos / 2;
//Moved screensetting init here from main menu V2.1 //Moved screensetting init here from main menu V2.1
int width = 320; int width = 320;
@ -256,11 +256,11 @@ int main(int argc, char *argv[])
graphics.menubuffer = CREATE_SURFACE(320, 240); graphics.menubuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.menubuffer, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(graphics.menubuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer = CREATE_SURFACE(320 + 16, 240 + 16); graphics.towerbg.buffer = CREATE_SURFACE(320 + 16, 240 + 16);
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(graphics.towerbg.buffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16); graphics.towerbg.buffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
SDL_SetSurfaceBlendMode(graphics.towerbuffer_lerp, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(graphics.towerbg.buffer_lerp, SDL_BLENDMODE_NONE);
graphics.tempBuffer = CREATE_SURFACE(320, 240); graphics.tempBuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE);