#include #include #include #include #include #include #include "world.h" #include "player.h" void handleInput(Player *player) { player->velocity.x = (float)(IsKeyDown(KEY_W)-IsKeyDown(KEY_S))*1.0f; player->velocity.z = (float)(IsKeyDown(KEY_D)-IsKeyDown(KEY_A))*1.0f; printf( "Player.velocity.x: %f\n" "Player.velocity.y: %f\n" "Player.velocity.z: %f\n" "\n\n", player->velocity.x, player->velocity.y, player->velocity.z ); if (IsKeyPressed(KEY_E)) { printf("Key E pressed\n"); } if (IsKeyPressed(KEY_SPACE) && player->is_on_floor) { printf("Key Space pressed\n"); player->velocity.y=1.0f; } if (IsKeyDown(KEY_LEFT_CONTROL)) { player->speed = 8; } else { player->speed = 6; } } int main(void) { InitWindow(1200, 800, "My game"); SetTargetFPS(165); World world = { .map = { { {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1} } } }; Player player = { .pos = (Vector3){5.0f, 10.0f, 5.0f}, .velocity = (Vector3){0.0f, 0.0f, 0.0f}, .speed = 10, .camera = (Camera3D){ .target = (Vector3){0.0f, 0.0f, 0.0f}, .up = (Vector3){0.0f, 1.0f, 0.0f}, .fovy = 60.0f, .projection = CAMERA_PERSPECTIVE, }, .hitbox = (Vector3){1.0f, 2.0f, 1.0f} }; player.camera.position = (Vector3){5.0f,10.0f,5.0f}; int cameraMode = CAMERA_FIRST_PERSON; DisableCursor(); char out[100]; while(!WindowShouldClose()) { printf("Camera position: (%f,%f,%f)\n", player.camera.position.x, player.camera.position.y, player.camera.position.z ); //UpdateCamera(&player.camera, cameraMode); handleInput(&player); handleMovement(&player); handleGravity(&world, &player); handleCollision(&world, &player); BeginDrawing(); BeginMode3D(player.camera); ClearBackground(BLACK); drawWorld(&world); EndMode3D(); snprintf( out, 100, "Advanced info:\n" "pos.x: %.2f\n" "pos.y: %.2f\n" "pos.z: %.2f\n", player.pos.x, player.pos.y, player.pos.z ); DrawText(out, 10, 40, 20, DARKGRAY); DrawFPS(10,10); EndDrawing(); } CloseWindow(); return 0; }