mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-08 18:09:45 +01:00
Update screenshake position in fixed-timestep loop
Otherwise the screen will shake too fast for my liking. Also I'm planning to add an FPS limiting option later (because right now, un-capping the FPS is pretty wasteful and eats up lots of resources, especially since I have only a 60hz monitor), and it'd feel weird if screen shaking updated every delta timestep.
This commit is contained in:
parent
57f87dc820
commit
8fde6f28a3
3 changed files with 16 additions and 7 deletions
|
@ -119,6 +119,9 @@ void Graphics::init()
|
|||
showmousecursor = true;
|
||||
|
||||
alpha = 1.0f;
|
||||
|
||||
screenshake_x = 0;
|
||||
screenshake_y = 0;
|
||||
}
|
||||
|
||||
int Graphics::font_idx(uint32_t ch) {
|
||||
|
@ -2679,7 +2682,6 @@ void Graphics::flashlight()
|
|||
|
||||
void Graphics::screenshake()
|
||||
{
|
||||
point tpoint;
|
||||
if(flipmode)
|
||||
{
|
||||
// tpoint.x = int((Math.random() * 7) - 4); tpoint.y = int((Math.random() * 7) - 4);
|
||||
|
@ -2687,10 +2689,8 @@ void Graphics::screenshake()
|
|||
// screenbuffer.draw(backbuffer, flipmatrix);
|
||||
// flipmatrix.translate(-tpoint.x, -tpoint.y);
|
||||
|
||||
tpoint.x = (fRandom() * 7) - 4;
|
||||
tpoint.y = (fRandom() * 7) - 4;
|
||||
SDL_Rect shakeRect;
|
||||
setRect(shakeRect,tpoint.x, tpoint.y, backBuffer->w, backBuffer->h);
|
||||
setRect(shakeRect,screenshake_x, screenshake_y, backBuffer->w, backBuffer->h);
|
||||
SDL_Surface* flipBackBuffer = FlipSurfaceVerticle(backBuffer);
|
||||
screenbuffer->UpdateScreen( flipBackBuffer, &shakeRect);
|
||||
SDL_FreeSurface(flipBackBuffer);
|
||||
|
@ -2701,16 +2701,20 @@ void Graphics::screenshake()
|
|||
//SDL_Rect rect;
|
||||
//setRect(rect, blackBars/2, 0, screenbuffer->w, screenbuffer->h);
|
||||
//SDL_BlitSurface(backBuffer, NULL, screenbuffer, &rect);
|
||||
tpoint.x = static_cast<Sint32>((fRandom() * 7) - 4);
|
||||
tpoint.y = static_cast<Sint32>((fRandom() * 7) - 4);
|
||||
SDL_Rect shakeRect;
|
||||
setRect(shakeRect,tpoint.x, tpoint.y, backBuffer->w, backBuffer->h);
|
||||
setRect(shakeRect,screenshake_x, screenshake_y, backBuffer->w, backBuffer->h);
|
||||
screenbuffer->UpdateScreen( backBuffer, &shakeRect);
|
||||
}
|
||||
|
||||
FillRect(backBuffer, 0x000000 );
|
||||
}
|
||||
|
||||
void Graphics::updatescreenshake()
|
||||
{
|
||||
screenshake_x = static_cast<Sint32>((fRandom() * 7) - 4);
|
||||
screenshake_y = static_cast<Sint32>((fRandom() * 7) - 4);
|
||||
}
|
||||
|
||||
void Graphics::render()
|
||||
{
|
||||
if(screenbuffer == NULL)
|
||||
|
|
|
@ -130,6 +130,10 @@ public:
|
|||
|
||||
void flashlight();
|
||||
void screenshake();
|
||||
void updatescreenshake();
|
||||
|
||||
int screenshake_x;
|
||||
int screenshake_y;
|
||||
|
||||
void render();
|
||||
void renderwithscreeneffects();
|
||||
|
|
|
@ -471,6 +471,7 @@ int main(int argc, char *argv[])
|
|||
if (game.infocus && game.screenshake > 0)
|
||||
{
|
||||
game.screenshake--;
|
||||
graphics.updatescreenshake();
|
||||
}
|
||||
|
||||
//We did editorinput, now it's safe to turn this off
|
||||
|
|
Loading…
Reference in a new issue