@@ -90,11 +90,16 @@ let obstacleSaw = {
90
90
91
91
ctx . restore ( ) ;
92
92
}
93
+
94
+ this . y_shift = sawHeight - 290 ;
93
95
} ,
94
96
x : - 80 ,
95
97
y : 0 ,
96
98
w : 160 ,
97
- h : - 160
99
+ h : - 160 ,
100
+ shift : true ,
101
+ x_shift : - 80 ,
102
+ y_shift : 0
98
103
} ;
99
104
100
105
let obstacleThorns = {
@@ -163,8 +168,7 @@ let electricSign = {
163
168
x : 0 ,
164
169
y : 0 ,
165
170
w : 140 ,
166
- h : - 140 ,
167
- obst : false
171
+ h : - 140
168
172
} ;
169
173
170
174
let obstacleLaser = {
@@ -409,24 +413,30 @@ let drawFloor = function() {
409
413
} ;
410
414
411
415
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
+ }
412
422
ctx . strokeStyle = "orangered" ;
413
423
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 ) ;
415
425
416
426
ctx . font = '14px monospace' ;
417
427
ctx . fillStyle = "white" ;
418
428
ctx . textAlign = "right" ;
419
429
ctx . textBaseline = "top" ;
420
- ctx . fillText ( "(x, y)" , obstacle . x , obstacle . y ) ;
430
+ ctx . fillText ( "(x, y)" , obj_x , obj_y ) ;
421
431
ctx . textAlign = "left" ;
422
432
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 ) ;
424
434
ctx . textAlign = "left" ;
425
435
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 ) ;
427
437
ctx . textAlign = "right" ;
428
438
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 ) ;
430
440
431
441
ctx . textAlign = "left" ;
432
442
ctx . textBaseline = "alphabetic" ;
@@ -443,13 +453,18 @@ let drawObstacleBoundingBox = function(obstacle) {
443
453
} ;
444
454
445
455
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 ;
448
462
}
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 ) {
453
468
return true ;
454
469
}
455
470
return false ;
@@ -829,4 +844,4 @@ let draw = function() {
829
844
initialize ( ) ;
830
845
} ) ( ) ;
831
846
832
- draw ( ) ;
847
+ draw ( ) ;
0 commit comments