Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9566 | turbocat | 1 | #include "ghoul.h" |
2 | #include "../game.h" |
||
3 | #include "../enemy.h" |
||
4 | #include "../PHL.h" |
||
5 | #include "../hero.h" |
||
6 | #include |
||
7 | |||
8 | void ghoulStep(Ghoul* g); |
||
9 | void ghoulDraw(Ghoul* g); |
||
10 | |||
11 | void createGhoul(int x, int y, int type) |
||
12 | { |
||
13 | int i; |
||
14 | for (i = 0; i < MAX_ENEMIES; i++) { |
||
15 | if (enemies[i] == NULL) { |
||
16 | Enemy* e = malloc(sizeof *e); |
||
17 | Ghoul* g = malloc(sizeof *g); |
||
18 | g->id = i; |
||
19 | g->hp = 2; |
||
20 | |||
21 | g->x = x; |
||
22 | g->y = y; |
||
23 | |||
24 | g->vsp = 0; |
||
25 | g->grav = 0.1; |
||
26 | |||
27 | g->dir = 0; |
||
28 | g->type = type; |
||
29 | g->onground = 0; |
||
30 | |||
31 | g->timer = 0; |
||
32 | g->state = 0; |
||
33 | g->invincible = 0; |
||
34 | |||
35 | g->imageIndex = 0; |
||
36 | |||
37 | g->mask.circle = 0; |
||
38 | g->mask.unused = 1; |
||
39 | g->mask.w = 24; |
||
40 | g->mask.h = 32; |
||
41 | g->mask.x = g->x + ((40 - g->mask.w) / 2); |
||
42 | g->mask.y = g->y + (40 - g->mask.h); |
||
43 | |||
44 | e->data = g; |
||
45 | e->enemyStep = ghoulStep; |
||
46 | e->enemyDraw = ghoulDraw; |
||
47 | e->type = 18; |
||
48 | |||
49 | enemies[i] = e; |
||
50 | i = MAX_ENEMIES; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | } |
||
55 | |||
56 | void ghoulStep(Ghoul* g) |
||
57 | { |
||
58 | if (g->invincible > 0) { |
||
59 | g->invincible -= 1; |
||
60 | } |
||
61 | |||
62 | if (g->state == 0) { //Wait |
||
63 | Mask area; |
||
64 | area.unused = area.circle = 0; |
||
65 | area.w = 280; |
||
66 | area.h = 80; |
||
67 | area.x = g->x - 120; |
||
68 | area.y = g->y - 20; |
||
69 | |||
70 | if (checkCollisionXY(area, herox, heroy + 20) == 1) { |
||
71 | g->state = 1; |
||
72 | g->mask.unused = 0; |
||
73 | g->imageIndex = 0; |
||
74 | |||
75 | g->dir = 1; |
||
76 | if (herox < g->x + 20) { |
||
77 | g->dir = -1; |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | else if (g->state == 1) { //Pop-up |
||
82 | g->imageIndex += 0.16; |
||
83 | |||
84 | if (g->imageIndex >= 4) { |
||
85 | g->state = 2; |
||
86 | g->vsp = -1; |
||
87 | g->imageIndex = 0; |
||
88 | PHL_PlaySound(sounds[sndPi05],CHN_ENEMIES); |
||
89 | } |
||
90 | } |
||
91 | else if (g->state == 2) { //Walking |
||
92 | g->mask.unused = 0; |
||
93 | if (g->onground == 0) { |
||
94 | //Vertical movement |
||
95 | g->y += g->vsp; |
||
96 | g->vsp += g->grav; |
||
97 | |||
98 | g->mask.y = g->y + (40 - g->mask.h); |
||
99 | |||
100 | PHL_Rect collide = getTileCollision(1, g->mask); |
||
101 | if (collide.x == -1) { |
||
102 | collide = getTileCollision(3, g->mask); |
||
103 | } |
||
104 | if (collide.x != -1) { |
||
105 | g->onground = 1; |
||
106 | g->vsp = 0; |
||
107 | g->y = collide.y - 40; |
||
108 | g->mask.y = g->y + (40 - g->mask.h); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | g->imageIndex += 0.1; |
||
113 | if (g->imageIndex >= 2) { |
||
114 | g->imageIndex -= 2; |
||
115 | } |
||
116 | |||
117 | double hsp = 1; |
||
118 | |||
119 | if ((int)g->imageIndex == 0) { |
||
120 | hsp = 0.5; |
||
121 | } |
||
122 | |||
123 | //Purple |
||
124 | if (g->type == 1) { |
||
125 | hsp *= 2; |
||
126 | } |
||
127 | |||
128 | g->x += hsp * g->dir; |
||
129 | g->mask.x = g->x + ((40 - g->mask.w) / 2); |
||
130 | |||
131 | if (g->onground == 1) { |
||
132 | if ((g->x < -20 || g->x > 660) || checkTileCollision(1, g->mask) == 1) { |
||
133 | g->dir *= -1; |
||
134 | |||
135 | PHL_Rect collide = getTileCollision(1, g->mask); |
||
136 | if (collide.x != -1) { |
||
137 | g->x = collide.x + (40 * g->dir); |
||
138 | } |
||
139 | } |
||
140 | else { |
||
141 | //check on ledge |
||
142 | g->mask.w = 5; |
||
143 | if (g->dir == 1) { |
||
144 | g->mask.x = g->x + 30; |
||
145 | } |
||
146 | if (g->dir == -1) { |
||
147 | g->mask.x = g->x + 5; |
||
148 | } |
||
149 | g->mask.y += 20; |
||
150 | |||
151 | if (checkTileCollision(1, g->mask) == 0 && checkTileCollision(3, g->mask) == 0) { |
||
152 | g->dir *= -1; |
||
153 | } |
||
154 | g->mask.w = 24; |
||
155 | g->mask.x = g->x + ((40 - g->mask.w) / 2); |
||
156 | g->mask.y = g->y + (40 - g->mask.h); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | g->mask.x = g->x + ((40 - g->mask.w) / 2); |
||
162 | g->mask.y = g->y + (40 - g->mask.h); |
||
163 | |||
164 | //Hit Player |
||
165 | { |
||
166 | if (checkCollision(g->mask, getHeroMask())) { |
||
167 | if (heroHit(10, g->x + 20) == 1 && g->type == 1) { |
||
168 | heroPoison(); |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | |||
173 | //Weapon Collision |
||
174 | { |
||
175 | int i; |
||
176 | for (i = 0; i < MAX_WEAPONS; i++) { |
||
177 | if (weapons[i] != NULL) { |
||
178 | if (weapons[i]->cooldown == 0) { |
||
179 | if (checkCollision(g->mask, weapons[i]->weaponMask)) { |
||
180 | weaponHit(weapons[i]); |
||
181 | |||
182 | g->hp -= 1; |
||
183 | g->invincible = 15; |
||
184 | //Death |
||
185 | if (g->hp <= 0) { |
||
186 | createEffect(2, g->x - 12, g->y - 6); |
||
187 | spawnCollectable(g->x + 20, g->y); |
||
188 | enemyDestroy(g->id); |
||
189 | } |
||
190 | i = MAX_WEAPONS; |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | |||
197 | } |
||
198 | |||
199 | void ghoulDraw(Ghoul* g) |
||
200 | { |
||
201 | if (g->state != 0 && g->invincible % 2 == 0) { |
||
202 | int cx = (int)g->imageIndex * 40, |
||
203 | cy = 160; |
||
204 | |||
205 | if (g->state == 1) { |
||
206 | cx += 160; |
||
207 | }else{ |
||
208 | if (g->dir == -1) { |
||
209 | cx += 80; |
||
210 | } |
||
211 | } |
||
212 | |||
213 | //Purple palette |
||
214 | cy += 160 * g->type; |
||
215 | |||
216 | PHL_DrawSurfacePart(g->x, g->y, cx, cy, 40, 40, images[imgEnemies]); |
||
217 | } |
||
218 | }=>>>>> |