Skip to content

Commit

Permalink
fix(game): fix ghost cloning issue + fix pole checkmark display + upd…
Browse files Browse the repository at this point in the history
…ate particles
  • Loading branch information
Mathieu Hermann committed Dec 5, 2024
1 parent 84a84ed commit 9470ec6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
28 changes: 12 additions & 16 deletions src/app/game/actors/pole.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Actor, type CollisionStartEvent, CollisionType, type Vector, vec, Color } from 'excalibur';
import { Actor, type CollisionStartEvent, CollisionType, type Vector, vec, Color, GraphicsGroup } from 'excalibur';
import { Config } from '../config';
import { Resources } from '../resources';
import { Skier } from './skier';
Expand All @@ -9,6 +9,7 @@ import { TrackStyles } from '../models/track-styles.enum';
export class Pole extends Actor {
private poleColor: 'red' | 'blue';
private gatesConfig: GatesConfig;
private graphicsGroup: GraphicsGroup;

constructor(position: Vector, color: 'red' | 'blue', gatesConfig: GatesConfig, isFinalPole: boolean) {
super({
Expand All @@ -23,9 +24,15 @@ export class Pole extends Actor {

this.poleColor = color;
this.gatesConfig = gatesConfig;
this.graphicsGroup = new GraphicsGroup({
members: [{
graphic: gatesConfig.poleSprites.get(color)!,
offset: vec(0, 0)
}]
});

if (!isFinalPole) {
this.graphics.use(gatesConfig.poleSprites.get(color)!);
this.graphics.use(this.graphicsGroup);
}
}

Expand All @@ -34,22 +41,11 @@ export class Pole extends Actor {
}

public displayPoleCheck(): void {
// TODO : Fix graphics
this.graphics.add(this.gatesConfig.poleCheckSprites.get(this.poleColor)!, {
anchor: vec(0.5, this.gatesConfig.trackStyle === TrackStyles.SL ? 2.5 : 2)
});
/*
const checkLayer = this.graphics.layers.create({
name: 'check',
order: 1,
offset: vec(this.gatesConfig.poleWidth / 2, 0)
});
checkLayer.graphics.push({
this.graphicsGroup.members.push({
graphic: this.gatesConfig.poleCheckSprites.get(this.poleColor)!,
options: { anchor: vec(0.5, this.gatesConfig.trackStyle === TrackStyles.SL ? 2.5 : 2) }
useBounds: false,
offset: this.gatesConfig.trackStyle === TrackStyles.SL ? vec(-2.5, -15): vec(2, -15)
});
*/
}

private onPreCollision(evt: CollisionStartEvent): void {
Expand Down
17 changes: 9 additions & 8 deletions src/app/game/actors/skier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Skier extends Actor {
this.particlesEmitter.pos.y = 2.5;
this.particlesEmitter.radius = 6;
this.particlesEmitter.particleLife = 2500;
this.particlesEmitter.minVel = 0;
this.particlesEmitter.minVel = 10;
this.particlesEmitter.maxVel = 50;
if (skierAction === SkierActions.SLIDE_LEFT) {
this.particlesEmitter.maxAngle = 1.6;
Expand All @@ -235,31 +235,32 @@ export class Skier extends Actor {
this.particlesEmitter.minAngle = 1.6;
this.particlesEmitter.pos.x = -8;
}
this.particlesEmitter.emitParticles(speedPercentage * slidingIntensity * 60);
this.particlesEmitter.emitParticles(speedPercentage * slidingIntensity * 20);
}

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

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

private emitRidingParticles(speedPercentage: number): void {
Expand All @@ -271,7 +272,7 @@ export class Skier extends Actor {
this.particlesEmitter.maxAngle = 6;
this.particlesEmitter.minAngle = 3.4;
this.particlesEmitter.pos.x = 0;
this.particlesEmitter.emitParticles(speedPercentage * 2);
this.particlesEmitter.emitParticles(speedPercentage);
}

private hasBreakingIntention(engine: Engine): boolean {
Expand Down
4 changes: 4 additions & 0 deletions src/app/game/models/stockable-ghost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export class StockableGhost {
public getSectorTime(sectorNumber: number): number | undefined {
return this.timedSectors ? this.timedSectors[sectorNumber - 1]?.time : undefined;
}

public static duplicate(ghost: StockableGhost): StockableGhost {
return new StockableGhost(ghost.trackId, ghost.date, ghost.eventId, ghost.rider, ghost.totalTime, ghost.timedSectors, [...ghost.positions!]);
}
}
1 change: 0 additions & 1 deletion src/app/game/models/track.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Gate } from '../actors/gate';
import { StockableRecord } from './stockable-record';
import { StockableTrack } from './stockable-track';
import type { TrackStyles } from './track-styles.enum';

Expand Down
6 changes: 3 additions & 3 deletions src/app/game/scenes/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class Race extends Scene {
private prepareRace(raceConfig: RaceConfig): void {
this.addTimer(this.uiTimer);
this.buildTrack(raceConfig.track);
this.skier = new Skier(raceConfig.rider, this.getSkierConfig(this.raceConfig.track.style));
this.skier = new Skier(raceConfig.rider, this.getSkierConfig(raceConfig.track.style));
this.add(this.skier);
this.startingHouse = new StartingHouse();
this.add(this.startingHouse);
Expand Down Expand Up @@ -235,13 +235,13 @@ export class Race extends Scene {

private buildGhosts(globalGhost?: StockableGhost, eventGhost?: StockableGhost): void {
if (globalGhost) {
this.globalRecordGhostDatas = globalGhost;
this.globalRecordGhostDatas = StockableGhost.duplicate(globalGhost)
this.globalRecordGhost = new Actor({ width: 30, height: 50, pos: vec(0, 0) });
this.add(this.globalRecordGhost);
}

if (eventGhost) {
this.eventRecordGhostDatas = eventGhost;
this.eventRecordGhostDatas = StockableGhost.duplicate(eventGhost);
if (this.eventRecordGhostDatas?.totalTime !== this.globalRecordGhostDatas?.totalTime) {
this.eventRecordGhost = new Actor({ width: 30, height: 50, pos: vec(0, 0) });
this.add(this.eventRecordGhost);
Expand Down
22 changes: 12 additions & 10 deletions src/app/game/utils/particles-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import { Color, EmitterType, ParticleEmitter, vec } from 'excalibur';

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

0 comments on commit 9470ec6

Please sign in to comment.