a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 8e09eb976a0b3d7d1ae73151fdea536557408679
parent 30092d15b10e40929a16ceccc2a108a6906f9520
Author: amin <dev@aminmesbah.com>
Date:   Sun,  9 Jun 2019 20:09:25 +0000

Don't consider tiles past world edge for collision

FossilOrigin-Name: 6b55c2606862ba486817a5d85fbce5427d8f68506f6e1f5a7968016e7c8c56d3
Diffstat:
Msrc/game.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -222,7 +222,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga { v2i c_i = world_room_get_chunk_index(current_room_i); - struct WorldChunk* c = world_chunk_get(game_state->world, c_i); + struct WorldChunk *c = world_chunk_get(game_state->world, c_i); assert(c); printf("------------\n"); printf("Current Player Room: "); @@ -400,13 +400,21 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga // NOTE(amin): pointer alias u32 *tile_set = tiles; + bool tile_is_past_world_edge = false; if (!math_v2i_eq(tile_pos.room, current_room_i)) { struct Room *room_containing_tile = world_room_get(game_state->world, tile_pos.room); - tile_set = room_containing_tile->tiles; + if (room_containing_tile) + { + tile_set = room_containing_tile->tiles; + } + else + { + tile_is_past_world_edge = true; + } } - if (tile_is_solid(tile_set, tile_pos.local)) + if ((!tile_is_past_world_edge) && tile_is_solid(tile_set, tile_pos.local)) { rect tile_aabb = { .min = {tile_x, tile_y},