Skip to content

Commit

Permalink
Merge pull request #10 from flo-bit/main
Browse files Browse the repository at this point in the history
less flickering
  • Loading branch information
flo-bit authored Jul 27, 2024
2 parents ddd7ce6 + b487c24 commit c15b3e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Game {

debug: boolean = false;

showStats: boolean = true;
showStats: boolean = false;

stats?: Stats;

Expand Down Expand Up @@ -78,10 +78,11 @@ export default class Game {
this.lightManager = new LightManager(this);

sound.add('music-intro', {
url: './music-intro.mp3'
url: './music-intro.mp3',
volume: 0.3
});
sound.add('music', { url: './music.mp3', loop: true });
sound.add('laser', { url: './laser.mp3', volume: 0.3 });
sound.add('music', { url: './music.mp3', loop: true, volume: 0.3 });
sound.add('laser', { url: './laser.mp3', volume: 0.1 });
}

async setupPhysicsWorld() {
Expand Down Expand Up @@ -192,8 +193,11 @@ export default class Game {
const interpolationSpeed = 0.05;
const interpolationFactor = 1 - Math.pow(1 - interpolationSpeed, deltaTime / (1000 / 60));

this.container.x += (position.x - this.container.x) * interpolationFactor;
this.container.y += (position.y - this.container.y) * interpolationFactor;
//this.container.x += (position.x - this.container.x) * interpolationFactor;
//this.container.y += (position.y - this.container.y) * interpolationFactor;

this.container.x = position.x;
this.container.y = position.y;
}

if (this.stats) this.stats.end();
Expand Down
16 changes: 11 additions & 5 deletions src/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class Light {

detail: number = 120;

shape?: PIXI.Graphics;

constructor(game: Game, options: LightOptions) {
this.game = game;

Expand All @@ -65,6 +67,10 @@ export class Light {
if (options.detail) this.detail = options.detail;
if (options.flicker !== undefined) this.flicker = options.flicker;

if (this.game.debug) {
this.shape = new PIXI.Graphics().circle(0, 0, 5).fill(this.color);
this.lightContainer.addChild(this.shape);
}
this.createLight();

this.game.container.addChild(this.lightContainer);
Expand Down Expand Up @@ -146,7 +152,7 @@ export class Light {
const rays = this.detail;

const angleStep = (Math.PI * 2) / rays;
const rayLength = 100000;
const rayLength = 10000000;

let firstPoint;

Expand Down Expand Up @@ -178,7 +184,7 @@ export class Light {
this.shadow.lineTo(firstPoint.x, firstPoint.y);
}
}
this.shadow.fill(0);
this.shadow.fill(0, 0);
}

update(deltaTime: number) {
Expand All @@ -190,9 +196,9 @@ export class Light {
this.light.alpha = this._alpha + (Math.random() - 0.5) * 0.03;
this.light.scale.set(this._scale + Math.random() * 0.1);

if (Math.random() < 1 / deltaTime) {
this.light.alpha = this._alpha * 0.5;
}
// if (Math.random() < 1 / deltaTime) {
// this.light.alpha = this._alpha * 0.5;
// }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export default class Player {
this.leftEye = new Eye(this.playerContainer, -this.size / 4, 0);
this.rightEye = new Eye(this.playerContainer, this.size / 4, 0);

this.x = 280;
this.y = 340;
this.x = 0;
this.y = 0;
}

createHealthBar() {
Expand Down

0 comments on commit c15b3e0

Please sign in to comment.