Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Sep 15, 2024
1 parent 026ce49 commit e177722
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
16 changes: 16 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@
#define KEYCODE_SPACE 0x20
#define KEYCODE_ESCAPE 0x1B

// puzzle window tiles
#define WINDOW_LEFT_TOP 0x28
#define WINDOW_LEFT_BOTTOM 0x29
#define WINDOW_TOP 0x24
#define WINDOW_BOTTOM 0x26
#define WINDOW_RIGHT_TOP 0x23
#define WINDOW_RIGHT_BOTTOM 0x29
#define WINDOW_HOR_EDGE 0x25
#define WINDOW_CORE 0x27

// puzzle icon tiles
#define ICON_QUIT 0x3B
#define ICON_REVEAL 0x3C
#define ICON_QUIT_SEL 0x3D
#define ICON_REVEAL_SEL 0x3E

// puzzle statuses
#define STATUS_SOLVED (1 << 0)
#define STATUS_OPENED (1 << 1)
Expand Down
30 changes: 15 additions & 15 deletions src/puzzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ void build_puzzle(uint8_t puzzle_id) {
puzzle_set_revealed_cells();

// build icons
set_tile(1, 38, 0x08, 0x00, LAYER0);
set_tile(2, 38, 0x09, 0x00, LAYER0);
set_tile(1, 38, ICON_QUIT, 0x00, LAYER0);
set_tile(2, 38, ICON_REVEAL, 0x00, LAYER0);

// set puzzle status
idx = retrieve_puzzle_status(current_puzzle_id + 1);
Expand Down Expand Up @@ -278,7 +278,7 @@ void puzzle_handle_mouse() {
tpy = *mouse_y >> 4;

if(tpy == 1 && tpx == 38) {
set_tile(1, 38, 0x0A, 0x00, LAYER0);
set_tile(1, 38, ICON_QUIT_SEL, 0x00, LAYER0);
if(mouse_buttons & 1) {
while(mouse_buttons != 0x00) {
asm("ldx #2");
Expand All @@ -288,11 +288,11 @@ void puzzle_handle_mouse() {
puzzle_quit();
}
} else {
set_tile(1, 38, 0x08, 0x00, LAYER0);
set_tile(1, 38, ICON_QUIT, 0x00, LAYER0);
}

if(tpy == 2 && tpx == 38) {
set_tile(2, 38, 0x0B, 0x00, LAYER0);
set_tile(2, 38, ICON_REVEAL_SEL, 0x00, LAYER0);
if(mouse_buttons & 1) {
while(mouse_buttons != 0x00) {
asm("ldx #2");
Expand All @@ -303,7 +303,7 @@ void puzzle_handle_mouse() {
puzzle_color_numbers();
}
} else {
set_tile(2, 38, 0x09, 0x00, LAYER0);
set_tile(2, 38, ICON_REVEAL, 0x00, LAYER0);
}

// release highlight
Expand Down Expand Up @@ -739,25 +739,25 @@ void build_window(uint8_t y, uint8_t x, uint8_t h, uint8_t w) {
uint8_t i,j;

// top and bottom borders
set_tile(y-1, x-1, 0x15, 0x00, LAYER0); // left-top
set_tile(y+h, x-1, 0x16, 0x00, LAYER0); // left-bottom
set_tile(y-1, x-1, WINDOW_LEFT_TOP, 0x00, LAYER0); // left-top
set_tile(y+h, x-1, WINDOW_LEFT_BOTTOM, 0x00, LAYER0); // left-bottom
for(i=0; i<w; i++) {
set_tile(y-1, x+i, 0x11, 0x00, LAYER0); // top layer
set_tile(y+h, x+i, 0x13, 0x00, LAYER0); // bottom layer
set_tile(y-1, x+i, WINDOW_TOP, 0x00, LAYER0); // top layer
set_tile(y+h, x+i, WINDOW_BOTTOM, 0x00, LAYER0); // bottom layer
}
set_tile(y-1, x+w, 0x10, MIRROR_X, LAYER0); // right-top
set_tile(y+h, x+w, 0x16, MIRROR_X, LAYER0); // right-bottom
set_tile(y-1, x+w, WINDOW_RIGHT_TOP, MIRROR_X, LAYER0); // right-top
set_tile(y+h, x+w, WINDOW_RIGHT_BOTTOM, MIRROR_X, LAYER0); // right-bottom

// left and right borders
for(i=0; i<h; i++) {
set_tile(y+i, x-1, 0x12, 0x00, LAYER0);
set_tile(y+i, x+w, 0x12, MIRROR_X, LAYER0);
set_tile(y+i, x-1, WINDOW_HOR_EDGE, 0x00, LAYER0);
set_tile(y+i, x+w, WINDOW_HOR_EDGE, MIRROR_X, LAYER0);
}

// core
for(i=0; i<h; i++) {
for(j=0; j<w; j++) {
set_tile(y+i, x+j, 0x14, MIRROR_X, LAYER0);
set_tile(y+i, x+j, WINDOW_CORE, MIRROR_X, LAYER0);
}
}

Expand Down

0 comments on commit e177722

Please sign in to comment.