| 1 |
local gl = require 'gl' |
| 2 |
local v2 = require 'dokidoki.v2' |
| 3 |
|
| 4 |
assert(player, 'missing player argument') |
| 5 |
|
| 6 |
picked = false |
| 7 |
|
| 8 |
local OFFSET_PIXELS = -4 |
| 9 |
local SEGMENTS = 16 |
| 10 |
local RADIUS = 32 |
| 11 |
|
| 12 |
local fade = 0.2 |
| 13 |
|
| 14 |
local pulse_time = 0 |
| 15 |
|
| 16 |
callback = callback or function () end |
| 17 |
|
| 18 |
self.sprite.image = assert(game.resources.factory_sprites[player]) |
| 19 |
|
| 20 |
function update() |
| 21 |
pulse_time = pulse_time + 1 |
| 22 |
|
| 23 |
if not picked and game.the_one_button.held(player) then |
| 24 |
picked = true |
| 25 |
callback() |
| 26 |
end |
| 27 |
if picked then |
| 28 |
fade = math.min(fade + 0.1, 1) |
| 29 |
self.sprite.color = {fade, fade, fade} |
| 30 |
end |
| 31 |
end |
| 32 |
|
| 33 |
function draw() |
| 34 |
local pos = self.transform.pos + OFFSET_PIXELS * self.transform.facing |
| 35 |
local pulse = (1 + math.cos(pulse_time/180*2*math.pi))/2 |
| 36 |
|
| 37 |
local color = fade * pulse + 1 * (1-pulse) |
| 38 |
|
| 39 |
gl.glPushMatrix() |
| 40 |
gl.glTranslated(pos.x, pos.y, 0) |
| 41 |
|
| 42 |
|
| 43 |
gl.glBegin(gl.GL_TRIANGLE_FAN) |
| 44 |
gl.glColor4d(0, 0, 0, 0.6) |
| 45 |
gl.glVertex2d(0, 0) |
| 46 |
for point = 0,SEGMENTS do |
| 47 |
local vert = v2.unit(math.pi/2 - point / SEGMENTS * math.pi * 2) * RADIUS |
| 48 |
gl.glVertex2d(vert.x, vert.y) |
| 49 |
end |
| 50 |
gl.glVertex2d(0, 0) |
| 51 |
gl.glEnd() |
| 52 |
|
| 53 |
|
| 54 |
if picked then |
| 55 |
gl.glBegin(gl.GL_TRIANGLE_FAN) |
| 56 |
local bottom_highlight_angle = player * math.pi / 2 - math.pi |
| 57 |
gl.glColor4d(0.5, 1, 1, 0.7) |
| 58 |
gl.glVertex2d(0, 0) |
| 59 |
for point = 0,SEGMENTS do |
| 60 |
gl.glVertex2d(math.sin(point / SEGMENTS * math.pi * 0.5 + bottom_highlight_angle) * RADIUS, math.cos(point / SEGMENTS * math.pi * 0.5 + bottom_highlight_angle) * RADIUS) |
| 61 |
end |
| 62 |
gl.glEnd() |
| 63 |
end |
| 64 |
|
| 65 |
gl.glColor3d(color, color, color) |
| 66 |
game.resources.a_button:draw() |
| 67 |
gl.glColor3d(1, 1, 1) |
| 68 |
gl.glPopMatrix() |
| 69 |
end |