# HG changeset patch # User Mike Pavone # Date 1389582090 28800 # Node ID a9500e8bff93e5a07718eb68b404daf95af8e243 # Parent f71eb24b3896a6ed17bd6152c869566392146179 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. diff -r f71eb24b3896 -r a9500e8bff93 src/creep.h --- a/src/creep.h Sun Jan 12 18:49:29 2014 -0800 +++ b/src/creep.h Sun Jan 12 19:01:30 2014 -0800 @@ -17,6 +17,7 @@ #define MAX_CREEPS 40 extern u16 cur_creeps; +extern u16 distances[20*14]; u16 spawn_creep(u8 species, s16 x, s16 y); void gen_distances(u16 x, u16 y); void print_distances(void); diff -r f71eb24b3896 -r a9500e8bff93 src/main.c --- a/src/main.c Sun Jan 12 18:49:29 2014 -0800 +++ b/src/main.c Sun Jan 12 19:01:30 2014 -0800 @@ -42,9 +42,9 @@ }; #define EMPTY 0 -#define WALL 'O' + TILE_FONTINDEX -#define TOWER 'T' + TILE_FONTINDEX -#define GOAL 'G' + TILE_FONTINDEX +#define WALL 'O'-32 + TILE_FONTINDEX +#define TOWER 'T'-32 + TILE_FONTINDEX +#define GOAL 'G'-32 + TILE_FONTINDEX u16 tilemap[40*28]; u16 countdown; @@ -61,6 +61,7 @@ TOWER, }; u8 build_order_size = 3; +u8 running = 0; void joy_event_handler(u16 joy, u16 changed, u16 state) { u16 went_down = changed & state; @@ -76,11 +77,23 @@ if (went_down & BUTTON_RIGHT) { cursor_x += cursor_width; } - if (went_down & BUTTON_A) { + if (went_down & BUTTON_A && !running) { tilemap[cursor_x + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); tilemap[cursor_x + 1 + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); tilemap[cursor_x + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL); + gen_distances(38, 14); + if (distances[122/16] == 0xFFFF) + { + tilemap[cursor_x + (cursor_y ) * 40] = 0; + tilemap[cursor_x + 1 + (cursor_y ) * 40] = 0; + tilemap[cursor_x + (cursor_y + 1) * 40] = 0; + tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = 0; + } + } + if (went_down & BUTTON_START) + { + running = 1; } } @@ -94,22 +107,23 @@ u16 i; VDP_setPlanSize(64, 32); - for (i = 6; i < 40*28; i += 4) + /*for (i = 6; i < 40*28; i += 4) if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) { tilemap[i] = 'O' + TILE_FONTINDEX; tilemap[i+1] = 'O' + TILE_FONTINDEX; } + */ - tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); - tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); - tilemap[38 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); - tilemap[39 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX); - gen_distances(38, 14); + tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); + tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); + tilemap[38 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); + tilemap[39 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, GOAL); for (i = 0; i < MAX_SPRITE; i++) { spriteDefCache[i].posx = -0x80; } + gen_distances(38, 14); //print_distances(); for (;;) { @@ -120,14 +134,17 @@ VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); } 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); - if (countdown) - --countdown; - else if (cur_creeps < 4) + if (running) { - spawn_creep(CREEP_NORMAL, 4, 122); - countdown = 300; + if (countdown) + --countdown; + else if (cur_creeps < 4) + { + spawn_creep(CREEP_NORMAL, 4, 122); + countdown = 300; + } + update_creeps(); } - update_creeps(); } return 0; }