Skip to content

Commit

Permalink
Some tweaks to player kinematics
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Sehmisch committed Sep 19, 2020
1 parent a725839 commit 21ad187
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// If you want to make some simple tweaks, then here might be the place to start.

const CONST = {
GRAVITY: 1000, // Gravity in pixels per second²
SCREEN_WIDTH: 1024,
SCREEN_HEIGHT: 768,
EXPLOSION_FORCE: 10000000,
GRAVITY: 1000, // Gravity in pixels per second²
EXPLOSION_FORCE: 10000000, // impulse caused by rocket explosions
EXPLOSION_MIN_RADIUS: 50, //radius in pixels from within the maximum explosion force is applied
EXPLOSION_MAX_RADIUS: 500, //radius in pixels from without explosions are completely ignored
PLAYER_ACCEL_GROUND: 2000, // player acceleration on ground
PLAYER_FRICTION_GROUND: 0.9, // fraction of speed the player loses per second while grounded
PLAYER_FRICTION_AIR: 0.05, // fraction of speed the player loses per second while airborne
PLAYER_FRICTION_GROUND: 0.999, // fraction of speed the player loses per second while grounded
PLAYER_ACCEL_AIR: 1000, // player acceleration while airborne
PLAYER_GROUND_BOUNCE: 0.5 // how much the player bounces when impacting the ground
PLAYER_FRICTION_AIR: 0.7, // fraction of speed the player loses per second while airborne
PLAYER_GROUND_BOUNCE: 0.75 // how much the player bounces when impacting the ground
}
2 changes: 1 addition & 1 deletion player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Player extends Entity {
if (this.isGrounded) {
frictionFraction = Math.pow((1 - CONST.PLAYER_FRICTION_GROUND), deltaTime )
} else {
frictionFraction = Math.pow((1 - CONST.PLAYER_FRICTION_GROUND), deltaTime )
frictionFraction = Math.pow((1 - CONST.PLAYER_FRICTION_AIR), deltaTime )
}
this.velocity.x *= frictionFraction
this.velocity.y *= frictionFraction
Expand Down
4 changes: 3 additions & 1 deletion renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class Renderer {
// objects
state.entities.forEach(r => {
if (r.sprite) {
this.ctx.drawImage(r.sprite, r.pos.x + offset.x - r.renderPivot.x, r.pos.y + offset.y - r.renderPivot.y )
let x = Math.round(r.pos.x + offset.x - r.renderPivot.x)
let y = Math.round(r.pos.y + offset.y - r.renderPivot.y)
this.ctx.drawImage(r.sprite,x ,y )
}
})

Expand Down

0 comments on commit 21ad187

Please sign in to comment.