summaryrefslogtreecommitdiff
path: root/main.c
blob: 606f575779567eb394ae458352fcfe3ee7bbeedd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * 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/>.
 */

#include <raylib.h>
#include <raymath.h>
#include <stdbool.h>
#define RCAMERA_IMPLEMENTATION
#define RL_CULL_DISTANCE_NEAR      0.01
#define RL_CULL_DISTANCE_FAR    1000.0
#include <rcamera.h>
#include <stddef.h>

#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;
}