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

Commit

Permalink
cleaning state
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsk committed Aug 25, 2013
1 parent 9c30ecd commit 0ce6196
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = function(
var tau = Math.PI * 2

return bs.define()
.tag('enemy')
.use(require('../components/attached'))
.use(require('../components/physical'))
.use(require('../components/health')(health))
Expand Down
1 change: 1 addition & 0 deletions entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ var player = bs.component([
})
.on('damaged', function(damage) {
this.flinch = 1
if (this.health < 1) this.game.restart()
})

module.exports = bs.define()
Expand Down
19 changes: 19 additions & 0 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Game(canvas) {
this.levels = {
speed : function(level) { return (Math.pow(level, 0.55) + level / 100) * 0.04 }
, health: function(level) { return Math.floor(Math.pow(level, 0.4) + level / 100) }
, frequency: function(level) { return Math.min(9, Math.floor(1.5 + Math.pow(level, 0.75) + level / 100)) }
}

this.canvas = canvas
Expand Down Expand Up @@ -205,6 +206,24 @@ Game.prototype.drawLevel = function(n) {
}
}

Game.prototype.restart = function() {
this.flash = 5
this.player.health = 15
var body = this.player.body
this.next(function() {
body.SetPosition({ x: 20, y: 0 })
body.SetLinearVelocity({ x: 0, y: 0 })
})
this.level = 1
this.levelticker = TEN_SECONDS
var spawned = this.find('enemy')
for (var i = 0; i < spawned.length; i += 1) {
spawned[i].flagged = true
}
this.ready = false
this.score = 0
}

Game.prototype.enqueue = function(entity) {
this.queue.push(entity)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Camera.prototype.draw = function() {
if (!this.game.ready) {
this.target[1] -= this.game.width * 0.2
}
lerp(this.pos, this.pos, this.target, 0.05)
lerp(this.pos, this.pos, this.target, this.game.ready ? 0.05 : 1)
}

Camera.prototype.tick = function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Field(game) {
return done(null,
fill(
ndarray = cave(zero(shape), caveopts)(10)
, !game.ready && !(position[0] || position[1]) ? function(x, y) {
, !(position[0] || position[1]) ? function(x, y) {
var val = ndarray.get(x, y)
if (y > 8) return (val ? (
perlin(
Expand Down
2 changes: 1 addition & 1 deletion lib/spawner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function Spawner(game) {
if (!(this instanceof Spawner)) return new Spawner(game)

var bombChance = 1
var frequency = 5
var speed = 0.25

var Bomb = require('../entities/bomb').tag('spawned')
Expand All @@ -14,6 +13,7 @@ function Spawner(game) {
game.field.grid.on('created', function(chunk) {
if (!game.ready) return

var frequency = game.levels.frequency(game.level)
var Enemy = EnemyGenerator(
2.1 // size
, game.levels.speed(game.level)
Expand Down

0 comments on commit 0ce6196

Please sign in to comment.