-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.moon
More file actions
178 lines (136 loc) · 3.38 KB
/
main.moon
File metadata and controls
178 lines (136 loc) · 3.38 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
export disable_reloader = true
export watch_class = ->
require "lovekit.all"
slow_mode = false
g = love.graphics
import timer, keyboard, audio from love
export n = (thing) ->
if type(thing) == "table"
thing.__name or (thing.__class and thing.__class.__name) or tostring thing
else
tostring thing
require "particle"
require "guns"
require "player"
require "background"
require "effects"
require "powerups"
require "enemy"
require "ui"
require "audio"
require "lovekit.screen_snap"
class EffectViewport extends Viewport
new: (...) =>
@effects = EffectList!
super ...
shake: =>
@effects\add effects.Shake 0.4
update: (dt) => @effects\update dt
apply: =>
super!
e\before @obj for e in *@effects
pop: =>
e\after @obj for e in *@effects
super!
s = @screen.scale
g.scale 1/s, 1/s
class World
new: (@viewport) =>
@bg = Background @viewport
@enemies = ReuseList!
@enemy_bullets = ReuseList!
@spawner = EnemyWave self, @enemies
@powerups = ReuseList!
draw: =>
@bg\draw!
@enemies\draw!
@powerups\draw!
@enemy_bullets\draw!
Emitter\draw_all!
update: (dt) =>
Emitter\update_all dt, self
@spawner\update dt
@enemies\update dt
@powerups\update dt
@enemy_bullets\update dt, self
@bg\update dt
collides: (thing) =>
@bg\collides thing
export class Game
new: =>
@start_time = timer.getTime!
@viewport = EffectViewport scale: 4
@world = World @viewport
@player = Player @world, 50, 100
@hud = Hud @viewport, @player
goto_gameover: =>
game_over = GameOver @hud.score, timer.getTime! - @start_time
dispatch\push_with_effect game_over, 2.0, fade_effect
update: (dt) =>
@viewport\update dt
@player\update dt
@world\update dt
@hud\update dt
if @player.health <= 0 and #@player.effects == 0
@goto_gameover!
draw: =>
@viewport\apply!
@world\draw!
@player\draw!
-- g.print tostring(timer.getFPS!), 2, 12
@hud\draw!
@viewport\pop!
snapper = nil
love.load = ->
export dispatch = Dispatch TitleScreen!
export sfx = Audio!
-- export game = Game!
music = audio.newSource "audio/theme.ogg"
music\setLooping true
music\play!
sfx\preload {
"die_enemy"
"hit_enemy"
"powerup"
"shoot"
"shoot_2"
"charge"
"start_game"
"die_player"
"hit_wall"
"hit_player"
}
font_image = imgfy"img/font.png"
font = g.newImageFont font_image.tex, " 1234567890"
g.setFont font
love.mousepressed = (x,y, button) ->
if game
x, y = game.viewport\unproject x, y
-- game.world.powerups\add GunPowerup, x, y
-- game.player\die!
-- game.world.bg\feed_energy 3
-- game.world.powerups\add HealthPowerup, x, y
-- emitters.PourSmoke\add w, x, y
love.keypressed = (key, code) ->
return if dispatch\send_key key, code
switch key
when "escape" then os.exit!
-- when "d"
-- game.player\die! if game
-- when "XX" -- cool
-- if snapper
-- slow_mode = false
-- snapper = nil
-- else
-- slow_mode = true
-- snapper = ScreenSnap!
-- when "s"
-- slow_mode = not slow_mode
-- print "slow mode:", slow_mode
love.update = (dt) ->
-- reloader\update!
dt /= 3 if slow_mode
dispatch\update dt
love.draw = ->
snapper\tick! if snapper
dispatch\draw!