Skip to content

Commit

Permalink
fix delta time math of black hole physics
Browse files Browse the repository at this point in the history
  • Loading branch information
44100hertz committed Jan 23, 2024
1 parent 10ea327 commit f34a846
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions games/redbricks/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function load() {
const gameSize = new Point(240, 240);
const playfield = new Playfield("playfield", gameSize);
let deathCount = 0;
let level = 1;
let level = 4;

let startTime;
function introduceLevel() {
Expand Down Expand Up @@ -80,7 +80,7 @@ class Game {
this.killBlocks = [];

this.blackHoles = [];
this.blackHolePower = 500;
this.blackHolePower = 5;

// Paddle
this.paddle = this.playfield.addEntity({
Expand Down Expand Up @@ -146,8 +146,8 @@ class Game {
} else {
this.blackHoles.forEach((hole) => {
const distance = hole.position.x - this.ball.x;
const dt2 = dt*dt*this.blackHolePower;
this.ball.velocity.x += distance * dt2;
const scale = dt * this.blackHolePower * Math.exp(-dt);
this.ball.velocity.x += distance * scale;
});

const nextBallPos = () => {
Expand Down

0 comments on commit f34a846

Please sign in to comment.