简体   繁体   English

Javascript - 如何识别圆弧的碰撞

[英]Javascript - How to identify the collision of an arc in a circle

I try to code a little game in javascript and there is the problem : I don't know how can I identify the empty arc in the eater circle to increment the score.我尝试在 javascript 中编写一个小游戏,但存在问题:我不知道如何识别食客圈中的空弧以增加分数。

I add collisions between the eater circle and the ball and if the ball touch the "body" of the eater, it will show Game Over (that was done) and if the ball touch the "mouth" of the eater, it must increment the score.我在食者圈和球之间添加碰撞,如果球接触食者的“身体”,它将显示游戏结束(已完成),如果球接触食者的“嘴”,它必须增加分数。

Here is the code of the little game : http://jsbin.com/gujove/edit?html,css,js,output这是小游戏的代码: http : //jsbin.com/gujove/edit?html,css,js,output

Don't hesitate to tell me if you have any idea on how to do it.如果您对如何操作有任何想法,请随时告诉我。

Thanks.谢谢。

Providing that you know the following:前提是您了解以下内容:

  • You know the coordinates of the center of the eater and the radius.你知道食者中心的坐标和半径。 (center of your reference plane) (参考平面的中心)
  • You can calculate the coordinates of the ends of the arc (centerY + sinA), (centerX+cosA) etc.您可以计算圆弧末端的坐标 (centerY + sinA)、(centerX+cosA) 等。
  • You know the center of the ball and the radius.你知道球的中心和半径。

Then:然后:

  • you have to calculate if the distance between the center of the ball and any of the arc ends is less or equal then the radius of the ball.(if distance is less, it means that the arc corner is inside the ball, hence you have hit)你必须计算球的中心和任何弧端之间的距离是否小于或等于球的半径。(如果距离较小,这意味着弧角在球内,因此你有打)

  • On top of that, angle for the line drawn from center of the eater to center of the ball, should be in beteween the angles of the lines drawn to the sides of the arc, if you consider the center of your eater as a reference point for the plane.最重要的是,如果您将食者的中心视为参考点,那么从食者中心到球中心绘制的线的角度应该在绘制到弧线两侧的线的角度之间为飞机。 (if the angle is in between and first condition holds, then you are passing the empty space. (如果角度介于两者之间并且第一个条件成立,那么您正在通过空白空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM