diff --git a/src/app/game/actors/gate-detector.ts b/src/app/game/actors/gate-detector.ts index 85d5e59..eb81ba4 100644 --- a/src/app/game/actors/gate-detector.ts +++ b/src/app/game/actors/gate-detector.ts @@ -1,4 +1,4 @@ -import { Actor, CollisionStartEvent, CollisionType, type PreCollisionEvent, type Vector, vec } from 'excalibur'; +import { Actor, type CollisionStartEvent, CollisionType, type Vector, vec } from 'excalibur'; import { Skier } from './skier'; export class GateDetector extends Actor { diff --git a/src/app/game/actors/skier.ts b/src/app/game/actors/skier.ts index 49c66d9..e45c7eb 100644 --- a/src/app/game/actors/skier.ts +++ b/src/app/game/actors/skier.ts @@ -1,4 +1,4 @@ -import { Actor, CollisionType, type Engine, GpuParticleEmitter, type ParticleEmitter, vec } from 'excalibur'; +import { Actor, CollisionType, type Engine, type ParticleEmitter, Scene, vec } from 'excalibur'; import { Config } from '../config'; import { Resources } from '../resources'; import type { Race } from '../scenes/race'; @@ -223,7 +223,6 @@ 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.particle.life = 2500; this.particlesEmitter.particle.minSpeed = 10; this.particlesEmitter.particle.maxSpeed = 50; if (skierAction === SkierActions.SLIDE_LEFT) { @@ -241,7 +240,6 @@ export class Skier extends Actor { private emitCarvingParticles(speedPercentage: number, carvingIntensity: number, skierAction: SkierActions): void { this.particlesEmitter.pos.y = -1; this.particlesEmitter.radius = 1; - this.particlesEmitter.particle.life = 2000; this.particlesEmitter.particle.minSpeed = 0; this.particlesEmitter.particle.maxSpeed = 0; this.particlesEmitter.particle.maxAngle = 1; @@ -253,7 +251,6 @@ export class Skier extends Actor { private emitBrakingParticles(speedPercentage: number): void { this.particlesEmitter.pos.y = -10; this.particlesEmitter.radius = 6; - this.particlesEmitter.particle.life = 2000; this.particlesEmitter.particle.minSpeed = 10; this.particlesEmitter.particle.maxSpeed = 50; this.particlesEmitter.particle.maxAngle = 6; @@ -265,13 +262,12 @@ export class Skier extends Actor { private emitRidingParticles(speedPercentage: number): void { this.particlesEmitter.pos.y = 0; this.particlesEmitter.radius = 8; - 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); + // this.particlesEmitter.emitParticles(speedPercentage * 0.01); } private hasBreakingIntention(engine: Engine): boolean { diff --git a/src/app/game/models/track.ts b/src/app/game/models/track.ts index 074bdd2..b3b065c 100644 --- a/src/app/game/models/track.ts +++ b/src/app/game/models/track.ts @@ -1,4 +1,4 @@ -import type { Gate } from '../actors/gate'; +import type { StockableGate } from './stockable-gate'; import { StockableTrack } from './stockable-track'; import type { TrackStyles } from './track-styles.enum'; @@ -8,9 +8,16 @@ export class Track { public builderVersion?: number; public style: TrackStyles; public date: Date; - public gates: Gate[]; + public gates: StockableGate[]; - constructor(id?: number, builderVersion?: number, name?: string, style?: TrackStyles, date?: Date, gates?: Gate[]) { + constructor( + id?: number, + builderVersion?: number, + name?: string, + style?: TrackStyles, + date?: Date, + gates?: StockableGate[] + ) { this.id = id; this.builderVersion = builderVersion; this.name = name!; @@ -24,14 +31,7 @@ export class Track { } public toStockable(): StockableTrack { - return new StockableTrack( - this.id, - this.builderVersion, - this.name, - this.style, - this.date, - this.gates.map(gate => gate.getStockableGate()) - ); + return new StockableTrack(this.id, this.builderVersion, this.name, this.style, this.date, this.gates); } private static formatTrackName(name: string): string { diff --git a/src/app/game/scenes/race.ts b/src/app/game/scenes/race.ts index 10ffcfb..8b94bdc 100644 --- a/src/app/game/scenes/race.ts +++ b/src/app/game/scenes/race.ts @@ -278,9 +278,8 @@ export class Race extends Scene { } private buildTrack(track: Track): void { - const gates = track.gates.map(gate => { - const stockableGate = gate.getStockableGate(); - return new Gate( + for (const stockableGate of track.gates) { + const gate = new Gate( TrackBuilder.getGatesConfig(track.style), vec(stockableGate.x, stockableGate.y), stockableGate.width, @@ -289,9 +288,7 @@ export class Race extends Scene { stockableGate.isFinal, stockableGate.sectorNumber ); - }); - for (const gate of gates) { - this.gates?.push(gate); + this.gates.push(gate); this.add(gate); } } diff --git a/src/app/game/utils/particles-builder.ts b/src/app/game/utils/particles-builder.ts index 88208f1..736a426 100644 --- a/src/app/game/utils/particles-builder.ts +++ b/src/app/game/utils/particles-builder.ts @@ -11,7 +11,7 @@ export class ParticlesBuilder { minAngle: 3.4, maxAngle: 6, opacity: 0.7, - life: 2000, + life: 1000, maxSize: 5, minSize: 5, startSize: 5, @@ -47,6 +47,6 @@ export class ParticlesBuilder { radius: 1, emitRate: 1, isEmitting: false - }) + }); } } diff --git a/src/app/game/utils/track-builder.ts b/src/app/game/utils/track-builder.ts index d10f88b..55780a4 100644 --- a/src/app/game/utils/track-builder.ts +++ b/src/app/game/utils/track-builder.ts @@ -1,10 +1,10 @@ import { type Vector, vec } from 'excalibur'; -import { Gate } from '../actors/gate'; import { Config } from '../config'; import { Track } from '../models/track'; import type { StockableTrack } from '../models/stockable-track'; import { TrackStyles } from '../models/track-styles.enum'; import type { GatesConfig } from '../models/gates-config'; +import { StockableGate } from '../models/stockable-gate'; export class TrackBuilder { /** @@ -24,11 +24,11 @@ export class TrackBuilder { let nextGatePosition = TrackBuilder.getNextGatePosition(nextGateWidth, gatesConfig); for (let index = 1; index < numberOfGates; index++) { - const gate = new Gate( - gatesConfig, - nextGatePosition, - nextGateWidth, + const gate = new StockableGate( + nextGatePosition.x, + nextGatePosition.y, TrackBuilder.getGateColor(index, trackStyle), + nextGateWidth, index, false, sectorGateNumbers.indexOf(index) + 1 @@ -50,27 +50,13 @@ export class TrackBuilder { */ public static buildTrack(stockableTrack: StockableTrack): Track { ('TrackBuilder - Rebuilding an existing track'); - const gates: Gate[] = []; - for (const stockableGate of stockableTrack.gates) { - gates.push( - new Gate( - TrackBuilder.getGatesConfig(stockableTrack.style), - vec(stockableGate.x, stockableGate.y), - stockableGate.width, - stockableGate.color, - stockableGate.gateNumber, - stockableGate.isFinal, - stockableGate.sectorNumber - ) - ); - } return new Track( stockableTrack.id, stockableTrack.builderVersion, stockableTrack.name, stockableTrack.style, stockableTrack.date, - gates + stockableTrack.gates ); } @@ -102,12 +88,16 @@ export class TrackBuilder { return gatesConfig.minWidth + Math.random() * (gatesConfig.maxWidth - gatesConfig.minWidth); } - private static generateFinalGate(verticalPosition: number, gateNumber: number, gatesConfig: GatesConfig): Gate { - return new Gate( - gatesConfig, - vec(Config.FINAL_GATE_POSITION, verticalPosition), - Config.FINAL_GATE_WIDTH, + private static generateFinalGate( + verticalPosition: number, + gateNumber: number, + gatesConfig: GatesConfig + ): StockableGate { + return new StockableGate( + Config.FINAL_GATE_POSITION, + verticalPosition, 'red', + Config.FINAL_GATE_WIDTH, gateNumber, true, Config.SECTORS_PER_RACE + 1