diff --git a/src/objects/gear-stick-object.ts b/src/objects/gear-stick-object.ts index 94b97f6..eb3e108 100644 --- a/src/objects/gear-stick-object.ts +++ b/src/objects/gear-stick-object.ts @@ -41,7 +41,7 @@ export class GearStickObject extends BaseGameObject { return this.currentGear; } - private switchGear(): void { + public switchGear(): void { this.currentGear = this.currentGear === "F" ? "R" : "F"; } diff --git a/src/objects/local-car-object.ts b/src/objects/local-car-object.ts index 2a5652f..cbf12cc 100644 --- a/src/objects/local-car-object.ts +++ b/src/objects/local-car-object.ts @@ -4,6 +4,7 @@ import { ObjectType } from "../enums/object-type.js"; import { CarObject } from "./car-object.js"; import { GearStickObject } from "./gear-stick-object.js"; import { JoystickObject } from "./joystick-object.js"; +import { WorldBackgroundObject } from "./backgrounds/world-background-object.js"; export class LocalCarObject extends CarObject { private readonly joystickObject: JoystickObject; @@ -48,6 +49,10 @@ export class LocalCarObject extends CarObject { public override update(deltaTimeStamp: DOMHighResTimeStamp): void { if (this.active) { + if (this.isCollidingWithBounds()) { + this.gearStickObject.switchGear(); + } + this.handleControls(); } @@ -66,6 +71,18 @@ export class LocalCarObject extends CarObject { this.setTypeId(ObjectType.RemoteCar); } + private isCollidingWithBounds(): boolean { + const collidingObjects = this.getCollidingObjects(); + + for (const object of collidingObjects) { + if (object instanceof WorldBackgroundObject) { + return true; + } + } + + return false; + } + private handleControls(): void { if (!this.joystickObject || !this.gearStickObject) return;