comparison src/main.c @ 18:60bb690233cf

merge
author William Morgan <bill@mrgn.org>
date Sun, 12 Jan 2014 19:11:54 -0800
parents ea345aa9cc30 a9500e8bff93
children 51a0972fcf76
comparison
equal deleted inserted replaced
17:ea345aa9cc30 18:60bb690233cf
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 TILE_ATTR_FULL(1, 0, 0, 0, 'T' + TILE_FONTINDEX) 46 #define TOWER TILE_ATTR_FULL(1, 0, 0, 0, 'T'-32 + TILE_FONTINDEX)
47 #define GOAL TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX) 47 #define GOAL TILE_ATTR_FULL(1, 0, 0, 0, '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 //u16 type_to_place = EMPTY; 81 //u16 type_to_place = EMPTY;
81 u16 type_to_place = WALL; 82 u16 type_to_place = WALL;
82 tilemap[cursor_x + (cursor_y ) * 40] = type_to_place; 83 tilemap[cursor_x + (cursor_y ) * 40] = type_to_place;
83 tilemap[cursor_x + 1 + (cursor_y ) * 40] = type_to_place; 84 tilemap[cursor_x + 1 + (cursor_y ) * 40] = type_to_place;
84 tilemap[cursor_x + (cursor_y + 1) * 40] = type_to_place; 85 tilemap[cursor_x + (cursor_y + 1) * 40] = type_to_place;
85 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = type_to_place; 86 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = type_to_place;
87 gen_distances(38, 14);
88 if (distances[122/16] == 0xFFFF)
89 {
90 tilemap[cursor_x + (cursor_y ) * 40] = 0;
91 tilemap[cursor_x + 1 + (cursor_y ) * 40] = 0;
92 tilemap[cursor_x + (cursor_y + 1) * 40] = 0;
93 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = 0;
94 }
95 }
96 if (went_down & BUTTON_START)
97 {
98 running = 1;
86 } 99 }
87 } 100 }
88 101
89 int main(void) 102 int main(void)
90 { 103 {
94 u8 cursor_tile_index = 1; 107 u8 cursor_tile_index = 1;
95 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0); 108 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0);
96 109
97 u16 i; 110 u16 i;
98 VDP_setPlanSize(64, 32); 111 VDP_setPlanSize(64, 32);
99 for (i = 6; i < 40*28; i += 4) 112 /*for (i = 6; i < 40*28; i += 4)
100 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) 113 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38)
101 { 114 {
102 tilemap[i] = WALL; 115 tilemap[i] = WALL;
103 tilemap[i+1] = WALL; 116 tilemap[i+1] = WALL;
104 } 117 }
118 */
105 119
106 tilemap[38 + 14*40] = GOAL; 120 tilemap[38 + 14*40] = GOAL;
107 tilemap[39 + 14*40] = GOAL; 121 tilemap[39 + 14*40] = GOAL;
108 tilemap[38 + 15*40] = GOAL; 122 tilemap[38 + 15*40] = GOAL;
109 tilemap[39 + 15*40] = GOAL; 123 tilemap[39 + 15*40] = GOAL;
110 gen_distances(38, 14);
111 for (i = 0; i < MAX_SPRITE; i++) 124 for (i = 0; i < MAX_SPRITE; i++)
112 { 125 {
113 spriteDefCache[i].posx = -0x80; 126 spriteDefCache[i].posx = -0x80;
114 } 127 }
128 gen_distances(38, 14);
115 //print_distances(); 129 //print_distances();
116 for (;;) 130 for (;;)
117 { 131 {
118 VDP_waitVSync(); 132 VDP_waitVSync();
119 VDP_updateSprites(); 133 VDP_updateSprites();
120 for (i = 0; i < 28; i++) 134 for (i = 0; i < 28; i++)
121 { 135 {
122 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); 136 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0);
123 } 137 }
124 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); 138 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);
125 if (countdown) 139 if (running)
126 --countdown;
127 else if (cur_creeps < 4)
128 { 140 {
129 spawn_creep(CREEP_NORMAL, 4, 122); 141 if (countdown)
130 countdown = 300; 142 --countdown;
143 else if (cur_creeps < 4)
144 {
145 spawn_creep(CREEP_NORMAL, 4, 122);
146 countdown = 300;
147 }
148 update_creeps();
131 } 149 }
132 update_creeps();
133 } 150 }
134 return 0; 151 return 0;
135 } 152 }