Skip to content

Commit

Permalink
Improve scrolling at different levels of scaling. Other random cleanups.
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan McQuen <[email protected]>
  • Loading branch information
ryanpcmcquen committed May 28, 2020
1 parent a75196e commit 17b30e9
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 82 deletions.
12 changes: 6 additions & 6 deletions assets/data/map_layout_0.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
0, 1, 2, 3, 4, 1, 5, _
27, 16, 17, 16, 16, 16, 17, _
27, 28, 28, 13, 14, 15, 17, _
27, 28, 28, 25, 26, 27, 17, _
27, 16, 40, 16, 16, 16, 17, _
27, 28, 16, 13, 14, 15, 17, _
27, 28, 16, 25, 26, 27, 17, _
27, 28, 28, 37, 38, 39, 17, _
27, 28, 28, 28, 28, 28, 17, _
48, 15, 28, 28, 28, 28, 37, 1, 2, 5, _
27, 28, 28, 28, 28, 17, 17, _
48, 15, 28, 28, 28, 17, 37, 1, 2, 5, _
_, 27, 16, 16, 16, 28, 16, 16, 16, 17
_, 27, 16, 16, 16, 28, 16, 16, 16, 17
_, 27, 16, 16, 16, 28, 16, 28, 16, 17
Expand All @@ -14,7 +14,7 @@
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 48, 15, 28, 28, 28, 28, 16, 16, 17
_, _, 27, 16, 16, 28, 7, 7, 16, 37, 1, 5
_, _, 27, 16, 16, 28, 16, 16, 16, 37, 1, 5
_, _, 48, 49, 50, 15, 16, 16, 16, 16, 16, 17
_, _, _, _, _, 27, 16, 16, 16, 16, 16, 37, 5
_, _, _, _, _, 48, 49, 15, 28, 16, 16, 16, 17
Expand Down
10 changes: 5 additions & 5 deletions assets/data/map_layout_1.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
0, 1, 2, 3, 4, 1, 5, _
27, 16, 17, 16, 16, 16, 17, _
27, 28, 17, 13, 14, 15, 17, _
27, 28, 28, 25, 26, 27, 17, _
27, 16, 40, 16, 16, 16, 17, _
27, 28, 16, 13, 14, 15, 17, _
27, 28, 16, 25, 26, 27, 17, _
27, 28, 28, 37, 38, 39, 17, _
27, 28, 28, 28, 28, 28, 17, _
27, 28, 28, 28, 28, 17, 17, _
48, 15, 28, 28, 28, 28, 37, 1, 2, 5, _
_, 27, 16, 16, 16, 28, 16, 16, 16, 17
_, 27, 16, 16, 16, 28, 16, 16, 16, 17
Expand All @@ -14,7 +14,7 @@
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 48, 15, 28, 28, 28, 28, 16, 16, 17
_, _, 27, 16, 16, 28, 7, 7, 16, 37, 1, 5
_, _, 27, 16, 16, 28, 16, 16, 16, 37, 1, 5
_, _, 48, 49, 50, 15, 16, 16, 16, 16, 16, 17
_, _, _, _, _, 27, 16, 16, 16, 16, 16, 37, 5
_, _, _, _, _, 48, 49, 15, 28, 16, 16, 16, 17
Expand Down
8 changes: 4 additions & 4 deletions assets/data/map_layout_2.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0, 1, 2, 3, 4, 1, 5, _
27, 16, 17, 16, 16, 16, 17, _
27, 28, 17, 13, 14, 15, 17, _
27, 28, 17, 25, 26, 27, 17, _
27, 16, 40, 16, 16, 16, 17, _
27, 28, 16, 13, 14, 15, 17, _
27, 28, 16, 25, 26, 27, 17, _
27, 28, 28, 37, 38, 39, 17, _
27, 28, 28, 28, 28, 28, 17, _
48, 15, 28, 28, 28, 28, 37, 1, 2, 5, _
Expand All @@ -14,7 +14,7 @@
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 48, 15, 28, 28, 28, 28, 16, 16, 17
_, _, 27, 16, 16, 28, 7, 7, 16, 37, 1, 5
_, _, 27, 16, 16, 28, 16, 16, 16, 37, 1, 5
_, _, 48, 49, 50, 15, 16, 16, 16, 16, 16, 17
_, _, _, _, _, 27, 16, 16, 16, 16, 16, 37, 5
_, _, _, _, _, 48, 49, 15, 28, 16, 16, 16, 17
Expand Down
8 changes: 4 additions & 4 deletions assets/data/map_layout_3.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0, 1, 2, 3, 4, 1, 5, _
27, 16, 17, 16, 16, 16, 17, _
27, 28, 17, 13, 14, 15, 17, _
27, 28, 17, 25, 26, 27, 17, _
27, 16, 40, 16, 16, 16, 17, _
27, 28, 16, 13, 14, 15, 17, _
27, 28, 16, 25, 26, 27, 17, _
27, 28, 28, 37, 38, 39, 17, _
27, 28, 28, 28, 28, 28, 17, _
48, 15, 28, 28, 28, 28, 37, 1, 2, 5, _
Expand All @@ -14,7 +14,7 @@
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 48, 15, 28, 28, 28, 28, 16, 16, 17
_, _, 27, 16, 16, 28, 7, 7, 16, 37, 1, 5
_, _, 27, 16, 16, 28, 16, 16, 16, 37, 1, 5
_, _, 48, 49, 50, 15, 16, 16, 16, 16, 16, 17
_, _, _, _, _, 27, 16, 16, 16, 16, 16, 37, 5
_, _, _, _, _, 48, 49, 15, 28, 16, 16, 16, 17
Expand Down
14 changes: 7 additions & 7 deletions assets/data/map_layout_4.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
0, 1, 2, 3, 4, 1, 5, _
27, 16, 17, 16, 16, 16, 17, _
27, 28, 17, 13, 14, 15, 17, _
27, 28, 17, 25, 26, 27, 17, _
27, 16, 40, 16, 16, 16, 17, _
27, 28, 16, 13, 14, 15, 17, _
27, 28, 16, 25, 26, 27, 17, _
27, 28, 28, 37, 38, 39, 17, _
27, 28, 28, 28, 28, 28, 17, _
48, 15, 28, 28, 28, 28, 37, 1, 2, 5, _
_, 27, 16, 16, 16, 28, 16, 16, 16, 17
27, 28, 28, 28, 28, 17, 17, _
48, 15, 28, 28, 28, 17, 37, 1, 2, 5, _
_, 27, 16, 16, 16, 17, 16, 16, 16, 17
_, 27, 16, 16, 16, 28, 16, 16, 16, 17
_, 27, 16, 16, 16, 28, 16, 28, 16, 17
_, 27, 16, 28, 28, 28, 16, 28, 16, 17
Expand All @@ -14,7 +14,7 @@
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 27, 16, 16, 16, 16, 28, 16, 16, 17
_, 48, 15, 28, 28, 28, 28, 16, 16, 17
_, _, 27, 16, 16, 28, 7, 16, 16, 37, 1, 5
_, _, 27, 16, 16, 28, 16, 16, 16, 37, 1, 5
_, _, 48, 49, 50, 15, 16, 16, 16, 16, 16, 17
_, _, _, _, _, 27, 16, 16, 16, 16, 16, 37, 5
_, _, _, _, _, 48, 49, 15, 28, 16, 16, 16, 17
Expand Down
Binary file modified basque.rdbg
Binary file not shown.
6 changes: 3 additions & 3 deletions line_count.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cloc|github.com/AlDanial/cloc v 1.84 T=0.50 s (14.0 files/s, 2714.0 lines/s)
cloc|github.com/AlDanial/cloc v 1.86 T=0.09 s (74.2 files/s, 14098.9 lines/s)
--- | ---

Language|files|blank|comment|code
:-------|-------:|-------:|-------:|-------:
C/C++ Header|6|211|147|980
C/C++ Header|6|206|120|985
C|1|5|0|14
--------|--------|--------|--------|--------
SUM:|7|216|147|994
SUM:|7|211|120|999
8 changes: 3 additions & 5 deletions source/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int FULLSCREEN_MODE = 0;
#define BACKGROUND_IMAGE IMAGE_DIR "tiles_packed.png"

#define MUSIC_INTRO_FILE AUDIO_DIR "Basque_sample_music.ogg"
#define MUSIC_VOLUME (MIX_MAX_VOLUME / 3)
#define MUSIC_VOLUME (MIX_MAX_VOLUME / 8)
// #define MUSIC_VOLUME 0

#define EDITOR_FONT FONT_DIR "BPtypewrite.ttf"
Expand All @@ -52,8 +52,6 @@ int FULLSCREEN_MODE = 0;
#define END_OF_ROW -2

#define PLAYER_INCREMENT 1
#define GLOBAL_INCREMENT (PLAYER_INCREMENT * 3)
#define GLOBAL_INCREMENT (PLAYER_INCREMENT * (SCALING + 1))

#define GAME_LOOP_DELAY 20
// Currently broken:
// #define FRAME_INTERVAL_REDUCTION 30
#define MIN_FRAMETIME_MSECS 30
7 changes: 5 additions & 2 deletions source/initialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ int init()

game.map.layout_file_base = MAP_LAYOUT_FILE_BASE;
game.map.layout_file = MAP_LAYOUT_FILE;
game.map.layout_modified_time = read_file_time(game.map.layout_file);
// TODO:
// Try to figure out why this was being set twice, the same
// goes for attributes_modified_time.
// game.map.layout_modified_time = read_file_time(game.map.layout_file);
game.map.layout_modified_time = 0;
game.map.attributes_file = MAP_ATTRIBUTES_FILE;
game.map.attributes_modified_time = read_file_time(game.map.attributes_file);
// game.map.attributes_modified_time = read_file_time(game.map.attributes_file);
game.map.attributes_modified_time = 0;

read_map_layout(&game);
Expand Down
64 changes: 18 additions & 46 deletions source/mechanics.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ void handle_collisions(GameState* game)
game->player.can_move.south = false;
game->player.can_move.west = false;

if (is_above_bound(game->player.global.y, PLAYER_SPRITE_ROW_HEIGHT / 2, game->player.bound.north)) {
if (is_above_bound(game->player.global.y - PLAYER_INCREMENT, PLAYER_SPRITE_ROW_HEIGHT / 2, game->player.bound.north)) {
game->player.can_move.north = true;
}
if (is_below_bound(game->player.global.x, PLAYER_SPRITE_WIDTH, game->player.bound.east)) {
if (is_below_bound(game->player.global.x + PLAYER_INCREMENT, PLAYER_SPRITE_WIDTH, game->player.bound.east)) {
game->player.can_move.east = true;
}
if (is_below_bound(game->player.global.y, PLAYER_SPRITE_ROW_HEIGHT, game->player.bound.south)) {
if (is_below_bound(game->player.global.y + PLAYER_INCREMENT, PLAYER_SPRITE_ROW_HEIGHT, game->player.bound.south)) {
game->player.can_move.south = true;
}
if (is_above_bound(game->player.global.x, 0, game->player.bound.west)) {
if (is_above_bound(game->player.global.x - PLAYER_INCREMENT, 0, game->player.bound.west)) {
game->player.can_move.west = true;
}
}
Expand Down Expand Up @@ -243,22 +243,6 @@ int write_map_layout(GameState* game)
}
}

// int next_cycle;

// int time_left()
// {
// int now;

// now = SDL_GetTicks();
// // SDL_Log("now: %i\n", now);
// // SDL_Log("next_cycle: %i\n", next_cycle);
// if (next_cycle <= now) {
// return 0;
// } else {
// return next_cycle - now;
// }
// }

void handle_input(App* app, GameState* game)
{
game->done = SDL_FALSE;
Expand All @@ -274,10 +258,9 @@ void handle_input(App* app, GameState* game)
int current_tile_x = 0;
int current_tile = 0;

// next_cycle = SDL_GetTicks() + FRAME_INTERVAL_REDUCTION;

while (!game->done) {
SDL_Event event;
int prev_time;

while (SDL_PollEvent(&event)) {
if (strcmp(game->map.layout_file, MAP_LAYOUT_FILE) == 0) {
Expand Down Expand Up @@ -400,11 +383,10 @@ void handle_input(App* app, GameState* game)
if (strcmp(game->map.layout_file, MAP_LIBRARY_FILE) != 0) {
// Load map_library.txt:
game->map.layout_file = MAP_LIBRARY_FILE;
read_map_layout(game);
} else {
game->map.layout_file = MAP_LAYOUT_FILE;
read_map_layout(game);
}
read_map_layout(game);
}
} break;
case SDLK_RETURN: {
Expand Down Expand Up @@ -517,40 +499,30 @@ void handle_input(App* app, GameState* game)
} break;
}

// @TODO:
// It is time to rework scrolling ...
//
// We probably want to have the player near the center of the screen
// at all times. Perhaps, we could do segmented scrolling, where
// scrolling happens once the player reaches some bounding
// rectangle that represents an arbitrary percentage of
// the screen (for example, 40%).
if (game->player.window.x < SCREEN_WIDTH) {
game->scroll.x = -(game->player.window.x * 2);
game->scroll.x = -(game->player.window.x * SCALING);
}
if (game->player.window.y < SCREEN_HEIGHT) {
game->scroll.y = -(game->player.window.y * 2);
game->scroll.y = -(game->player.window.y * SCALING);
}

generate_map(app, game);
if (strcmp(game->map.layout_file, MAP_LAYOUT_FILE) == 0) {
sprite_blit(app, game->player_image, game->player.window.x, game->player.window.y, game->player.direction);
}

present_scene(app);

// @Bug:
// This is a bit broken now.
// Cap frame rate:
// SDL_Delay(time_left());
// next_cycle += FRAME_INTERVAL_REDUCTION;
int curr_time = SDL_GetTicks();
int time_elapsed = curr_time - prev_time;

// SDL_Log("%i\n", time_left());
// SDL_Log("%i\n", next_cycle);
if (time_elapsed < MIN_FRAMETIME_MSECS) {
// Not enough time has elapsed. Let's limit the frame rate!
SDL_Delay(MIN_FRAMETIME_MSECS - time_elapsed);
curr_time = SDL_GetTicks();
time_elapsed = curr_time - prev_time;
}
prev_time = curr_time;

// Allegedly this keeps the app from running at too
// high of a frame rate. We also VSync.
SDL_Delay(GAME_LOOP_DELAY);
present_scene(app);
}
}
}

0 comments on commit 17b30e9

Please sign in to comment.