aboutsummaryrefslogtreecommitdiffstats
path: root/src/player.c
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-07-04 14:06:42 +0000
committernathan <nathansmith@disroot.org>2025-07-04 14:06:42 +0000
commita5b8ea449bbb6fe30a6bf27843eab1df6a21ccef (patch)
tree1be8416daa7a089b058a351bf8abd29f636c09c5 /src/player.c
parent2b2b69ee31f00aa46ab6baa967e12437ce7334d1 (diff)
downloadFindThings-a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef.tar.gz
FindThings-a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef.tar.bz2
FindThings-a5b8ea449bbb6fe30a6bf27843eab1df6a21ccef.zip
Started getting walking on heightmap working
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c22
1 files changed, 22 insertions, 0 deletions
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);
}