This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateSize: function(width, height){ | |
// get current center | |
var centerX = this.pos.x + this.size.x/2, | |
centerY = this.pos.y + this.size.y/2; | |
// set new width / height | |
this.size.x = width; | |
this.size.y = height; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyGame = new ig.Game.extend({ | |
levelToLoad: level1, | |
// levelName ex: test3 | |
changeLevel: function(levelName){ | |
// prepend and capitalize | |
var levelObjName = 'Level' + levelName.charAt(0).toUpperCase() + levelName.slice(1), | |
levelPath = 'game.levels.' + levelName; | |
delete ig.modules['dom.ready']; // reset dom event handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var delta = this.lifeSpanTimer.delta(); | |
color.r = Math.floor(delta.map(0, 1, this.startColor.r, this.endColor.r )); | |
color.g = Math.floor(delta.map(0, 1, this.startColor.g, this.endColor.g )); | |
color.b = Math.floor(delta.map(0, 1, this.startColor.b, this.endColor.b )); | |
color.a = Math.floor(delta.map(0, 1, this.startColor.a, this.endColor.a )); | |
ctx.fillStyle = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ',' + color.a + ')'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create impact collision listener | |
var listener = new b2.ContactListener(); | |
listener.Add = callback; | |
listener.Remove = callback; | |
listener.Persist = callback; | |
listener.Result = callback; | |
// attach to box2d world |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ig.BackgroundMap.inject({ | |
drawFull: function(context) { | |
var ctx = context = context || ig.system.context, | |
scale = ig.system.scale, | |
tileWidthScaled = Math.floor(this.tilesize * scale), | |
tileHeightScaled = Math.floor(this.tilesize * scale), | |
tile; | |
ctx.save(); | |
ctx.scale(scale, scale); | |
for( var y = 0; y < this.height; y++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add tile | |
ig.game.addItem({ | |
_layer : 'bg', | |
update: function(){ | |
var mainMap = ig.game.getMapByName('main'), | |
tileSize = mainMain.tilesize, | |
ctx = ig.game.bgCanvasContext, | |
x = tileSize * x * ig.system.scale, | |
y = tileSize * y * ig.system.scale; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mX = ig.input.mouse.x, | |
mY = ig.input.mouse.y, | |
spawnX = this.pos.x + this.size.x/2, | |
spawnY = this.pos.y + this.size.y/2, | |
r = Math.atan2(mY - spawnY, mX - spawnX), | |
directionX = Math.cos(r) * 50, | |
directionY = Math.sin(r) * 50; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var distance = this.distanceTo(this.target), | |
d = this.angleTo(this.target), | |
steerX = Math.cos(d), | |
steerY = Math.sin(d), | |
newX = (this.target.pos.x + distance / this.target.vel.x) - this.pos.x, | |
newY = (this.target.pos.y + distance / this.target.vel.y) - this.pos.y, | |
// keep speed 10 or less | |
speed = Math.min(distance, 30) / 6; | |
this.vel.x += steerX * speed; | |
this.vel.y += steerY * speed; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// also tried this slightly different way behaves different but the hard turn problem remains | |
var mass = 1, | |
maxSpeed = 1000, | |
maxSteer = 200, | |
distance = this.distanceTo(this.target), | |
d = this.angleTo(this.target), | |
steerX = Math.cos(d) * this.speed - this.vel.x, | |
steerY = Math.sin(d) * this.speed - this.vel.y; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setVelocity: function () { | |
var difX = ((ig.input.mouse.x - (this.size.x / 2)) - this.pos.x).round(); | |
var difY = ((ig.input.mouse.y - (this.size.y / 2)) - this.pos.y).round(); | |
var max = 100, | |
maxX = (difX > 0)? max : -max, | |
maxY = (difY > 0)? max : -max; | |