Parallax-Bicycle/Road.js

42 lines
907 B
JavaScript

"use strict";
class Road
{
constructor(inCanvas, inPos)
{
this.canvas = inCanvas;
this.pos = inPos;
this.size = new Vector(this.canvas.width, this.canvas.height * 0.1);
this.speed = 300; // Pixels / sec
this.lineOffset = 0;
this.roadColour = "#3d3d3d";
this.dashColour = "rgb(234, 236, 245)";
}
update(dt)
{
this.lineOffset -= this.speed * dt;
}
render(context)
{
context.save();
context.translate(this.pos.x, this.pos.y);
context.fillStyle = this.roadColour;
context.fillRect(0, 0, this.size.x, this.size.y);
context.beginPath();
context.moveTo(0, this.size.y / 2.2);
context.lineTo(this.size.x, this.size.y / 2.2);
context.lineWidth = 5;
context.setLineDash([35, 20]);
context.lineDashOffset = this.lineOffset;
context.strokeStyle = this.dashColour;
context.stroke();
context.restore();
}
}