From c5ddc289f50620ecb4d25193f32f38253e3fd1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 4 Jul 2017 00:06:54 +0200 Subject: [PATCH] Slope collisions with the demons --- demon.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/demon.lua b/demon.lua index e2e7229..e525f54 100755 --- a/demon.lua +++ b/demon.lua @@ -102,8 +102,8 @@ function demon:update(dt) self.y = self.y + self.yspeed end - if not solid_at(self.x , self.y + self.height, self) and self.GOLEFT - or not solid_at(self.x + self.width, self.y + self.height, self) and not self.GOLEFT + if not solid_at(self.x , self.y + self.height+14, self) and self.GOLEFT + or not solid_at(self.x + self.width, self.y + self.height+14, self) and not self.GOLEFT then self.GOLEFT = not self.GOLEFT end @@ -198,6 +198,26 @@ function demon:on_collide(e1, e2, dx, dy) self.x = self.x + dx self.GOLEFT = not self.GOLEFT end + elseif e2.type == "slopeleft" and self.DO_JUMP == 0 then + self.yspeed = 0 + self.y = e2.y - self.height + e2.height -((self.x + self.width - e2.x) / (e2.width / e2.height)) + if self.x + self.width >= e2.x + e2.width then + self.y = e2.y - self.height + end + if self.x + self.width < e2.x + 4 then + self.y = e2.y + e2.height - self.height + end + + elseif e2.type == "sloperight" and self.DO_JUMP == 0 then + self.yspeed = 0 + self.y = e2.y - self.height +((self.x + 0 - e2.x) / (e2.width / e2.height)) + if self.x <= e2.x then + self.y = e2.y - self.height + end + if self.x > e2.x + e2.width then + self.y = e2.y + e2.height - self.height + end + elseif e2.type == "ninja" then if math.abs(dx) < math.abs(dy) and dx ~= 0 then self.xspeed = 0