Snap camera to integer values so there's no floating point errors.
This commit is contained in:
parent
3dac286089
commit
3a8db50da8
@ -37,13 +37,20 @@ public:
|
||||
camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow);
|
||||
camera.SetTarget(player.pos);
|
||||
camera.SetWorldBoundary({0,0},WORLD_SIZE*24);
|
||||
camera.EnableWorldBoundary(true);
|
||||
camera.EnableWorldBoundary(false);
|
||||
view=TileTransformedView{GetScreenSize(),{1,1}};
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
HandleUserInput(fElapsedTime);
|
||||
UpdateCamera(fElapsedTime);
|
||||
RenderWorld();
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandleUserInput(float fElapsedTime){
|
||||
if(GetKey(RIGHT).bHeld){
|
||||
player.pos.x+=fElapsedTime*player.moveSpd;
|
||||
}
|
||||
@ -56,19 +63,21 @@ public:
|
||||
if(GetKey(DOWN).bHeld){
|
||||
player.pos.y+=fElapsedTime*player.moveSpd;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateCamera(float fElapsedTime){
|
||||
camera.Update(fElapsedTime);
|
||||
view.SetWorldOffset(camera.GetViewPosition());
|
||||
//view.HandlePanAndZoom();
|
||||
// called once per frame
|
||||
view.SetWorldOffset(vi2d(camera.GetViewPosition()));
|
||||
}
|
||||
|
||||
void RenderWorld(){
|
||||
Clear(BLACK);
|
||||
for (int x = view.GetTopLeftTile().x/24; x <= view.GetBottomRightTile().x/24; x++){
|
||||
for (int y = view.GetTopLeftTile().y/24; y <= view.GetBottomRightTile().y/24; y++){
|
||||
view.DrawRect(vi2d{x,y}*24,{24,24},DARK_GREY);
|
||||
for (int x = view.GetTopLeftTile().x/24-1; x <= view.GetBottomRightTile().x/24; x++){
|
||||
for (int y = view.GetTopLeftTile().y/24-1; y <= view.GetBottomRightTile().y/24; y++){
|
||||
view.DrawRect(vi2d{x,y}*24,{24,24},VERY_DARK_GREY);
|
||||
}
|
||||
}
|
||||
view.DrawCircle(player.pos,8);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user