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; } }