-
Notifications
You must be signed in to change notification settings - Fork 26
/
laserfield.lua
163 lines (142 loc) · 4.12 KB
/
laserfield.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
laserfield = class:new()
function laserfield:init(x, y, dir, r)
self.cox = x
self.coy = y
self.x = x
self.y = y
self.dir = dir
self.active = true
self.inputstate = "off"
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
if #self.r > 0 and self.r[1] ~= "link" then
local v = convertr(self.r[1], {"string", "bool"}, true)
if v[1] ~= nil then
self.dir = v[1]
end
if v[2] ~= nil and v[2] 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(laserfields) 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
self.outtable = {}
end
function laserfield:input(t)
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
function laserfield: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[2]) == v.cox and tonumber(self.r[3]) == v.coy then
v:addoutput(self)
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 laserfield:update(dt)
if self.destroy then
return true
end
end
function laserfield: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)
for x = self.startx, self.endx do
love.graphics.draw(laserfieldimg, math.floor((x-xscroll-1)*16*scale), (self.y-20/16-yscroll)*16*scale, 0, scale, scale)
end
--Sidethings
love.graphics.draw(emancesideimg, emancesidequad[spriteset][2], parstartleft, ((self.y-1-yscroll)*16-4)*scale, 0, scale, scale)
love.graphics.draw(emancesideimg, emancesidequad[spriteset][2], parstartright+16*scale, ((self.y-1-yscroll)*16+4)*scale, math.pi, scale, scale)
else
parstartup = math.floor((self.starty-1-yscroll)*16*scale)
parstartdown = math.floor((self.endy-1-yscroll)*16*scale)
for y = self.starty, self.endy do
love.graphics.draw(laserfieldimg, math.floor((self.x-xscroll-5/16)*16*scale), (y-1-yscroll)*16*scale, math.pi/2, scale, scale, 8, 1)
end
--Sidethings
love.graphics.draw(emancesideimg, emancesidequad[spriteset][2], math.floor(((self.x-xscroll)*16-4)*scale), parstartup-8*scale, math.pi/2, scale, scale)
love.graphics.draw(emancesideimg, emancesidequad[spriteset][2], math.floor(((self.x-xscroll)*16-12)*scale), parstartdown+8*scale, -math.pi/2, scale, scale)
end
end
end
function laserfield: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