-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.cpp
More file actions
132 lines (111 loc) · 4.08 KB
/
tile.cpp
File metadata and controls
132 lines (111 loc) · 4.08 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
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
#include "sim_entity.h"
const v2 tile_diagonal = v2 {1.0f, 1.0f};
const f32 tile_z = 0.15f;
const i32 tile_texture_size = 64;
const f32 spikes_z = tile_z;
const i32 spikes_texture_size = tile_texture_size;
sim_entity_*
create_tile(game_state_* game_state, v2 position, tile_info_ info) {
const f32 tile_mass = 100.0f;
const f32 tile_orientation = 0.0f;
sim_entity_* tile = create_block_entity(game_state,
TILE,
position,
tile_diagonal,
tile_mass,
tile_orientation,
PHY_FIXED_FLAG | PHY_GROUND_FLAG);
tile->body->inv_moment = 0.0f;
tile->body->inv_mass = 0.0f;
tile->tile_info = info;
return tile;
}
UPDATE_FUNC(TILE) {
phy_body_* body = entity->body;
rect_i source_rect;
source_rect.min_x = entity->tile_info.tex_coord_x * tile_texture_size;
source_rect.max_x = source_rect.min_x + tile_texture_size;
source_rect.min_y = entity->tile_info.tex_coord_y * tile_texture_size;
source_rect.max_y = source_rect.min_y + tile_texture_size;
push_texture(&game_state->main_render_group,
body->position,
v2 {32.0f, 32.0f},
VIRTUAL_PIXEL_SIZE,
game_state->terrain_1,
source_rect,
rgba_{0},
body->orientation,
tile_z);
}
sim_entity_*
create_spikes(game_state_* game_state, v2 position, i32 direction) {
const f32 spikes_mass = 100.0f;
const f32 spikes_orientation = 0.0f;
v2 diagonal;
v2 center;
switch (direction) {
case DIR_UP: {
diagonal = v2 {1.0f, 0.5f};
center = position - v2 {0.0f, 0.25f};
} break;
case DIR_DOWN: {
diagonal = v2 {1.0f, 0.5f};
center = position + v2 {0.0f, 0.25f};
} break;
case DIR_LEFT: {
diagonal = v2 {0.5f, 1.0f};
center = position - v2 {0.25f, 0.0f};
} break;
case DIR_RIGHT: {
diagonal = v2 {0.5f, 1.0f};
center = position + v2 {0.25f, 0.0f};
} break;
}
sim_entity_* spikes = create_block_entity(game_state,
SPIKES,
center,
diagonal,
spikes_mass,
spikes_orientation,
PHY_FIXED_FLAG);
spikes->body->inv_moment = 0.0f;
spikes->body->inv_mass = 0.0f;
spikes->spikes_info.direction = direction;
return spikes;
}
UPDATE_FUNC(SPIKES) {
phy_body_* body = entity->body;
rect_i source_rect;
source_rect.min_x = entity->spikes_info.direction * spikes_texture_size;
source_rect.max_x = source_rect.min_x + spikes_texture_size;
source_rect.min_y = 2 * spikes_texture_size;
source_rect.max_y = source_rect.min_y + spikes_texture_size;
v2 center;
switch (entity->spikes_info.direction) {
case DIR_UP: {
center = body->position + v2 {0.0f, 0.25f};
} break;
case DIR_DOWN: {
center = body->position - v2 {0.0f, 0.25f};
} break;
case DIR_LEFT: {
center = body->position + v2 {0.25f, 0.0f};
} break;
case DIR_RIGHT: {
center = body->position - v2 {0.25f, 0.0f};
} break;
}
push_texture(&game_state->main_render_group,
center,
v2 {32.0f, 32.0f},
VIRTUAL_PIXEL_SIZE,
game_state->terrain_1,
source_rect,
rgba_{0},
body->orientation,
spikes_z);
entity_ties_* collision = get_hash_item(&game_state->collision_map, entity->id);
if (collision && collision->type == PLAYER) {
kill_player(game_state);
}
}