@@ -8,6 +8,8 @@ var CircleContains = require('../../geom/circle/Contains');
88var Class = require ( '../../utils/Class' ) ;
99var CONST = require ( './const' ) ;
1010var Events = require ( './events' ) ;
11+ var FuzzyLessThan = require ( '../../math/fuzzy/LessThan' ) ;
12+ var FuzzyGreaterThan = require ( '../../math/fuzzy/GreaterThan' ) ;
1113var RadToDeg = require ( '../../math/RadToDeg' ) ;
1214var Rectangle = require ( '../../geom/rectangle/Rectangle' ) ;
1315var RectangleContains = require ( '../../geom/rectangle/Contains' ) ;
@@ -960,54 +962,38 @@ var Body = new Class({
960962 */
961963 update : function ( delta )
962964 {
965+ var velocity = this . velocity ;
966+
963967 if ( this . moves )
964968 {
965969 this . world . updateMotion ( this , delta ) ;
966970
967- var velocity = this . velocity ;
968-
969971 this . position . x += this . getMoveX ( velocity . x * delta ) ;
970972 this . position . y += this . getMoveY ( velocity . y * delta ) ;
971973 }
972974
975+ // Calculate the delta
976+ this . _dx = this . position . x - this . prev . x ;
977+ this . _dy = this . position . y - this . prev . y ;
978+
973979 var worldBlocked = this . worldBlocked ;
974980
975981 // World Bounds check
976982 if ( this . collideWorldBounds && ! worldBlocked . none )
977983 {
978- var worldBounds = this . world . bounds ;
979-
980- var bx = ( this . worldBounce ) ? this . worldBounce . x : this . bounce . x ;
981- var by = ( this . worldBounce ) ? this . worldBounce . y : this . bounce . y ;
984+ var bx = ( this . worldBounce ) ? - this . worldBounce . x : - this . bounce . x ;
985+ var by = ( this . worldBounce ) ? - this . worldBounce . y : - this . bounce . y ;
982986
983- // Reverse the velocity for the bounce and flip the delta
984- velocity . x *= - bx ;
987+ // Reverse the velocity for the bounce
985988
986- if ( bx !== 0 )
989+ if ( ( worldBlocked . left && velocity . x < 0 ) || ( worldBlocked . right && velocity . x > 0 ) )
987990 {
988- if ( worldBlocked . left )
989- {
990- this . x = worldBounds . x + ( 1 * bx ) ;
991- }
992- else if ( worldBlocked . right )
993- {
994- this . right = worldBounds . right - ( 1 * bx ) ;
995- }
991+ velocity . x *= bx ;
996992 }
997993
998- // Reverse the velocity for the bounce and flip the delta
999- velocity . y *= - by ;
1000-
1001- if ( by !== 0 )
994+ if ( ( worldBlocked . down && velocity . y > 0 ) || ( worldBlocked . up && velocity . y < 0 ) )
1002995 {
1003- if ( worldBlocked . up )
1004- {
1005- this . y = worldBounds . y + ( 1 * by ) ;
1006- }
1007- else if ( worldBlocked . down )
1008- {
1009- this . bottom = worldBounds . bottom - ( 1 * by ) ;
1010- }
996+ velocity . y *= by ;
1011997 }
1012998
1013999 if ( this . onWorldBounds )
@@ -1016,10 +1002,6 @@ var Body = new Class({
10161002 }
10171003 }
10181004
1019- // Calculate the delta
1020- this . _dx = this . position . x - this . prev . x ;
1021- this . _dy = this . position . y - this . prev . y ;
1022-
10231005 this . updateCenter ( ) ;
10241006
10251007 this . angle = Math . atan2 ( velocity . y , velocity . x ) ;
@@ -1137,13 +1119,13 @@ var Body = new Class({
11371119 worldBlocked . right = true ;
11381120 }
11391121
1140- if ( pos . y <= bounds . y && check . up )
1122+ if ( check . up && pos . y <= bounds . y )
11411123 {
11421124 set = true ;
11431125 pos . y = bounds . y ;
11441126 worldBlocked . up = true ;
11451127 }
1146- else if ( this . bottom >= bounds . bottom && check . down )
1128+ else if ( check . down && this . bottom >= bounds . bottom )
11471129 {
11481130 set = true ;
11491131 pos . y = bounds . bottom - this . height ;
@@ -1159,11 +1141,6 @@ var Body = new Class({
11591141 return set ;
11601142 } ,
11611143
1162- getOverlapX : function ( body , bias )
1163- {
1164-
1165- } ,
1166-
11671144 /**
11681145 * Sets the offset of the Body's position from its Game Object's position.
11691146 *
0 commit comments