Skip to content

Commit 223f481

Browse files
committed
changed box for saw
1 parent b82df3b commit 223f481

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

main.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ let obstacleSaw = {
9090

9191
ctx.restore();
9292
}
93+
94+
this.y_shift = sawHeight-290;
9395
},
9496
x: -80,
9597
y: 0,
9698
w: 160,
97-
h: -160
99+
h: -160,
100+
shift: true,
101+
x_shift: -80,
102+
y_shift: 0
98103
};
99104

100105
let obstacleThorns = {
@@ -163,8 +168,7 @@ let electricSign = {
163168
x: 0,
164169
y: 0,
165170
w: 140,
166-
h: -140,
167-
obst: false
171+
h: -140
168172
};
169173

170174
let obstacleLaser = {
@@ -409,24 +413,30 @@ let drawFloor = function() {
409413
};
410414

411415
let drawBoundingBox = function(obstacle) {
416+
var obj_x = obstacle.x;
417+
var obj_y = obstacle.y;
418+
if (obstacle.shift) {
419+
obj_x += obstacle.x_shift;
420+
obj_y += obstacle.y_shift;
421+
}
412422
ctx.strokeStyle = "orangered";
413423
ctx.lineWidth = 1;
414-
ctx.strokeRect(obstacle.x, obstacle.y, obstacle.w, obstacle.h);
424+
ctx.strokeRect(obj_x, obj_y, obstacle.w, obstacle.h);
415425

416426
ctx.font = '14px monospace';
417427
ctx.fillStyle = "white";
418428
ctx.textAlign = "right";
419429
ctx.textBaseline = "top";
420-
ctx.fillText("(x, y)", obstacle.x, obstacle.y);
430+
ctx.fillText("(x, y)", obj_x, obj_y);
421431
ctx.textAlign = "left";
422432
ctx.textBaseline = "top";
423-
ctx.fillText("(x + w, y)", obstacle.x + obstacle.w, obstacle.y);
433+
ctx.fillText("(x + w, y)", obj_x + obstacle.w, obj_y);
424434
ctx.textAlign = "left";
425435
ctx.textBaseline = "bottom";
426-
ctx.fillText("(x + w, y + h)", obstacle.x + obstacle.w, obstacle.y + obstacle.h);
436+
ctx.fillText("(x + w, y + h)", obj_x + obstacle.w, obj_y + obstacle.h);
427437
ctx.textAlign = "right";
428438
ctx.textBaseline = "bottom";
429-
ctx.fillText("(x, y + h)", obstacle.x, obstacle.y + obstacle.h);
439+
ctx.fillText("(x, y + h)", obj_x, obj_y + obstacle.h);
430440

431441
ctx.textAlign = "left";
432442
ctx.textBaseline = "alphabetic";
@@ -443,13 +453,18 @@ let drawObstacleBoundingBox = function(obstacle) {
443453
};
444454

445455
let is_overlapping = function(object1, object2) {
446-
if (!object2.obst) {
447-
return false;
456+
var obj_x=object2.x;
457+
var obj_y=object2.y;
458+
459+
if (object2.shift) {
460+
obj_x += object2.x_shift;
461+
obj_y += object2.y_shift;
448462
}
449-
if (object1.x + object1.w > object2.x &&
450-
object1.y > object2.y + object2.h &&
451-
object1.x < object2.x + object2.w &&
452-
object1.y + object1.h < object2.y) {
463+
464+
if (object1.x + object1.w > obj_x &&
465+
object1.y > obj_y + object2.h &&
466+
object1.x < obj_x + object2.w &&
467+
object1.y + object1.h < obj_y) {
453468
return true;
454469
}
455470
return false;
@@ -829,4 +844,4 @@ let draw = function() {
829844
initialize();
830845
})();
831846

832-
draw();
847+
draw();

0 commit comments

Comments
 (0)