Skip to content

Instantly share code, notes, and snippets.

@kitsunde
Last active December 18, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitsunde/5857020 to your computer and use it in GitHub Desktop.
Save kitsunde/5857020 to your computer and use it in GitHub Desktop.
var collidables = new Collidables();
function GameObject(){
var x = 0;
var y = 0;
var width = 100;
var height = 100;
this.collidable = new Collidable({
bounds: 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