Skip to content

Commit

Permalink
v1.1.0 Bug fixes
Browse files Browse the repository at this point in the history
- Abandons window rendering. Rendering the strings to the background are
  sufficient.
  - Clearly I'm not understanding something or I'm mis-using the library.
    Rendering the window tile messes up the background layer.
- Pause menu and grid rendering finally fixed. Aesthetically, the game looks
  a lot better
  • Loading branch information
schuylermartin45 committed Feb 3, 2023
1 parent 3c59d2f commit 5b4e4b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
15 changes: 9 additions & 6 deletions src/gb2048.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ int main() {
render_init_font();

// TODO make a better splash screen
render_window_show(false);
render_str_relative(REL_POS_1, REL_POS_0, "-- Gameboy 2048 --");
render_str_relative(REL_POS_1, REL_POS_1, "Press start!");
render_str_relative(REL_POS_1, REL_POS_2, "Schuyler M. - 2022");
// Wait for the start-screen, then abuse the scanline register and seed
// with a value derived by the current scan line value.
wait_on_button_pressed(J_START | J_A);
render_window_hide();
SHOW_SPRITES;
const uint16_t seed = LY_REG | (uint16_t)DIV_REG << 8;
initarand(seed);

Expand All @@ -75,12 +74,16 @@ int main() {
else if (buttons & J_RIGHT) direction = BOARD_RIGHT;
else if (buttons & J_START) {
// TODO make a better pause menu
render_window_show(true);
HIDE_SPRITES;
clear_bkg_data();
render_str_relative(REL_POS_1, REL_POS_1, "Paused");
// First wait (for any button) starts "pause mode". This second wait
// keeps the pause menu open.
wait_on_button_pressed(J_START);
render_window_hide();
clear_bkg_data();
SHOW_SPRITES;
render_init_grid();
render_board(&board);
continue;
}

Expand All @@ -90,7 +93,7 @@ int main() {
render_board(&board);
// Allow the final board to render then draw the menu
if (endgame != ENDGAME_NONE) {
render_window_show(true);
HIDE_SPRITES;
switch (endgame) {
case ENDGAME_WIN_2048:
render_str_relative(
Expand All @@ -115,7 +118,7 @@ int main() {
break;
}
wait_on_button_pressed(J_START | J_A);
render_window_hide();
SHOW_SPRITES;
// Allow the user to play again
if ((endgame == ENDGAME_WIN_4096) || (endgame == ENDGAME_LOSS)) {
board_init(&board);
Expand Down
26 changes: 5 additions & 21 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ void render_grid_tile(
*/
void render_board(const Board* board) {
/** Render the score **/
render_window_show(false);
uint8_t score_buff[WINDOW_STR_LEN_MAX + 1] = { '\0' };
// Hide our 00-pad score cheating
if (board->score) {
Expand Down Expand Up @@ -161,26 +160,11 @@ void render_board(const Board* board) {
/** Window Mode: String and Menu Rendering **/

/*
** Shows the window layer.
** @param hide_sprites (Optional) Optionally hide the sprite layer.
** Clears the background data.
*/
void render_window_show(const bool hide_sprites) {
SHOW_WIN;
// If requested, hide sprites as they intersect with the window layer.
if (hide_sprites) {
HIDE_SPRITES;
}
}

/*
** Hides and clears the window layer
*/
void render_window_hide() {
HIDE_WIN;
SHOW_SPRITES;

void clear_bkg_data() {
// Clear the window as to not leak visual data between rendering calls
fill_win_rect(
fill_bkg_rect(
MIN_X_WND_TILE_POS,
MIN_Y_WND_TILE_POS,
MAX_X_WND_TILE_POS,
Expand Down Expand Up @@ -221,7 +205,7 @@ void render_str_xy(const uint8_t x, const uint8_t y, const uint8_t* str) {
uint8_t buff[WINDOW_STR_LEN_MAX];
const uint8_t length = _render_init_str_buff(str, buff);

set_win_tiles(x, y, length, 1, buff);
set_bkg_tiles(x, y, length, 1, buff);
}

/*
Expand Down Expand Up @@ -266,5 +250,5 @@ void render_str_relative(
break;
}

set_win_tiles(x, y, length, 1, buff);
set_bkg_tiles(x, y, length, 1, buff);
}
6 changes: 2 additions & 4 deletions src/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ void render_board(const Board* board);

/** Window Mode: String and Menu Rendering **/

/// Shows the window layer
void render_window_show(const bool hide_sprites);
/// Hides and clears the window layer
void render_window_hide();
/// Clears the background data.
void clear_bkg_data();

/// Renders a string to an X/Y tile coordinate
void render_str_xy(const uint8_t x, const uint8_t y, uint8_t* str);
Expand Down

0 comments on commit 5b4e4b4

Please sign in to comment.