From 8547054a6049579ff8eb327add595ce4e71eb8c0 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 11 Jun 2023 19:45:05 -0500 Subject: [PATCH] Add position boundary checking --- Crawler/main.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Crawler/main.cpp b/Crawler/main.cpp index 84793f09..d64fe002 100644 --- a/Crawler/main.cpp +++ b/Crawler/main.cpp @@ -52,7 +52,7 @@ struct Player{ class Crawler : public olc::PixelGameEngine { - const vi2d WORLD_SIZE={64,64}; + const vi2d WORLD_SIZE={64,8}; Camera2D camera; TileTransformedView view; Player player=Player{{},100}; @@ -72,7 +72,7 @@ public: camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow); camera.SetTarget(player.pos); camera.SetWorldBoundary({0,0},WORLD_SIZE*24); - camera.EnableWorldBoundary(false); + camera.EnableWorldBoundary(true); //Graphics GFX_Pl_sheet.Load("assets/nico-warrior.png"); @@ -118,6 +118,7 @@ public: player.AddAnimation(IDLE_W,pl_idle_w); view=TileTransformedView{GetScreenSize(),{1,1}}; + player.pos={4*24,4*24}; player.UpdateAnimation(IDLE_S); return true; @@ -135,26 +136,42 @@ public: void HandleUserInput(float fElapsedTime){ bool setIdleAnimation=true; if(GetKey(RIGHT).bHeld){ - player.pos.x+=fElapsedTime*player.moveSpd; + if(player.pos.x+12+fElapsedTime*player.moveSpd0){ + player.pos.x-=fElapsedTime*player.moveSpd; + } else { + player.pos.x=12; + } if(setIdleAnimation){ player.UpdateAnimation(WALK_W); } setIdleAnimation=false; } if(GetKey(UP).bHeld){ - player.pos.y-=fElapsedTime*player.moveSpd; + if(player.pos.y-12+fElapsedTime*player.moveSpd>0){ + player.pos.y-=fElapsedTime*player.moveSpd; + } else { + player.pos.y=12; + } if(setIdleAnimation){ player.UpdateAnimation(WALK_N); } setIdleAnimation=false; } if(GetKey(DOWN).bHeld){ - player.pos.y+=fElapsedTime*player.moveSpd; + if(player.pos.y+12+fElapsedTime*player.moveSpd