-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcursor.c
116 lines (84 loc) · 2.22 KB
/
cursor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
struct Cursor {
unsigned char row;
unsigned char col;
} cursor;
int cursor_update() {
UBYTE keys, diff;
int cx, cy, update_pos;
//constants
int row_min = 0;
int row_max = 3;
int col_min = 0;
int col_max = 4;
int sprite_x_size = 8;
int sprite_y_size = 16;
keys = joypad();
if(keys != joypad_prev) {
//calculate which key changed
diff = (joypad_prev ^ keys) & keys;
joypad_prev = keys;
switch(diff) {
case J_UP: if(cursor.row > row_min) cursor.row--; break;
case J_DOWN: if(cursor.row < row_max) cursor.row++; break;
case J_LEFT: if(cursor.col > col_min) cursor.col--; break;
case J_RIGHT: if(cursor.col < col_max) cursor.col++; break;
case J_A: set_command(cursor.row, cursor.col, 1); return 1;
case J_B: set_command(cursor.row, cursor.col, -1); return 1;
case J_SELECT: init_level(); return 0;
}
update_pos = 1;
}
if(update_pos) {
cx = (sprite_x_size * 3) + (cursor.col * 24);
cy = (sprite_y_size * 2) + (cursor.row * 24);
if (cursor.row > 1) {
cy += 8;
}
if (cursor.row > 2) {
cy += 8;
}
//top-left
move_sprite(0, cx, cy);
//bottom-left
move_sprite(1, cx, cy + 16);
//top-right
move_sprite(2, cx + 24, cy);
//bottom-right
move_sprite(3, cx + 24, cy + 16);
//top-left edge
move_sprite(4, cx + 8, cy);
//top-right edge
move_sprite(5, cx + 16, cy);
//bottom-left edge
move_sprite(6, cx + 8, cy + 16);
//bottom-right edge
move_sprite(7, cx + 16, cy + 16);
}
return 0;
}
void cursor_reset() {
cursor.row = 0;
cursor.col = 0;
}
void cursor_init() {
//0 topleft corner + left edge
//2 top edge + center blank tile
//corners
set_sprite_tile(0, 0);
set_sprite_tile(1, 0);
set_sprite_prop(1, S_FLIPY);
set_sprite_tile(2, 0);
set_sprite_prop(2, S_FLIPX);
set_sprite_tile(3, 0);
set_sprite_prop(3, S_FLIPX | S_FLIPY);
//edges
set_sprite_tile(4, 2);
set_sprite_tile(5, 2);
set_sprite_prop(5, S_FLIPX);
set_sprite_tile(6, 2);
set_sprite_prop(6, S_FLIPY);
set_sprite_tile(7, 2);
set_sprite_prop(7, S_FLIPX | S_FLIPY);
joypad_prev = joypad();
cursor_update();
}