2025-05-25 19:59:06 +02:00
|
|
|
/*
|
|
|
|
* Tux-Town is a chill life-simulation game.
|
|
|
|
* Copyright (C) 2025 orangerot <me@orangerot.dev>
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2025-06-05 01:40:21 +02:00
|
|
|
#include <raylib.h>
|
2025-05-30 17:39:13 +02:00
|
|
|
#include <raymath.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#define RCAMERA_IMPLEMENTATION
|
|
|
|
#define RL_CULL_DISTANCE_NEAR 0.01
|
|
|
|
#define RL_CULL_DISTANCE_FAR 1000.0
|
2025-06-05 01:40:21 +02:00
|
|
|
#include <rcamera.h>
|
2025-05-25 19:59:06 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2025-06-05 03:43:25 +02:00
|
|
|
#define ASSET_IMPLEMENTATION
|
2025-06-05 01:40:21 +02:00
|
|
|
#include "assets.h"
|
2025-06-05 03:43:25 +02:00
|
|
|
#include "world.h"
|
2025-05-26 13:43:30 +02:00
|
|
|
|
2025-05-25 19:59:06 +02:00
|
|
|
int main(void) {
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
|
|
|
|
|
|
|
Camera camera = { 0 };
|
2025-05-30 17:39:13 +02:00
|
|
|
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f };
|
2025-05-25 19:59:06 +02:00
|
|
|
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;
|
|
|
|
|
2025-05-30 17:39:13 +02:00
|
|
|
|
|
|
|
Vector3 player_pos = (Vector3) {0.f, 0.f, 0.f};
|
2025-05-27 17:17:56 +02:00
|
|
|
|
2025-06-05 01:40:21 +02:00
|
|
|
|
|
|
|
enum Asset tree = tree_oak;
|
|
|
|
enum Asset house = tent_detailedOpen;
|
2025-05-27 17:17:56 +02:00
|
|
|
|
2025-05-25 19:59:06 +02:00
|
|
|
Vector3 position = {0};
|
2025-06-05 01:40:21 +02:00
|
|
|
|
|
|
|
LoadModels();
|
2025-06-05 03:43:25 +02:00
|
|
|
|
|
|
|
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);
|
2025-05-25 19:59:06 +02:00
|
|
|
|
|
|
|
// SetTargetFPS(60);
|
2025-05-30 17:39:13 +02:00
|
|
|
DisableCursor();
|
2025-05-25 19:59:06 +02:00
|
|
|
while (!WindowShouldClose()) {
|
2025-05-30 17:39:13 +02:00
|
|
|
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));
|
2025-05-25 19:59:06 +02:00
|
|
|
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
BeginMode3D(camera);
|
2025-06-05 03:43:25 +02:00
|
|
|
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);
|
|
|
|
// }
|
2025-06-05 01:40:21 +02:00
|
|
|
DrawModel(assets[house], (Vector3) {-1, 0, 0}, 1.f, WHITE);
|
2025-05-25 19:59:06 +02:00
|
|
|
DrawGrid(20, 10.0f);
|
2025-05-30 17:39:13 +02:00
|
|
|
Vector3 capsule_top = player_pos;
|
|
|
|
capsule_top.y += 0.2f;
|
|
|
|
DrawCapsule(Vector3Add(player_pos, (Vector3){0,.1f,0}), capsule_top, .1f, 8, 8, BLUE);
|
2025-05-25 19:59:06 +02:00
|
|
|
EndMode3D();
|
|
|
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
2025-06-05 03:43:25 +02:00
|
|
|
DrawTexture(world_terrain.map_texture, 0, 0, WHITE);
|
2025-05-25 19:59:06 +02:00
|
|
|
EndDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseWindow();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|