From 601961a245a48112029341437912fe13b54dac0b Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 6 Jul 2025 05:13:16 -0600 Subject: rreeee --- src/assets.c | 4 +++- src/assets.h | 6 ++++-- src/entity.c | 29 +++++++++++++++++++++++++++++ src/entity.h | 25 +++++++++++++++++++++++++ src/game.c | 13 +++++++++++++ src/game.h | 8 ++++++-- src/world.c | 2 +- src/world.h | 2 +- 8 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 src/entity.c create mode 100644 src/entity.h (limited to 'src') diff --git a/src/assets.c b/src/assets.c index 79c7ef9..b42dfae 100644 --- a/src/assets.c +++ b/src/assets.c @@ -5,7 +5,9 @@ const char imageAssetPaths[IMAGE_ASSET_COUNT][FT_NAMEMAX] = { }; const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX] = { - "heightmap.png" + "heightmap.png", + "mint.png", + "nickel.png" }; void initAssets(Assets* assets) diff --git a/src/assets.h b/src/assets.h index 43c4b43..f276088 100644 --- a/src/assets.h +++ b/src/assets.h @@ -4,7 +4,7 @@ #define ASSETS_H #define IMAGE_ASSET_COUNT 1 -#define TEXTURE_ASSET_COUNT 1 +#define TEXTURE_ASSET_COUNT 3 extern const char imageAssetPaths[IMAGE_ASSET_COUNT][FT_NAMEMAX]; extern const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX]; @@ -18,7 +18,9 @@ enum { // Texture asset ids. enum { - HEIGHT_MAP_TEXTURE + HEIGHT_MAP_TEXTURE, + MINT_TEXTURE, + NICK_TEXTURE }; typedef struct { diff --git a/src/entity.c b/src/entity.c new file mode 100644 index 0000000..ac3606b --- /dev/null +++ b/src/entity.c @@ -0,0 +1,29 @@ +#include "entity.h" +#include "game.h" + +// TODO: Entity creation system +Entity createEntity(EntityId id, Vector3 position) +{ + Entity entity; + entity.id = id; + entity.position = position; + + return entity; +} + +void updateEntity(Entity* entity, Game* game) +{ + switch (entity->id) + { + case OLD_MINT: + DrawBillboard(game->player.camera, game->assets.textures[MINT_TEXTURE], + entity->position, 1.0, WHITE); + break; + case STICKY_NICKEL: + DrawBillboard(game->player.camera, game->assets.textures[NICK_TEXTURE], + entity->position, 1.0, WHITE); + break; + default: + break; + } +} diff --git a/src/entity.h b/src/entity.h new file mode 100644 index 0000000..0c431ea --- /dev/null +++ b/src/entity.h @@ -0,0 +1,25 @@ +#include "utils.h" + +// Pretty much any object in the game. + +#ifndef ENTITY_H +#define ENTITY_H + +typedef int8_t EntityId; + +enum { + ENTITY_NONE = -1, + OLD_MINT, + STICKY_NICKEL +}; + +typedef struct { + EntityId id; + Vector3 position; + BoundingBox box; +} Entity; + +Entity createEntity(EntityId id, Vector3 position); +void updateEntity(Entity* entity, Game* game); + +#endif diff --git a/src/game.c b/src/game.c index 7a5be42..4de6a32 100644 --- a/src/game.c +++ b/src/game.c @@ -23,6 +23,14 @@ void initGame(Game* game) // World. game->world = createWorld(&game->assets); + game->entities[0] = createEntity(OLD_MINT, (Vector3){100.0, 0.0, 100.0}); + game->entities[1] = createEntity(STICKY_NICKEL, + (Vector3){100.0, 0.0, 105.0}); + game->entities[0].position.y = getWorldHeightAtLocation(game->world, + 100, 100) + 1.0; + game->entities[1].position.y = getWorldHeightAtLocation(game->world, + 100, 105) + 1.0; + DisableCursor(); } @@ -41,6 +49,11 @@ void updateGameScene(Game* game) updateWorld(&game->world, game); + for (int index = 0; index < 2; ++index) + { + updateEntity(&game->entities[index], game); + } + EndMode3D(); } diff --git a/src/game.h b/src/game.h index 8817633..ab162ad 100644 --- a/src/game.h +++ b/src/game.h @@ -3,6 +3,7 @@ #include "assets.h" #include "player.h" #include "world.h" +#include "entity.h" #ifndef GAME_H #define GAME_H @@ -10,14 +11,17 @@ typedef enum { MAIN_MENU_SCENE, GAME_SCENE -} SceneID; +} SceneId; struct Game { - SceneID sceneId; + SceneId sceneId; Settings settings; Assets assets; Player player; World world; + + // For testing only. + Entity entities[2]; }; void initGame(Game* game); diff --git a/src/world.c b/src/world.c index 0a6b544..db6e55d 100644 --- a/src/world.c +++ b/src/world.c @@ -43,7 +43,7 @@ float getWorldPixelHeight(World world, int x, int y) return (float)height / count; } -float getWorldHeightAtLocation(World world, int x, int y) +float getWorldHeightAtLocation(World world, float x, float y) { float toMapX = (float)world.image->width / world.size.x; float toMapY = (float)world.image->height / world.size.z; diff --git a/src/world.h b/src/world.h index d843094..6a214b6 100644 --- a/src/world.h +++ b/src/world.h @@ -19,6 +19,6 @@ void freeWorld(World world); // Dam, I wanta live in a free world ): float getWorldPixelHeight(World world, int x, int y); -float getWorldHeightAtLocation(World world, int x, int y); +float getWorldHeightAtLocation(World world, float x, float y); #endif -- cgit v1.2.3