Hey, can anyone help me to get my ball to “shoot” upwards. Kinda like a canon, so my ball shoots, and i can change the degrees its shoots after.
My code is very simple, cause im new to this program.
We are trying to make it into a “Angry Birds” kinda like game.
My code:
int mouseCounter = 0;
float boldSize = 20;
float gravity = 1;
float friction = 0.90;
float[] xList = new float [1000];
float[] yList = new float [1000];
float[] xSpeedList = new float [1000];
float[] ySpeedList = new float [1000];
float[] redFarve = new float [1000];
float[] greenFarve = new float [1000];
float[] blueFarve = new float [1000];
void setup(){
size(1680,1005);
frameRate(60);
smooth();
//noStroke();
}
void draw(){
clear();
for(int index = 0; index < xList.length; index++){
float x = xList[index];
float y = yList[index];
float xSpeed = xSpeedList[index];
float ySpeed = ySpeedList[index];
fill(redFarve[index],greenFarve[index],blueFarve[index]);
ellipse(x,y,boldSize,boldSize);
x = x + xSpeed;
y = y + ySpeed;
ySpeed = ySpeed + gravity;
if(x >= width - 10 || x < 10){
xSpeed = -xSpeed;
}
if (y >= height - 10 || y < 10){
ySpeed = -ySpeed * friction;
}
xList[index] = x;
yList[index] = y;
xSpeedList[index] = xSpeed;
ySpeedList[index] = ySpeed;
}
}
void mousePressed(){
xList [mouseCounter] = random(mouseX,mouseX);
yList[mouseCounter] = random(mouseY,mouseY);
xSpeedList[mouseCounter] = random(10,20);
ySpeedList[mouseCounter] = random(10,20);
redFarve[mouseCounter] = random(0,255);
greenFarve[mouseCounter] = random(0,255);
blueFarve[mouseCounter] = random(0,255);
mouseCounter = mouseCounter + 1;
}
So what would i have to change in my code to make it shoot directly towards x and then make it fall down becuase of my gravity. Would it be able for the “user” to set a shooting angle via my code?