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

Commit

Permalink
things!
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsk committed Aug 24, 2013
1 parent 1dd302d commit 56cef89
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var special = bs.component('player')
var y = this.game.height / 60

var def = new b2BodyDef
def.position = new b2Vec2(x, y)
def.position = new b2Vec2(0, 0)
def.type = b2Body.b2_dynamicBody
def.userData = null
def.fixedRotation = true
Expand Down
9 changes: 9 additions & 0 deletions game-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var createGame = require('./game')
var canvas = document.getElementById('main')

canvas.width = 800
canvas.height = 600

module.exports = createGame(canvas)

document.body.appendChild(canvas)
2 changes: 2 additions & 0 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ Game.prototype.draw = function() {

ctx.fillStyle = '#0f0'
ctx.fillRect(mousex - 3, mousey - 3, 6, 6)

this.camera.draw()
}
9 changes: 7 additions & 2 deletions lib/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ function Camera(game, field) {
this.target = this.pos.slice(0)
}

var temp = []
Camera.prototype.draw = function() {
this.target[0] = this.game.player.b2Pos.x * 30 - this.game.width / 2
this.target[1] = this.game.player.b2Pos.y * 30 - this.game.height / 2
lerp(this.pos, this.pos, this.target, 0.01)
}

var temp = [0,0]
Camera.prototype.tick = function() {
lerp(this.target, this.pos, this.target, 0.01)
temp[0] = round(this.target[0] / this.shape[0])
temp[1] = round(this.target[1] / this.shape[1])
this.field.move(temp)
Expand Down
10 changes: 9 additions & 1 deletion lib/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ function Field(game) {
, getter: function(position, done) {
var shape = this.shape
process.nextTick(function() {
return done(null, cave(zero(shape))(10))
var ndarray = cave(zero(shape))(10)
for (var i = 0; i < 15; i += 1) {
ndarray.set(
(Math.random() * shape[0])|0
, (Math.random() * shape[1])|0
, 0
)
}
return done(null, ndarray)
})
}
})
Expand Down

0 comments on commit 56cef89

Please sign in to comment.