Mercurial > repos > genjam1
comparison src/main.c @ 22:b725a715b358
cursor now blinks the current selection
author | William Morgan <bill@mrgn.org> |
---|---|
date | Mon, 13 Jan 2014 21:48:22 -0800 |
parents | bb7dfb42b320 |
children | 330e58fb01aa |
comparison
equal
deleted
inserted
replaced
21:bb7dfb42b320 | 22:b725a715b358 |
---|---|
42 | 42 |
43 }; | 43 }; |
44 | 44 |
45 u16 countdown; | 45 u16 countdown; |
46 | 46 |
47 int cursor_x = 0; // tiles | 47 s16 cursor_x = 0; // tiles |
48 int cursor_y = 0; // tiles | 48 s16 cursor_y = 0; // tiles |
49 int pixels_per_tile = 8; | 49 u16 cursor_selection = WALL; |
50 const int cursor_width = 2; // tiles | 50 #define CURSOR_BLINK_RATE 16 |
51 #define CURSOR_WIDTH 2; // tiles | |
52 | |
53 #define PIXELS_PER_TILE 8 | |
51 | 54 |
52 | 55 |
53 u16 build_order[3] = { | 56 u16 build_order[3] = { |
54 EMPTY, | 57 EMPTY, |
55 WALL, | 58 WALL, |
56 TOWER, | 59 TOWER, |
57 }; | 60 }; |
58 u8 build_order_size = 3; | 61 u8 build_order_size = 3; |
59 u8 running = 0; | 62 u8 running = 0; |
60 | 63 |
64 void clear_cursor() { | |
65 VDP_setTileMap(VDP_PLAN_A, 0, cursor_x, cursor_y); | |
66 VDP_setTileMap(VDP_PLAN_A, 0, cursor_x + 1, cursor_y); | |
67 VDP_setTileMap(VDP_PLAN_A, 0, cursor_x, cursor_y + 1); | |
68 VDP_setTileMap(VDP_PLAN_A, 0, cursor_x + 1, cursor_y + 1); | |
69 } | |
70 | |
61 void joy_event_handler(u16 joy, u16 changed, u16 state) { | 71 void joy_event_handler(u16 joy, u16 changed, u16 state) { |
62 u16 went_down = changed & state; | 72 u16 went_down = changed & state; |
63 if (went_down & BUTTON_UP) { | 73 if (went_down & BUTTON_UP) { |
64 cursor_y -= cursor_width; | 74 clear_cursor(); |
75 cursor_y -= CURSOR_WIDTH; | |
65 } | 76 } |
66 if (went_down & BUTTON_DOWN) { | 77 if (went_down & BUTTON_DOWN) { |
67 cursor_y += cursor_width; | 78 clear_cursor(); |
79 cursor_y += CURSOR_WIDTH; | |
68 } | 80 } |
69 if (went_down & BUTTON_LEFT) { | 81 if (went_down & BUTTON_LEFT) { |
70 cursor_x -= cursor_width; | 82 clear_cursor(); |
83 cursor_x -= CURSOR_WIDTH; | |
71 } | 84 } |
72 if (went_down & BUTTON_RIGHT) { | 85 if (went_down & BUTTON_RIGHT) { |
73 cursor_x += cursor_width; | 86 clear_cursor(); |
87 cursor_x += CURSOR_WIDTH; | |
74 } | 88 } |
75 if (went_down & BUTTON_A && !running) { | 89 if (went_down & BUTTON_A && !running) { |
76 //u16 type_to_place = EMPTY; | 90 //u16 type_to_place = EMPTY; |
77 place_object(WALL, cursor_x, cursor_y); | 91 place_object(WALL, cursor_x, cursor_y); |
78 gen_distances(38, 14); | 92 gen_distances(38, 14); |
114 //print_distances(); | 128 //print_distances(); |
115 for (;;) | 129 for (;;) |
116 { | 130 { |
117 VDP_waitVSync(); | 131 VDP_waitVSync(); |
118 VDP_updateSprites(); | 132 VDP_updateSprites(); |
133 if ((getTick() % CURSOR_BLINK_RATE) == 0) { | |
134 VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][0], cursor_x, cursor_y); | |
135 VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][1], cursor_x + 1, cursor_y); | |
136 VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][2], cursor_x, cursor_y + 1); | |
137 VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][3], cursor_x + 1, cursor_y + 1); | |
138 } | |
139 if ((getTick() % CURSOR_BLINK_RATE) == CURSOR_BLINK_RATE >> 1) { | |
140 clear_cursor(); | |
141 } | |
119 for (i = 0; i < 28; i++) | 142 for (i = 0; i < 28; i++) |
120 { | 143 { |
121 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); | 144 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); |
122 } | 145 } |
123 VDP_setSprite(0, cursor_x * pixels_per_tile, cursor_y * pixels_per_tile, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), spriteDefCache[0].link); | 146 VDP_setSprite(0, cursor_x * PIXELS_PER_TILE, cursor_y * PIXELS_PER_TILE, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), spriteDefCache[0].link); |
124 if (running) | 147 if (running) |
125 { | 148 { |
126 if (countdown) | 149 if (countdown) |
127 --countdown; | 150 --countdown; |
128 else if (cur_creeps < 4) | 151 else if (cur_creeps < 4) |