Debian Codegraph @

dokidoki/scripts/sprite.lua

raw symbols SCIP
1 local gl = require 'gl'
2
3 color = color or false
4
5 if not image then
6 if resource then
7 image = game.resources[resource]
8 else
9 -- create a dummy 1x1 square if there's no given image
10 image = {
11 draw = function (_)
12 gl.glBegin(gl.GL_QUADS)
13 gl.glVertex2d(0, 0)
14 gl.glVertex2d(1, 0)
15 gl.glVertex2d(1, 1)
16 gl.glVertex2d(0, 1)
17 gl.glEnd()
18 end
19 }
20 end
21 end
22
23 function draw()
24 -- TODO: do these transforms directly, much faster!
25 gl.glPushMatrix()
26 gl.glTranslated(self.transform.pos.x, self.transform.pos.y, 0)
27 -- slooooow and stupid rotation:
28 local f = self.transform.facing
29 gl.glRotated(180/math.pi * math.atan2(f.y, f.x), 0, 0, 1)
30 gl.glScaled(self.transform.scale_x, self.transform.scale_y, 0)
31
32 if color then gl.glColor4d(color[1], color[2], color[3], color[4] or 1) end
33 image:draw()
34 if color then gl.glColor3d(1, 1, 1) end
35
36 gl.glPopMatrix()
37 end