1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#include "wizard.h"
#include "../enemy.h"
#include "../game.h"
#include "../hero.h"
#include <stdlib.h>
void createWizard(int x, int y)
{
int i;
for (i = 0; i < MAX_ENEMIES; i++) {
if (enemies[i] == NULL) {
Enemy* e = malloc(sizeof *e);
Wizard* w = malloc(sizeof *w);
w->id = i;
w->x = x;
w->y = y;
w->imageIndex = 0;
w->state = 0;
w->timer = 50;
w->visible = 1;
w->mask.circle = w->mask.unused = 0;
w->mask.w = 24;
w->mask.h = 38;
w->mask.x = w->x + 8;
w->mask.y = w->y + 2;
e->data = w;
e->enemyStep = wizardStep;
e->enemyDraw = wizardDraw;
e->type = 21;
enemies[i] = e;
i = MAX_ENEMIES;
}
}
}
void wizardStep(Wizard* w)
{
w->imageIndex += 0.3;
if (w->imageIndex >= 3) {
w->imageIndex -= 3;
}
//Stand still
if (w->state == 0) {
w->timer -= 1;
if (w->timer <= 0) {
PHL_PlaySound(sounds[sndPi10], CHN_ENEMIES);
w->state = 1;
w->timer = 15;
}
}
//Flash
else if (w->state == 1 || w->state == 3) {
if (w->visible == 0) {
w->visible = 1;
}else{
w->visible = 0;
}
w->timer -= 1;
if (w->timer <= 0) {
if (w->state == 1) {
w->state = 2;
w->timer = 60;
}
else if (w->state == 3) {
w->visible = 1;
w->state = 0;
w->timer = 50;
}
}
}
//Invisible
else if (w->state == 2) {
w->visible = 0;
w->timer -= 1;
if (w->timer <= 0) {
PHL_PlaySound(sounds[sndPi03], CHN_ENEMIES);
w->state = 3;
w->timer = 15;
//Horizontal Jump
int gridX = w->x / 40,
gridY = w->y / 40,
lastGridX = gridX;
do {
gridX = (rand() % 16) + 1;
} while (collisionTiles[gridX][gridY] != 0 ||
collisionTiles[gridX][gridY+1] != 1 ||
gridX == lastGridX);
w->x = gridX * 40;
w->mask.x = w->x + 8;
}
}
if (w->state == 0 || w->state == 3) {
//Hit Player
if (checkCollision(w->mask, getHeroMask())) {
heroHit(15, w->x + 20);
}
//Weapon Collision
int i;
for (i = 0; i < MAX_WEAPONS; i++) {
if (weapons[i] != NULL) {
if (checkCollision(w->mask, weapons[i]->weaponMask)) {
weaponHit(weapons[i]);
createEffect(2, w->x - 12, w->y - 6);
spawnCollectable(w->x + 20, w->y);
enemyDestroy(w->id);
i = MAX_WEAPONS;
}
}
}
}
}
void wizardDraw(Wizard* w)
{
if (w->visible == 1) {
PHL_DrawSurfacePart(w->x, w->y, 520 + (((int)w->imageIndex) * 40), 480, 40, 40, images[imgEnemies]);
}
}
|