Permalink
Browse files

blow up planet

  • Loading branch information...
1 parent 002a10f commit 32f045bf191273aaff34f8bdf52fbaaff214af87 @leafo committed Dec 16, 2012
Showing with 68 additions and 22 deletions.
  1. +3 −2 main.moon
  2. +0 −1 pickup.moon
  3. +36 −4 tank.moon
  4. +2 −1 util.moon
  5. +27 −14 world.moon
View
@@ -75,8 +75,8 @@ class Game
new: =>
@player = Player 100, 100, @
- @world = World @player
@current_level = 1
+ @world = @levels[@current_level] @player
onload: =>
sfx\play_music "xmoon"
@@ -113,9 +113,10 @@ class Game
mousepressed: (x,y) =>
x, y = @world.viewport\unproject x,y
-- @world.particles\add EnergyEmitter @world, x,y
- @world.entities\add Energy x,y
+ -- @world.entities\add Energy x,y
-- print "boom: #{x}, #{y}"
-- @world.particles\add Explosion @world, x,y
+ @world\blow_up_planet!
load_font = (img, chars)->
font_image = imgfy img
View
@@ -55,7 +55,6 @@ class Energy extends Box
__tostring: => "Energy<>"
-
class BombPad extends Box
w: 48
h: 32
View
@@ -8,7 +8,20 @@ import approach_dir from require "util"
export *
+class FlyOut extends effects.Effect
+ before: =>
+ g.push!
+ p = @p!
+ g.scale p*2 + 1
+ g.setColor 255,255,255, (1 - p) * 255
+
+ after: =>
+ g.pop!
+
class Tank
+ locked: false
+ hidden: false
+
ox: 6
oy: 6
sprite: "8,8,14,12"
@@ -57,17 +70,23 @@ class Tank
@hit_seq = nil
aim_to: (dt, pt) =>
+ return if @locked
+
for mount in *@guns
{gun, gx, gy} = mount
{ox, oy} = Vec2d(gx, gy)\rotate @dir\radians!
dir = pt - Vec2d @x + ox, @y + oy
gun\aim_to dt, dir
shoot: =>
+ return if @locked
+
for mount in *@guns
mount[1]\shoot unpack mount, 2
move: (dt, dir) =>
+ return if @locked
+
@moving = true
approach_dir @dir, dir, @spin * dt
@@ -81,20 +100,22 @@ class Tank
@box.y = @y - hsize
draw: =>
- @effects\before!
+ return if @hidden
g.push!
g.translate @x, @y
+ @effects\before!
+
-- body
sprite\draw @sprite, 0,0, @dir\radians!, nil, nil, @ox, @oy
for mount in *@guns
mount[1]\draw unpack mount, 2
- g.pop!
-
@effects\after!
+
+ g.pop!
-- @box\outline!
class Player extends Tank
@@ -111,7 +132,7 @@ class Player extends Tank
size: 40
}
- new: (x, y, @world) =>
+ new: (x, y) =>
super x,y
@held_energy = {}
@ring_alpha = 0
@@ -120,6 +141,10 @@ class Player extends Tank
@mount_gun MachineGun, 0, -4
@mount_gun MachineGun, 0, 4
+ shoot: (...) =>
+ return if @sucking
+ super ...
+
update: (dt, world) =>
super dt
@@ -177,4 +202,11 @@ class Player extends Tank
__tostring: => "Player<>"
+ take_off: (done_fn) =>
+ return if @locked
+
+ @locked = true
+ e = FlyOut 0.5
+ e.on_finish = done_fn
+ @effects\add e
View
@@ -34,7 +34,8 @@ box_text = (msg, x, y, center=true) ->
g.push!
if center
- g.translate x - w/2, y - h/2
+ center = 0.5 if center == true
+ g.translate x - w*center, y - h/2
else
g.translate x, y - h/2
View
@@ -1,6 +1,6 @@
{graphics: g, :timer, :mouse} = love
-{floor: f, min: _min, :cos, :sin, :abs} = math
+{floor: f, min: _min, :cos, :sin, :abs, :random} = math
import box_text from require "util"
@@ -9,6 +9,7 @@ export *
class World
disable_project: false
energy_count: 0
+ energy_needed: 100
new: (@player) =>
@viewport = EffectViewport scale: 3
@@ -39,12 +40,7 @@ class World
@background = TiledBackground "img/stars.png", @viewport
- @explode = Animator sprite, {
- 3,4,5,6,7,8,9,10,11
- }, 0.05
- @flare = (...) => sprite\draw "48,32,32,32", ...
-
- @level_progress = HorizBar 80, 10
+ @level_progress = HorizBar 80, 6
draw_background: =>
g.push!
@@ -66,9 +62,6 @@ class World
@particles\draw!
g.setColor 255,255,255,255
- -- @explode\draw @player.x, @player.y
- -- @flare @player.x, @player.y
-
@viewport\pop!
draw_hud: =>
@@ -111,10 +104,14 @@ class World
w = w/3
h = h/3
- box_text "Energy: #{@player.energy_count or 0}", 10, 10, false
+ box_text "Energy: #{@energy_count or 0}", 10, 10, false
box_text "Score: #{@player.score or 0}", 10, 20, false
@level_progress\draw w - 10 - @level_progress.w, 7
+
+ if @energy_count >= @energy_needed and timer.getTime! % 1 >= 0.5
+ box_text "Press E", w - 10, 20, 1.0
+
g.pop!
@@ -137,7 +134,6 @@ class World
@colors\render ->
@draw_hud!
-
g.setColor 255,255,255
g.scale 2
@@ -152,8 +148,7 @@ class World
@particles\update dt, @
@bomb_pad\update dt, @
-
- @explode\update dt
+ @seq\update dt if @seq
-- respond to collision
@collide\clear!
@@ -173,3 +168,21 @@ class World
for thing in *@collide\get_touching enemy.box
enemy\take_hit thing, @
+ @level_progress.value = _min 1.0, @energy_count / @energy_needed
+
+ blow_up_planet: =>
+ @player\take_off ->
+ @player.hidden = true
+ @seq = Sequence ->
+ for i=1,100
+ cx, cy = @viewport.x, @viewport.y
+
+ for i=1,3
+ x = cx + random! * @viewport.w
+ y = cy + random! * @viewport.h
+ @particles\add Explosion @, x, y
+
+ wait 0.1
+
+ @seq = nil
+

0 comments on commit 32f045b

Please sign in to comment.