1 decade ago by quidmonkey
I'd like something like this in future Impact versions:
Added to github for those interested.
ig.module( 'plugins.hitbox' ) .requires( 'impact.entity' ) .defines(function(){ ig.Entity.inject({ hitbox: { left: null, right: null, top: null, bottom: null }, init: function( x, y, settings ){ this.parent( x, y, settings ); if( !this.hitbox.left ){ this.hitbox = { left: x, right: x + this.size.x, top: y, bottom: y + this.size.y } } }, touches: function( other ){ return !( this.hitbox.left > other.hitbox.right || this.hitbox.right < other.hitbox.left || this.hitbox.top > other.hitbox.bottom || this.hitbox.bottom < other.hitbox.top ); }, update: function(){ this.parent(); this.hitbox.right -= this.hitbox.left + this.pos.x; this.hitbox.left = this.pos.x; this.hitbox.bottom -= this.hitbox.top + this.pos.y; this.hitbox.top = this.pos.y; } }); });
Added to github for those interested.