/* * Tux-Town is a chill life-simulation game. * Copyright (C) 2025 orangerot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #define RCAMERA_IMPLEMENTATION #define RL_CULL_DISTANCE_NEAR 0.01 #define RL_CULL_DISTANCE_FAR 1000.0 #include #include #define ASSET_IMPLEMENTATION #include "assets.h" #include "world.h" int main(void) { const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); Camera camera = { 0 }; camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; camera.fovy = 45.0f; camera.projection = CAMERA_PERSPECTIVE; Vector3 player_pos = (Vector3) {0.f, 0.f, 0.f}; enum Asset tree = tree_oak; enum Asset house = tent_detailedOpen; Vector3 position = {0}; LoadModels(); struct World world_terrain = { .floor = assets[ground_grass], .wall = assets[cliff_top_rock], .size = 32 }; gen_terrain(&world_terrain); // #define NUM_TREES MAP_SIZE * MAP_SIZE / 100 // int *trees_x = LoadRandomSequence(NUM_TREES, -MAP_SIZE / 2, MAP_SIZE / 2); // int *trees_y = LoadRandomSequence(NUM_TREES, - MAP_SIZE / 2, MAP_SIZE / 2); // SetTargetFPS(60); DisableCursor(); while (!WindowShouldClose()) { Vector2 mousePositionDelta = GetMouseDelta(); // UpdateCamera(&camera, CAMERA_THIRD_PERSON); Vector3 camera_forward = GetCameraForward(&camera); camera.target = Vector3Add(player_pos, (Vector3){0,.2f,0}); camera.position = Vector3Add(camera.target, Vector3Scale(camera_forward, -2.f)); CameraYaw(&camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, true); CameraPitch(&camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, true, true, false); Vector3 camera_forward_flat = camera_forward; camera_forward_flat.y = 0; camera_forward_flat = Vector3Normalize(camera_forward_flat); float velocity = 1.f * GetFrameTime(); if (IsKeyDown(KEY_UP)) player_pos = Vector3Add(player_pos, Vector3Scale(camera_forward_flat, velocity)); if (IsKeyDown(KEY_DOWN)) player_pos = Vector3Add(player_pos, Vector3Scale(camera_forward_flat, -velocity)); if (IsKeyDown(KEY_RIGHT)) player_pos = Vector3Add(player_pos, Vector3Scale(GetCameraRight(&camera), velocity)); if (IsKeyDown(KEY_LEFT)) player_pos = Vector3Add(player_pos, Vector3Scale(GetCameraRight(&camera), -velocity)); BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); draw_world(&world_terrain); // for (int tree_i = 0; tree_i < NUM_TREES; tree_i++) { // DrawModel(assets[tree], (Vector3) {trees_x[tree_i], 0, trees_y[tree_i]}, 1.f, WHITE); // } DrawModel(assets[house], (Vector3) {-1, 0, 0}, 1.f, WHITE); DrawGrid(20, 10.0f); Vector3 capsule_top = player_pos; capsule_top.y += 0.2f; DrawCapsule(Vector3Add(player_pos, (Vector3){0,.1f,0}), capsule_top, .1f, 8, 8, BLUE); EndMode3D(); DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); DrawTexture(world_terrain.map_texture, 0, 0, WHITE); EndDrawing(); } CloseWindow(); return 0; }