How do you add or subtract PVectors arrays in processing?
This is my code for my class Ball for my game but i have to change in it PVectors
class Ball {
int billHeadYCentre=300;
int ballSizeX=20;
int ballSizeY=20;
int circleX=0;
float circleY=random(10, 200);
float yspeed = random(0.2, 1.2);
float xspeed = random(1.15, 1.2);
float x;
float y;
float gravity=0.1 ;
float airfriction = 0.00011;
float friction = 0.00011;
float hatWidth = 100;
float hatHeight = 2;
int hatBounceRate = 2;
boolean gameOverScreen =true;
PVector[] ballSpeed= new PVector[5];
PVector[] ballLocation= new PVector[5];
// PVector[] gravity= new PVector[1];
void display () {
strokeWeight(2);
fill(255);
ellipse(circleX, circleY, ballSizeX, ballSizeY);
for (int i=0; i<5; i++) {
ballSpeed[i] = new PVector(random(1.15, 1.2), random(0.2, 1.2));
ballLocation[i]= new PVector(0, 0);
}
// gravity[0]=new PVector(0, 0.05);
}
void gravity () {
circleY = circleY + yspeed;
yspeed= yspeed + gravity;
yspeed= yspeed - (yspeed *airfriction);
}
void bounceBottom(int surface) {
circleY = surface-(ballSizeY/2);
yspeed =yspeed * -1;
yspeed = yspeed - (yspeed * friction);
}
void bottomStop(int height) {
circleY=height;
yspeed =0;
gameOverScreen();
}
void mousePressed() {
if (mousePressed) {
restart();
}
}
void restart() {
setup();
}
void bounceTop(int surface) {
circleY = surface+(ballSizeY/2);
yspeed = yspeed *-1;
yspeed = yspeed - (yspeed * friction);
}
void xSpeed() {
circleX += xspeed;
xspeed -= (xspeed * airfriction);
}
void bounceLeft(int surface) {
circleX = surface+(ballSizeX/2);
xspeed*=-1;
xspeed -= (xspeed * friction);
}
void bounceRight(int surface) {
circleX = surface-(ballSizeX/2);
xspeed*=-1;
xspeed -= (xspeed * friction);
}
void stayInsideTheScreen() {
if (circleY+(ballSizeY/2) > height) {
bottomStop(height);
}
if (circleY-(ballSizeY/2) < 0) {
bounceTop(0);
}
if (circleX-(ballSizeX/2) < 0) {
bounceLeft(0);
}
if (circleX+(ballSizeX/2) > width) {
bounceRight(width);
}
}
void watchHatBounce() {
if ((circleX+(ballSizeX/2) > mouseX-(hatWidth/2)) && (circleX-(ballSizeX/2) < mouseX+(hatWidth/2))) {
if (dist(circleX, circleY, circleX, billHeadYCentre)<=(ballSizeX/2)) {
xspeed = (circleX - mouseX)/5;
}
}
if ((circleX+(ballSizeX/2) > mouseX-(hatWidth/2)) && (circleX-(ballSizeX/2) < mouseX+(hatWidth/2))) {
if (dist(circleX, circleY, circleX, billHeadYCentre)<=(ballSizeX/2)) {
bounceBottom(billHeadYCentre);
}
}
}