Permalink
Browse files

ready to build

  • Loading branch information...
1 parent 4571455 commit a62e7ee457a247c3fe92837847bee4352d6f0324 @leafo committed Dec 17, 2012
Showing with 89 additions and 25 deletions.
  1. +35 −0 enemies.moon
  2. +23 −3 levels.moon
  3. +13 −11 main.moon
  4. +5 −0 tank.moon
  5. +13 −11 world.moon
View
@@ -1,4 +1,7 @@
+import random, floor from math
+{graphics: g} = love
+
export *
class Enemy extends Tank
@@ -119,3 +122,35 @@ gun_sprites = {
orange: "35,85,8,4"
}
+class EnemySpawner extends Sequence
+ range: {15, 25}
+
+ draw: =>
+ -- g.setColor 255,255,255
+ -- g.point unpack @center
+
+ new: (world, x,y, types, num_enemies={2,6}) =>
+ @center = Vec2d x, y
+ @enemies = {}
+ super ->
+ wait random! * 2
+ num = random unpack num_enemies
+ for i=1,num
+ offset = Vec2d.random! * random unpack @range
+ enemy_cls = types[random #types]
+ enemy = enemy_cls unpack @center + offset
+ table.insert @enemies, enemy
+ world.entities\add enemy
+
+ while true
+ wait 1.0
+ all_dead = true
+ for e in *@enemies
+ all_dead = false if e.alive
+
+ break if all_dead
+
+ wait 4 + math.random! * 2
+ @enemies = {}
+ again!
+
View
@@ -5,7 +5,10 @@ width = 16
tid = (row, col) -> row * width + col
class Level1 extends World
- energy_needed: 20
+ energy_needed: 10
+
+ enemy_types: { Green }
+ num_spawns: 3
bg_tiles: {
{ 100, tid 0, 1 }
@@ -17,7 +20,10 @@ class Level1 extends World
}
class Level2 extends World
- energy_needed: 40
+ energy_needed: 20
+
+ enemy_types: { Green, Blue }
+ num_spawns: 4
bg_tiles: {
{ 100, tid 0, 0 }
@@ -26,11 +32,25 @@ class Level2 extends World
}
class Level3 extends World
- energy_needed: 40
+ energy_needed: 30
+
+ enemy_types: { Green, Blue, Red }
+ num_spawns: 5
bg_tiles: {
{ 100, tid 0, 2 }
{ 20, tid 1, 2 }
{ 3, tid 2, 2 }
}
+class Endless extends World
+ energy_needed: 40
+ enemy_types: { Green, Blue, Red, Orange }
+ num_spawns: 7
+
+ new: (...) =>
+ levels = { Level1, Level2, Level3 }
+ @bg_tiles = levels[math.random #levels].bg_tiles
+ super ...
+
+
View
@@ -14,7 +14,7 @@ require "levels"
require "lovekit.screen_snap"
-{graphics: g, :timer, :mouse} = love
+{graphics: g, :timer, :mouse, :keyboard} = love
{floor: f, min: _min, :cos, :sin, :abs} = math
import box_text from require "util"
@@ -58,7 +58,6 @@ class FadeOutScreen
tween @, 1.0, shroud_alpha: 255
fn!
@shroud_alpha = 0
- @seq = nil
transition_to: (state) =>
@transition -> dispatch\push state
@@ -69,6 +68,7 @@ class Title extends FadeOutScreen
super ...
onload: =>
+ print "loading title..."
sfx\play_music "xmoon-title"
draw_inner: =>
@@ -96,12 +96,12 @@ class Tutorial extends FadeOutScreen
@transition_to Game!
class Intermission extends FadeOutScreen
- new: (@fn, ...) =>
+ new: (@game, @fn, ...) =>
super ...
draw_inner: =>
cx, cy = @viewport\center!
- box_text "Congratulations", cx, cy - 10
+ box_text "You Beat Level #{@game.current_level}", cx, cy - 10
box_text "Press Enter To Go To Next Level", cx, cy + 10
on_key: (key) =>
@@ -129,6 +129,7 @@ class Game
Level1
Level2
Level3
+ Endless
}
paused: false
@@ -141,7 +142,8 @@ class Game
load_next_world: =>
@current_level += 1
w = @levels[@current_level]
- error "Ran out of levels!" unless w
+ w = @levels[#@levels] unless w
+
@world = w @, @player
onload: =>
@@ -168,7 +170,8 @@ class Game
if @player.health <= 0
dispatch\push GameOver @player
else
- dispatch\push Intermission ->
+ dispatch\push Intermission @, ->
+ dispatch\pop!
@load_next_world!
on_key: (key) =>
@@ -191,10 +194,10 @@ class Game
mousepressed: (x,y, btn) =>
x, y = @world.viewport\unproject x,y
- -- @world.particles\add EnergyEmitter @world, x,y
-
- if btn == "r"
+ if btn == "r" and keyboard.isDown "f2"
@world.entities\add Energy x,y
+
+ -- @world.particles\add EnergyEmitter @world, x,y
-- print "boom: #{x}, #{y}"
-- @world.particles\add Explosion @world, x,y
@@ -221,7 +224,6 @@ love.load = ->
"energy-collect"
}
- sfx.play_music = ->
- dispatch = Dispatcher Game! -- Tutorial! -- Game!
+ dispatch = Dispatcher Title!
dispatch\bind love
View
@@ -144,6 +144,11 @@ class Player extends Tank
@health = @@health
+ reset: =>
+ @health = @@health
+ @locked = false
+ @hidden = false
+
loadout: =>
@mount_gun MachineGun, 0, -4
@mount_gun MachineGun, 0, 4
View
@@ -40,6 +40,8 @@ class World
new: (@game, @player) =>
@viewport = EffectViewport scale: 3
@player.world = @
+ @player\reset!
+
@collide = UniformGrid!
@entities = DrawList!
@@ -66,24 +68,24 @@ class World
@map_box = Box 0,0, @map.real_width, @map.real_height
@bomb_pad = BombPad 80, 80
- -- create some enemies
- es = {
- Green, Blue, Red, Orange
- }
- k = 1
- for xx = 1,2
- for yy = 1,2
- @entities\add es[k] 150 + xx * 40, 150 + yy * 40
- k = k + 1
- k = 1 if k > #es
-
@background = TiledBackground "img/stars.png", @viewport
@level_progress = with HorizBar 80, 6
.color = { 128, 128 , 255, 128 }
@health_bar = HorizBar 80, 6
+ @prepare_enemies!
+
+ prepare_enemies: =>
+ return unless @enemy_types
+ num = @num_spawns or 2
+
+ bounds = @map\to_box!\shrink 120
+ for i=1,num
+ x,y = bounds\random_point!
+ @particles\add EnemySpawner @,x,y, @enemy_types
+
draw_background: =>
g.push!
g.scale @viewport.screen.scale

0 comments on commit a62e7ee

Please sign in to comment.