Compute camera position after resolving collisions

This commit is contained in:
Jean-André Santoni 2017-06-25 14:49:09 +02:00
parent 4e6759c030
commit e6b791857e
2 changed files with 10 additions and 9 deletions

View File

@ -51,7 +51,17 @@ function lutro.update(dt)
entities[i]:update(dt)
end
end
detect_collisions()
-- camera
camera_x = - ninja.x + SCREEN_WIDTH/2 - ninja.width/2;
if camera_x > 0 then
camera_x = 0
end
if camera_x < -(map.width * map.tilewidth) + SCREEN_WIDTH then
camera_x = -(map.width * map.tilewidth) + SCREEN_WIDTH
end
end
function lutro.draw()

View File

@ -169,15 +169,6 @@ function ninja:update(dt)
self.anim = anim;
self.anim:update(dt)
-- camera
camera_x = - self.x + SCREEN_WIDTH/2 - self.width/2;
if camera_x > 0 then
camera_x = 0
end
if camera_x < -(map.width * map.tilewidth) + SCREEN_WIDTH then
camera_x = -(map.width * map.tilewidth) + SCREEN_WIDTH
end
end
function ninja:draw()