refactor: collider tracks collisions

This commit is contained in:
cha0s 2019-04-19 12:06:56 -05:00
parent b9e3f76750
commit f9e9ac362c

View File

@ -26,6 +26,7 @@ export class Collider extends decorate(Trait) {
initialize() {
this._collisionGroup = this.params.get('collisionGroup');
this._collidesWithGroups = this.params.get('collidesWithGroups').toJS();
this._isCollidingWith = [];
this._isSensor = this.params.get('isSensor');
}
@ -37,10 +38,29 @@ export class Collider extends decorate(Trait) {
return this._collidesWithGroups;
}
get isCollidingWith() {
return this._isCollidingWith;
}
get isSensor() {
return this._isSensor;
}
listeners() {
return {
collisionEnd: (other) => {
const index = this._isCollidingWith.indexOf(other);
this._isCollidingWith.splice(index, 1);
},
collisionStart: (other) => {
this._isCollidingWith.push(other);
},
};
}
methods() {
return {