Skip to content

Commit

Permalink
Changing background color depending on winning player
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed May 26, 2024
1 parent 0c29339 commit 396b274
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Binary file modified assets/tiles/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/tiles/tiles.pyxel
Binary file not shown.
2 changes: 2 additions & 0 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,10 @@ void end_game_state(uint8_t black, uint8_t white) {
// display winner
if(black > white) {
write_string("PLAYER 1 WINS!", 14, 0);
set_background(stone_color1 + 0x10);
} else if(white > black) {
write_string("PLAYER 2 WINS!", 14, 0);
set_background(stone_color2 + 0x10);
} else {
write_string("IT'S A TIE!", 14, 0);
}
Expand Down
18 changes: 14 additions & 4 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ void init_screen() {
*
*/
void clear_screen() {
// set background
set_background(TILE_BG);

// set all foreground tiles to transparent
clear_foreground();
}

/**
* @brief Which tile to use for the background
*
* @param tile_id background tile index
*/
void set_background(uint8_t tile_id) {
uint8_t i = 0, j=0;
uint32_t map_base_addr;

Expand All @@ -68,13 +81,10 @@ void clear_screen() {

for (j=0; j<MAPHEIGHT; j++) {
for (i=0; i<MAPWIDTH; i++) {
VERA.data0 = TILE_BG; // background tile
VERA.data0 = tile_id; // background tile
VERA.data0 = PALETTEBYTE; // palette offset data
}
}

// set all foreground tiles to transparent
clear_foreground();
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ extern clock_t prevtick;
*/
void init_screen();

/**
* @brief Which tile to use for the background
*
* @param tile_id background tile index
*/
void set_background(uint8_t tile_id);

/**
* @brief Clears the screen
*
Expand Down

0 comments on commit 396b274

Please sign in to comment.