Mercurial > repos > genjam1
annotate src/main.c @ 21:bb7dfb42b320
Small refactor to object placement. Add spawn point object
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 12 Jan 2014 23:53:18 -0800 |
parents | 51a0972fcf76 |
children | b725a715b358 |
rev | line source |
---|---|
2
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <genesis.h> |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include "creep.h" |
20
51a0972fcf76
Move some tilemap/distance stuff out of creep.c and main.c into a separate source file
Michael Pavone <pavone@retrodev.com>
parents:
18
diff
changeset
|
3 #include "map.h" |
2
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
5 // I now realize this should be one tile that uses the flipping flags. oops. |
10 | 6 const u32 cursor_tiles[4*8] = { |
7 0x21100000, // top left | |
8 0x10000000, | |
9 0x10000000, | |
10 0x00000000, | |
11 0x00000000, | |
12 0x00000000, | |
13 0x00000000, | |
14 0x00000000, | |
15 | |
16 0x00000000, // bottom left | |
17 0x00000000, | |
18 0x00000000, | |
19 0x00000000, | |
20 0x00000000, | |
21 0x10000000, | |
22 0x10000000, | |
23 0x21100000, | |
24 | |
25 0x00000112, // top right | |
26 0x00000001, | |
27 0x00000001, | |
28 0x00000000, | |
29 0x00000000, | |
30 0x00000000, | |
31 0x00000000, | |
32 0x00000000, | |
33 | |
34 0x00000000, // bottom right | |
35 0x00000000, | |
36 0x00000000, | |
37 0x00000000, | |
38 0x00000000, | |
39 0x00000001, | |
40 0x00000001, | |
41 0x00000112, | |
42 | |
43 }; | |
44 | |
7
3ed112d64b1b
Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
45 u16 countdown; |
4
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
46 |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
47 int cursor_x = 0; // tiles |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
48 int cursor_y = 0; // tiles |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
49 int pixels_per_tile = 8; |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
50 const int cursor_width = 2; // tiles |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
51 |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
52 |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
53 u16 build_order[3] = { |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
54 EMPTY, |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
55 WALL, |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
56 TOWER, |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
57 }; |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
58 u8 build_order_size = 3; |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
59 u8 running = 0; |
10 | 60 |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
61 void joy_event_handler(u16 joy, u16 changed, u16 state) { |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
62 u16 went_down = changed & state; |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
63 if (went_down & BUTTON_UP) { |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
64 cursor_y -= cursor_width; |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
65 } |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
66 if (went_down & BUTTON_DOWN) { |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
67 cursor_y += cursor_width; |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
68 } |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
69 if (went_down & BUTTON_LEFT) { |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
70 cursor_x -= cursor_width; |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
71 } |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
72 if (went_down & BUTTON_RIGHT) { |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
73 cursor_x += cursor_width; |
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
74 } |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
75 if (went_down & BUTTON_A && !running) { |
17 | 76 //u16 type_to_place = EMPTY; |
21
bb7dfb42b320
Small refactor to object placement. Add spawn point object
Michael Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
77 place_object(WALL, cursor_x, cursor_y); |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
78 gen_distances(38, 14); |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
79 if (distances[122/16] == 0xFFFF) |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
80 { |
21
bb7dfb42b320
Small refactor to object placement. Add spawn point object
Michael Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
81 place_object(EMPTY, cursor_x, cursor_y); |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
82 } |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
83 } |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
84 if (went_down & BUTTON_START) |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
85 { |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
86 running = 1; |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
87 } |
10 | 88 } |
89 | |
2
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 int main(void) |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 { |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
92 JOY_init(); |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
93 JOY_setEventHandler(&joy_event_handler); |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
94 |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
95 u8 cursor_tile_index = 1; |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
96 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0); |
10 | 97 |
4
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
98 u16 i; |
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
99 VDP_setPlanSize(64, 32); |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
100 /*for (i = 6; i < 40*28; i += 4) |
4
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
101 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) |
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
102 { |
17 | 103 tilemap[i] = WALL; |
104 tilemap[i+1] = WALL; | |
4
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
105 } |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
106 */ |
21
bb7dfb42b320
Small refactor to object placement. Add spawn point object
Michael Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
107 place_object(GOAL, 38, 14); |
bb7dfb42b320
Small refactor to object placement. Add spawn point object
Michael Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
108 place_object(SPAWN, 0, 14); |
bb7dfb42b320
Small refactor to object placement. Add spawn point object
Michael Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
109 gen_distances(38, 14); |
13
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
110 for (i = 0; i < MAX_SPRITE; i++) |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
111 { |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
112 spriteDefCache[i].posx = -0x80; |
d118fe8fb1db
Make cursor and creeps play nice
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
113 } |
11
c0bb53eaa6f4
Calculate distances from goal for all passible points for pathfinding purposes
Mike Pavone <pavone@retrodev.com>
parents:
7
diff
changeset
|
114 //print_distances(); |
2
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 for (;;) |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 { |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 VDP_waitVSync(); |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 VDP_updateSprites(); |
4
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
119 for (i = 0; i < 28; i++) |
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
120 { |
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
121 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); |
d73f53857e5f
Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents:
2
diff
changeset
|
122 } |
15
f71eb24b3896
placement of red walls with a button
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
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); |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
124 if (running) |
7
3ed112d64b1b
Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
125 { |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
126 if (countdown) |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
127 --countdown; |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
128 else if (cur_creeps < 4) |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
129 { |
21
bb7dfb42b320
Small refactor to object placement. Add spawn point object
Michael Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
130 spawn_creep(CREEP_NORMAL, 0+4, 14*8+4); |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
131 countdown = 300; |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
132 } |
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.
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
133 update_creeps(); |
7
3ed112d64b1b
Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
134 } |
2
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 return 0; |
8f23be2db808
Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 } |