-
Notifications
You must be signed in to change notification settings - Fork 17
/
faithplate.lua
179 lines (150 loc) · 4.85 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
faithplate = class("faithplate")
function faithplate:init(x, y, r)
self.cox = x
self.coy = y
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.power = true
self.mask = {true}
self.animationtimer = 1
self.includetable = {"player", "box", "enemy"}
self.xspeed = 0
self.yspeed = 20
self.input1state = "off"
--Input list
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
--Xspeed
if #self.r > 0 then
if string.sub(self.r[1], 1, 1) == "m" then
self.xspeed = -tonumber(string.sub(self.r[1], 2))
else
self.xspeed = tonumber(self.r[1])
end
table.remove(self.r, 1)
end
--Yspeed
if #self.r > 0 then
self.yspeed = tonumber(self.r[1]) or 20
table.remove(self.r, 1)
end
--POWER
if #self.r > 0 and self.r[1] ~= "link" then
if self.r[1] == "true" then
self.power = false
end
table.remove(self.r, 1)
end
--determine rough direction
if self.yspeed > math.abs(self.xspeed)*2 then
self.dir = "up"
elseif self.xspeed > 0 then
self.dir = "right"
else
self.dir = "left"
end
end
function faithplate:input(t, input)
if input == "power" then
if t == "on" and self.input1state == "off" then
self.power = not self.power
elseif t == "off" and self.input1state == "on" then
self.power = not self.power
elseif t == "toggle" then
self.power = not self.power
end
self.input1state = t
end
end
function faithplate:link()
while #self.r > 3 do
for j, w in pairs(outputs) do
for i, v in pairs(objects[w]) do
if tonumber(self.r[3]) == v.cox and tonumber(self.r[4]) == v.coy then
v:addoutput(self, self.r[2])
end
end
end
table.remove(self.r, 1)
table.remove(self.r, 1)
table.remove(self.r, 1)
table.remove(self.r, 1)
end
end
function faithplate:update(dt)
if self.animationtimer < 1 then
self.animationtimer = self.animationtimer + dt / faithplatetime
end
if self.power then
local intable = checkrect(self.x+.5, self.y-0.125, 1, 0.125, self.includetable)
for i = 1, #intable, 2 do
if not objects[intable[i]][intable[i+1]].ignorefaithplates then
if objects[intable[i]][intable[i+1]].speedy >= 0 then
objects[intable[i]][intable[i+1]].speedy = -self.yspeed
objects[intable[i]][intable[i+1]].speedx = self.xspeed
objects[intable[i]][intable[i+1]].x = self.x+1-objects[intable[i]][intable[i+1]].width/2
if objects[intable[i]][intable[i+1]].faithplate then
objects[intable[i]][intable[i+1]]:faithplate(self.dir)
end
self.animationtimer = 0
end
end
end
end
end
function faithplate:draw()
local quad = 2
if self.power then
quad = 1
end
love.graphics.setScissor(math.floor((self.cox-1-xscroll)*16*scale), (self.coy-yscroll-4)*16*scale, 32*scale, (2.5+2/16)*16*scale)
love.graphics.setColor(unpack(background))
love.graphics.rectangle("fill", math.floor((self.cox-1-xscroll)*16*scale), (self.coy-yscroll-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, faithplatequad[quad], math.floor((self.cox+1-xscroll)*16*scale), (self.coy-yscroll-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, faithplatequad[quad], math.floor((self.cox-1-xscroll)*16*scale), (self.coy-yscroll-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, faithplatequad[quad], math.floor((self.cox-1-xscroll)*16*scale), (self.coy-yscroll-1.5-ymod)*16*scale, 0, scale, scale)
end
else
if self.dir ~= "left" then
love.graphics.draw(faithplateplateimg, faithplatequad[quad], math.floor((self.cox-1-xscroll)*16*scale), (self.coy-yscroll-1.5)*16*scale, 0, scale, scale)
else
love.graphics.draw(faithplateplateimg, faithplatequad[quad], math.floor((self.cox+1-xscroll)*16*scale), (self.coy-yscroll-1.5)*16*scale, 0, -scale, scale)
end
end
love.graphics.setScissor()
end