Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Commit

Permalink
don't spawn in walls
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsk committed Aug 25, 2013
1 parent ef8ddc8 commit 745e174
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/spawner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@ function Spawner(game) {
var x = chunk.position[0] * chunk.shape[0]
var y = chunk.position[1] * chunk.shape[1]
for (var i = 0; i < 10; i += 1) {
var enemy = new Enemy
game.add(enemy)
enemy.body.SetPosition(new b2Vec2(Math.random() * 30 + x, Math.random() * 30 + y))
var ex = Math.random() * 30
var ey = Math.random() * 30
if (chunk.get(ex|0, ey|0)) {
var enemy = new Enemy
game.add(enemy)
enemy.body.SetPosition(new b2Vec2(x + ex, y + ey))
}
}
})

game.field.grid.on('removed', function(chunk) {
var cx = chunk.position[0] * chunk.shape[0]
var cy = chunk.position[1] * chunk.shape[1]
var spawned = game.find('spawned')
var n = 0
for (var i = 0; i < spawned.length; i += 1) {
var b = spawned[i].body
var x = b.m_xf.position.x
var y = b.m_xf.position.y
if (x > cx && y > cy && x < cx+30 && y < cy+30) {
n += 1
if (x > cx && y > cy && x < cx+30 && y < cy+30)
spawned[i].flagged = true
}
}
console.log(n, 'removed')
})
}

0 comments on commit 745e174

Please sign in to comment.