-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmisc.moon
More file actions
167 lines (117 loc) · 2.8 KB
/
misc.moon
File metadata and controls
167 lines (117 loc) · 2.8 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{graphics: g} = love
import floor from math
line_height = 8
ez_approach = (val, target, dt) ->
approach val, target, (math.abs(val - target) + 1) * dt * 10
export ^
class Stage
new: (@game) =>
@hud = @make_hud!
@timer = Timer!
@particles = DrawList!
@entities = DrawList!
@done = false
@shroud = 255
@entities\add Sequence ->
tween @, 0.2, shroud: 0
make_hud: => Hud @
update: (dt) =>
@entities\update dt, @
@particles\update dt
@hud\update dt, @
@timer\update dt unless @locked
if @timer.time == 0 and not @locked
@locked = true
@entities\add Sequence ->
if @on_done!
wait 1.0
tween @, 1.0, shroud: 255
@done = true
on_done: => true
draw: =>
@entities\draw!
@particles\draw!
draw_top: =>
if @shroud > 0
@game.viewport\draw { 20,20,20, @shroud }
collides: =>
false
class Timer
time: 10
draw: (x,y) =>
old_font = g.getFont!
g.setFont fonts.number_font
p tostring(@), x, y
g.setFont old_font
update: (dt) =>
@time -= dt
@time = 0 if @time < 0
true
reset: =>
@time = 10
__tostring: =>
"0:%02d"\format math.ceil(@time)
class Hud
new: (@stage) =>
@inventory = @stage.game.inventory
for key, val in pairs @inventory
@[key] = val
draw: =>
v = @stage.game.viewport
g.push!
g.translate 43, 1
p @stage.name, 0, 0
p "Money: $#{floor @money}", 0, line_height
g.pop!
g.push!
offset = v.w / 3
g.translate 0, v.h - line_height
p "Steak: #{floor @steak}", 0, 0
p "Pasta: #{floor @pasta}", offset, 0
p "Soda: #{floor @soda}", offset * 2, 0
g.pop!
@stage.timer\draw 0, 0
update: (dt) =>
for key in pairs @inventory
@[key] = ez_approach @[key], @inventory[key], dt
true
class HorizBar
color: { 255, 128, 128, 128 }
border: true
padding: 1
tween_speed: 1
new: (@w, @h, @value=0.5)=>
@display_value = @value
update: (dt) =>
@display_value = ez_approach @display_value, @value, @tween_speed * dt / 5
true
draw: (x, y) =>
g.push!
val = @display_value
if @border
COLOR\push 255,255,255
g.setLineWidth 0.6
g.rectangle "line", x, y, @w, @h
COLOR\push @color
w = val * (@w - @padding*2)
g.rectangle "fill", x + @padding, y + @padding, w, @h - @padding*2
COLOR\pop 2
else
COLOR\push @color
w = val * @w
g.rectangle "fill", x, y, w, @h
COLOR\pop!
g.pop!
class RevealString extends Sequence
new: (@str, @x, @y, rate=0.05) =>
@chr = 0
super ->
while @chr < #@str
@chr += 1
wait rate
@done = true
while true
wait 100
draw: =>
p @str\sub(1, @chr), @x, @y
{ :Stage, :RevealString, :HorizBar, :Timer, :Hud }