0
我想弄清楚如何在这种情况下将黑球标为bBall,以便从白球(wBall)击中它的方向,然后消失打到侧边或角落的一个口袋,我该如何去完成这个?在处理中需要帮助建立台球游戏
ball wBall, bBall;
int click;
String msg;
Boolean moving = false;
int difx, dify;
float cdistance;
int steps = 20;
void setup(){
click=0;
size(800,400);
background(16,77,27);
wBall = new ball(35,#ffffff);
bBall = new ball(35,#000000);
msg="";
}
void mouseClicked(){
if(!moving){
click++;
}
}
void draw(){
background(16,77,27);
String msg;
fill(0,0,0);
ellipse(15,15,30,30);
ellipse(785,15,30,30);
ellipse(15,385,30,30);
ellipse(785,385,30,30);
ellipse(410,15,30,30);
ellipse(410,385,30,30);
msg="the click count is "+click;
println("the click count is "+click);
//Moving Balls\\
fill(255,255,255);
noStroke();
bBall.xpos=(250);
bBall.ypos=height/2;
bBall.update();
if(click==0){
wBall.xpos=mouseX;
wBall.ypos=mouseY;
}else if(click==1){
difx = wBall.xpos-bBall.xpos;
dify = wBall.ypos-bBall.ypos;
}else if(click==2){
cdistance = dist(wBall.xpos,wBall.ypos,bBall.xpos,bBall.ypos);
if (cdistance>bBall.ballDiam/2){
moving = true;
wBall.xpos-=difx/steps;
wBall.ypos-=dify/steps;
}else{
moving = false;
wBall.visible=false;
click=3;
}
}
wBall.update();
}
class ball{
int xpos, ypos;
color myColor;
int ballDiam;
boolean visible = true;
ball(int tempdiam, color tempColor){
myColor=tempColor;
ballDiam=tempdiam;
}
void update(){
if(visible){
fill(myColor);
ellipse(xpos,ypos,ballDiam,ballDiam);
}
}
}
非常有帮助!谢谢!我会试着对我的下一个问题做更具体的描述! – user2612494