File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 829
829
830
830
// default speed
831
831
this . accel = new me . Vector2d ( ) ;
832
+
833
+ // max velocity to be applied on entity movement
834
+ this . maxVel = new me . Vector2d ( 1000 , 1000 ) ;
832
835
833
836
// some default contants
834
837
this . gravity = 0.98 ;
928
931
this . accel . x = ( x != 0 ) ? x : this . accel . x ;
929
932
this . accel . y = ( x != 0 ) ? y : this . accel . y ;
930
933
} ,
934
+
935
+
936
+ /**
937
+ * cap the entity velocity to the specified value<br>
938
+ * (!) this will only cap the y velocity for now(!)
939
+ * @param {Int } x max velocity on x axis
940
+ * @param {Int } y max velocity on y axis
941
+ * @protected
942
+ */
943
+ setMaxVelocity : function ( x , y ) {
944
+ this . maxVel . x = x ;
945
+ this . maxVel . y = y ;
946
+ } ,
931
947
932
948
/**
933
949
* make the player move left of right
1088
1104
this . falling = true ;
1089
1105
this . vel . y += ( this . gravity * me . timer . tick ) ;
1090
1106
}
1107
+
1108
+ // cap the y velocity
1109
+ if ( this . vel . y != 0 )
1110
+ {
1111
+ this . vel . y = this . vel . y . clamp ( - this . maxVel . y , this . maxVel . y ) ;
1112
+ }
1091
1113
1092
1114
// check for collision
1093
1115
collision = this . collisionMap . checkCollision (
You can’t perform that action at this time.
0 commit comments