-
Notifications
You must be signed in to change notification settings - Fork 0
/
quad.lua
149 lines (126 loc) · 2.95 KB
/
quad.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
quad = class("quad")
--COLLIDE?
--INVISIBLE?
--BREAKABLE?
--COINBLOCK?
--COIN?
--_NOT_ PORTALABLE?
--LEFT SLANT?
--RIGHT SLANT?
--MIRROR?
--GRATE?
--PLATFORM TYPE?
--WATER TILE?
--BRIDGE?
--SPIKES?
--FOREGROUND?
function quad:init(img, imgdata, x, y, width, height)
--get if empty?
self.image = img
self.quadobj = love.graphics.newQuad((x-1)*17, (y-1)*17, 16, 16, width, height)
self.props = getquadprops(imgdata, x, y)
end
function quad:getproperty(s)
return self.props[s]
end
function quad:quad()
return self.quadobj
end
function getquadprops(imgdata, x, y)
local self = {}
--get collision
self.collision = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17)
if a > 127 then
self.collision = true
end
--get invisible
self.invisible = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+1)
if a > 127 then
self.invisible = true
end
--get breakable
self.breakable = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+2)
if a > 127 then
self.breakable = true
end
--get coinblock
self.coinblock = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+3)
if a > 127 then
self.coinblock = true
end
--get coin
self.coin = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+4)
if a > 127 then
self.coin = true
end
--get not portalable
self.portalable = true
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+5)
if a > 127 then
self.portalable = false
end
--get left slant
self.slantupleft = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+6)
if a > 127 then
self.slantupleft = true
end
--get right slant
self.slantupright = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+7)
if a > 127 then
self.slantupright = true
end
--get mirror
self.mirror = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+8)
if a > 127 then
self.mirror = true
end
--get grate
self.grate = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+9)
if a > 127 then
self.grate = true
end
--get platform
self.platform = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+10)
if a > 127 then
self.platform = true
end
--get watertile
self.water = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+11)
if a > 127 then
self.water = true
end
--get bridge
self.bridge = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+12)
if a > 127 then
self.bridge = true
end
--get spikes
local t = {"left", "top", "right", "bottom"}
for i = 1, #t do
local v = t[i]
self["spikes" .. v] = false
local r, g, b, a = imgdata:getPixel(x*17-1, (y-1)*17+12+i)
if a > 127 then
self["spikes" .. v] = true
end
end
--get foreground
self.foreground = false
local r, g, b, a = imgdata:getPixel(x*17-2, (y-1)*17+16)
if a > 127 then
self.foreground = true
end
return self
end