Skip to content

Commit

Permalink
Merge pull request #23 from hobnob/features/gravity
Browse files Browse the repository at this point in the history
Clock speed be damned!
  • Loading branch information
hobnob committed Nov 30, 2012
2 parents eb60734 + 0d28463 commit 7780711
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function player()
//The C key clones a playable, so that the player can use
//that instead
case gamejs.event.K_c:
if ( _numClones < 10 )
if ( _numClones < 100 )
{
this.clone();
_numClones++;
Expand Down
8 changes: 4 additions & 4 deletions js/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function playerCollides(playable, rect, drag)
newX -= drag;
}
playable.setVelocity( newX, 0 );
playable.rect.bottom = (rect.top - 0.1);
playable.rect.bottom = (rect.top - 0.01);
playable.setMovement('walk');
}
else if ( playable.rect.collideLine(bottomEdge[0], bottomEdge[1]) )
{
playable.setVelocity( playable.getVelocity().x, 0 );
playable.rect.top = (rect.bottom + 0.1);
playable.rect.top = (rect.bottom + 0.01);
}

//Check the left and right colliision points. If a collision is
Expand All @@ -71,12 +71,12 @@ function playerCollides(playable, rect, drag)
if ( playable.rect.collideLine(leftEdge[0], leftEdge[1]) )
{
playable.setVelocity( 0, playable.getVelocity().y );
playable.rect.right = (rect.left - 0.1);
playable.rect.right = (rect.left - 0.01);

}
else if ( playable.rect.collideLine(rightEdge[0], rightEdge[1]) )
{
playable.setVelocity( 0, playable.getVelocity().y );
playable.rect.left = (rect.right + 0.1);
playable.rect.left = (rect.right + 0.01);
}
}
11 changes: 7 additions & 4 deletions js/lib/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function world()
const MIN_X_VELOCITY = -250;

//The minimum Y velocity a player can trvel (heading up)
const MIN_Y_VELOCITY = -225;
const MIN_Y_VELOCITY = -350;

/**
* @var boolean Whether the world has fully loaded
Expand Down Expand Up @@ -244,7 +244,7 @@ function world()
_gameTime += msDuration;

//Apply the gravitational pull of the world
_applyGravity();
_applyGravity( msDuration );

//Apply updates to the player and any objects in the world
_p.update( msDuration );
Expand Down Expand Up @@ -456,13 +456,16 @@ function world()
/**
* Applies the gravitational pull of the world on all playables
*/
var _applyGravity = function()
var _applyGravity = function( msDuration )
{
//Loop through each player and increase the Y velocity downward.
//If the player is jumping, this has the affect of slowing the
//player down. Otherwise the player is falling.
_p.getPlayables().forEach(function(obj){
obj.setVelocity( obj.getVelocity().x, (obj.getVelocity().y + 10) )
var newVelocityY = obj.getVelocity().y
newVelocityY += Math.round(0.3 * msDuration);

obj.setVelocity( obj.getVelocity().x, newVelocityY )

//the velocity cannot exceed the maximums, so ensuer that the player
//is not falling too fast
Expand Down

0 comments on commit 7780711

Please sign in to comment.