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 829829
830830 // default speed
831831 this . accel = new me . Vector2d ( ) ;
832+
833+ // max velocity to be applied on entity movement
834+ this . maxVel = new me . Vector2d ( 1000 , 1000 ) ;
832835
833836 // some default contants
834837 this . gravity = 0.98 ;
928931 this . accel . x = ( x != 0 ) ? x : this . accel . x ;
929932 this . accel . y = ( x != 0 ) ? y : this . accel . y ;
930933 } ,
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+ } ,
931947
932948 /**
933949 * make the player move left of right
10881104 this . falling = true ;
10891105 this . vel . y += ( this . gravity * me . timer . tick ) ;
10901106 }
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+ }
10911113
10921114 // check for collision
10931115 collision = this . collisionMap . checkCollision (
You can’t perform that action at this time.
0 commit comments