Created
June 25, 2013 08:55
-
-
Save kitsunde/5857016 to your computer and use it in GitHub Desktop.
This file contains 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 collidables = new Collidables(); | |
function GameObject(){ | |
this.collidable = new Collidable({ | |
get: function(){ | |
return new BoundingBox(this.x, | |
this.y, | |
this.x + this.width, | |
this.y + this.height); | |
}, | |
}); | |
this.collidable.on("collide", function(){ | |
console.log("OUCH :'("); | |
}); | |
this.powerUp = function(){ | |
this.collidable.ephemeral = true; | |
setTimeout(function(){ | |
this.collidable.ephemeral = false; | |
}, 2000); | |
}; | |
} | |
var obj = new GameObject(); | |
var obj2 = new GameObject(); | |
collidables.add(obj); | |
collidables.add(obj2); | |
collidables.collisions(); | |
// [obj, obj2] | |
collidables.handle(); | |
// Send collide events to all collidables | |
if(obj.collidable.isCollidingWith(obj2.collidable)){ | |
console.log("TERRIBLE THINGS JUST HAPPENED"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment