Make car move

This commit is contained in:
Mikkel Troels Kongsted 2024-03-01 22:36:17 +01:00
parent d970236709
commit eaf9fbff4d

View File

@ -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,15 +83,27 @@ 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 {
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;
}
}
class Matrix {