forked from Stabyourself/mari0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faithplate.lua
100 lines (83 loc) · 2.94 KB
/
faithplate.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
faithplate = class:new()
function faithplate:init(x, y, dir)
self.cox = x
self.coy = y
self.dir = dir
self.x = x-1
self.y = y-1
self.width = 2
self.height = 0.125
self.active = true
self.static = true
self.category = 26
self.mask = {true}
self.animationtimer = 1
self.includetable = {"player", "box", "goomba"}
end
function faithplate:update(dt)
if self.animationtimer < 1 then
self.animationtimer = self.animationtimer + dt / faithplatetime
end
local intable = checkrect(self.x+.5, self.y-0.125, 1, 0.125, self.includetable)
for i = 1, #intable, 2 do
if self.dir == "up" then
objects[intable[i]][intable[i+1]].speedy = -40
elseif self.dir == "right" then
objects[intable[i]][intable[i+1]].speedy = -30
objects[intable[i]][intable[i+1]].speedx = 30
elseif self.dir == "left" then
objects[intable[i]][intable[i+1]].speedy = -30
objects[intable[i]][intable[i+1]].speedx = -30
end
if objects[intable[i]][intable[i+1]].faithplate then
objects[intable[i]][intable[i+1]]:faithplate(self.dir)
end
self.animationtimer = 0
end
end
function faithplate:draw()
love.graphics.setScissor(math.floor((self.cox-1-xscroll)*16*scale), (self.coy-4)*16*scale, 32*scale, (2.5+2/16)*16*scale)
love.graphics.setColor(unpack(backgroundcolor[background]))
love.graphics.rectangle("fill", math.floor((self.cox-1-xscroll)*16*scale), (self.coy-1.5)*16*scale, 32*scale, 2*scale)
love.graphics.setColor(1, 1, 1)
if self.animationtimer < 1 then
if self.dir == "right" then
local rot = 0
if self.animationtimer < 0.1 then
rot = math.pi/4*(self.animationtimer/0.1)
elseif self.animationtimer < 0.3 then
rot = math.pi/4
else
rot = math.pi/4*(1 - (self.animationtimer-0.3)/0.7)
end
love.graphics.draw(faithplateplateimg, math.floor((self.cox+1-xscroll)*16*scale), (self.coy-1.5)*16*scale, rot, scale, scale, 32)
elseif self.dir == "left" then
local rot = 0
if self.animationtimer < 0.1 then
rot = math.pi/4*(self.animationtimer/0.1)
elseif self.animationtimer < 0.3 then
rot = math.pi/4
else
rot = math.pi/4*(1 - (self.animationtimer-0.3)/0.7)
end
love.graphics.draw(faithplateplateimg, math.floor((self.cox-1-xscroll)*16*scale), (self.coy-1.5)*16*scale, -rot, -scale, scale, 32)
elseif self.dir == "up" then
local ymod = 0
if self.animationtimer < 0.1 then
ymod = .5*(self.animationtimer/0.1)
elseif self.animationtimer < 0.3 then
ymod = .5
else
ymod = .5*(1 - (self.animationtimer-0.3)/0.7)
end
love.graphics.draw(faithplateplateimg, math.floor((self.cox-1-xscroll)*16*scale), (self.coy-1.5-ymod)*16*scale, 0, scale, scale)
end
else
if self.dir ~= "left" then
love.graphics.draw(faithplateplateimg, math.floor((self.cox-1-xscroll)*16*scale), (self.coy-1.5)*16*scale, 0, scale, scale)
else
love.graphics.draw(faithplateplateimg, math.floor((self.cox+1-xscroll)*16*scale), (self.coy-1.5)*16*scale, 0, -scale, scale)
end
end
love.graphics.setScissor()
end