Skip to content

Commit e95ebb6

Browse files
committed
Make water renderer work with smaller textures at different sizes
1 parent 21406e3 commit e95ebb6

5 files changed

Lines changed: 26 additions & 28 deletions

File tree

assets/images/water.bmp

-59.2 KB
Binary file not shown.

include/Tile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class Water : public GroundTile
512512
chop=!chop;
513513
if (chop) {
514514
static_rotation++;
515-
static_rotation%=BLOCK_SIZE;
515+
static_rotation%=BLOCK_SIZE * 2;
516516
}
517517
}
518518

include/constants.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
#if defined(NXDK)
55
inline constexpr int WINDOW_WIDTH = 640;
66
inline constexpr int WINDOW_HEIGHT = 480;
7+
inline constexpr int BLOCK_SIZE = 40;
78
#elif defined(__vita__)
89
inline constexpr int WINDOW_WIDTH = 960;
910
inline constexpr int WINDOW_HEIGHT = 544;
11+
inline constexpr int BLOCK_SIZE = 40;
12+
#elif defined(__PSP__)
13+
inline constexpr int WINDOW_WIDTH = 480;
14+
inline constexpr int WINDOW_HEIGHT = 272;
15+
inline constexpr int BLOCK_SIZE = 16;
1016
#else
11-
inline constexpr int WINDOW_WIDTH = 640;
12-
inline constexpr int WINDOW_HEIGHT = 480;
17+
inline constexpr int WINDOW_WIDTH = 800;
18+
inline constexpr int WINDOW_HEIGHT = 600;
19+
inline constexpr int BLOCK_SIZE = 40;
1320
#endif
1421

1522
inline constexpr int COLUMNS = 20;
1623
inline constexpr int ROWS = 15;
17-
inline constexpr int BLOCK_SIZE = 16;
1824

1925
inline constexpr int BEAM_PERSISTANCE = 4; //beam lasts for this many 0.025 second intervals
2026

src/Draw.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,20 @@ void Draw::BlitSquare(SDL_Texture * texture, int x, int y, int dx, int dy) {
2626
}
2727

2828
void Draw::BlitWater(SDL_Texture * texture, int rotation, int dx, int dy) {
29-
SDL_Rect sr, dr;
29+
// Slow down the water by half for small block sizes
30+
if (BLOCK_SIZE < 20) {
31+
rotation /= 2;
32+
}
33+
rotation = rotation % BLOCK_SIZE;
3034
dx *= BLOCK_SIZE;
3135
dy *= BLOCK_SIZE;
32-
for (int i = 0; i < 4; i++){
33-
switch (i)
34-
{
35-
case 0:
36-
sr = {0,0,rotation, rotation};
37-
dr = {dx, dy, rotation, rotation};
38-
break;
39-
case 1:
40-
sr = {rotation, 0,BLOCK_SIZE-rotation, rotation};
41-
dr = {dx+rotation, dy, BLOCK_SIZE-rotation, rotation};
42-
break;
43-
case 2:
44-
sr = {0,rotation,rotation, BLOCK_SIZE-rotation};
45-
dr = {dx, dy+rotation, rotation, BLOCK_SIZE-rotation};
46-
break;
47-
case 3:
48-
sr = {rotation,rotation,BLOCK_SIZE-rotation, BLOCK_SIZE-rotation};
49-
dr = {dx+rotation, dy+rotation, BLOCK_SIZE-rotation, BLOCK_SIZE-rotation};
50-
break;
51-
default:
52-
break;
53-
}
54-
SDL_RenderCopy(renderer, texture, &sr, &dr);
36+
SDL_Rect dr={dx + rotation, dy, BLOCK_SIZE - rotation, BLOCK_SIZE};
37+
SDL_Rect sr={0, 0, BLOCK_SIZE - rotation, BLOCK_SIZE};
38+
SDL_RenderCopy(renderer, texture, &sr, &dr);
39+
if (rotation > 0) {
40+
SDL_Rect dr2={dx, dy, rotation, BLOCK_SIZE};
41+
SDL_Rect sr2={BLOCK_SIZE - rotation, 0, rotation, BLOCK_SIZE};
42+
SDL_RenderCopy(renderer, texture, &sr2, &dr2);
5543
}
5644
}
5745

src/Window.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <SDL_ttf.h>
1010

11+
#include "constants.h"
12+
1113
Window::Window(const std::string &title, int width, int height) {
1214
#ifdef NXDK
1315
XVideoSetMode(width, height, 16, REFRESH_DEFAULT);
@@ -34,6 +36,8 @@ Window::Window(const std::string &title, int width, int height) {
3436
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Couldn't create renderer: %s", SDL_GetError());
3537
exit(4);
3638
}
39+
40+
SDL_RenderSetLogicalSize(renderer, COLUMNS * BLOCK_SIZE, ROWS * BLOCK_SIZE);
3741
}
3842

3943
Window::~Window() {

0 commit comments

Comments
 (0)