diff options
author | nathan <nathansmith@disroot.org> | 2025-07-04 14:06:42 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-07-04 14:06:42 +0000 |
commit | a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef (patch) | |
tree | 1be8416daa7a089b058a351bf8abd29f636c09c5 | |
parent | 2b2b69ee31f00aa46ab6baa967e12437ce7334d1 (diff) | |
download | FindThings-a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef.tar.gz FindThings-a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef.tar.bz2 FindThings-a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef.zip |
Started getting walking on heightmap working
-rw-r--r-- | assets/heightmap.png | bin | 179712 -> 111957 bytes | |||
-rw-r--r-- | src/assets.h | 4 | ||||
-rw-r--r-- | src/game.c | 4 | ||||
-rw-r--r-- | src/game.h | 8 | ||||
-rw-r--r-- | src/player.c | 22 | ||||
-rw-r--r-- | src/player.h | 2 | ||||
-rw-r--r-- | src/settings.h | 3 | ||||
-rw-r--r-- | src/utils.c | 1 | ||||
-rw-r--r-- | src/utils.h | 4 |
9 files changed, 41 insertions, 7 deletions
diff --git a/assets/heightmap.png b/assets/heightmap.png Binary files differindex b3aa460..76a2ea0 100644 --- a/assets/heightmap.png +++ b/assets/heightmap.png diff --git a/src/assets.h b/src/assets.h index c5fb7ac..43c4b43 100644 --- a/src/assets.h +++ b/src/assets.h @@ -9,7 +9,7 @@ extern const char imageAssetPaths[IMAGE_ASSET_COUNT][FT_NAMEMAX]; extern const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX]; -typedef int8_t Assetid; +typedef int8_t AssetId; // Image asset ids. enum { @@ -21,7 +21,7 @@ enum { HEIGHT_MAP_TEXTURE }; -typedef struct Assets { +typedef struct { Image images[IMAGE_ASSET_COUNT]; Texture textures[TEXTURE_ASSET_COUNT]; } Assets; @@ -27,6 +27,9 @@ void initGame(Game* game) game->heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = game->assets.textures[HEIGHT_MAP_TEXTURE]; + game->heightmapColors = LoadImageColors( + game->assets.images[HEIGHT_MAP_IMAGE]); + DisableCursor(); } @@ -73,5 +76,6 @@ void closeGame(Game* game) { closeAssets(&game->assets); UnloadModel(game->heightmap); + UnloadImageColors(game->heightmapColors); CloseWindow(); } @@ -6,18 +6,20 @@ #ifndef GAME_H #define GAME_H -typedef enum SceneID { +typedef enum { MAIN_MENU_SCENE, GAME_SCENE } SceneID; -typedef struct Game { +struct Game { SceneID sceneId; Settings settings; Assets assets; Player player; + Model heightmap; -} Game; + Color* heightmapColors; +}; void initGame(Game* game); void updateGame(Game* game); diff --git a/src/player.c b/src/player.c index ec6eaf2..880aa34 100644 --- a/src/player.c +++ b/src/player.c @@ -18,6 +18,26 @@ Player createPlayer() }; } +// TODO: subpixel hackery +void readoutMapHeight(Player* player, Game* game) +{ + Vector3 position = player->position; + Image* map = &game->assets.images[HEIGHT_MAP_IMAGE]; + + // Map player position to height map pixel. + int pixelX = (int)roundf(position.x) * (map->width / 100); + int pixelY = (int)roundf(position.z) * (map->height / 100); + pixelX = Clamp(pixelX, 0, map->width); + pixelY = Clamp(pixelY, 0, map->height); + + Color color = game->heightmapColors[pixelY * map->width + pixelX]; + float height = Vector3Length((Vector3){color.r, color.g, color.b}) + * (30.0 / 255.0) - 15.0; + + printf("%f\n", height); + player->position.y = height + 1.0; +} + // TODO: move magic numbers to settings void updatePlayer(Player* player, Game* game) { @@ -72,4 +92,6 @@ void updatePlayer(Player* player, Game* game) // Apply camera. camera->position = player->position; camera->target = Vector3Add(player->position, player->direction); + + readoutMapHeight(player, game); } diff --git a/src/player.h b/src/player.h index 4983752..bc061f8 100644 --- a/src/player.h +++ b/src/player.h @@ -3,7 +3,7 @@ #ifndef PLAYER_H #define PLAYER_H -typedef struct Player { +typedef struct { Vector3 position; Vector3 direction; Vector3 velocity; diff --git a/src/settings.h b/src/settings.h index 3576955..da67539 100644 --- a/src/settings.h +++ b/src/settings.h @@ -3,7 +3,7 @@ #ifndef SETTINGS_H #define SETTINGS_H -typedef struct Settings { +typedef struct { // Window. int windowWidth; int windowHeight; @@ -17,5 +17,6 @@ typedef struct Settings { } Settings; Settings defaultSettings(); +// Bite my shiny metal ass! #endif diff --git a/src/utils.c b/src/utils.c index 2916c30..635a1f7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,2 +1,3 @@ #include "utils.h" +// Why does the universe feel strange to exist in? diff --git a/src/utils.h b/src/utils.h index e289189..db6f7a8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -38,4 +38,8 @@ typedef enum FTError { #define TOGGLE_BIT(b, n) (b ^ (0x1 << n)) #define HAS_FLAG(v, f) ((v & f) == f) +// Helpful for debugging +#define PRINT_VECTOR2(v) printf("%f %f\n", v.x, v.y) +#define PRINT_VECTOR3(v) printf("%f %f %f\n", v.x, v.y, v.z) + #endif |