-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.lua
55 lines (51 loc) · 1.53 KB
/
platform.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require("lovepunk.entity")
require("helpfuldog")
Platform = Entity.new(0, 0, 80, 12)
Platform.__index = Platform
function Platform.new(x, y)
local self = setmetatable({}, Platform)
self.x = x
self.y = y
self.originX = 0
self.speed = gs/1.7
self.accel = self.speed / 10
self.v = {x=1, y=0}
self.type = "level"
self.image = love.graphics.newImage("assets/img/platform.png")
self.collisionMap = {["level"]="touch"}
return self
end
function Platform:update(dt)
self:move()
local distToAdd = 0
if (self.v.x > 0) then distToAdd = distToAdd + self.width end
if self:collide("level", self.x + self.v.x, self.y) then self.v.x = self.v.x * -1 end
end
function Platform:draw()
love.graphics.draw(self.image, self.x, self.y, 0, self.scaleX, self.scaleY, self.originX, self.originY)
end
function Platform:move()
local _,_,cols = self.scene.bumpWorld:check(self, self.x + self.v.x, self.y + self.v.y-1, entityFilter)
for _, c in pairs(cols) do
if (c.other.type == "level") then
self.v.x = self.v.x + c.normal.x*math.abs(self.v.x)
self.v.y = self.v.y + c.normal.y*math.abs(self.v.y)
end
if (c.other.type == "player") then
print ("occurring")
if (sign(self.v.x) == sign(c.other.v.x) or isCloseTo(c.other.v.x, 0, 0.5)) then c.other.v.x = c.other.v.x + self.v.x/1.5 end
end
end
self.x = self.x + self.v.x
self.y = self.y + self.v.y
self.scene.bumpWorld:update(self, self.x, self.y)
end
function Platform:flip(reverse)
if (reverse) then
self.originX = self.width
self.scaleX = -1
else
self.originX = 0
self.scaleX = 1
end
end