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

Commit

Permalink
almost fun maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsk committed Aug 25, 2013
1 parent 745e174 commit 8dea6ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion components/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ module.exports = function(
}
))
.use(require('../components/harmful')(true))
.use(require('../components/target-player')(speed))
.use(shapes)

function shapes(def) {
return require('../components/draw-circle')(size * 15, '#00f')(def)
return require('../components/draw-circle')(size * 15, '#EB3E38')(def)
}
}
21 changes: 21 additions & 0 deletions components/target-player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var b2Vec2 = require('box2dweb-commonjs').Box2D.Common.Math.b2Vec2
var bs = require('bindlestiff')

module.exports = targetPlayer

function targetPlayer(speed) {
var tempVec = new b2Vec2
return bs.component('target-player')
.needs('attached')
.needs('body')
.on('tick', function() {
var tx = this.game.player.body.m_xf.position.x
var ty = this.game.player.body.m_xf.position.y
var cx = this.body.m_xf.position.x
var cy = this.body.m_xf.position.y
var a = Math.atan2(ty - cy, tx - cx)
tempVec.x = Math.cos(a) * speed
tempVec.y = Math.sin(a) * speed
this.body.ApplyImpulse(tempVec, this.body.GetWorldCenter())
})
}
2 changes: 1 addition & 1 deletion entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = bs.define()
.use(require('../components/gravity'))

module.exports.prototype.fireBullet = function() {
this.shootTimer = 10
this.shootTimer = 5
var bullet = new Bullet
var tx = this.game.mouse.x - this.game.width / 2
var ty = this.game.mouse.y - this.game.height / 2
Expand Down
8 changes: 6 additions & 2 deletions lib/spawner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ module.exports = Spawner
function Spawner(game) {
if (!(this instanceof Spawner)) return new Spawner(game)

var Enemy = require('../components/enemy')(2, 2, 0, 0).tag('spawned')
var frequency = 3
var speed = 0.25

var EnemyGenerator = require('../components/enemy')
var b2Vec2 = require('box2dweb-commonjs').Box2D.Common.Math.b2Vec2

game.field.grid.on('created', function(chunk) {
var Enemy = EnemyGenerator(2.1, speed, 0, 0).tag('spawned')
var x = chunk.position[0] * chunk.shape[0]
var y = chunk.position[1] * chunk.shape[1]
for (var i = 0; i < 10; i += 1) {
for (var i = 0; i < frequency; i += 1) {
var ex = Math.random() * 30
var ey = Math.random() * 30
if (chunk.get(ex|0, ey|0)) {
Expand Down

0 comments on commit 8dea6ba

Please sign in to comment.