0

HTML5 canvas collision question

I have some code: https://code.sololearn.com/WFF3N151BDBi/#html I am trying to keep this circle on above the rectangle on the bottom of the screen. I am trying to make that bottom rectangle in-passable by the circle that I move with my mouse. I am having a difficult time trying to make up the math to make this possible. Any help is greatly appreciated. As well as tips on my code to make things more efficient.

27th May 2018, 11:12 AM
Bradley
3 Réponses
+ 2
set an if-statement like... if(circle.y<rect.y){ mouseCanMoveCircle(); } else{ mouseCannotMoveCircle(); }
27th May 2018, 11:36 AM
᠌᠌Code X
᠌᠌Code X - avatar
0
mouseCan(not)MoveCIrcle does not seen to be a function. Can you elaborate ?
27th May 2018, 1:18 PM
Bradley
0
.... function handeler(event){ var x= event.clientX; var y= event.clientY; // set horizontal bounds circle1.x= Math.max(circle1.radius, Math.min(rect1.w+rect1.x-circle1.radius, x)); // set vertical bounds circle1.y= Math.max(circle1.radius, Math.min(rect1.h+rect1.y-circle1.radius, y)); } ....
28th May 2018, 9:00 AM
KrOW
KrOW - avatar