diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index db98105b..75a3aea4 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -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((fRandom() * 7) - 4); - tpoint.y = static_cast((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((fRandom() * 7) - 4); + screenshake_y = static_cast((fRandom() * 7) - 4); +} + void Graphics::render() { if(screenbuffer == NULL) diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index 4987f066..318385aa 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -130,6 +130,10 @@ public: void flashlight(); void screenshake(); + void updatescreenshake(); + + int screenshake_x; + int screenshake_y; void render(); void renderwithscreeneffects(); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 9d905dac..0610dc82 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -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