diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/entity.c | 11 | ||||
| -rw-r--r-- | src/entity.h | 1 | ||||
| -rw-r--r-- | src/game.c | 27 | ||||
| -rw-r--r-- | src/game.h | 4 | ||||
| -rw-r--r-- | src/player.c | 24 | ||||
| -rw-r--r-- | src/settings.c | 3 | ||||
| -rw-r--r-- | src/settings.h | 1 | ||||
| -rw-r--r-- | src/world.c | 21 | ||||
| -rw-r--r-- | src/world.h | 3 |
9 files changed, 74 insertions, 21 deletions
diff --git a/src/entity.c b/src/entity.c index 70a7db5..93d713a 100644 --- a/src/entity.c +++ b/src/entity.c @@ -215,6 +215,17 @@ void placeEntityOnGround(Entity* entity, const World* world) setEntityPosition(entity, position); } +bool entityIsPlace(EntityId id) +{ + switch (id) + { + case POND: + case SAMANTHAS_SPOT: + return true; + default: + return false; + } +} InteractionCommand interactWithOldMint(Entity* entity, Game* game, Selection selection) diff --git a/src/entity.h b/src/entity.h index 72fadb4..aad3a05 100644 --- a/src/entity.h +++ b/src/entity.h @@ -96,6 +96,7 @@ Entity createEntity(EntityId id, Vector3 position); void updateEntity(Entity* entity, Game* game); void setEntityPosition(Entity* entity, Vector3 position); void placeEntityOnGround(Entity* entity, const World* world); +bool entityIsPlace(EntityId id); InteractionCommand interactWithEntity(Entity* entity, Game* game, Selection selection); @@ -79,7 +79,7 @@ void initGame(Game* game) game->player = createPlayer(); game->player.position = Vector3Scale(game->world.size, 0.5); - //DisableCursor(); + disableGameCursor(game); } void updateMainMenuScene(Game* game) @@ -122,6 +122,19 @@ void drawGameScreen(Game* game) void updateGameScene(Game* game) { + // Handle toggle cursor. + if (IsKeyPressed(game->settings.toggleCursorKey)) + { + if (game->isCursorEnabled) + { + disableGameCursor(game); + } + else + { + enableGameCursor(game); + } + } + BeginTextureMode(game->screen.render); ClearBackground(BLACK); BeginMode3D(game->player.camera); @@ -184,3 +197,15 @@ void closeGame(Game* game) freeWorld(game->world); CloseWindow(); } + +void enableGameCursor(Game* game) +{ + game->isCursorEnabled = true; + EnableCursor(); +} + +void disableGameCursor(Game* game) +{ + game->isCursorEnabled = false; + DisableCursor(); +} @@ -23,6 +23,7 @@ struct Game { Player player; World world; Model skybox; + bool isCursorEnabled; struct { RenderTexture render; @@ -36,4 +37,7 @@ void initGame(Game* game); void updateGame(Game* game); void closeGame(Game* game); +void enableGameCursor(Game* game); +void disableGameCursor(Game* game); + #endif diff --git a/src/player.c b/src/player.c index 417c7e1..7da0b01 100644 --- a/src/player.c +++ b/src/player.c @@ -84,21 +84,21 @@ void updatePlayer(Player* player, Game* game) camera->target = Vector3Add(player->position, player->direction); /* #ifdef FT_DEBUG_MODE */ -/* Ray ray = (Ray){ */ -/* .position = player->position, */ -/* .direction = player->direction */ -/* }; */ + Ray ray = (Ray){ + .position = player->position, + .direction = player->direction + }; -/* DrawRay(ray, YELLOW); */ + DrawRay(ray, YELLOW); -/* int tests; */ -/* WorldUID uid = castRayAtWorld(&game->world, ray, &tests); */ + int tests; + WorldUID uid = castRayAtWorld(&game->world, ray, true, &tests); -/* //printf("%d\n", tests); */ + //printf("%d\n", tests); -/* if (uid != -1) */ -/* { */ -/* DrawBoundingBox(game->world.entities[uid].box, RED); */ -/* } */ + if (uid != -1) + { + DrawBoundingBox(game->world.entities[uid].box, RED); + } /* #endif */ } diff --git a/src/settings.c b/src/settings.c index 159cb6a..9eb1fd2 100644 --- a/src/settings.c +++ b/src/settings.c @@ -16,6 +16,7 @@ Settings defaultSettings() .forwardKey = KEY_W, .backwardKey = KEY_S, .rightKey = KEY_D, - .leftKey = KEY_A + .leftKey = KEY_A, + .toggleCursorKey = KEY_LEFT_ALT }; } diff --git a/src/settings.h b/src/settings.h index 711d7bd..668e615 100644 --- a/src/settings.h +++ b/src/settings.h @@ -27,6 +27,7 @@ typedef struct { KeyboardKey backwardKey; KeyboardKey rightKey; KeyboardKey leftKey; + KeyboardKey toggleCursorKey; } Settings; Settings defaultSettings(); diff --git a/src/world.c b/src/world.c index 42e3488..75fc0ab 100644 --- a/src/world.c +++ b/src/world.c @@ -1,5 +1,6 @@ #include "world.h" #include "game.h" +#include "entity.h" size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world) { @@ -935,8 +936,8 @@ float getWorldHeightAtLocation(const World* world, float x, float y) return 0.0; } -void castRayBVH(const World* world, BVHNode node, Ray ray, int* tests, - WorldUID* closest, float* closestDistance) +void castRayBVH(const World* world, BVHNode node, Ray ray, bool includePlaces, + int* tests, WorldUID* closest, float* closestDistance) { if (!GetRayCollisionBox(ray, node.box).hit) { @@ -962,6 +963,13 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, int* tests, world->entities[node.entities[index]].position, ray.position); + // Don't include places. + if (!includePlaces && + entityIsPlace(world->entities[node.entities[index]].id)) + { + continue; + } + if (distance < *closestDistance) { *closest = node.entities[index]; @@ -974,19 +982,20 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, int* tests, { for (int index = 0; index < node.branchCount; ++index) { - castRayBVH(world, *node.branches[index], ray, tests, closest, - closestDistance); + castRayBVH(world, *node.branches[index], ray, includePlaces, tests, + closest, closestDistance); } } return; } -WorldUID castRayAtWorld(const World* world, Ray ray, int* tests) +WorldUID castRayAtWorld(const World* world, Ray ray, bool includePlaces, + int* tests) { WorldUID uid = -1; float distance = Vector3LengthSqr(world->size); - castRayBVH(world, world->bvh, ray, tests, &uid, &distance); + castRayBVH(world, world->bvh, ray, includePlaces, tests, &uid, &distance); return uid; } diff --git a/src/world.h b/src/world.h index 08c4f39..10306d3 100644 --- a/src/world.h +++ b/src/world.h @@ -89,6 +89,7 @@ void freeWorld(World world); // When dealing with the world in 2d use y in place of z. float getWorldHeightAtLocation(const World* world, float x, float y); Vector2 worldPositionToPixel(const World* world, float x, float y); -WorldUID castRayAtWorld(const World* world, Ray ray, int* tests); +WorldUID castRayAtWorld(const World* world, Ray ray, bool includePlaces, + int* tests); #endif |
