Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 706b23e

Browse files
committed
Define sizes and speeds in terms of meters.
1 parent 8bb58c4 commit 706b23e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

game.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
game_state_t game_state;
99

10-
const double PLAYER_WIDTH = TILE_WIDTH;
11-
const double PLAYER_HEIGHT = PLAYER_WIDTH;
10+
const double PLAYER_WIDTH_METERS = 0.8;
11+
const double PLAYER_WIDTH = PLAYER_WIDTH_METERS * METERS_TO_PIXELS;
12+
13+
const double PLAYER_HEIGHT_METERS = 1.0;
14+
const double PLAYER_HEIGHT = PLAYER_HEIGHT_METERS * METERS_TO_PIXELS;
15+
1216
const color_t PLAYER_COLOR = rgb(150.3, 250.5, 20.6);
13-
const double PLAYER_SPEED = 128; // in pixels per second
17+
18+
const double PLAYER_SPEED_METERS_PER_SECOND = 3.0;
19+
const double PLAYER_SPEED = PLAYER_SPEED_METERS_PER_SECOND * METERS_TO_PIXELS;
1420

1521
void put_pixel(pixel_buffer_t* pixel_buffer, uint x, uint y, color_t color) {
1622
uint offset = pixel_buffer->width * y + x;

game.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const uint WORLD_WIDTH = 2;
1212
const uint WORLD_HEIGHT = 2;
1313
const uint TILE_MAP_WIDTH = 16;
1414
const uint TILE_MAP_HEIGHT = 9;
15+
16+
const double METERS_TO_PIXELS = SCREEN_WIDTH / TILE_MAP_WIDTH; // Each tile is a meter
17+
1518
const uint TILE_WIDTH = SCREEN_WIDTH / TILE_MAP_WIDTH;
1619
const uint TILE_HEIGHT = SCREEN_HEIGHT / TILE_MAP_HEIGHT;
1720
const color_t TILE_COLOR = rgb(100, 100, 100);

0 commit comments

Comments
 (0)