-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.moon
More file actions
344 lines (263 loc) · 7.16 KB
/
main.moon
File metadata and controls
344 lines (263 loc) · 7.16 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
export disable_reloader = true
export watch_class = ->
require "lovekit.all"
-- reloader = require "lovekit.reloader"
g = love.graphics
import timer, keyboard, audio from love
import concat from table
require "lovekit.screen_snap"
-- snapper = ScreenSnap!
require "autotile"
require "attack"
require "enemy"
require "effects"
require "ui"
require "levels.all"
p = (str, ...) -> g.print str\lower!, ...
-- prints lines of text over time
class Printer extends Sequence
rate: 0.1
line_height: 8
new: (str) =>
@line = 1
@char = 1
@lines = split str, "\n"
super ->
while @line <= #@lines
wait @rate
@char += 1
if @char > #@lines[@line]
@char = 1
@line += 1
-- all done
@line = #@lines
@char = #@lines[@line]
wait 1.0
draw: (x, y) =>
for i=1,@line
text = @lines[i]
text = text\sub 1, @char if i == @line
p text, x, y + i * @line_height
class Player extends Entity
watch_class self
w: 8, h: 4
ox: 1, oy: 8
speed: 80
step_rate: 0.25
max_life: 100
alive: true
__tostring: => concat { "<Player: ", tostring(@box), ">" }
new: (...) =>
super ...
@sprite = Spriter imgfy"img/sprite.png", 10, 13, 3
@last_direction = "down"
@cur_attack = nil
@step_time = @step_rate
@weapon = Spear self
@life = @max_life
with @sprite
@anim = StateAnim "stand_down", {
stand_down: \seq {5}
stand_up: \seq {8}
stand_right: \seq {11}
stand_left: \seq {11}, 0, true
walk_down: \seq {3, 4}, 0.25
walk_up: \seq {6, 7}, 0.25
walk_right: \seq {9, 10}, 0.25
walk_left: \seq {9, 10}, 0.25, true
}
attack: =>
@weapon\try_attack! unless @stunned
take_hit: (enemy) =>
return if @hit or @locked or @life <= 0
sfx\play "player_is_hit"
@world.game.viewport\shake!
@life = @life - 12
if @life <= 0
@life = 0
@on_die!
@hit = Sequence.join Flash!, Sequence ->
@velocity = enemy.box\vector_to(@box) * 10
@stunned = true
tween @velocity, 0.3, [1]: 0, [2]: 0
@stunned = false
on_die: =>
@locked = true
sfx\play "player_die"
x, y = @box\center!
@world.particles\add BloodEmitter @world, x, y, nil, 100, nil, ->
@world\restart!
draw: =>
if @last_direction == "up"
@weapon\draw! if @weapon
@draw_player!
else
@draw_player!
@weapon\draw! if @weapon
draw_player: =>
return if @life <= 0
@hit\before! if @hit
@anim\draw @box.x - @ox, @box.y - @oy
@hit\after! if @hit
movement_vector: (dt) =>
return Vec2d 0,0 if @locked
v = movement_vector @speed
if v\is_zero!
@step_time = @step_rate
else
@step_time += dt
if @step_time >= @step_rate
sfx\play "step"
@step_time = 0
v
update: (dt) =>
@velocity = @movement_vector dt unless @stunned
if not @stunned
@anim\set_state @direction_name!
@weapon\update dt if @weapon
@anim\update dt
if @hit
@hit = nil unless @hit\update dt
super dt
true -- still alive
hello = Printer "hello\nworld!\n\nahehfehf\n\nAHHHHHFeefh\n\n...\nhelp me"
class Game
onload: (@dispatch) => sfx\play_music "slime"
new: =>
@viewport = EffectViewport scale: 3
-- g.setLineWidth 1/@viewport.screen.scale
-- cheat to last level
level = if love.keyboard.isDown"1" and love.keyboard.isDown"2"
levels.Floor9
else
levels.Floor1
@player = Player nil, 428, 401
@set_world level self
@health_bar = HorizBar 45, 8
@effect = ViewportFade @viewport, "in"
set_world: (world) =>
@world = world
@player.world = @world
@player.box.x, @player.box.y = unpack @world.start_pos
world.entities\add @player
draw: =>
@viewport\center_on @player
@viewport\apply!
@world\draw!
-- p "I & you Lee! Forever Yours, Leafo.", 0,0
-- hello\draw 10, 10
@health_bar.value = @player.life / @player.max_life
@health_bar\draw @viewport.x + 2, @viewport.y + @viewport.h - 10
@effect\draw! if @effect
@viewport\pop!
p tostring(timer.getFPS!), 2, 2
update: (dt) =>
return if dt > 1.0 -- o well
-- reloader\update dt
return if @pause
@viewport\update dt
@world\update dt
if @effect
e = @effect
@effect = nil if not @effect\update(dt) and e == @effect
hello\update dt
snapper\tick dt if snapper
on_key: (key, code) =>
switch key
when "x"
@player\attack!
class Intro
text: {
"Slimes!\n\nthey're everywhere!"
"they've invaded the castle,\n and are living in\n the catacombs."
"they're attacking our\n soldiers.\n\nthey've stolen our princess."
"you must get them! "
}
onload: (@dispatch) => sfx.music\stop!
new: =>
@i = 1
@viewport = EffectViewport scale: 3
@effect = ViewportFade @viewport, "in"
begin: =>
@dispatch\pop!
@dispatch\push Game!
update: (dt) =>
if love.keyboard.isDown "x"
dt = dt * 6
if @effect
@effect = nil if not @effect\update dt
else
if not @writer
if @text[@i] == nil
@begin!
return
@writer = Printer @text[@i]
@i += 1
@writer = nil if not @writer\update dt
on_key: (key, code) =>
if key == "escape"
@begin!
true
draw: =>
@viewport\apply!
@writer\draw 10, 10 if @writer
@effect\draw! if @effect
@viewport\pop!
export class Outro extends Intro
text: {
"Upon slaying the Huge Slime,\n you discover the castle\n toilets."
"Excrement falls down and\n festers in a pile.\n\nWhat is this!?"
"The slimes have evolved\n from our own waste.\n\nAnd now they torment us."
"What will become of this\n kingdom?",
"The slimes are at last dead.\n\n\nBut at what cost?"
}
begin: =>
@dispatch\pop 2
class Title
onload: (@dispatch) => sfx\play_music "slime_title"
new: =>
@bg = imgfy "img/title.png"
@viewport = EffectViewport scale: 1
@effect = ViewportFade @viewport, "in"
draw: =>
@bg\draw 0,0
@effect\draw! if @effect
update: (dt) =>
if @effect
@effect = nil if not @effect\update dt
on_key: (key, code) =>
return if @effect
if key == "return"
sfx\play "game_start"
@effect = ViewportFade @viewport, "out", ->
@dispatch\push Intro!
export fonts = {}
load_font = (img, chars)->
font_image = imgfy img
g.newImageFont font_image.tex, chars
love.load = ->
-- g.setBackgroundColor 61, 52, 47
g.setBackgroundColor 61/2, 52/2, 47/2
fonts.main = load_font "img/font.png", [[ abcdefghijklmnopqrstuvwxyz-1234567890!.,:;'"?$&]]
fonts.damage = load_font "img/font2.png", [[ 1234567890]]
export sfx = lovekit.audio.Audio!
sfx\preload {
"game_start"
"step"
"player_is_hit"
"player_strike"
"enemy_is_hit"
"player_die"
"enemy_die"
"spread_shot"
"single_shot"
"hit_switch"
}
g.setFont fonts.main
-- game = Game!
dispatch = Dispatcher Title!
dispatch\bind love
love.mousepressed = (x,y, button) ->
-- x, y = game.viewport\unproject x, y
-- print "mouse", x, y, button
-- print game.world.map