feat: draw world bounds and add world_room

This commit is contained in:
Orangerot 2025-06-12 00:51:42 +02:00
parent fe42371c8c
commit f13cac1a0d
4 changed files with 67 additions and 30 deletions

View file

@ -21,25 +21,29 @@
#ifndef ASSETS_H
#define ASSETS_H
#define ASSET_PATH "assets/kenney_nature-kit/Models/OBJ format/"
#define ASSETS(ASSET) \
ASSET(ground_riverOpen) \
ASSET(ground_riverCornerSmall) \
ASSET(ground_riverSideOpen) \
ASSET(ground_riverSide) \
ASSET(ground_riverCross) \
ASSET(ground_riverSplit) \
ASSET(ground_riverStraight) \
ASSET(ground_riverCorner) \
ASSET(ground_riverBend) \
ASSET(ground_riverEndClosed) \
ASSET(ground_riverTile) \
ASSET(ground_grass) \
ASSET(cliff_top_rock) \
ASSET(tree_oak) \
ASSET(tent_detailedOpen)
#define ASSET_PATH_NATURE "assets/kenney_nature-kit/Models/OBJ format/"
#define ASSET_PATH_FURNITURE "assets/kenney_furniture-kit/Models/OBJ format/"
#define AS_ENUM(name) name,
#define ASSETS(ASSET) \
ASSET(ASSET_PATH_NATURE, ground_riverOpen) \
ASSET(ASSET_PATH_NATURE, ground_riverCornerSmall) \
ASSET(ASSET_PATH_NATURE, ground_riverSideOpen) \
ASSET(ASSET_PATH_NATURE, ground_riverSide) \
ASSET(ASSET_PATH_NATURE, ground_riverCross) \
ASSET(ASSET_PATH_NATURE, ground_riverSplit) \
ASSET(ASSET_PATH_NATURE, ground_riverStraight) \
ASSET(ASSET_PATH_NATURE, ground_riverCorner) \
ASSET(ASSET_PATH_NATURE, ground_riverBend) \
ASSET(ASSET_PATH_NATURE, ground_riverEndClosed) \
ASSET(ASSET_PATH_NATURE, ground_riverTile) \
ASSET(ASSET_PATH_NATURE, ground_grass) \
ASSET(ASSET_PATH_NATURE, cliff_top_rock) \
ASSET(ASSET_PATH_NATURE, tree_oak) \
ASSET(ASSET_PATH_NATURE, tent_detailedOpen) \
ASSET(ASSET_PATH_FURNITURE, floorFull) \
ASSET(ASSET_PATH_FURNITURE, wall)
#define AS_ENUM(path, name) name,
enum Asset {
ASSETS(AS_ENUM)
ASSET_LEN
@ -48,7 +52,7 @@ enum Asset {
#ifdef ASSET_IMPLEMENTATION
Model assets[ASSET_LEN];
#define AS_ARRAY(name) assets[name] = LoadModel(ASSET_PATH #name ".obj");
#define AS_ARRAY(path, name) assets[name] = LoadModel(path #name ".obj");
void LoadModels() {
ASSETS(AS_ARRAY)
}

13
main.c
View file

@ -49,8 +49,6 @@ int main(void) {
enum Asset tree = tree_oak;
enum Asset house = tent_detailedOpen;
Vector3 position = {0};
LoadModels();
struct World world_terrain = {
@ -59,7 +57,14 @@ int main(void) {
.size = 32
};
struct World world_room = {
.floor = assets[floorFull],
.wall = assets[wall],
.size = 8
};
gen_terrain(&world_terrain);
gen_room(&world_room);
// #define NUM_TREES MAP_SIZE * MAP_SIZE / 100
// int *trees_x = LoadRandomSequence(NUM_TREES, -MAP_SIZE / 2, MAP_SIZE / 2);
@ -88,12 +93,12 @@ int main(void) {
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
draw_world(&world_terrain);
draw_world(IsKeyDown(KEY_SPACE) ? &world_room : &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);
DrawGrid(20, 1.f);
Vector3 capsule_top = player_pos;
capsule_top.y += 0.2f;
DrawCapsule(Vector3Add(player_pos, (Vector3){0,.1f,0}), capsule_top, .1f, 8, 8, BLUE);

23
world.c
View file

@ -136,9 +136,13 @@ void gen_terrain(struct World *world) {
generate_river(world, global_minimum_map_i);
}
// void gen_room() {
//
// }
void gen_room(struct World *world) {
int map_size = world->size;
world->map = GenImageColor(map_size, map_size, BLACK);
world->map_texture = LoadTextureFromImage(world->map);
world->map_data = LoadImageColors(world->map);
}
//
// void unload_world() {}
@ -152,13 +156,18 @@ void draw_world(struct World *world) {
int x = i % map_size, y = i / map_size;
int gradients[4][2] = {{0,-1},{-1,0},{0,1},{1,0}};
for (int gradient_i = 0; gradient_i < 4; gradient_i++) {
int dx = CLAMP(x + gradients[gradient_i][0], 0, map_size - 1);
int dy = CLAMP(y + gradients[gradient_i][1], 0, map_size - 1);
for (int height = map_data[i].g; height < map_data[dy * map_size + dx].g; height++) {
int dx = x + gradients[gradient_i][0];
int dy = y + gradients[gradient_i][1];
int is_border = (dx < 0 || dx >= map_size || dy < 0 || dy >= map_size);
dx = CLAMP(dx, 0, map_size - 1);
dy = CLAMP(dy, 0, map_size - 1);
int height = MAX(map_data[dy * map_size + dx].g, is_border);
for (int step = map_data[i].g; step < height; step++) {
DrawModelEx(wall,
(Vector3){
.x = map_size * (x / (float) map_size - 0.5f),
.y = height,
.y = step,
.z = map_size * (y / (float) map_size - 0.5f)
},
(Vector3) {0, 1, 0}, gradient_i * 90.f, (Vector3) {1,1,1}, WHITE);

19
world.h
View file

@ -1,3 +1,21 @@
/*
* 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 "assets.h"
#include <stddef.h>
@ -16,6 +34,7 @@ struct World {
};
void gen_terrain(struct World *world);
void gen_room(struct World *world);
void draw_world(struct World *world);
#endif