diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..3934c2a --- /dev/null +++ b/src/main.c @@ -0,0 +1,136 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include <raylib.h> +#include <rcamera.h> + +#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 = 0.06f; + } else { + player->speed = 0.04f; + } +} + +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} + }, + } + }; + + Player player = { + .pos = (Vector3){5.0f, 10.0f, 5.0f}, + .velocity = (Vector3){0.0f, 0.0f, 0.0f}, + .speed = 0.04f, + .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 = createHitbox((Vector3[]){ + { 1.0f, 0.0f, 1.0f}, + { 1.0f, 0.0f, -1.0f}, + {-1.0f, 0.0f, 1.0f}, + { 1.0f, 0.0f, -1.0f}, + + { 1.0f, 2.0f, 1.0f}, + { 1.0f, 2.0f, -1.0f}, + {-1.0f, 2.0f, 1.0f}, + { 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); + handleCollision(&world, &player); + handleGravity(&world, &player); + handleMovement(&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; +} |