|
diff --git a/interface.c b/interface.c
|
| 1 |
#include "all.h" |
1 |
#include "all.h" |
| 2 |
|
2 |
|
| 3 |
void DrawCrosshair(void) { |
3 |
void draw_crosshair(void) { |
| 4 |
int screenWidth = GetScreenWidth(); |
4 |
int screenWidth = GetScreenWidth(); |
| 5 |
int screenHeight = GetScreenHeight(); |
5 |
int screenHeight = GetScreenHeight(); |
| 6 |
DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); |
6 |
DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); |
| 7 |
DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); |
7 |
DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); |
| 8 |
} |
8 |
} |
| 9 |
|
9 |
|
| 10 |
void DrawDebugInfo(void) { |
10 |
void draw_debug_info(void) { |
| 11 |
DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); |
11 |
DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); |
| 12 |
DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); |
12 |
DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); |
| 13 |
DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.player.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); |
13 |
DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.player.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); |
| ... |
|
diff --git a/main.c b/main.c
|
| ... |
| 54 |
SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); |
54 |
SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); |
| 55 |
|
55 |
|
| 56 |
vfs_init(VFS_DATA_PAK); |
56 |
vfs_init(VFS_DATA_PAK); |
| 57 |
InitGame(); |
57 |
init_game(); |
| 58 |
game.screen_width = width; |
58 |
game.screen_width = width; |
| 59 |
game.screen_height = height; |
59 |
game.screen_height = height; |
| 60 |
SetMap(map_path.data); |
60 |
set_map(map_path.data); |
| 61 |
|
61 |
|
| 62 |
if (target_fps >= 0) { |
62 |
if (target_fps >= 0) { |
| 63 |
game.target_fps = target_fps; |
63 |
game.target_fps = target_fps; |
| ... |
| 69 |
} |
69 |
} |
| 70 |
|
70 |
|
| 71 |
if (skip_title) { |
71 |
if (skip_title) { |
| 72 |
if (LoadMap(game.map_path)) { |
72 |
if (load_map(game.map_path)) { |
| 73 |
game.mode = STATE_PLAYING; |
73 |
game.mode = STATE_PLAYING; |
| 74 |
game.cursor_captured = true; |
74 |
game.cursor_captured = true; |
| 75 |
DisableCursor(); |
75 |
DisableCursor(); |
| ... |
| 81 |
while (!WindowShouldClose()) { |
81 |
while (!WindowShouldClose()) { |
| 82 |
// Global Map Switching (Debug/Demo) |
82 |
// Global Map Switching (Debug/Demo) |
| 83 |
if (IsKeyPressed(KEY_ONE)) { |
83 |
if (IsKeyPressed(KEY_ONE)) { |
| 84 |
if (LoadMap("maps/demo1.map")) { |
84 |
if (load_map("maps/demo1.map")) { |
| 85 |
game.mode = STATE_PLAYING; |
85 |
game.mode = STATE_PLAYING; |
| 86 |
game.cursor_captured = true; |
86 |
game.cursor_captured = true; |
| 87 |
DisableCursor(); |
87 |
DisableCursor(); |
| 88 |
} |
88 |
} |
| 89 |
} |
89 |
} |
| 90 |
if (IsKeyPressed(KEY_TWO)) { |
90 |
if (IsKeyPressed(KEY_TWO)) { |
| 91 |
if (LoadMap("maps/demo2.map")) { |
91 |
if (load_map("maps/demo2.map")) { |
| 92 |
game.mode = STATE_PLAYING; |
92 |
game.mode = STATE_PLAYING; |
| 93 |
game.cursor_captured = true; |
93 |
game.cursor_captured = true; |
| 94 |
DisableCursor(); |
94 |
DisableCursor(); |
| 95 |
} |
95 |
} |
| 96 |
} |
96 |
} |
| 97 |
if (IsKeyPressed(KEY_THREE)) { |
97 |
if (IsKeyPressed(KEY_THREE)) { |
| 98 |
if (LoadMap("maps/demo3.map")) { |
98 |
if (load_map("maps/demo3.map")) { |
| 99 |
game.mode = STATE_PLAYING; |
99 |
game.mode = STATE_PLAYING; |
| 100 |
game.cursor_captured = true; |
100 |
game.cursor_captured = true; |
| 101 |
DisableCursor(); |
101 |
DisableCursor(); |
| ... |
| 105 |
// Game State Switcher |
105 |
// Game State Switcher |
| 106 |
switch (game.mode) { |
106 |
switch (game.mode) { |
| 107 |
case STATE_MENU: |
107 |
case STATE_MENU: |
| 108 |
UpdateMenu(); |
108 |
update_menu(); |
| 109 |
DrawMenu(); |
109 |
draw_menu(); |
| 110 |
break; |
110 |
break; |
| 111 |
case STATE_PLAYING: |
111 |
case STATE_PLAYING: |
| 112 |
UpdateGame(); |
112 |
update_game(); |
| 113 |
DrawGame(); |
113 |
draw_game(); |
| 114 |
break; |
114 |
break; |
| 115 |
} |
115 |
} |
| 116 |
} |
116 |
} |
| 117 |
|
117 |
|
| 118 |
UnloadMap(); |
118 |
unload_map(); |
| 119 |
UnloadAssets(); |
119 |
unload_assets(); |
| 120 |
vfs_shutdown(); |
120 |
vfs_shutdown(); |
| 121 |
CloseWindow(); |
121 |
CloseWindow(); |
| 122 |
sb_free(&map_path); |
122 |
sb_free(&map_path); |
| ... |
|
diff --git a/map.c b/map.c
|
| ... |
| 74 |
return (Vector3){ x, z, -y }; |
74 |
return (Vector3){ x, z, -y }; |
| 75 |
} |
75 |
} |
| 76 |
|
76 |
|
| 77 |
Map ParseMap(const char *filename) { |
77 |
Map parse_map(const char *filename) { |
| 78 |
size_t size; |
78 |
size_t size; |
| 79 |
char *data = (char *)vfs_read(filename, &size); |
79 |
char *data = (char *)vfs_read(filename, &size); |
| 80 |
Map map = { 0 }; |
80 |
Map map = { 0 }; |
| ... |
| 153 |
return map; |
153 |
return map; |
| 154 |
} |
154 |
} |
| 155 |
|
155 |
|
| 156 |
void FreeMap(Map map) { |
156 |
void free_map(Map map) { |
| 157 |
for (int i = 0; i < map.entity_count; i++) { |
157 |
for (int i = 0; i < map.entity_count; i++) { |
| 158 |
MapEntity *e = &map.entities[i]; |
158 |
MapEntity *e = &map.entities[i]; |
| 159 |
if (e->properties) free(e->properties); |
159 |
if (e->properties) free(e->properties); |
| ... |
| 165 |
if (map.entities) free(map.entities); |
165 |
if (map.entities) free(map.entities); |
| 166 |
} |
166 |
} |
| 167 |
|
167 |
|
| 168 |
Plane PlaneFromPoints(Vector3 p1, Vector3 p2, Vector3 p3) { |
168 |
Plane plane_from_points(Vector3 p1, Vector3 p2, Vector3 p3) { |
| 169 |
Vector3 v1 = Vector3Subtract(p2, p1); |
169 |
Vector3 v1 = Vector3Subtract(p2, p1); |
| 170 |
Vector3 v2 = Vector3Subtract(p3, p1); |
170 |
Vector3 v2 = Vector3Subtract(p3, p1); |
| 171 |
Vector3 normal = Vector3Normalize(Vector3CrossProduct(v1, v2)); |
171 |
Vector3 normal = Vector3Normalize(Vector3CrossProduct(v1, v2)); |
| 172 |
return (Plane){ normal, Vector3DotProduct(normal, p1) }; |
172 |
return (Plane){ normal, Vector3DotProduct(normal, p1) }; |
| 173 |
} |
173 |
} |
| 174 |
|
174 |
|
| 175 |
void PolyFree(Polygon p) { |
175 |
void poly_free(Polygon p) { |
| 176 |
if (p.verts) free(p.verts); |
176 |
if (p.verts) free(p.verts); |
| 177 |
} |
177 |
} |
| 178 |
|
178 |
|
| 179 |
Polygon PolyClip(Polygon poly, Plane plane) { |
179 |
Polygon poly_clip(Polygon poly, Plane plane) { |
| 180 |
if (poly.count == 0) return poly; |
180 |
if (poly.count == 0) return poly; |
| 181 |
|
181 |
|
| 182 |
array(Vector3) out_verts; |
182 |
array(Vector3) out_verts; |
| ... |
| 215 |
return res; |
215 |
return res; |
| 216 |
} |
216 |
} |
| 217 |
|
217 |
|
| 218 |
Polygon CreateLargeQuad(Plane plane) { |
218 |
Polygon create_large_quad(Plane plane) { |
| 219 |
Vector3 n = plane.normal; |
219 |
Vector3 n = plane.normal; |
| 220 |
Vector3 up = (fabsf(n.y) < 0.999f) ? (Vector3){ 0, 1, 0 } : (Vector3){ 1, 0, 0 }; |
220 |
Vector3 up = (fabsf(n.y) < 0.999f) ? (Vector3){ 0, 1, 0 } : (Vector3){ 1, 0, 0 }; |
| 221 |
Vector3 right = Vector3Normalize(Vector3CrossProduct(up, n)); |
221 |
Vector3 right = Vector3Normalize(Vector3CrossProduct(up, n)); |
| ... |
| 235 |
return poly; |
235 |
return poly; |
| 236 |
} |
236 |
} |
| 237 |
|
237 |
|
| 238 |
Vector2 GetUV(Vector3 p, MapPlane *mp, Plane plane) { |
238 |
Vector2 get_uv(Vector3 p, MapPlane *mp, Plane plane) { |
| 239 |
Vector3 n = plane.normal; |
239 |
Vector3 n = plane.normal; |
| 240 |
Vector3 up = (fabsf(n.y) < 0.999f) ? (Vector3){ 0, 1, 0 } : (Vector3){ 1, 0, 0 }; |
240 |
Vector3 up = (fabsf(n.y) < 0.999f) ? (Vector3){ 0, 1, 0 } : (Vector3){ 1, 0, 0 }; |
| 241 |
Vector3 right = Vector3Normalize(Vector3CrossProduct(up, n)); |
241 |
Vector3 right = Vector3Normalize(Vector3CrossProduct(up, n)); |
| ... |
| 247 |
return (Vector2){ u / 64.0f, v / 64.0f }; |
247 |
return (Vector2){ u / 64.0f, v / 64.0f }; |
| 248 |
} |
248 |
} |
| 249 |
|
249 |
|
| 250 |
void UnloadMap(void) { |
250 |
void unload_map(void) { |
| 251 |
if (game.map.models) { |
251 |
if (game.map.models) { |
| 252 |
for (int i = 0; i < game.map.count; i++) { |
252 |
for (int i = 0; i < game.map.count; i++) { |
| 253 |
UnloadModel(game.map.models[i]); |
253 |
UnloadModel(game.map.models[i]); |
| ... |
| 258 |
} |
258 |
} |
| 259 |
} |
259 |
} |
| 260 |
|
260 |
|
| 261 |
bool LoadMap(const char *filename) { |
261 |
bool load_map(const char *filename) { |
| 262 |
TraceLog(LOG_INFO, "Loading map: %s", filename); |
262 |
TraceLog(LOG_INFO, "Loading map: %s", filename); |
| 263 |
|
263 |
|
| 264 |
Map map = ParseMap(filename); |
264 |
Map map = parse_map(filename); |
| 265 |
if (map.entity_count == 0) { |
265 |
if (map.entity_count == 0) { |
| 266 |
TraceLog(LOG_ERROR, "Failed to load map or map is empty: %s", filename); |
266 |
TraceLog(LOG_ERROR, "Failed to load map or map is empty: %s", filename); |
| 267 |
return false; |
267 |
return false; |
| 268 |
} |
268 |
} |
| 269 |
|
269 |
|
| 270 |
UnloadMap(); |
270 |
unload_map(); |
| 271 |
|
271 |
|
| 272 |
array(TextureGroup) groups; |
272 |
array(TextureGroup) groups; |
| 273 |
array_init(groups); |
273 |
array_init(groups); |
| ... |
| 316 |
MapBrush *brush = &e->brushes[j]; |
316 |
MapBrush *brush = &e->brushes[j]; |
| 317 |
for (int p_idx = 0; p_idx < brush->plane_count; p_idx++) { |
317 |
for (int p_idx = 0; p_idx < brush->plane_count; p_idx++) { |
| 318 |
MapPlane *mp = &brush->planes[p_idx]; |
318 |
MapPlane *mp = &brush->planes[p_idx]; |
| 319 |
Plane plane = PlaneFromPoints(mp->p[0], mp->p[1], mp->p[2]); |
319 |
Plane plane = plane_from_points(mp->p[0], mp->p[1], mp->p[2]); |
| 320 |
|
320 |
|
| 321 |
if (Vector3Length(plane.normal) < 0.5f) continue; |
321 |
if (Vector3Length(plane.normal) < 0.5f) continue; |
| 322 |
|
322 |
|
| 323 |
Polygon poly = CreateLargeQuad(plane); |
323 |
Polygon poly = create_large_quad(plane); |
| 324 |
for (int k = 0; k < brush->plane_count; k++) { |
324 |
for (int k = 0; k < brush->plane_count; k++) { |
| 325 |
if (p_idx == k) continue; |
325 |
if (p_idx == k) continue; |
| 326 |
Plane clipPlane = PlaneFromPoints(brush->planes[k].p[0], brush->planes[k].p[1], brush->planes[k].p[2]); |
326 |
Plane clipPlane = plane_from_points(brush->planes[k].p[0], brush->planes[k].p[1], brush->planes[k].p[2]); |
| 327 |
if (Vector3Length(clipPlane.normal) < 0.5f) continue; |
327 |
if (Vector3Length(clipPlane.normal) < 0.5f) continue; |
| 328 |
|
328 |
|
| 329 |
Polygon next = PolyClip(poly, clipPlane); |
329 |
Polygon next = poly_clip(poly, clipPlane); |
| 330 |
PolyFree(poly); |
330 |
poly_free(poly); |
| 331 |
poly = next; |
331 |
poly = next; |
| 332 |
} |
332 |
} |
| 333 |
|
333 |
|
| ... |
| 355 |
array_push(group->vertices, v0.x); array_push(group->vertices, v0.y); array_push(group->vertices, v0.z); |
355 |
array_push(group->vertices, v0.x); array_push(group->vertices, v0.y); array_push(group->vertices, v0.z); |
| 356 |
array_push(group->vertices, v1.x); array_push(group->vertices, v1.y); array_push(group->vertices, v1.z); |
356 |
array_push(group->vertices, v1.x); array_push(group->vertices, v1.y); array_push(group->vertices, v1.z); |
| 357 |
array_push(group->vertices, v2.x); array_push(group->vertices, v2.y); array_push(group->vertices, v2.z); |
357 |
array_push(group->vertices, v2.x); array_push(group->vertices, v2.y); array_push(group->vertices, v2.z); |
| 358 |
Vector2 uv0 = GetUV(v0, mp, plane); |
358 |
Vector2 uv0 = get_uv(v0, mp, plane); |
| 359 |
Vector2 uv1 = GetUV(v1, mp, plane); |
359 |
Vector2 uv1 = get_uv(v1, mp, plane); |
| 360 |
Vector2 uv2 = GetUV(v2, mp, plane); |
360 |
Vector2 uv2 = get_uv(v2, mp, plane); |
| 361 |
array_push(group->texcoords, uv0.x); array_push(group->texcoords, uv0.y); |
361 |
array_push(group->texcoords, uv0.x); array_push(group->texcoords, uv0.y); |
| 362 |
array_push(group->texcoords, uv1.x); array_push(group->texcoords, uv1.y); |
362 |
array_push(group->texcoords, uv1.x); array_push(group->texcoords, uv1.y); |
| 363 |
array_push(group->texcoords, uv2.x); array_push(group->texcoords, uv2.y); |
363 |
array_push(group->texcoords, uv2.x); array_push(group->texcoords, uv2.y); |
| ... |
| 367 |
array_push(group->normals, out_normal.x); array_push(group->normals, out_normal.y); array_push(group->normals, out_normal.z); |
367 |
array_push(group->normals, out_normal.x); array_push(group->normals, out_normal.y); array_push(group->normals, out_normal.z); |
| 368 |
} |
368 |
} |
| 369 |
} |
369 |
} |
| 370 |
PolyFree(poly); |
370 |
poly_free(poly); |
| 371 |
} |
371 |
} |
| 372 |
} |
372 |
} |
| 373 |
} |
373 |
} |
| ... |
| 390 |
memcpy(mesh.normals, g->normals.data, g->normals.length * sizeof(float)); |
390 |
memcpy(mesh.normals, g->normals.data, g->normals.length * sizeof(float)); |
| 391 |
UploadMesh(&mesh, false); |
391 |
UploadMesh(&mesh, false); |
| 392 |
Model model = LoadModelFromMesh(mesh); |
392 |
Model model = LoadModelFromMesh(mesh); |
| 393 |
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = GetTexture(g->texture); |
393 |
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = get_texture(g->texture); |
| 394 |
array_push(final_models, model); |
394 |
array_push(final_models, model); |
| 395 |
array_free(g->vertices); |
395 |
array_free(g->vertices); |
| 396 |
array_free(g->texcoords); |
396 |
array_free(g->texcoords); |
| ... |
| 401 |
game.map.count = (int)final_models.length; |
401 |
game.map.count = (int)final_models.length; |
| 402 |
array_free(groups); |
402 |
array_free(groups); |
| 403 |
|
403 |
|
| 404 |
FreeMap(map); |
404 |
free_map(map); |
| 405 |
TraceLog(LOG_INFO, "Processed %d brushes into %d models", total_brushes, game.map.count); |
405 |
TraceLog(LOG_INFO, "Processed %d brushes into %d models", total_brushes, game.map.count); |
| 406 |
return true; |
406 |
return true; |
| 407 |
} |
407 |
} |
| 408 |
|
408 |
|
| 409 |
bool CheckMapCollision(Vector3 start, Vector3 end, RayCollision *outCollision) { |
409 |
bool check_map_collision(Vector3 start, Vector3 end, RayCollision *outCollision) { |
| 410 |
Vector3 diff = Vector3Subtract(end, start); |
410 |
Vector3 diff = Vector3Subtract(end, start); |
| 411 |
float maxDist = Vector3Length(diff); |
411 |
float maxDist = Vector3Length(diff); |
| 412 |
if (maxDist < 0.001f) return false; |
412 |
if (maxDist < 0.001f) return false; |
| ... |
|
diff --git a/maps/demo4.map b/maps/demo4.map
|
|
|
1 |
// Game: Stalag |
|
|
2 |
// Format: Standard |
|
|
3 |
// entity 0 |
|
|
4 |
{ |
|
|
5 |
"classname" "worldspawn" |
|
|
6 |
// brush 0 |
|
|
7 |
{ |
|
|
8 |
( -128 -80 -16 ) ( -128 -79 -16 ) ( -128 -80 -15 ) __TB_empty -16 0 0 1 1 |
|
|
9 |
( -64 -80 -16 ) ( -64 -80 -15 ) ( -63 -80 -16 ) __TB_empty 0 0 0 1 1 |
|
|
10 |
( -64 -80 -16 ) ( -63 -80 -16 ) ( -64 -79 -16 ) __TB_empty 0 16 0 1 1 |
|
|
11 |
( 64 48 0 ) ( 64 49 0 ) ( 65 48 0 ) __TB_empty 0 16 0 1 1 |
|
|
12 |
( 64 656 16 ) ( 65 656 16 ) ( 64 656 17 ) __TB_empty 0 0 0 1 1 |
|
|
13 |
( 64 48 16 ) ( 64 48 17 ) ( 64 49 16 ) __TB_empty -16 0 0 1 1 |
|
|
14 |
} |
|
|
15 |
// brush 1 |
|
|
16 |
{ |
|
|
17 |
( -128 -80 0 ) ( -128 -79 0 ) ( -128 -80 1 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
18 |
( -128 -80 0 ) ( -128 -80 1 ) ( -127 -80 0 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
19 |
( -128 -80 0 ) ( -127 -80 0 ) ( -128 -79 0 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
20 |
( -112 48 112 ) ( -112 49 112 ) ( -111 48 112 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
21 |
( -112 656 16 ) ( -111 656 16 ) ( -112 656 17 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
22 |
( -112 48 16 ) ( -112 48 17 ) ( -112 49 16 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
23 |
} |
|
|
24 |
// brush 2 |
|
|
25 |
{ |
|
|
26 |
( 48 -80 0 ) ( 48 -79 0 ) ( 48 -80 1 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
27 |
( 48 -80 0 ) ( 48 -80 1 ) ( 49 -80 0 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
28 |
( 48 -80 0 ) ( 49 -80 0 ) ( 48 -79 0 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
29 |
( 64 48 112 ) ( 64 49 112 ) ( 65 48 112 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
30 |
( 64 656 16 ) ( 65 656 16 ) ( 64 656 17 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
31 |
( 64 48 16 ) ( 64 48 17 ) ( 64 49 16 ) interior/interior_wall_003 0 0 0 1 1 |
|
|
32 |
} |
|
|
33 |
// brush 3 |
|
|
34 |
{ |
|
|
35 |
( 48 480 112 ) ( 48 481 112 ) ( 47 480 113 ) interior/interior_wall_001 0 0 90 1 1 |
|
|
36 |
( 48 480 112 ) ( 47 480 113 ) ( 49 480 112 ) interior/interior_wall_001 16 6.4000015 0 1 1.25 |
|
|
37 |
( 48 480 112 ) ( 49 480 112 ) ( 48 481 112 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
38 |
( 32 656 144 ) ( 32 657 144 ) ( 33 656 144 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
39 |
( 48 656 128 ) ( 49 656 128 ) ( 47 656 129 ) interior/interior_wall_001 16 6.4000015 0 1 1.25 |
|
|
40 |
( 48 656 128 ) ( 47 656 129 ) ( 48 657 128 ) interior/interior_wall_001 0 -16 90 1 1 |
|
|
41 |
} |
|
|
42 |
// brush 4 |
|
|
43 |
{ |
|
|
44 |
( -112 480 128 ) ( -111 480 129 ) ( -112 479 128 ) interior/interior_wall_001 -16 -16 270 1 1 |
|
|
45 |
( -112 480 128 ) ( -113 480 128 ) ( -111 480 129 ) interior/interior_wall_001 -16 6.4000015 180 1 -1.25 |
|
|
46 |
( -112 656 112 ) ( -113 656 112 ) ( -112 655 112 ) interior/interior_wall_001 0 16 180 1 1 |
|
|
47 |
( -96 480 144 ) ( -96 479 144 ) ( -97 480 144 ) interior/interior_wall_001 0 16 180 1 1 |
|
|
48 |
( -112 656 112 ) ( -111 656 113 ) ( -113 656 112 ) interior/interior_wall_001 -16 6.4000015 180 1 -1.25 |
|
|
49 |
( -112 656 112 ) ( -112 655 112 ) ( -111 656 113 ) interior/interior_wall_001 -16 0 270 1 1 |
|
|
50 |
} |
|
|
51 |
// brush 5 |
|
|
52 |
{ |
|
|
53 |
( -96 480 144 ) ( -96 481 144 ) ( -96 480 145 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
54 |
( -96 480 144 ) ( -96 480 145 ) ( -95 480 144 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
55 |
( -96 480 144 ) ( -95 480 144 ) ( -96 481 144 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
56 |
( 32 656 160 ) ( 32 657 160 ) ( 33 656 160 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
57 |
( 32 656 160 ) ( 33 656 160 ) ( 32 656 161 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
58 |
( 32 656 160 ) ( 32 656 161 ) ( 32 657 160 ) interior/interior_wall_001 0 0 0 1 1 |
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
// entity 1 |
|
|
62 |
{ |
|
|
63 |
"classname" "info_player_start" |
|
|
64 |
"origin" "-32 624 16" |
|
|
65 |
} |
|
diff --git a/player.c b/player.c
|
| ... |
| 59 |
Vector3 end = Vector3Add(start, Vector3Scale(dir, dist)); |
59 |
Vector3 end = Vector3Add(start, Vector3Scale(dir, dist)); |
| 60 |
|
60 |
|
| 61 |
RayCollision col; |
61 |
RayCollision col; |
| 62 |
if (CheckMapCollision(start, end, &col)) { |
62 |
if (check_map_collision(start, end, &col)) { |
| 63 |
float adjustedDist = col.distance - PLAYER_RADIUS; |
63 |
float adjustedDist = col.distance - PLAYER_RADIUS; |
| 64 |
if (adjustedDist < closestHit.distance) { |
64 |
if (adjustedDist < closestHit.distance) { |
| 65 |
closestHit = col; |
65 |
closestHit = col; |
| ... |
| 99 |
Vector3 start = vStart; |
99 |
Vector3 start = vStart; |
| 100 |
Vector3 end = Vector3Add(vStart, (Vector3){0, verticalMove - eyeHeight, 0}); |
100 |
Vector3 end = Vector3Add(vStart, (Vector3){0, verticalMove - eyeHeight, 0}); |
| 101 |
RayCollision vCol; |
101 |
RayCollision vCol; |
| 102 |
if (CheckMapCollision(start, end, &vCol) && vCol.normal.y > 0.5f) { |
102 |
if (check_map_collision(start, end, &vCol) && vCol.normal.y > 0.5f) { |
| 103 |
game.player.pos.y = vCol.point.y + eyeHeight; |
103 |
game.player.pos.y = vCol.point.y + eyeHeight; |
| 104 |
game.player.velocity.y = 0; |
104 |
game.player.velocity.y = 0; |
| 105 |
game.player.is_grounded = true; |
105 |
game.player.is_grounded = true; |
| ... |
| 112 |
float headHeight = PLAYER_HEIGHT - PLAYER_EYE_HEIGHT; |
112 |
float headHeight = PLAYER_HEIGHT - PLAYER_EYE_HEIGHT; |
| 113 |
Vector3 end = Vector3Add(vStart, (Vector3){0, verticalMove + headHeight, 0}); |
113 |
Vector3 end = Vector3Add(vStart, (Vector3){0, verticalMove + headHeight, 0}); |
| 114 |
RayCollision vCol; |
114 |
RayCollision vCol; |
| 115 |
if (CheckMapCollision(start, end, &vCol)) { |
115 |
if (check_map_collision(start, end, &vCol)) { |
| 116 |
game.player.pos.y = vCol.point.y - headHeight - 1.0f; |
116 |
game.player.pos.y = vCol.point.y - headHeight - 1.0f; |
| 117 |
game.player.velocity.y = 0; |
117 |
game.player.velocity.y = 0; |
| 118 |
} else { |
118 |
} else { |
| ... |
| 123 |
Vector3 start = vStart; |
123 |
Vector3 start = vStart; |
| 124 |
Vector3 end = Vector3Add(vStart, (Vector3){0, -eyeHeight - 2.0f, 0}); |
124 |
Vector3 end = Vector3Add(vStart, (Vector3){0, -eyeHeight - 2.0f, 0}); |
| 125 |
RayCollision vCol; |
125 |
RayCollision vCol; |
| 126 |
if (CheckMapCollision(start, end, &vCol) && vCol.normal.y > 0.5f) { |
126 |
if (check_map_collision(start, end, &vCol) && vCol.normal.y > 0.5f) { |
| 127 |
game.player.is_grounded = true; |
127 |
game.player.is_grounded = true; |
| 128 |
if (vCol.distance < eyeHeight + 1.0f) { |
128 |
if (vCol.distance < eyeHeight + 1.0f) { |
| 129 |
game.player.pos.y = vCol.point.y + eyeHeight; |
129 |
game.player.pos.y = vCol.point.y + eyeHeight; |
| ... |
| 170 |
game.player.is_grounded = false; |
170 |
game.player.is_grounded = false; |
| 171 |
} |
171 |
} |
| 172 |
|
172 |
|
| 173 |
void UpdatePlayer(void) { |
173 |
void update_player(void) { |
| 174 |
float dt = GetFrameTime(); |
174 |
float dt = GetFrameTime(); |
| 175 |
Vector3 oldPos = game.player.pos; |
175 |
Vector3 oldPos = game.player.pos; |
| 176 |
|
176 |
|
| ... |
| 189 |
Vector3 headPos = game.player.pos; |
189 |
Vector3 headPos = game.player.pos; |
| 190 |
Vector3 headEnd = Vector3Add(headPos, (Vector3){0, PLAYER_HEIGHT - PLAYER_EYE_HEIGHT + PLAYER_CROUCH_OFFSET, 0}); |
190 |
Vector3 headEnd = Vector3Add(headPos, (Vector3){0, PLAYER_HEIGHT - PLAYER_EYE_HEIGHT + PLAYER_CROUCH_OFFSET, 0}); |
| 191 |
RayCollision col; |
191 |
RayCollision col; |
| 192 |
if (CheckMapCollision(headPos, headEnd, &col)) { |
192 |
if (check_map_collision(headPos, headEnd, &col)) { |
| 193 |
canStand = false; |
193 |
canStand = false; |
| 194 |
} |
194 |
} |
| 195 |
} |
195 |
} |
| ... |