Mercurial > repos > genjam1
comparison src/main.c @ 16:a9500e8bff93
Wait to spawn creeps until player hits start. Prevent player from placing walls in such a way to completely block creeps from goal. Remove placeholder walls.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 12 Jan 2014 19:01:30 -0800 |
parents | f71eb24b3896 |
children | 60bb690233cf |
comparison
equal
deleted
inserted
replaced
15:f71eb24b3896 | 16:a9500e8bff93 |
---|---|
40 0x00000112, | 40 0x00000112, |
41 | 41 |
42 }; | 42 }; |
43 | 43 |
44 #define EMPTY 0 | 44 #define EMPTY 0 |
45 #define WALL 'O' + TILE_FONTINDEX | 45 #define WALL 'O'-32 + TILE_FONTINDEX |
46 #define TOWER 'T' + TILE_FONTINDEX | 46 #define TOWER 'T'-32 + TILE_FONTINDEX |
47 #define GOAL 'G' + TILE_FONTINDEX | 47 #define GOAL 'G'-32 + TILE_FONTINDEX |
48 | 48 |
49 u16 tilemap[40*28]; | 49 u16 tilemap[40*28]; |
50 u16 countdown; | 50 u16 countdown; |
51 | 51 |
52 int cursor_x = 0; // tiles | 52 int cursor_x = 0; // tiles |
59 EMPTY, | 59 EMPTY, |
60 WALL, | 60 WALL, |
61 TOWER, | 61 TOWER, |
62 }; | 62 }; |
63 u8 build_order_size = 3; | 63 u8 build_order_size = 3; |
64 u8 running = 0; | |
64 | 65 |
65 void joy_event_handler(u16 joy, u16 changed, u16 state) { | 66 void joy_event_handler(u16 joy, u16 changed, u16 state) { |
66 u16 went_down = changed & state; | 67 u16 went_down = changed & state; |
67 if (went_down & BUTTON_UP) { | 68 if (went_down & BUTTON_UP) { |
68 cursor_y -= cursor_width; | 69 cursor_y -= cursor_width; |
74 cursor_x -= cursor_width; | 75 cursor_x -= cursor_width; |
75 } | 76 } |
76 if (went_down & BUTTON_RIGHT) { | 77 if (went_down & BUTTON_RIGHT) { |
77 cursor_x += cursor_width; | 78 cursor_x += cursor_width; |
78 } | 79 } |
79 if (went_down & BUTTON_A) { | 80 if (went_down & BUTTON_A && !running) { |
80 tilemap[cursor_x + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); | 81 tilemap[cursor_x + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); |
81 tilemap[cursor_x + 1 + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); | 82 tilemap[cursor_x + 1 + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); |
82 tilemap[cursor_x + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); | 83 tilemap[cursor_x + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); |
83 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); | 84 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); |
85 gen_distances(38, 14); | |
86 if (distances[122/16] == 0xFFFF) | |
87 { | |
88 tilemap[cursor_x + (cursor_y ) * 40] = 0; | |
89 tilemap[cursor_x + 1 + (cursor_y ) * 40] = 0; | |
90 tilemap[cursor_x + (cursor_y + 1) * 40] = 0; | |
91 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = 0; | |
92 } | |
93 } | |
94 if (went_down & BUTTON_START) | |
95 { | |
96 running = 1; | |
84 } | 97 } |
85 } | 98 } |
86 | 99 |
87 int main(void) | 100 int main(void) |
88 { | 101 { |
92 u8 cursor_tile_index = 1; | 105 u8 cursor_tile_index = 1; |
93 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0); | 106 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0); |
94 | 107 |
95 u16 i; | 108 u16 i; |
96 VDP_setPlanSize(64, 32); | 109 VDP_setPlanSize(64, 32); |
97 for (i = 6; i < 40*28; i += 4) | 110 /*for (i = 6; i < 40*28; i += 4) |
98 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) | 111 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) |
99 { | 112 { |
100 tilemap[i] = 'O' + TILE_FONTINDEX; | 113 tilemap[i] = 'O' + TILE_FONTINDEX; |
101 tilemap[i+1] = 'O' + TILE_FONTINDEX; | 114 tilemap[i+1] = 'O' + TILE_FONTINDEX; |
102 } | 115 } |
116 */ | |
103 | 117 |
104 tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 118 tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); |
105 tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 119 tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); |
106 tilemap[38 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 120 tilemap[38 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); |
107 tilemap[39 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); | 121 tilemap[39 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); |
108 gen_distances(38, 14); | |
109 for (i = 0; i < MAX_SPRITE; i++) | 122 for (i = 0; i < MAX_SPRITE; i++) |
110 { | 123 { |
111 spriteDefCache[i].posx = -0x80; | 124 spriteDefCache[i].posx = -0x80; |
112 } | 125 } |
126 gen_distances(38, 14); | |
113 //print_distances(); | 127 //print_distances(); |
114 for (;;) | 128 for (;;) |
115 { | 129 { |
116 VDP_waitVSync(); | 130 VDP_waitVSync(); |
117 VDP_updateSprites(); | 131 VDP_updateSprites(); |
118 for (i = 0; i < 28; i++) | 132 for (i = 0; i < 28; i++) |
119 { | 133 { |
120 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); | 134 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); |
121 } | 135 } |
122 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); | 136 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); |
123 if (countdown) | 137 if (running) |
124 --countdown; | |
125 else if (cur_creeps < 4) | |
126 { | 138 { |
127 spawn_creep(CREEP_NORMAL, 4, 122); | 139 if (countdown) |
128 countdown = 300; | 140 --countdown; |
141 else if (cur_creeps < 4) | |
142 { | |
143 spawn_creep(CREEP_NORMAL, 4, 122); | |
144 countdown = 300; | |
145 } | |
146 update_creeps(); | |
129 } | 147 } |
130 update_creeps(); | |
131 } | 148 } |
132 return 0; | 149 return 0; |
133 } | 150 } |