@@ -18,12 +18,15 @@ import cos,sin,abs from math
1818
1919p = ( str, ... ) -> g. print str\ lower!, ...
2020
21- export sprite
21+ export fonts = {}
22+ export sprite, dispatch
2223
2324local snapper
25+ local Game
2426
2527class World
2628 disable_project : false
29+ energy_count : 0
2730
2831 new : ( @player ) =>
2932 @viewport = EffectViewport scale : 3
@@ -45,6 +48,7 @@ class World
4548 \ add_tiles tiles
4649
4750 @map_box = Box 0 , 0 , @map . real_width, @map . real_height
51+ @bomb_pad = BombPad 80 , 80
4852
4953 -- create some enemies
5054 for xx = 1 , 2
@@ -67,6 +71,8 @@ class World
6771 draw_ground : =>
6872 @viewport \ apply!
6973 @map \ draw @viewport
74+ @bomb_pad \ draw!
75+
7076 @viewport \ pop!
7177
7278 draw_entities : =>
@@ -95,17 +101,12 @@ class World
95101 @entity_project \ render -> @draw_entities !
96102
97103 g. setColor 0 , 0 , 0
98- hud_height = 80
99- -- g.rectangle "fill", 0, 0, g.getWidth!, hud_height
100-
101- -- g.rectangle "fill", 0, g.getHeight! - hud_height,
102- -- g.getWidth!, hud_height
103104
104105 g. setColor 255 , 255 , 255
105106
106107 g. scale 2
107108 p tostring ( timer. getFPS!) , 2 , 2
108- p " Loadout: 1 " , 2 , 12
109+ p " Energy: #{@energy_count} " , 2 , 12
109110
110111 update : ( dt) =>
111112 @viewport \ update dt
@@ -114,6 +115,8 @@ class World
114115 @entities \ update dt, @
115116 @particles \ update dt, @
116117
118+ @bomb_pad \ update dt, @
119+
117120 @explode \ update dt
118121
119122 -- respond to collision
@@ -134,6 +137,53 @@ class World
134137 for thing in * @collide \ get_touching enemy. box
135138 enemy\ take_hit thing, @
136139
140+
141+ class Title
142+ new : =>
143+ @viewport = EffectViewport scale : 3
144+ @title_image = imgfy " img/title.png"
145+ @shroud_alpha = 0
146+ @colors = ColorSeparate !
147+
148+ draw : =>
149+ @colors \ render ->
150+ @viewport \ apply!
151+ @title_image \ draw 0 , 0
152+
153+ cx, cy = @viewport \ center!
154+ @box_text " Press Enter To Begin" , cx, cy - 10
155+
156+ if @shroud_alpha > 0
157+ @viewport \ draw { 0 , 0 , 0 , @shroud_alpha }
158+
159+ g. setColor 255 , 255 , 255 , 255
160+ @viewport \ pop!
161+
162+ box_text : ( msg, x, y) =>
163+ msg = msg\ lower!
164+ w, h = fonts. main\ getWidth( msg) , fonts. main\ getHeight!
165+ g. push!
166+ g. translate x - w/ 2 , y - h/ 2
167+ g. rectangle " fill" , 0 , 0 , w, h
168+ g. setColor 0 , 0 , 0
169+ g. print msg, 0 , 0
170+ g. pop!
171+
172+ update : ( dt) =>
173+ @seq \ update dt if @seq
174+ @colors . factor = math.sin ( timer. getTime! * 3 ) * 25 + 75
175+
176+ on_key : ( key) =>
177+ if key == " return" or key == " "
178+ @transition_to Game !
179+
180+ transition_to : ( state) =>
181+ @seq = Sequence ->
182+ tween @, 1.0 , shroud_alpha : 255
183+ dispatch\ push state
184+ @shroud_alpha = 0
185+ @seq = nil
186+
137187class Game
138188 paused : false
139189
@@ -171,12 +221,13 @@ class Game
171221
172222 mousepressed : ( x, y) =>
173223 x, y = @world . viewport\ unproject x, y
224+
225+ -- @world.particles\add EnergyEmitter @world, x,y
174226 @world . entities\ add Energy , x, y
175227
176228 -- print "boom: #{x}, #{y}"
177229 -- @world.particles\add Explosion @world, x,y
178230
179- export fonts = {}
180231load_font = ( img, chars) ->
181232 font_image = imgfy img
182233 g. newImageFont font_image. tex, chars
@@ -189,6 +240,6 @@ love.load = ->
189240
190241 g. setFont fonts. main
191242
192- d = Dispatcher Game !
193- d \ bind love
243+ dispatch = Dispatcher Title !
244+ dispatch \ bind love
194245
0 commit comments