feat: draw world bounds and add world_room
This commit is contained in:
parent
fe42371c8c
commit
f13cac1a0d
42
assets.h
42
assets.h
|
@ -21,25 +21,29 @@
|
||||||
#ifndef ASSETS_H
|
#ifndef ASSETS_H
|
||||||
#define ASSETS_H
|
#define ASSETS_H
|
||||||
|
|
||||||
#define ASSET_PATH "assets/kenney_nature-kit/Models/OBJ format/"
|
#define ASSET_PATH_NATURE "assets/kenney_nature-kit/Models/OBJ format/"
|
||||||
#define ASSETS(ASSET) \
|
#define ASSET_PATH_FURNITURE "assets/kenney_furniture-kit/Models/OBJ format/"
|
||||||
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 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 {
|
enum Asset {
|
||||||
ASSETS(AS_ENUM)
|
ASSETS(AS_ENUM)
|
||||||
ASSET_LEN
|
ASSET_LEN
|
||||||
|
@ -48,7 +52,7 @@ enum Asset {
|
||||||
#ifdef ASSET_IMPLEMENTATION
|
#ifdef ASSET_IMPLEMENTATION
|
||||||
Model assets[ASSET_LEN];
|
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() {
|
void LoadModels() {
|
||||||
ASSETS(AS_ARRAY)
|
ASSETS(AS_ARRAY)
|
||||||
}
|
}
|
||||||
|
|
13
main.c
13
main.c
|
@ -49,8 +49,6 @@ int main(void) {
|
||||||
enum Asset tree = tree_oak;
|
enum Asset tree = tree_oak;
|
||||||
enum Asset house = tent_detailedOpen;
|
enum Asset house = tent_detailedOpen;
|
||||||
|
|
||||||
Vector3 position = {0};
|
|
||||||
|
|
||||||
LoadModels();
|
LoadModels();
|
||||||
|
|
||||||
struct World world_terrain = {
|
struct World world_terrain = {
|
||||||
|
@ -59,7 +57,14 @@ int main(void) {
|
||||||
.size = 32
|
.size = 32
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct World world_room = {
|
||||||
|
.floor = assets[floorFull],
|
||||||
|
.wall = assets[wall],
|
||||||
|
.size = 8
|
||||||
|
};
|
||||||
|
|
||||||
gen_terrain(&world_terrain);
|
gen_terrain(&world_terrain);
|
||||||
|
gen_room(&world_room);
|
||||||
|
|
||||||
// #define NUM_TREES MAP_SIZE * MAP_SIZE / 100
|
// #define NUM_TREES MAP_SIZE * MAP_SIZE / 100
|
||||||
// int *trees_x = LoadRandomSequence(NUM_TREES, -MAP_SIZE / 2, MAP_SIZE / 2);
|
// int *trees_x = LoadRandomSequence(NUM_TREES, -MAP_SIZE / 2, MAP_SIZE / 2);
|
||||||
|
@ -88,12 +93,12 @@ int main(void) {
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
BeginMode3D(camera);
|
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++) {
|
// 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[tree], (Vector3) {trees_x[tree_i], 0, trees_y[tree_i]}, 1.f, WHITE);
|
||||||
// }
|
// }
|
||||||
DrawModel(assets[house], (Vector3) {-1, 0, 0}, 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;
|
Vector3 capsule_top = player_pos;
|
||||||
capsule_top.y += 0.2f;
|
capsule_top.y += 0.2f;
|
||||||
DrawCapsule(Vector3Add(player_pos, (Vector3){0,.1f,0}), capsule_top, .1f, 8, 8, BLUE);
|
DrawCapsule(Vector3Add(player_pos, (Vector3){0,.1f,0}), capsule_top, .1f, 8, 8, BLUE);
|
||||||
|
|
23
world.c
23
world.c
|
@ -136,9 +136,13 @@ void gen_terrain(struct World *world) {
|
||||||
generate_river(world, global_minimum_map_i);
|
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() {}
|
// void unload_world() {}
|
||||||
|
|
||||||
|
@ -152,13 +156,18 @@ void draw_world(struct World *world) {
|
||||||
int x = i % map_size, y = i / map_size;
|
int x = i % map_size, y = i / map_size;
|
||||||
int gradients[4][2] = {{0,-1},{-1,0},{0,1},{1,0}};
|
int gradients[4][2] = {{0,-1},{-1,0},{0,1},{1,0}};
|
||||||
for (int gradient_i = 0; gradient_i < 4; gradient_i++) {
|
for (int gradient_i = 0; gradient_i < 4; gradient_i++) {
|
||||||
int dx = CLAMP(x + gradients[gradient_i][0], 0, map_size - 1);
|
int dx = x + gradients[gradient_i][0];
|
||||||
int dy = CLAMP(y + gradients[gradient_i][1], 0, map_size - 1);
|
int dy = y + gradients[gradient_i][1];
|
||||||
for (int height = map_data[i].g; height < map_data[dy * map_size + dx].g; height++) {
|
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,
|
DrawModelEx(wall,
|
||||||
(Vector3){
|
(Vector3){
|
||||||
.x = map_size * (x / (float) map_size - 0.5f),
|
.x = map_size * (x / (float) map_size - 0.5f),
|
||||||
.y = height,
|
.y = step,
|
||||||
.z = map_size * (y / (float) map_size - 0.5f)
|
.z = map_size * (y / (float) map_size - 0.5f)
|
||||||
},
|
},
|
||||||
(Vector3) {0, 1, 0}, gradient_i * 90.f, (Vector3) {1,1,1}, WHITE);
|
(Vector3) {0, 1, 0}, gradient_i * 90.f, (Vector3) {1,1,1}, WHITE);
|
||||||
|
|
19
world.h
19
world.h
|
@ -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 <raylib.h>
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -16,6 +34,7 @@ struct World {
|
||||||
};
|
};
|
||||||
|
|
||||||
void gen_terrain(struct World *world);
|
void gen_terrain(struct World *world);
|
||||||
|
void gen_room(struct World *world);
|
||||||
void draw_world(struct World *world);
|
void draw_world(struct World *world);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue