From eaf9fbff4dd40606936dffe8778f8211906de34f Mon Sep 17 00:00:00 2001 From: Mikkel Troels Kongsted Date: Fri, 1 Mar 2024 22:36:17 +0100 Subject: [PATCH] Make car move --- index.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 71433b4..3779de8 100644 --- a/index.ts +++ b/index.ts @@ -41,7 +41,7 @@ class CanvasGraphics implements Graphics { // Draw car body this.setFill(200, 0, 0); - this.fillRect([-20, -40], [80, 20]); + this.fillRect([-20, -40], [80, 21]); this.fillRect([-20, -20], [100, 20]); // Draw rear wheel @@ -83,14 +83,26 @@ interface Entity { class Car implements Entity { private pos: Vec2 = [0, 0]; - private angle: Rad = Math.PI / -4; + private angle: Rad = 0; private speeder = 1.0; public render(graphics: Graphics): void { graphics.drawCar(this.pos, this.angle); } + public update(delta: number): void { - this.pos[0] += this.speeder * delta * 100; + if (this.angle > Math.PI / -2) { + this.angle += this.speeder * -0.005 * Math.PI; + this.pos[0] += this.speeder * delta * 100; + } + } + + public setSpeeder(speeder: number): void { + this.speeder = speeder; + } + + public getAngle(): number { + return this.angle; } }