Some work on implementing underpill.
[poca-love.git] / images.lua
blobf054c20a4390f8f11336d92edca70dcd6a2b45f2
1 images = {
2 ['0'] = { -- tile
3 color = {.3, .3, .3},
4 shape = 'floortile',
5 },
6 ['1'] = { -- greenx
7 color = {0, 1, 0},
8 center = 'plain',
9 },
10 ['2'] = { -- green+
11 color = {0, 1, 0},
12 center = 'plain',
14 ['3'] = { -- yellowx
15 color = {1, 1, 0},
16 center = 'plain',
18 ['4'] = { -- yellow+
19 color = {1, 1, 0},
20 center = 'plain',
22 ['5'] = { -- redx
23 color = {1, 0, 0},
24 center = 'dot',
26 ['6'] = { -- red+
27 color = {1, 0, 0},
28 center = 'dot',
30 ['7'] = { -- regenex
31 color = {.4, .7, 0},
32 center = 'plain',
34 ['8'] = { -- regene+
35 color = {.4, .7, 0},
36 center = 'plain',
38 ['9'] = { -- regenex - pressed
39 color = {.6, .3, .3},
40 shape = 'floortile',
42 A = { -- regene+ - pressed
43 color = {.6, .3, .3},
44 shape = 'floortile',
46 B = { -- bluesave
47 shape = 'bmp',
48 bmp = love.graphics.newImage('gfx/bluesave.png'),
50 C = { -- blueload
51 shape = 'bmp',
52 bmp = love.graphics.newImage('gfx/blueload.png'),
54 D = { -- blackload
55 shape = 'bmp',
56 bmp = love.graphics.newImage('gfx/blackload.png'),
58 F = { -- redsave
59 shape = 'bmp',
60 bmp = love.graphics.newImage('gfx/redsave.png'),
62 H = { --loadredx
63 color = {.5, 0, 0},
64 center = 'dot',
66 I = { --loadred+
67 color = {.5, 0, 0},
68 center = 'dot',
70 J = { --gift
71 color = {.3, .3, .3},
72 shape = 'gift',
74 K = { --devilgift
75 color = {1, 0, 0},
76 shape = 'gift',
78 L = { -- blacksave
79 shape = 'bmp',
80 bmp = love.graphics.newImage('gfx/blacksave.png'),
82 N = { -- wiseman
83 shape = 'bmp',
84 bmp = love.graphics.newImage('gfx/wiseman.png'),
86 O = { -- pill
87 shape = 'bmp',
88 bmp = love.graphics.newImage('gfx/pill.png'),
90 P = { -- purple+
91 color = {.6, 0, .6},
92 center = 'purple',
94 Q = { -- purplex
95 color = {.6, 0, .6},
96 center = 'purple',
98 R = { -- killed
99 shape = 'bmp',
100 bmp = love.graphics.newImage('gfx/dead.png'),
102 Z = { -- trinket
103 shape = 'trinket',
106 a = { -- green+ - memory
107 color = {0, 1, 0},
108 center = 'plain',
109 memory = true,
111 b = { -- greenx - memory
112 color = {0, 1, 0},
113 center = 'plain',
114 memory = true,
116 c = { --loadred+ - memory
117 color = {.5, 0, 0},
118 center = 'dot',
119 memory = true,
121 d = { --loadredx - memory
122 color = {.5, 0, 0},
123 center = 'dot',
124 memory = true,
126 e = { -- red+ - memory
127 color = {1, 0, 0},
128 center = 'dot',
129 memory = true,
131 f = { -- redx - memory
132 color = {1, 0, 0},
133 center = 'dot',
134 memory = true,
136 g = { -- regene+ - pressed - memory
137 color = {.6, .3, .3},
138 shape = 'floortile',
139 memory = true,
141 h = { -- regenex - memory
142 color = {.6, .3, .3},
143 shape = 'floortile',
144 memory = true,
146 i = { -- regenex - pressed - memory
147 color = {.6, .3, .3},
148 shape = 'floortile',
149 memory = true,
151 j = { -- yellow+ - memory
152 color = {1, 1, 0},
153 center = 'plain',
154 memory = true,
156 k = { -- yellowx - memory
157 color = {1, 1, 0},
158 center = 'plain',
159 memory = true,
161 l = { -- regene+ - memory
162 color = {.6, .3, .3},
163 shape = 'floortile',
164 memory = true,
166 m = { -- purple+ - memory
167 color = {.6, 0, .6},
168 center = 'plain',
169 memory = true,
171 n = { -- purplex - memory
172 color = {.6, 0, .6},
173 center = 'plain',
174 memory = true,
176 floor_regene_x = {
177 bmp = love.graphics.newImage('gfx/floor_regene_x.png'),
179 floor_regene_plus = {
180 bmp = love.graphics.newImage('gfx/floor_regene_plus.png'),
184 function add_scale(t)
185 for k, v in pairs(t) do if type(v) == 'table' and v.bmp then
186 -- determine correct scale and offset for bitmaps
187 local sizex, sizey = v.bmp:getWidth(), v.bmp:getHeight()
188 v.scale = math.max(sizex, sizey)
189 v.offsetx = (v.scale - sizex) / 2 / v.scale
190 v.offsety = (v.scale - sizey) / 2 / v.scale
191 -- retro style
192 v.bmp:setFilter('linear', 'nearest')
193 end end
196 add_scale(images)
199 function draw_floor(x, y, stepped, sleep, shape)
200 love.graphics.push()
201 love.graphics.scale(screen.tilesize)
202 love.graphics.translate(x, y)
203 love.graphics.setColor(images['0'].color, 1)
204 love.graphics.rectangle('fill', -.50,-.50, 1.00,1.00)
205 love.graphics.setColor(1,1,1, .4)
206 if stepped then
207 love.graphics.polygon('fill', .50,-.50, .50,.50, -.50,.50)
208 else
209 love.graphics.polygon('fill', -.50,-.50, .50,-.50, -.50,.50)
211 love.graphics.setColor(0,0,0, .4)
212 if stepped then
213 love.graphics.polygon('fill', -.50,-.50, .50,-.50, .50,.50)
214 else
215 love.graphics.polygon('fill', -.50,-.50, .50,.50, -.50,.50)
217 love.graphics.setColor(images['0'].color, 1)
218 love.graphics.rectangle('fill', -.45,-.45, .90,.90)
219 if sleep then
220 love.graphics.setColor(1,1,1, 1)
221 local img
222 if shape == '+' then img = images.floor_regene_plus else img = images.floor_regene_x end
223 love.graphics.draw(img.bmp, img.offsetx -.50, img.offsety -.50, 0, 1/img.scale, 1/img.scale)
225 love.graphics.pop()
229 function draw_image(pftile, x, y, phase, scale)
230 if not phase then phase = 0 end
231 function arrow(color, angle, distance, base)
232 if not quality then quality = 'fill' end
233 base = ((base or 0) + 1) / 10
234 if angle % (math.pi / 2) > .1 then
235 distance = distance * math.sqrt(2)
237 distance = distance + .5
238 local ox, oy = math.sin(angle) * (distance - .5), math.cos(angle) * (distance - .5)
239 local ex, ey = math.sin(angle) * distance, math.cos(angle) * distance
240 love.graphics.setColor(color)
241 love.graphics.polygon(quality, ex, ey,
242 ox + math.sin(angle + math.pi / 2) * base, oy + math.cos(angle + math.pi / 2) * base,
243 ox - math.sin(angle + math.pi / 2) * base, oy - math.cos(angle + math.pi / 2) * base
247 if not pftile.name then return end
248 if images[pftile.name].memory then
249 draw_image(pftile.memory, x, y, phase, .5)
250 return
252 love.graphics.push()
253 love.graphics.setLineWidth(0.01)
254 love.graphics.scale(screen.tilesize)
255 love.graphics.translate(x, y)
256 if scale then love.graphics.scale(scale) end
257 love.graphics.push()
258 local function gifts_aperture()
259 local ph = playfield.giftsphase
260 love.graphics.rectangle('fill', -.5 * ph, -.5 * ph, 1 * ph, 1 * ph)
262 if pftile.ingift then --draw gift surface without aperture
263 love.graphics.stencil(gifts_aperture, "replace", 1)
264 love.graphics.setStencilTest("less", 1)
266 if pftile.ingift or images[pftile.name].shape == 'gift' then
267 if images[pftile.name].shape == 'gift' then
268 love.graphics.setColor(images[pftile.name].color, 1)
269 love.graphics.rectangle('fill', -.5, -.5, 1, 1)
271 love.graphics.setColor(1,1,1, .4)
272 love.graphics.polygon('fill', -.50,-.50, .50,-.50, -.50,.50)
273 love.graphics.setColor(0,0,0, .4)
274 love.graphics.polygon('fill', -.50,-.50, .50,.50, -.50,.50)
276 if pftile.ingift then --invert stencil to draw gift contents
277 love.graphics.setStencilTest("gequal", 1)
280 if images[pftile.name].color then
281 love.graphics.setColor(images[pftile.name].color, 1)
282 else
283 love.graphics.setColor(1,1,1, 1)
285 if pftile.kind == 'regene' then
286 for a = 1, 8 do if pftile.arrows[a] then
287 arrow(pftile.color or images[pftile.name].color, math.pi / 4 * (a + 1) , pftile.arrows[a], phase) --!!
288 end end
289 elseif pftile.arrows then
290 for a = 1, 8 do if pftile.arrows[a] then
291 arrow(pftile.color or images[pftile.name].color, math.pi / 4 * (a + 1 + phase) , pftile.arrows[a], nil)
292 end end
294 if images[pftile.name].shape == 'bmp' then
295 love.graphics.setColor(1,1,1, 1)
296 love.graphics.draw(images[pftile.name].bmp, images[pftile.name].offsetx -.50, images[pftile.name].offsety -.50, 0, 1/images[pftile.name].scale, 1/images[pftile.name].scale)
298 if images[pftile.name].shape == 'trinket' then
299 local trinket = levels[game.currentlevel].trinket
300 if not trinkets[trinket] then trinket = 'cigarettes' end --!! until all trinkets are implemented
301 love.graphics.setColor(1,1,1, 1)
302 love.graphics.draw(trinkets[trinket].bmp, trinkets[trinket].offsetx -.50, trinkets[trinket].offsety -.50, 0, 1/trinkets[trinket].scale, 1/trinkets[trinket].scale)
304 love.graphics.pop()
305 if images[pftile.name].center then
306 --center == 'plain'
307 love.graphics.setColor(.5,.5,.5, 1)
308 if pftile.devil then love.graphics.setColor(.9,.3,.3, 1) end
309 love.graphics.rectangle('fill', -.15,-.15, .30,.30)
310 if pftile.center == 'dot' or images[pftile.name].center == 'dot' then
311 love.graphics.setColor(.1,.1,.1, 1)
312 love.graphics.circle('fill', 0,0, .1)
314 if images[pftile.name].center == 'purple' then
315 love.graphics.setColor(.1,.1,.1, 1)
316 if game.temppurple then
317 love.graphics.rectangle('fill', -.05,-.05, .1, .1)
318 else
319 love.graphics.rectangle('line', -.05,-.05, .1, .1)
322 if images[pftile.name].center == 'bmp' then
323 love.graphics.setColor(1,1,1, 1)
324 love.graphics.draw(images[pftile.name].bmp, images[pftile.name].offsetx -.50, images[pftile.name].offsety -.50, 0, 1/images[pftile.name].scale, 1/images[pftile.name].scale)
327 if pftile.ingift then --darken gifts content
328 love.graphics.setColor(0,0,0, .9 - playfield.giftsphase)
329 gifts_aperture()
331 love.graphics.setStencilTest()
332 love.graphics.pop()
333 love.graphics.setColor(1, 1, 1, 1)
334 --small images in loadred
335 if pftile.name ~= 'R' and pftile.arrowgift then
336 draw_image(pftile.arrowgift, x, y, 0, pftile.arrowgiftphase or .4)
341 function draw_playfield()
342 -- layer 1: playfield
343 inplayfield(function (x, y, p)
344 local stepped = playfield.clickedx == x and playfield.clickedy == y
345 draw_floor(x - .5 + screen.playfieldx, y - .5 + screen.playfieldy, stepped, p.sleep, p.shape)
346 end)
347 -- layer 2: all images and arrows
348 inplayfield(function (x, y, p)
349 if p.name ~= '0' or p.shape or p.ingift then
350 draw_image(p, x - .5 + screen.playfieldx, y - .5 + screen.playfieldy, p.phase)
352 end)
353 -- layer 3: dead player
354 if game.showkill then
355 playfield[playfield.clickedx][playfield.clickedy].name = 'R'
356 draw_image(playfield[playfield.clickedx][playfield.clickedy], playfield.clickedx - .5 + screen.playfieldx, playfield.clickedy - .5 + screen.playfieldy)