|
|
|
@ -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.moveSpd<WORLD_SIZE.x*24){ |
|
|
|
|
player.pos.x+=fElapsedTime*player.moveSpd; |
|
|
|
|
} else { |
|
|
|
|
player.pos.x=WORLD_SIZE.x*24-12; |
|
|
|
|
} |
|
|
|
|
player.UpdateAnimation(WALK_E); |
|
|
|
|
setIdleAnimation=false; |
|
|
|
|
} |
|
|
|
|
if(GetKey(LEFT).bHeld){ |
|
|
|
|
player.pos.x-=fElapsedTime*player.moveSpd; |
|
|
|
|
if(player.pos.x-12+fElapsedTime*player.moveSpd>0){ |
|
|
|
|
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<WORLD_SIZE.y*24){ |
|
|
|
|
player.pos.y+=fElapsedTime*player.moveSpd; |
|
|
|
|
} else { |
|
|
|
|
player.pos.y=WORLD_SIZE.y*24-12; |
|
|
|
|
} |
|
|
|
|
if(setIdleAnimation){ |
|
|
|
|
player.UpdateAnimation(WALK_S); |
|
|
|
|
} |
|
|
|
|