mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added collision detection
This commit is contained in:
parent
ff6456fd47
commit
a6058ce3d3
3 changed files with 55 additions and 16 deletions
38
lib/Chuck/Collision/Detector.js
Normal file
38
lib/Chuck/Collision/Detector.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
define(["Box2D/Box2D"], function(Box2D) {
|
||||
|
||||
function Detector(me) {
|
||||
this.me = me;
|
||||
|
||||
this.listener = new Box2D.Dynamics.b2ContactListener();
|
||||
this.listener.chuckDetector = this;
|
||||
this.listener.BeginContact = this.BeginContact;
|
||||
this.listener.PostSolve = this.PostSolve;
|
||||
this.listener.EndContact = this.EndContact;
|
||||
}
|
||||
|
||||
Detector.prototype.getListener = function() {
|
||||
return this.listener;
|
||||
}
|
||||
|
||||
Detector.prototype.handleStand = function(point, isColliding) {
|
||||
if (point.GetFixtureA().GetUserData() == 'myFeet' || point.GetFixtureB().GetUserData() == 'myFeet') {
|
||||
this.me.onFootSensorDetection(isColliding);
|
||||
}
|
||||
}
|
||||
|
||||
/** Extension **/
|
||||
|
||||
Detector.prototype.BeginContact = function(point) {
|
||||
this.chuckDetector.handleStand(point, true);
|
||||
}
|
||||
|
||||
Detector.prototype.PostSolve = function(point, impulse) {
|
||||
this.chuckDetector.handleStand(point, true);
|
||||
}
|
||||
|
||||
Detector.prototype.EndContact = function(point) {
|
||||
this.chuckDetector.handleStand(point, false);
|
||||
}
|
||||
|
||||
return Detector;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue