Ejemplo n.º 1
0
function pellet(c) {
  var pelletMax = 40

  return bs.define()
    .use(require('../components/attached'))
    .use(require('../components/physical'))
    .use(require('../components/body')(
      function createBody() {
        var bd = new b2BodyDef
        bd.position = new b2Vec2(0, -5)
        bd.type = b2Body.b2_dynamicBody
        bd.userData = {}
        bd.fixedRotation = true
        return bd
      },
      function createFixture() {
        var fd = new b2FixtureDef
        fd.restitution = 0.5
        fd.shape = new b2CircleShape(0.5/3)
        this.r = 5
        return fd
      }
    ))
    .use(require('../components/bounce-burst'))
    .use(bs.component()
      .on('init', function() {
        pelletCounter += 1
        if (pelletCounter > pelletMax) this.flagged = true
        this.c = c
        this.t = 140 - ((Math.random() * 40)|0)
      })
      .on('tick', function() {
        this.t -= 1
        if (!this.t) this.flagged = true
      })
      .on('destroy', function() {
        pelletCounter -= 1
      })
    )
    .use(require('../components/draw-circle')(5))
    .use(require('../components/gravity'))
}
Ejemplo n.º 2
0
    ctx.rotate(this.rotation)
    ctx.fillStyle = lighten('#362F34', (this.flinch * 200)|0)
    ctx.fillRect(
        -15 - this.pop
      , -15 - this.pop
      ,  30 + this.pop * 2
      ,  30 + this.pop * 2
    )
    ctx.restore()
  })
  .on('damaged', function(damage) {
    this.flinch = 1
    if (this.health < 1) this.game.restart()
  })

module.exports = bs.define()
  .use(require('../components/attached'))
  .use(require('../components/physical'))
  .use(require('../components/controllable'))
  .use(require('../components/health')(15))
  .use(player)
  .use(require('../components/vulnerable')(0))
  .use(require('../components/gravity'))

module.exports.prototype.fireBullet = function() {
  this.shootTimer = 8
  var bullet = new Bullet
  var tx = this.game.mouse.x - (this.body.m_xf.position.x * 30 - this.game.camera.pos[0])
  var ty = this.game.mouse.y - (this.body.m_xf.position.y * 30 - this.game.camera.pos[1])
  var a = Math.atan2(ty, tx)
  var rx = Math.cos(a)
Ejemplo n.º 3
0
var bs = require('bindlestiff')

var Bullet = module.exports = bs.define()

  .use(require('../systems/physics').component)