mirror of
https://github.com/libretro/lutro-platformer.git
synced 2024-11-23 16:19:46 +00:00
Complete the level 1
This commit is contained in:
parent
4280d947cf
commit
2407299555
File diff suppressed because one or more lines are too long
24
elevator.lua
24
elevator.lua
@ -5,7 +5,16 @@ elevator.__index = elevator
|
||||
|
||||
function newElevator(object)
|
||||
local n = object
|
||||
n.speed = 1
|
||||
if object.properties.yspeed then
|
||||
n.yspeed = object.properties.yspeed
|
||||
else
|
||||
n.yspeed = 0
|
||||
end
|
||||
if object.properties.xspeed then
|
||||
n.xspeed = object.properties.xspeed
|
||||
else
|
||||
n.xspeed = 0
|
||||
end
|
||||
|
||||
n.anim = newAnimation(lutro.graphics.newImage(
|
||||
"assets/elevator.png"), 48, 8, 1, 10)
|
||||
@ -14,11 +23,13 @@ end
|
||||
|
||||
function elevator:update(dt)
|
||||
self.anim:update(dt)
|
||||
self.y = self.y + self.speed
|
||||
self.x = self.x + self.xspeed
|
||||
self.y = self.y + self.yspeed
|
||||
|
||||
local elev = solid_at(ninja.x + ninja.width/2, ninja.y + ninja.height + self.height/2)
|
||||
if elev and elev == self then
|
||||
ninja.y = ninja.y + self.speed
|
||||
ninja.x = ninja.x + self.xspeed
|
||||
ninja.y = ninja.y + self.yspeed
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,9 +41,14 @@ function elevator:on_collide(e1, e2, dx, dy)
|
||||
if e2.type == "ground" or e2.type == "stopper" then
|
||||
|
||||
if math.abs(dy) < math.abs(dx) and dy ~= 0 then
|
||||
self.speed = -self.speed
|
||||
self.yspeed = -self.yspeed
|
||||
self.y = self.y + dy
|
||||
end
|
||||
|
||||
if math.abs(dx) < math.abs(dy) and dx ~= 0 then
|
||||
self.xspeed = -self.xspeed
|
||||
self.x = self.x + dx
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
3
main.lua
3
main.lua
@ -133,12 +133,13 @@ function lutro.draw()
|
||||
lutro.graphics.translate(camera_x, camera_y)
|
||||
|
||||
tiled_draw_layer(map.layers[1])
|
||||
tiled_draw_layer(map.layers[2])
|
||||
for i=1, #entities do
|
||||
if entities[i].draw then
|
||||
entities[i]:draw(dt)
|
||||
end
|
||||
end
|
||||
tiled_draw_layer(map.layers[2])
|
||||
|
||||
|
||||
lutro.graphics.pop()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user