diff --git a/src/actors/starting-gate.ts b/src/actors/starting-gate.ts new file mode 100644 index 0000000..6bff74a --- /dev/null +++ b/src/actors/starting-gate.ts @@ -0,0 +1,15 @@ +import { Actor, Vector } from "excalibur"; +import { Resources } from "../resources"; + +export class StartingGate extends Actor { + constructor(anchor: Vector, position: Vector) { + super({ + anchor: anchor, + pos: position, + width: 70, + height: 5, + }); + + this.graphics.use(Resources.StartingGate.toSprite()); + } +} diff --git a/src/actors/starting-house.ts b/src/actors/starting-house.ts new file mode 100644 index 0000000..e3c8a36 --- /dev/null +++ b/src/actors/starting-house.ts @@ -0,0 +1,36 @@ +import { Actor, toRadians, vec } from "excalibur"; +import { Resources } from "../resources"; +import { StartingGate } from "./starting-gate"; +import { Config } from "../config"; + +export class StartingHouse extends Actor { + private gate: StartingGate; + + constructor() { + super({ + anchor: vec(0.5, 0), + pos: vec(0, -10), + width: 400, + height: 300, + z: 11 + }); + + this.graphics.use(Resources.StartingHouse.toSprite()); + this.gate = new StartingGate(vec(0.5, 0), vec(25, -5)); + this.addChild(this.gate); + } + + public update(): void { + if (this.canDestroy()) { + this.kill(); + } + } + + public openGate(): void { + this.gate.rotation = toRadians(90); + } + + private canDestroy(): boolean { + return this.scene.camera.y - this.pos.y < - Config.DISPLAY_HEIGHT * Config.VISIBLE_ON_SCREEN_MARGIN_FACTOR; + } +} diff --git a/src/config.ts b/src/config.ts index e199123..26d7544 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,7 +5,7 @@ export class Config { static DISPLAY_WIDTH = 800; static DISPLAY_HEIGHT = 800; static VISIBLE_ON_SCREEN_MARGIN_FACTOR = 1.5; - static CAMERA_ZOOM = 0.6; + static CAMERA_ZOOM = 0.65; static DISPLAY_MIN_MARGIN = 25; static DISPLAY_MAX_RIGHT_POSITION = (Config.DISPLAY_WIDTH / 2) - this.DISPLAY_MIN_MARGIN; static DISPLAY_MAX_LEFT_POSITION = -Config.DISPLAY_MAX_RIGHT_POSITION; diff --git a/src/game.ts b/src/game.ts index e2fd974..48e54b5 100644 --- a/src/game.ts +++ b/src/game.ts @@ -28,6 +28,8 @@ export class Game extends Engine { Resources.EventRecordGhostSliding, Resources.EventRecordGhostBraking, + Resources.StartingGate, + Resources.StartingHouse, Resources.PoleRed, Resources.PoleBlue, Resources.PoleTouchedRed, diff --git a/src/images/sprites/starting_gate.png b/src/images/sprites/starting_gate.png new file mode 100644 index 0000000..68a422f Binary files /dev/null and b/src/images/sprites/starting_gate.png differ diff --git a/src/images/sprites/starting_house.png b/src/images/sprites/starting_house.png new file mode 100644 index 0000000..06e28b2 Binary files /dev/null and b/src/images/sprites/starting_house.png differ diff --git a/src/resources.ts b/src/resources.ts index 3f243e5..dbf982b 100644 --- a/src/resources.ts +++ b/src/resources.ts @@ -15,6 +15,8 @@ import eventRecordGhostCarving from "./images/sprites/eventRecordGhost_carving.p import eventRecordGhostSliding from "./images/sprites/eventRecordGhost_sliding.png"; import eventRecordGhostBraking from "./images/sprites/eventRecordGhost_braking.png"; +import startingGate from "./images/sprites/starting_gate.png"; +import startingHouse from "./images/sprites/starting_house.png"; import poleRed from "./images/sprites/pole_red.png"; import poleBlue from "./images/sprites/pole_blue.png"; import poleTouchedRed from "./images/sprites/pole_touched_red.png"; @@ -47,6 +49,8 @@ const Resources = { EventRecordGhostSliding: new ImageSource(eventRecordGhostSliding), EventRecordGhostBraking: new ImageSource(eventRecordGhostBraking), + StartingGate: new ImageSource(startingGate), + StartingHouse: new ImageSource(startingHouse), PoleRed: new ImageSource(poleRed), PoleBlue: new ImageSource(poleBlue), PoleTouchedRed: new ImageSource(poleTouchedRed), diff --git a/src/scenes/race.ts b/src/scenes/race.ts index ddfb59c..addaa19 100644 --- a/src/scenes/race.ts +++ b/src/scenes/race.ts @@ -16,6 +16,7 @@ import { SkierActions } from "../models/skier-actions.enum"; import { SkierGraphics } from "../utils/skier-graphics"; import { StockableGhost } from "../models/stockable-ghost"; import { TimedSector } from "../models/timed-sector"; +import { StartingHouse } from "../actors/starting-house"; export class Race extends Scene { @@ -35,6 +36,7 @@ export class Race extends Scene { private skierCameraGhost?: Actor; private skierPositions: SkierPositioning[] = []; private gates: Gate[] = []; + private startingHouse?: StartingHouse; private startTime?: number; private endTime?: number; private timedSectors: TimedSector[] = []; @@ -94,6 +96,7 @@ export class Race extends Scene { this.listenStopRaceEvent(); this.skier!.startRace(); (this.engine as Game).soundPlayer.playSound(Resources.StartRaceSound, 0.3); + this.startingHouse?.openGate(); } public stopRace(): void { @@ -196,6 +199,8 @@ export class Race extends Scene { this.track = this.buildTrack(trackName, askedTrackStyle); this.skier = new Skier(skierName, this.getSkierConfig(this.track.style)); this.add(this.skier); + this.startingHouse = new StartingHouse(); + this.add(this.startingHouse); this.skierCameraGhost = new Actor({ width: 1, height: 1, pos: vec(this.skier.pos.x, this.skier.pos.y + Config.FRONT_GHOST_DISTANCE) }); this.setupCamera();