-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtape_gfx.lua
More file actions
125 lines (93 loc) · 3.2 KB
/
Copy pathtape_gfx.lua
File metadata and controls
125 lines (93 loc) · 3.2 KB
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
local gfx <const> = playdate.graphics
local gear_table = gfx.imagetable.new(45 / 5)
local gear_img = gfx.image.new("images/gear")
local gear_i = 1
for i = 5,45,5 do
gear_table:setImage(gear_i, gear_img:rotatedImage(i))
gear_i += 1
end
local gear_anim = gfx.animation.loop.new(100, gear_table)
local switch_img = gfx.image.new("images/switch")
local label_img = gfx.image.new("images/label")
local label_height <const> = 17
local label_animator = gfx.animator.new(0.5, 0, 0)
local default_switch_offset = {
x = 88 + 135,
y = 150
}
local default_label_offset = {
x = 57,
y = 177
}
local gear1_offset = {
x = 126,
y = 106
}
local gear2_offset = {
x = 276,
y = 106
}
function moveTapeGFXTo(tape_gfx, x, y)
tape_gfx.tape_spr:moveTo(x, y)
tape_gfx.gear_spr1:moveTo(gear1_offset.x + x, gear1_offset.y + y)
tape_gfx.gear_spr2:moveTo(gear2_offset.x + x, gear2_offset.y + y)
tape_gfx.switch_offset.x = default_switch_offset.x + x
tape_gfx.switch_offset.y = default_switch_offset.y + y
tape_gfx.label_offset.x = default_label_offset.x + x
tape_gfx.label_offset.y = default_label_offset.y + y
end
function makeTapeGFX(img_file)
local tape_img = gfx.image.new(img_file)
local tape_gfx = {
tape_spr = gfx.sprite.new(tape_img),
gear_spr1 = gfx.sprite.new(gear_anim:image()),
gear_spr2 = gfx.sprite.new(gear_anim:image()),
switch_spr = gfx.sprite.new(switch_img),
label_spr = gfx.sprite.new(label_img),
switch_offset = {x = 0, y = 0},
label_offset = {x = 0, y = 0}
}
tape_gfx.tape_spr:setCenter(0, 0)
tape_gfx.tape_spr:add()
tape_gfx.gear_spr1:add()
tape_gfx.gear_spr2:add()
tape_gfx.switch_spr:add()
tape_gfx.label_spr:add()
tape_gfx.label_spr:setZIndex(-1)
moveTapeGFXTo(tape_gfx, 0, 0)
return tape_gfx
end
function setTapeGFXRate(tape_gfx, rate, max_rate)
local offset = 135 * (rate / max_rate)
tape_gfx.switch_spr:moveTo(tape_gfx.switch_offset.x + offset, tape_gfx.switch_offset.y)
gear_anim.delay = 10 * (max_rate / rate)
end
function setTapeGFXStartOffset(tape_gfx, startOffset)
local offset = 270 * startOffset - 135
tape_gfx.switch_spr:moveTo(tape_gfx.switch_offset.x + offset, tape_gfx.switch_offset.y)
end
function setTapeGFXTargetLength(tape_gfx, targetLength)
local offset = 270 * targetLength - 135
tape_gfx.switch_spr:moveTo(tape_gfx.switch_offset.x + offset, tape_gfx.switch_offset.y)
end
function setTapeGFXVolume(tape_gfx, volume)
local offset = 270 * volume - 135
tape_gfx.switch_spr:moveTo(tape_gfx.switch_offset.x + offset, tape_gfx.switch_offset.y)
end
function pauseTapeGFX(tape_gfx)
gear_anim.paused = true
end
function unpauseTapeGFX(tape_gfx)
gear_anim.paused = false
end
function setLabelIndex(i)
label_animator = gfx.animator.new(500,
label_animator:currentValue(),
i * label_height - label_height,
playdate.easingFunctions.inOutCubic)
end
function updateTapeGFX(tape_gfx)
tape_gfx.gear_spr1:setImage(gear_anim:image())
tape_gfx.gear_spr2:setImage(gear_anim:image())
tape_gfx.label_spr:moveTo(tape_gfx.label_offset.x, tape_gfx.label_offset.y - label_animator:currentValue())
end