lost_soul

A 3D walking simulator game
Log | Files | Refs | README | LICENSE

main.c (2810B)


      1 #include <raylib.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 #define SCREEN_WIDTH 1024
      6 #define SCREEN_HEIGHT 768
      7 
      8 float velocity = 0.50;
      9 float velocity_speed = 1.0;
     10 float speed = 400.0;
     11 
     12 Shader shader;
     13 Camera camera;
     14 
     15 void init() {
     16     SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT | FLAG_WINDOW_UNDECORATED);
     17     SetTraceLogLevel(LOG_ALL);
     18     SetTargetFPS(60);
     19     InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Lost Soul");
     20     InitAudioDevice();
     21 }
     22 
     23 void input(float dt) {
     24     if (IsKeyDown(KEY_TAB)) {
     25         EnableCursor();
     26     }
     27 
     28     if (IsKeyDown(KEY_ONE)) {
     29         DisableCursor();
     30     }
     31 
     32     if (IsKeyPressed(KEY_BACKSPACE)) {
     33         Vector3 tmp = camera.target;
     34         Vector3 pos = camera.position;
     35         printf("TARGET: %f - %f - %f \n", tmp.x, tmp.y, tmp.z);
     36         printf("POSITION: %f - %f - %f \n", pos.x, pos.y, pos.z);
     37     }
     38 
     39     if (IsKeyDown(KEY_LEFT_SHIFT)) {
     40         velocity *= velocity_speed * 2.0;
     41     }
     42 }
     43 
     44 void setup_camera() {
     45     camera.position = (Vector3){-1.7414374, 2, 3.4975357};  // Camera position
     46     camera.target = (Vector3){8.08, 5.36, 3.28};            // Camera looking at point
     47     camera.up = (Vector3){0.0, 1.0, 0.0};                   // Camera up vector (rotation towards target)
     48     camera.fovy = 90.0;                                     // Camera field-of-view Y
     49     // camera.type = CAMERA_PERSPECTIVE;                       // Camera mode type
     50     DisableCursor();
     51 }
     52 
     53 void draw_crosshair() {
     54     DrawCircle(SCREEN_WIDTH / 2 - 1, SCREEN_HEIGHT / 2 - 1, 2, WHITE);
     55 }
     56 
     57 void window_resized() {
     58     // Adjust any necessary variables if the window is resized
     59 }
     60 
     61 int main() {
     62     init();
     63 
     64     // Load assets
     65     // NOTE: These file paths and functions would need to exist in your project
     66     // Texture2D soil = LoadTexture("assets/textures/soil.png");
     67     // Texture2D kosni = LoadTexture("assets/textures/kosni.png");
     68     // Model model = LoadModel("common/cow.obj");
     69 
     70     Music audio = LoadMusicStream("assets/music/o.mp3");
     71     PlayMusicStream(audio);
     72     SetMusicVolume(audio, 0.2);
     73 
     74     setup_camera();
     75 
     76     while (!WindowShouldClose()) {
     77         if (IsWindowResized()) {
     78             window_resized();
     79         }
     80 
     81         float frame_counter = GetFrameTime();
     82 
     83         input(frame_counter);
     84 
     85         UpdateMusicStream(audio);
     86         UpdateCamera(&camera, CAMERA_FIRST_PERSON);
     87 
     88         BeginDrawing();
     89         ClearBackground((Color){33, 33, 33, 255});
     90         BeginMode3D(camera);
     91 
     92         // Example drawing function calls
     93         // DrawModel(model, (Vector3){0.0f, 0.0f, 0.0f}, 1.0f, WHITE);
     94         DrawCubeWires((Vector3){0.0f, 0.0f, 0.0f}, 20, 20, 20, YELLOW);
     95 				DrawGrid(10, 10);
     96 
     97         EndMode3D();
     98         draw_crosshair();
     99         DrawFPS(5, 5);
    100         EndDrawing();
    101     }
    102 
    103     CloseWindow();
    104     CloseAudioDevice();
    105 
    106     return 0;
    107 }
    108