Skip to content

Commit

Permalink
refactor(particles): WIP trying to use new particlesEmitters from alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuher committed Dec 5, 2024
1 parent 1209718 commit 4b3d2de
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@angular/router": "^18.0.0",
"date-fns": "4.1.0",
"dexie": "^4.0.9",
"excalibur": "0.29.3",
"excalibur": "0.30.0-alpha.1295",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
Expand Down
8 changes: 4 additions & 4 deletions src/app/game/actors/gate-detector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Actor, CollisionType, type PreCollisionEvent, type Vector, vec } from 'excalibur';
import { Actor, CollisionStartEvent, CollisionType, type PreCollisionEvent, type Vector, vec } from 'excalibur';
import { Skier } from './skier';

export class GateDetector extends Actor {
Expand All @@ -13,11 +13,11 @@ export class GateDetector extends Actor {
}

override onInitialize() {
this.on('precollision', evt => this.onPreCollision(evt));
this.on('collisionstart', evt => this.onPreCollision(evt));
}

private onPreCollision(event: PreCollisionEvent): void {
if (event.other instanceof Skier) {
private onPreCollision(event: CollisionStartEvent): void {
if (event.other.owner instanceof Skier) {
this.parent!.emit('passed');
this.kill();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/game/actors/pole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Pole extends Actor {
}

private onPreCollision(evt: CollisionStartEvent): void {
if (evt.other instanceof Skier) {
if (evt.other.owner instanceof Skier) {
(this.scene!.engine as Game).soundPlayer.playSound(
Resources.PoleHittingSound,
Config.POLE_HIT_SOUND_VOLUME
Expand Down
50 changes: 25 additions & 25 deletions src/app/game/actors/skier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Actor, CollisionType, type Engine, type ParticleEmitter, vec } from 'excalibur';
import { Actor, CollisionType, type Engine, GpuParticleEmitter, type ParticleEmitter, vec } from 'excalibur';
import { Config } from '../config';
import { Resources } from '../resources';
import type { Race } from '../scenes/race';
Expand Down Expand Up @@ -223,53 +223,53 @@ export class Skier extends Actor {
private emitSlidingParticles(speedPercentage: number, slidingIntensity: number, skierAction: SkierActions): void {
this.particlesEmitter.pos.y = 2.5;
this.particlesEmitter.radius = 6;
this.particlesEmitter.particleLife = 2500;
this.particlesEmitter.minVel = 10;
this.particlesEmitter.maxVel = 50;
this.particlesEmitter.particle.life = 2500;
this.particlesEmitter.particle.minSpeed = 10;
this.particlesEmitter.particle.maxSpeed = 50;
if (skierAction === SkierActions.SLIDE_LEFT) {
this.particlesEmitter.maxAngle = 1.6;
this.particlesEmitter.minAngle = 0.5;
this.particlesEmitter.particle.maxAngle = 1.6;
this.particlesEmitter.particle.minAngle = 0.5;
this.particlesEmitter.pos.x = 8;
} else {
this.particlesEmitter.maxAngle = 2.6;
this.particlesEmitter.minAngle = 1.6;
this.particlesEmitter.particle.maxAngle = 2.6;
this.particlesEmitter.particle.minAngle = 1.6;
this.particlesEmitter.pos.x = -8;
}
this.particlesEmitter.emitParticles(speedPercentage * slidingIntensity * 20);
this.particlesEmitter.emitParticles(speedPercentage * slidingIntensity * 40);
}

private emitCarvingParticles(speedPercentage: number, carvingIntensity: number, skierAction: SkierActions): void {
this.particlesEmitter.pos.y = -1;
this.particlesEmitter.radius = 1;
this.particlesEmitter.particleLife = 2000;
this.particlesEmitter.minVel = 1;
this.particlesEmitter.maxVel = 5;
this.particlesEmitter.maxAngle = 1;
this.particlesEmitter.minAngle = 1;
this.particlesEmitter.particle.life = 2000;
this.particlesEmitter.particle.minSpeed = 0;
this.particlesEmitter.particle.maxSpeed = 0;
this.particlesEmitter.particle.maxAngle = 1;
this.particlesEmitter.particle.minAngle = 1;
this.particlesEmitter.pos.x = skierAction === SkierActions.CARVE_LEFT ? 8 : -8;
this.particlesEmitter.emitParticles(speedPercentage * carvingIntensity * 2);
}

private emitBrakingParticles(speedPercentage: number): void {
this.particlesEmitter.pos.y = -10;
this.particlesEmitter.radius = 6;
this.particlesEmitter.particleLife = 2000;
this.particlesEmitter.minVel = 10;
this.particlesEmitter.maxVel = 50;
this.particlesEmitter.maxAngle = 6;
this.particlesEmitter.minAngle = 3.4;
this.particlesEmitter.particle.life = 2000;
this.particlesEmitter.particle.minSpeed = 10;
this.particlesEmitter.particle.maxSpeed = 50;
this.particlesEmitter.particle.maxAngle = 6;
this.particlesEmitter.particle.minAngle = 3.4;
this.particlesEmitter.pos.x = 0;
this.particlesEmitter.emitParticles(speedPercentage * 20);
this.particlesEmitter.emitParticles(speedPercentage * 30);
}

private emitRidingParticles(speedPercentage: number): void {
this.particlesEmitter.pos.y = 0;
this.particlesEmitter.radius = 8;
this.particlesEmitter.particleLife = 500;
this.particlesEmitter.minVel = 0;
this.particlesEmitter.maxVel = 0;
this.particlesEmitter.maxAngle = 6;
this.particlesEmitter.minAngle = 3.4;
this.particlesEmitter.particle.life = 500;
this.particlesEmitter.particle.minSpeed = 0;
this.particlesEmitter.particle.maxSpeed = 0;
this.particlesEmitter.particle.maxAngle = 6;
this.particlesEmitter.particle.minAngle = 3.4;
this.particlesEmitter.pos.x = 0;
this.particlesEmitter.emitParticles(speedPercentage);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/game/actors/spectator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Spectator extends Actor {
}

private onPreCollision(evt: CollisionStartEvent): void {
if (evt.other instanceof Skier) {
if (evt.other.owner instanceof Skier) {
(this.scene!.engine as Game).soundPlayer.playSound(
this.hitSound,
Config.SPECTATOR_HIT_SOUND_INTENSITY,
Expand Down
54 changes: 40 additions & 14 deletions src/app/game/utils/particles-builder.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
import { Color, EmitterType, ParticleEmitter, vec } from 'excalibur';
import { Color, EmitterType, GpuParticleEmitter, ParticleEmitter, vec } from 'excalibur';

export class ParticlesBuilder {
public static getParticlesEmitter(): ParticleEmitter {
return new ParticleEmitter({
pos: vec(0, -20),
emitterType: EmitterType.Circle,
particle: {
minSpeed: 1,
maxSpeed: 10,
minAngle: 3.4,
maxAngle: 6,
opacity: 0.7,
life: 2000,
maxSize: 5,
minSize: 5,
startSize: 5,
endSize: 1,
beginColor: Color.fromRGB(23, 106, 170, 0.1),
endColor: Color.Transparent
},
radius: 1,
minVel: 1,
maxVel: 10,
minAngle: 3.4,
maxAngle: 6,
emitRate: 1,
opacity: 0.7,
fadeFlag: true,
particleLife: 2000,
maxSize: 5,
minSize: 5,
startSize: 5,
endSize: 1,
beginColor: Color.fromRGB(23, 106, 170, 0.1),
endColor: Color.Transparent,
isEmitting: false
});
}

public static getGpuParticlesEmitter(): GpuParticleEmitter {
return new GpuParticleEmitter({
pos: vec(0, -20),
emitterType: EmitterType.Circle,
maxParticles: 1000,
particle: {
minSpeed: 1,
maxSpeed: 10,
minAngle: 3.4,
maxAngle: 6,
opacity: 0.7,
life: 2000,
maxSize: 5,
minSize: 5,
startSize: 5,
endSize: 1,
beginColor: Color.fromRGB(23, 106, 170, 0.1),
endColor: Color.Transparent
},
radius: 1,
emitRate: 1,
isEmitting: false
})
}
}
15 changes: 4 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3129,11 +3129,6 @@ core-js-compat@^3.37.1, core-js-compat@^3.38.0:
dependencies:
browserslist "^4.24.2"

[email protected]:
version "3.36.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.36.1.tgz#c97a7160ebd00b2de19e62f4bbd3406ab720e578"
integrity sha512-BTvUrwxVBezj5SZ3f10ImnX2oRByMxql3EimVqMysepbC9EeMUOpLwdy6Eoili2x6E4kf+ZUB5k/+Jv55alPfA==

core-util-is@~1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
Expand Down Expand Up @@ -3629,12 +3624,10 @@ events@^3.2.0:
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==

[email protected]:
version "0.29.3"
resolved "https://registry.yarnpkg.com/excalibur/-/excalibur-0.29.3.tgz#68f578626bbbed69ed277fc1c9181b7b9ebdb8a9"
integrity sha512-R1Nzf5/U2oSuIcWKZinAUR8b3eW71bwC6UvnqSt08d2uTVpaIDwl6cyVvB+1jY5GeA0BWmFS/wQ/PaNKTZDP7A==
dependencies:
core-js "3.36.1"
[email protected]:
version "0.30.0-alpha.1295"
resolved "https://registry.yarnpkg.com/excalibur/-/excalibur-0.30.0-alpha.1295.tgz#d66a829034750de82d39d08766cc9114e8aaee7b"
integrity sha512-SOEEp9Sb9LxZWZjCMk9mpP8YfA/2J+rgMxKdAKaGt+cOJ7C7IQN3VGUD9pdEWN2n8RN41ebBkq2mmOJqncbhTw==

execa@^5.0.0:
version "5.1.1"
Expand Down

0 comments on commit 4b3d2de

Please sign in to comment.