mirror of
https://github.com/libretro/lutro-platformer.git
synced 2024-12-03 13:50:42 +00:00
Basic collisions with slopes
This commit is contained in:
parent
6fc08d233d
commit
ca71166824
@ -11,7 +11,44 @@ function detect_collisions()
|
||||
return
|
||||
end
|
||||
|
||||
if e1.x < e2.x + e2.width
|
||||
if (e2.type == "slopeleft" or e2.type == "sloperight")
|
||||
and e1.x < e2.x + e2.width
|
||||
and e1.x + e1.width > e2.x
|
||||
and e1.y < e2.y + e2.height
|
||||
and e1.height + e1.y > e2.y
|
||||
and e1.on_collide
|
||||
then
|
||||
local e1cx = e1.x + e1.width / 2.0
|
||||
local e2cx = e2.x + e2.width / 2.0
|
||||
local dx
|
||||
if e1cx < e2cx then
|
||||
dx = e2.x - (e1.x + e1.width)
|
||||
else
|
||||
dx =(e2.x + e2.width) - e1.x
|
||||
end
|
||||
|
||||
local e1cy = e1.y + e1.height / 2.0
|
||||
local e2cy = e2.y + e2.height / 2.0
|
||||
local dy
|
||||
if e1cy < e2cy then
|
||||
dy = e2.y - (e1.y + e1.height)
|
||||
else
|
||||
dy = (e2.y + e2.height) - e1.y
|
||||
end
|
||||
|
||||
if e2.type == "slopeleft" then
|
||||
local slope_y = e2.y + e2.height -(e1.x + e1.width - e2.x) / (e2.width / e2.height)
|
||||
if e1.y + e1.height > slope_y then
|
||||
e1:on_collide(e1, e2, dx, dy)
|
||||
end
|
||||
elseif e2.type == "sloperight" then
|
||||
local slope_y = e2.y +((e1.x - 1 - e2.x) / (e2.width / e2.height))
|
||||
if e1.y + e1.height > slope_y then
|
||||
e1:on_collide(e1, e2, dx, dy)
|
||||
end
|
||||
end
|
||||
|
||||
elseif e1.x < e2.x + e2.width
|
||||
and e1.x + e1.width > e2.x
|
||||
and e1.y < e2.y + e2.height
|
||||
and e1.height + e1.y > e2.y
|
||||
|
@ -46,7 +46,9 @@ function shuriken:draw()
|
||||
end
|
||||
|
||||
function shuriken:on_collide(e1, e2, dx, dy)
|
||||
if e2.type == "ground" and self.die == 0 then
|
||||
if (e2.type == "ground"
|
||||
or e2.type == "slopeleft"
|
||||
or e2.type == "sloperight") and self.die == 0 then
|
||||
self.speed = 0
|
||||
self.anim.speed = 0
|
||||
self.die = 30
|
||||
|
Loading…
Reference in New Issue
Block a user