Skip to content

Commit

Permalink
Merge pull request #5 from mathieuher/startingHouse
Browse files Browse the repository at this point in the history
feat(race): add starting house and starting gate
  • Loading branch information
mathieuher authored Feb 1, 2024
2 parents 7d5157b + d4e2f6c commit 4f346a2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/actors/starting-gate.ts
Original file line number Diff line number Diff line change
@@ -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());
}
}
36 changes: 36 additions & 0 deletions src/actors/starting-house.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class Game extends Engine {
Resources.EventRecordGhostSliding,
Resources.EventRecordGhostBraking,

Resources.StartingGate,
Resources.StartingHouse,
Resources.PoleRed,
Resources.PoleBlue,
Resources.PoleTouchedRed,
Expand Down
Binary file added src/images/sprites/starting_gate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/sprites/starting_house.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions src/scenes/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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[] = [];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4f346a2

Please sign in to comment.