diff options
Diffstat (limited to 'game.c')
| -rw-r--r-- | game.c | 72 |
1 files changed, 32 insertions, 40 deletions
@@ -112,9 +112,18 @@ bool LoadMap(const char *filename) { float x, y, z; sscanf(e->properties[j].value, "%f %f %f", &x, &y, &z); if (strcmp(classname, "info_player_start") == 0) { - game.camera.position = (Vector3){ x, z, -y }; - game.camera.target = Vector3Add(game.camera.position, (Vector3){0, 0, 1}); - TraceLog(LOG_INFO, "Player spawn set to: %f, %f, %f", game.camera.position.x, game.camera.position.y, game.camera.position.z); + game.pos = (Vector3){ x, z, -y }; + game.camera.position = game.pos; + float angle = 0; + for (int k = 0; k < e->property_count; k++) { + if (strcmp(e->properties[k].key, "angle") == 0) { + angle = (float)atof(e->properties[k].value); + } + } + game.yaw = (angle + 90.0f) * DEG2RAD; + game.pitch = 0; + game.camera.target = Vector3Add(game.pos, (Vector3){sinf(game.yaw), 0, cosf(game.yaw)}); + TraceLog(LOG_INFO, "Player spawn set to: %f, %f, %f (yaw: %f)", game.pos.x, game.pos.y, game.pos.z, game.yaw); } } } @@ -219,15 +228,27 @@ void InitGame(void) { game.world_models = NULL; game.world_model_count = 0; + // Load UI Font + size_t font_size = 0; + void *font_data = vfs_read("fonts/LiberationSans-Bold.ttf", &font_size); + if (font_data) { + game.font_ui = LoadFontFromMemory(".ttf", font_data, (int)font_size, 20, NULL, 0); + vfs_free(font_data); + } else { + game.font_ui = GetFontDefault(); + } + LoadMap("maps/demo1.map"); game.cursor_captured = false; EnableCursor(); + + game.move_mode = MOVE_NORMAL; + game.velocity = (Vector3){ 0, 0, 0 }; + game.is_grounded = false; } void UpdateGame(void) { - float dt = GetFrameTime(); - if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) { game.cursor_captured = !game.cursor_captured; if (game.cursor_captured) DisableCursor(); @@ -248,39 +269,7 @@ void UpdateGame(void) { } } - // Manual first-person movement - Vector3 forward = Vector3Normalize(Vector3Subtract(game.camera.target, game.camera.position)); - Vector3 right = Vector3Normalize(Vector3CrossProduct(forward, game.camera.up)); - - Vector3 move = { 0 }; - if (IsKeyDown(KEY_W)) move = Vector3Add(move, forward); - if (IsKeyDown(KEY_S)) move = Vector3Subtract(move, forward); - if (IsKeyDown(KEY_D)) move = Vector3Add(move, right); - if (IsKeyDown(KEY_A)) move = Vector3Subtract(move, right); - - if (Vector3Length(move) > 0) { - move = Vector3Scale(Vector3Normalize(move), PLAYER_MOVE_SPEED * dt); - game.camera.position = Vector3Add(game.camera.position, move); - game.camera.target = Vector3Add(game.camera.target, move); - } - - if (game.cursor_captured) { - // Manual rotation - Vector2 mouseDelta = GetMouseDelta(); - float yaw = -mouseDelta.x * PLAYER_MOUSE_SENSITIVITY; - float pitch = -mouseDelta.y * PLAYER_MOUSE_SENSITIVITY; - - Vector3 view = Vector3Subtract(game.camera.target, game.camera.position); - - // Yaw - view = Vector3RotateByAxisAngle(view, game.camera.up, yaw); - - // Pitch - Vector3 axis = Vector3Normalize(Vector3CrossProduct(view, game.camera.up)); - view = Vector3RotateByAxisAngle(view, axis, pitch); - - game.camera.target = Vector3Add(game.camera.position, view); - } + UpdatePlayer(); } void DrawGame(void) { @@ -300,7 +289,10 @@ void DrawGame(void) { int screenHeight = GetScreenHeight(); DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); - DrawFPS(10, 10); - DrawText(TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), 10, 30, 20, GREEN); + + DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); + DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); + DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); + EndDrawing(); } |
