有没有一种方法可以在java中创建循环的Hitbox?
我试着做一个简单的游戏,你只需要打一些圆圈,我想知道是否有可能制作圆形而不是长方形 此代码是在processing 3.5.1 btw中编写的。。。 我已经放出了一些代码,基本上就是我设置主菜单的代码有没有一种方法可以在java中创建循环的Hitbox?,java,processing,Java,Processing,我试着做一个简单的游戏,你只需要打一些圆圈,我想知道是否有可能制作圆形而不是长方形 此代码是在processing 3.5.1 btw中编写的。。。 我已经放出了一些代码,基本上就是我设置主菜单的代码 //Random ellipse position int posx = (int)random(100, 1820); int posy = (int)random(100, 980); //Score count int score =
//Random ellipse position
int posx = (int)random(100, 1820);
int posy = (int)random(100, 980);
//Score count
int score = 0;
//Circlesize/Difficulty
int circlesize = 100;
//Hitbox
float hitsize = 50;
void setup(){
size(1920,1080);
background(255);
}
void draw(){
//What do to if the circle is pressed
if(mousePressed && mouseX >= (posx - hitsize) && mouseX <= (posx + hitsize) && mouseY >= (posy - hitsize) && mouseY <= (posy + hitsize)){
//Randomize next location for ellipse
posx = (int)random(100,1820);
posy = (int)random(100, 980);
//Make a new ellipse
background(255);
fill(255, 0, 0);
ellipse(posx, posy, circlesize, circlesize);
//Add a point to score
score ++;
}
}
//随机椭圆位置
int posx=(int)随机(1001820);
int posy=(int)随机(100980);
//计分
智力得分=0;
//圈圈/难度
int circlesize=100;
//杀手锏
浮动大小=50;
无效设置(){
规模(19201080);
背景(255);
}
作废提款(){
//如果按下圆圈怎么办
如果(mousePressed&&mouseX>=(posx-hitsize)&&mouseX=(posy-hitsize)&&mouseY简短回答:是的。您只需检查圆心之间的距离。如果该距离小于两个圆半径的总和,则两个圆相交
无耻的自我提升:是一个关于处理过程中碰撞检测的教程。根据Kevin所说的,
您可以在if中使用codedist(x1,y1,x2,y2)<50
来检查前两个参数(x1,y1)是否为x2和y2的50px。
一个例子:
int buttonX = 200;// the x position of the circle
int buttonY = 200;// the y position of the circle
ellipse(buttonX, buttonY,100,100);// the button
// if mouseX and mouseY are inside the radius of the 100px diameter button then it is active
if(dist(mouseX, mouseY, buttonX, buttonY) < 50) {
// the mouse is inside of the circle
}
int buttonX=200;//圆的x位置
int buttonY=200;//圆的y位置
椭圆(buttonX,buttonY,100100);//按钮
//如果mouseX和mouseY位于100px直径按钮的半径内,则该按钮处于激活状态
如果(距离(鼠标、鼠标、按钮、按钮)<50){
//鼠标在圆圈内
}
我希望他的帮助,如果您有任何问题,请随时提问。点击框检查圆形或球形对象非常简单!只需计算从圆的原点/中心到交互作用的距离,如果该距离大于半径,则该距离不是该圆上的交互作用。使用欧几里德数学,您不需要即使你必须消除过度的争吵,我也会尝试一下的谢谢工作,谢谢你的帮助流氓没问题仅供参考,我链接的页面确实解释了如何做到这一点。@KevinWorkman哦,天哪,我应该更仔细地阅读教程…我相应地编辑了我的回答…对不起:)