From d5f150619d4fedbc0a36dde4ad00b813de979a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sat, 8 May 2021 09:18:50 +0200 Subject: [PATCH] add world boundary collision --- code/apps/client/source/platform_raylib.c | 9 ++++----- code/modules/source/physics.c | 7 ++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/code/apps/client/source/platform_raylib.c b/code/apps/client/source/platform_raylib.c index 60d334e..fe85320 100644 --- a/code/apps/client/source/platform_raylib.c +++ b/code/apps/client/source/platform_raylib.c @@ -149,7 +149,6 @@ void DEBUG_draw_ground(uint64_t key, entity_view data) { int32_t y = data.y * view->chunk_size * view->block_size; int32_t size = view->chunk_size * view->block_size; - int32_t half_size = size/2; int16_t block_size = view->block_size; int32_t half_block_size = block_size/2; int16_t offset = 10; @@ -157,10 +156,10 @@ void DEBUG_draw_ground(uint64_t key, entity_view data) { switch (data.kind) { case EKIND_CHUNK: { - DrawRectangleEco(x+offset-half_size, y+offset-half_size, size-offset, size-offset, LIME); + DrawRectangleEco(x+offset, y+offset, size-offset, size-offset, LIME); for (uint16_t i = 0; i < view->chunk_size*view->chunk_size; i++) { - int32_t bx = i % view->block_size * block_size + x - half_size + offset; - int32_t by = i / view->block_size * block_size + y - half_size + offset; + int32_t bx = i % view->block_size * block_size + x + offset; + int32_t by = i / view->block_size * block_size + y + offset; DrawRectangleEco(bx+block_offset-half_block_size, by+block_offset-half_block_size, block_size-block_offset, @@ -168,7 +167,7 @@ void DEBUG_draw_ground(uint64_t key, entity_view data) { GREEN); } - DrawTextEco(TextFormat("%.01f %.01f", data.x, data.y), x-half_size+5, y-half_size+5, 65 , BLACK, 0.0); + DrawTextEco(TextFormat("%.01f %.01f", data.x, data.y), x+5, y+5, 65 , BLACK, 0.0); }break; default:break; diff --git a/code/modules/source/physics.c b/code/modules/source/physics.c index 4378d21..cbc6b9a 100644 --- a/code/modules/source/physics.c +++ b/code/modules/source/physics.c @@ -16,10 +16,11 @@ void MoveWalk(ecs_iter_t *it) { v[i].y = zpl_lerp(v[i].y, 0.0f, PHY_WALK_DRAG); // NOTE(zaklaus): world bounds - /*{ - double w = (double)world_world_size()*world_chunk_size()*world_block_size();; + { + double w = (double)world_dim()/2.0; p[i].x = zpl_clamp(p[i].x, -w, w); - }*/ + p[i].y = zpl_clamp(p[i].y, -w, w); + } librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0)); }