-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_enemy_zombie.c
118 lines (104 loc) · 3.66 KB
/
entity_enemy_zombie.c
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
#include "entity.h"
#include "entity_enemy.h"
#include "entity_projectile_gib.h"
#include "audio.h"
animation_t zombie_animations[] = {
{ // 0: Idle
.time = 1,
.num_frames = 1,
.frames = (animation_frame_t[]) {
{.name = "default"},
},
},
{ // 1: Walk
.time = 0.40f,
.num_frames = 4,
.frames = (animation_frame_t[]) {
{.name = "run_1"},
{.name = "run_2"},
{.name = "run_3"},
{.name = "run_4"},
},
},
{ // 2: Run
.time = 0.20f,
.num_frames = 4,
.frames = (animation_frame_t[]) {
{.name = "run_1"},
{.name = "run_2"},
{.name = "run_3"},
{.name = "run_4"},
},
},
{ // 3: Attack prepare
.time = 0.25f,
.num_frames = 4,
.frames = (animation_frame_t[]) {
{.name = "default"},
{.name = "default"},
{.name = "shoot"},
{.name = "shoot"},
},
},
{ // 4: Attack
.time = 0.25f,
.num_frames = 4,
.frames = (animation_frame_t[]) {
{.name = "shoot"},
{.name = "default"},
{.name = "default"},
{.name = "default"},
},
},
};
// hack for caching parsed frame names per-map
static ref_entt_t * last_ref_entt = NULL;
enemy_state_t zombie_enemy_states[_ENEMY_STATE_NULL] = {
[ENEMY_STATE_IDLE] = {ENEMY_ANIMATION_IDLE, 0.0, 0.1, _ENEMY_STATE_NULL},
[ENEMY_STATE_PATROL] = {ENEMY_ANIMATION_WALK, 0.5, 0.5, _ENEMY_STATE_NULL},
[ENEMY_STATE_FOLLOW] = {ENEMY_ANIMATION_IDLE, 0.0, 0.1, _ENEMY_STATE_NULL},
[ENEMY_STATE_ATTACK_RECOVER] = {ENEMY_ANIMATION_IDLE, 0.0, 1.1, ENEMY_STATE_IDLE},
[ENEMY_STATE_ATTACK_EXEC] = {ENEMY_ANIMATION_ATTACK, 0.0, 0.4, ENEMY_STATE_ATTACK_RECOVER},
[ENEMY_STATE_ATTACK_PREPARE] = {ENEMY_ANIMATION_ATTACK_PREPARE, 0.0, 0.4, ENEMY_STATE_ATTACK_EXEC},
[ENEMY_STATE_ATTACK_AIM] = {ENEMY_ANIMATION_IDLE, 0.0, 0.1, ENEMY_STATE_ATTACK_PREPARE},
[ENEMY_STATE_EVADE] = {ENEMY_ANIMATION_IDLE, 0.0, 0.1, ENEMY_STATE_ATTACK_AIM},
};
void entity_enemy_zombie_init(entity_t * e);
void entity_enemy_zombie_receive_damage(entity_t * e, entity_t *from, int32_t amount);
void entity_enemy_zombie_attack(entity_t * e);
void entity_enemy_zombie_constructor(entity_t * e) {
entity_enemy_constructor(e, 0);
e->_receive_damage = entity_enemy_zombie_receive_damage;
e->_attack = entity_enemy_zombie_attack;
entity_enemy_zombie_init(e);
}
void entity_enemy_zombie_init(entity_t * e) {
e->_speed = 0;
e->_attack_distance = 350;
e->_health = 60;
e->_state_collection = (enemy_state_collection_t) {
.num_states = _ENEMY_STATE_NULL,
.states = zombie_enemy_states
};
e->_set_state(e, e->_state);
entity_parse_animation_frames(
e->_params->entity_generic_params.ref_entt,
zombie_animations,
sizeof(zombie_animations)/sizeof(zombie_animations[0]),
&last_ref_entt
);
e->_animation_collection = (animation_collection_t) {
.animations = zombie_animations,
.num_animations = sizeof(zombie_animations)/sizeof(zombie_animations[0]),
};
entity_set_model(e);
}
void entity_enemy_zombie_receive_damage(entity_t * e, entity_t * from, int32_t amount) {
if (amount > 60) {
entity_enemy_receive_damage(e, from, amount);
}
}
void entity_enemy_zombie_attack(entity_t * e) {
e->_play_sound(e, sfx_enemy_hit);
e->_spawn_projectile(e, ENTITY_ID_PROJECTILE_GIB, 600, 0, -0.5);
}