Skip to content

Commit

Permalink
Add a dull palette too and the ability to choose dull or lit when ren…
Browse files Browse the repository at this point in the history
…dering the puzzle pieces.
  • Loading branch information
otrho committed Oct 19, 2021
1 parent d8b8861 commit b6d1fac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions linkage/source/backgrounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ void init_puzzle_bg() {

// Load the tile image data.
CpuFastSet(piecesTiles, CHAR_BASE_ADR(CHAR_BASE_IDX), 512 | COPY32);

// Copy the glowy palette in and manually create our dull palette, which is all black except the
// last colour. These correspond to DULL_PALETTE and LIT_PALETTE in backgrounds.h.
CpuFastSet(piecesPal, BG_PALETTE, 8 | COPY32);
s32 black = 0;
CpuFastSet(&black, BG_PALETTE + 16, 8 | FILL | COPY32);
BG_PALETTE[31] = RGB5(0x1f, 0, 0x1f);

// Make sure scroll is at the top left.
REG_BG1HOFS = 0;
Expand Down
3 changes: 3 additions & 0 deletions linkage/source/backgrounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
#define CHAR_BASE_IDX 0
#define MAP_BASE_IDX 28

#define LIT_PALETTE 0
#define DULL_PALETTE 1

void init_puzzle_bg();
7 changes: 4 additions & 3 deletions linkage/source/linkage.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void puzzle_loop(struct CursorScroll* cursor_scroll) {

if (keys_up & KEY_A) {
rotate_piece(cursor_scroll->cursor_x, cursor_scroll->cursor_y, +1);
update_puzzle_board(cursor_scroll->cursor_x, cursor_scroll->cursor_y);
update_puzzle_board(cursor_scroll->cursor_x, cursor_scroll->cursor_y, DULL_PALETTE);
}
if (keys_up & KEY_B) {
rotate_piece(cursor_scroll->cursor_x, cursor_scroll->cursor_y, -1);
Expand All @@ -192,7 +192,7 @@ static void puzzle_loop(struct CursorScroll* cursor_scroll) {
update_screen_cursor_scroll(cursor_scroll);
}
if (keys_up & (KEY_A | KEY_B)) {
update_puzzle_board(cursor_scroll->cursor_x, cursor_scroll->cursor_y);
update_puzzle_board(cursor_scroll->cursor_x, cursor_scroll->cursor_y, DULL_PALETTE);
}
draw_sprites();
}
Expand Down Expand Up @@ -236,9 +236,10 @@ int main() {
VBlankIntrWait();
for (s32 y = 0; y < height; y++) {
for (s32 x = 0; x < width; x++) {
update_puzzle_board(x, y);
update_puzzle_board(x, y, DULL_PALETTE);
}
}
update_puzzle_board(origin_x, origin_y, LIT_PALETTE);

struct CursorScroll cursor_scroll;
init_cursor_scroll(&cursor_scroll, width, height, origin_x, origin_y);
Expand Down
4 changes: 2 additions & 2 deletions linkage/source/puzzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ static const u16 c_dirs_piece_map[16] = {
#define NUM_Y_BG_TILES 32 // 32 8x8 tiles in bg quadrant row.
#define NUM_Y_MAP_TILES 8 // 8 8x8 tiles in our tile set row.

void update_puzzle_board(s32 x, s32 y) {
u16 piece_tiles_idx = c_dirs_piece_map[PUZZLE_PIECE_AT(x, y)->dirs];
void update_puzzle_board(s32 x, s32 y, u16 pal_idx) {
u16 piece_tiles_idx = CHAR_PALETTE(pal_idx) | c_dirs_piece_map[PUZZLE_PIECE_AT(x, y)->dirs];

// I'm hoping the compiler makes this much more efficient. I should check the ASM.
s32 scr_blk_idx = (y * 2) / NUM_Y_BG_TILES * 2 + (x * 2) / NUM_Y_BG_TILES;
Expand Down
2 changes: 1 addition & 1 deletion linkage/source/puzzle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
void generate_puzzle(s32 width, s32 height, s32* origin_x, s32* origin_y);

void rotate_piece(s32 x, s32 y, s32 dir);
void update_puzzle_board(s32 x, s32 y);
void update_puzzle_board(s32 x, s32 y, u16 pal_idx);

0 comments on commit b6d1fac

Please sign in to comment.