Skip to content

Commit

Permalink
path can be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rand256 committed Jan 17, 2020
1 parent 9d82aab commit fa38a49
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions client/zone/js-modules/path-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function PathDrawer() {
);
}

function drawRobot(position, angle) {
function drawRobot(position, path) {
const ctx = canvasObjects.getContext("2d");
function rotateRobot(img, angle) {
var canvasimg = document.createElement("canvas");
Expand All @@ -111,7 +111,7 @@ export function PathDrawer() {

let multiplier = Math.max(20/img_rocky.width,84/img_rocky.width * scaleFactor/maxScaleFactor);
ctx.drawImage(
rotateRobot(img_rocky, angle),
path ? rotateRobot(img_rocky, path.current_angle) : img_rocky,
robotPositionInPixels[0] - img_rocky.width * multiplier / 2, // x
robotPositionInPixels[1] - img_rocky.height * multiplier / 2, // y
img_rocky.width * multiplier, // width
Expand Down Expand Up @@ -144,13 +144,15 @@ export function PathDrawer() {
ctx.imageSmoothingQuality = 'high';
ctx.clearRect(0, 0, canvas.width, canvas.height);

ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = pathColor;
drawLines(path.points, ctx);
ctx.stroke();
if (path) {
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = pathColor;
drawLines(path.points, ctx);
ctx.stroke();
}

if(predictedPath) {
if (predictedPath) {
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = pathColor;
Expand All @@ -165,7 +167,7 @@ export function PathDrawer() {
ctxObjects.clearRect(0, 0, canvasObjects.width, canvasObjects.height);

drawCharger(chargerPosition);
drawRobot(robotPosition, path.current_angle);
drawRobot(robotPosition, path);
}

// noinspection JSDuplicatedDeclaration
Expand Down

0 comments on commit fa38a49

Please sign in to comment.