xxxxxxxxxx
var ball1x = 0;
var ball1y = 0;
var ball1z = 0;
var zin = true;
var shotx = 0;
var shoty = 0;
var shotz = 0;
var shooting = false;
function setup() {
createCanvas(windowWidth, windowHeight,WEBGL);
background(100);
}
function draw() {
distToBall1 = floor(dist(mouseX,mouseY,ball1x+width/2,ball1y+height/2)); // 2D distance check
distToBall3D = floor(dist(shotx,shoty,shotz,ball1x,ball1y,ball1z)); // 3D distance check
print(distToBall1);
print(distToBall3D);
push();
// this is the shot that links to the mouse \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
shotx = mouseX-width/2;
shoty = mouseY-height/2;
translate(shotx,shoty,shotz);
push();
translate(0,0,-1000)
rotateX(radians(90));
cylinder(2,2000);
pop();
sphere(25); /////////////////////////// THIS IS THE BALL YOU ARE SHOOTING
pop();
if(distToBall3D < 50){ // this is checking the distance to the ball (x and y and z)
ball1x = floor(random(-width/2,width/2));
ball1y = floor(random(-height/2,height/2));
}
// This is the ball that we are trying to catch
push();
translate(ball1x,ball1y,ball1z);
sphere(25);
pop();
//print("X: " + ball1x + " Y: " + ball1y + " Z: " + ball1z);
if (zin){
ball1z += 8;
if (ball1z >= 600){
zin = false;
}
}
if (!zin) {
//print(zin);
ball1z -= 8;
if(ball1z < -1000){
zin = true;
}
}
if (shooting) {
print(shooting);
shotz -= 100;
if(shotz < -5000){
shooting = false;
shotz = 0;
}
}
} // end of draw
function mouseClicked() {
shooting = true;
}
//