-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemies.cpp
More file actions
87 lines (72 loc) · 3.13 KB
/
enemies.cpp
File metadata and controls
87 lines (72 loc) · 3.13 KB
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
const f32 turret_width = 0.5f;
const v2 turret_diagonal = v2 {turret_width, turret_width};
const f32 turret_shot_width = 0.2f;
const v2 turret_shot_diagonal = v2 {turret_shot_width, turret_shot_width};
sim_entity_* create_turret(game_state_* game_state, v2 position, v2 direction) {
const f32 turret_mass = 5.0f;
const f32 turret_orientation = 0.0f;
sim_entity_* turret = create_block_entity(game_state,
TURRET,
position,
turret_diagonal,
turret_mass,
turret_orientation,
PHY_FIXED_FLAG);
turret->body->inv_mass = 0.0f;
turret->body->inv_moment = 0.0f;
turret->turret_state.direction = direction;
return turret;
}
UPDATE_FUNC(TURRET) {
// const f32 turret_speed = 3.0f;
const f32 turret_shoot_delay = 2.0f;
turret_state_* state = &entity->turret_state;
state->shoot_timer += dt;
// f32 gravity_orientation = atanv(game_state->gravity_normal) + fPI_OVER_2;
if (state->shoot_timer > turret_shoot_delay) {
state->shoot_timer = 0.0f;
v2 start_position = entity->body->position +
entity->turret_state.direction * (0.5f * (turret_width + turret_shot_width));
create_turret_shot(game_state, start_position, entity->turret_state.direction);
}
push_rect(&game_state->main_render_group,
color_ {0.67f, 0.54f, 0.23f},
entity->body->position,
turret_diagonal,
entity->body->orientation,
0.5f,
0);
}
sim_entity_* create_turret_shot(game_state_* game_state, v2 position, v2 direction) {
const f32 turret_shot_mass = 0.1f;
const f32 turret_shot_orientation = 0.0f;
const f32 turret_shot_speed = 10.0f;
sim_entity_* shot = create_fillet_block_entity(game_state,
TURRET_SHOT,
position,
turret_shot_diagonal,
0.09f,
turret_shot_mass,
turret_shot_orientation,
PHY_WEIGHTLESS_FLAG);
shot->body->velocity = turret_shot_speed * direction;
return shot;
}
UPDATE_FUNC(TURRET_SHOT) {
entity_ties_* collision = get_hash_item(&game_state->collision_map,
entity->id);
if (collision && collision->type != TURRET) {
if (collision->type == PLAYER) {
kill_player(game_state);
}
remove_entity(game_state, entity);
} else {
push_rect(&game_state->main_render_group,
color_ {1.0f, 0.23f, 0.54f},
entity->body->position,
turret_shot_diagonal,
entity->body->orientation,
0.5f,
0);
}
}