-
Notifications
You must be signed in to change notification settings - Fork 17
/
emancipationgrill.lua
230 lines (200 loc) · 6.71 KB
/
emancipationgrill.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
emancipationgrill = class("emancipationgrill")
function emancipationgrill:init(x, y, r)
self.x = x
self.y = y
self.r = {unpack(r)}
self.dir = "hor"
self.active = true
self.inputstate = "off"
self.thickness = 4 -- For aabb checks
table.remove(self.r, 1)
table.remove(self.r, 1)
--Input list
--DIR
if #self.r > 0 and self.r[1] ~= "link" then
self.dir = self.r[1]
table.remove(self.r, 1)
end
--OFF
if #self.r > 0 and self.r[1] ~= "link" then
if self.r[1] == "true" then
self.active = false
end
table.remove(self.r, 1)
end
self.destroy = false
if getTile(self.x, self.y) == true then
self.destroy = true
end
for i, v in pairs(emancipationgrills) do
local a, b = v:getTileInvolved(self.x, self.y)
if a and b == self.dir then
self.destroy = true
end
end
self.particles = {}
self.particles.i = {}
self.particles.dir = {}
self.particles.speed = {}
self.particles.mod = {}
self.involvedtiles = {}
--find start and end
if self.dir == "hor" then
local curx = self.x
while curx >= 1 and getTile(curx, self.y) == false do
self.involvedtiles[curx] = self.y
curx = curx - 1
end
self.startx = curx + 1
local curx = self.x
while curx <= mapwidth and getTile(curx, self.y) == false do
self.involvedtiles[curx] = self.y
curx = curx + 1
end
self.endx = curx - 1
self.range = math.floor(((self.endx - self.startx + 1 + emanceimgwidth/16)*16)*scale)
else
local cury = self.y
while cury >= 1 and getTile(self.x, cury) == false do
self.involvedtiles[cury] = self.x
cury = cury - 1
end
self.starty = cury + 1
local cury = self.y
while cury <= mapheight and getTile(self.x, cury) == false do
self.involvedtiles[cury] = self.x
cury = cury + 1
end
self.endy = cury - 1
self.range = math.floor(((self.endy - self.starty + 1 + emanceimgwidth/16)*16)*scale)
end
for i = 1, self.range/16/scale do
table.insert(self.particles.i, math.random())
table.insert(self.particles.speed, (1-emanceparticlespeedmod)+math.random()*emanceparticlespeedmod*2)
if math.random(2) == 1 then
table.insert(self.particles.dir, 1)
else
table.insert(self.particles.dir, -1)
end
table.insert(self.particles.mod, math.random(4)-2)
end
end
function emancipationgrill: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 emancipationgrill:update(dt)
if self.destroy then
return true
end
for i, v in pairs(self.particles.i) do
self.particles.i[i] = self.particles.i[i] + emanceparticlespeed/(self.range/16/scale)*dt*self.particles.speed[i]
while self.particles.i[i] > 1 do
self.particles.i[i] = self.particles.i[i]-1
self.particles.speed[i] = (1-emanceparticlespeedmod)+math.random()*emanceparticlespeedmod*2
if math.random(2) == 1 then
self.particles.dir[i] = 1
else
self.particles.dir[i] = -1
end
self.particles.mod[i] = math.random(4)-2
end
end
end
function emancipationgrill:draw()
if self.destroy == false then
if self.dir == "hor" then
parstartleft = math.floor((self.startx-1-xscroll)*16*scale)
parstartright = math.floor((self.endx-1-xscroll)*16*scale)
if self.active then
love.graphics.setScissor(parstartleft, ((self.y-yscroll-1)*16-self.thickness/2)*scale,
self.range - emanceimgwidth*scale, self.thickness*scale)
love.graphics.setColor(unpack(emancelinecolor))
love.graphics.rectangle("fill", math.floor((self.startx-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-self.thickness/2)*scale,
self.range, self.thickness*scale)
love.graphics.setColor(1, 1, 1)
for i, v in pairs(self.particles.i) do
local y = ((self.y-1-yscroll)*16-self.particles.mod[i])*scale
if self.particles.dir[i] == 1 then
local x = parstartleft+self.range*v
love.graphics.draw(emanceparticleimg, math.floor(x), y, math.pi/2, scale, scale)
else
local x = parstartright-self.range*v
love.graphics.draw(emanceparticleimg, math.floor(x), y, -math.pi/2, scale, scale, 1)
end
end
love.graphics.setScissor()
end
--Sidethings
love.graphics.draw(emancesideimg, parstartleft, ((self.y-1-yscroll)*16-4)*scale, 0, scale, scale)
love.graphics.draw(emancesideimg, parstartright+16*scale, ((self.y-1-yscroll)*16+4)*scale, math.pi, scale, scale)
else --ver
parstartup = math.floor((self.starty-yscroll-1)*16*scale)
parstartdown = math.floor((self.endy-yscroll-1)*16*scale)
if self.active then
love.graphics.setScissor(math.floor(((self.x-1-xscroll)*16+self.thickness*1.5)*scale), parstartup-8*scale,
self.thickness*scale, self.range - emanceimgwidth*scale)
love.graphics.setColor(unpack(emancelinecolor))
love.graphics.rectangle("fill", math.floor(((self.x-1-xscroll)*16+self.thickness*1.5)*scale), parstartup-8*scale,
self.thickness*scale, self.range - emanceimgwidth*scale)
love.graphics.setColor(1, 1, 1)
for i, v in pairs(self.particles.i) do
local x = ((self.x-1-xscroll)*16-self.particles.mod[i]+9)*scale
if self.particles.dir[i] == 1 then
local y = parstartup-yscroll+self.range*v
love.graphics.draw(emanceparticleimg, math.floor(x), y, math.pi, scale, scale)
else
local y = parstartdown-yscroll-self.range*v
love.graphics.draw(emanceparticleimg, math.floor(x), y, 0, scale, scale, 1)
end
end
love.graphics.setScissor()
end
--Sidethings
love.graphics.draw(emancesideimg, math.floor(((self.x-xscroll)*16-4)*scale), parstartup-8*scale, math.pi/2, scale, scale)
love.graphics.draw(emancesideimg, math.floor(((self.x-xscroll)*16-12)*scale), parstartdown+8*scale, -math.pi/2, scale, scale)
end
end
end
function emancipationgrill:getTileInvolved(x, y)
if self.active then
if self.dir == "hor" then
if self.involvedtiles[x] == y then
return true, "hor"
else
return false, "hor"
end
else
if self.involvedtiles[y] == x then
return true, "ver"
else
return false, "ver"
end
end
else
return false
end
end
function emancipationgrill:input(t, input)
if input == "power" then
if t == "on" and self.inputstate == "off" then
self.active = not self.active
elseif t == "off" and self.inputstate == "on" then
self.active = not self.active
elseif t == "toggle" then
self.active = not self.active
end
self.inputstate = t
end
end