// Updates the ball's position, and reverses speed if it hits the wall
void update() {
x = x + speedX* mouseY/100;
y = y + speedY* mouseY/100;
// Reverse speed if it hits the wall
if (x + edge + radius > width || x - edge - radius < 0) {
speedX = - speedX;
}
if (y + edge + radius > height || y - edge - radius < 0) {
speedY = - speedY;
}
}
void mouse() {
if (mousePressed) {
resizeControl = 1;
if(mouseButton == RIGHT) {
if (resizeControl == 1) {
if(radius<50 && radicont==1) {
radius=radius+1;
if(radius==49) {
radicont=0;
}
}
if(radius>10 && radicont==0) {
radius=radius-1;
if(radius==11) {
radicont=1;
}
}
}
}
else if (mouseButton == LEFT) {
resizeControl = 0;
}
}
}
}
I am aware of needing to use minim but I wasn't sure how to implement it. When I tried to add a song.play() to the if statement I would get a "token void" error or something along those lines. I know this means that it doesn't know what to play so I was wondering how to initiate the 'song' in the Ball class and get it to work with the collisions.
I was doing some coding then all of a sudden without changing anything (that i am aware of) it just stopped working.
Can you guys please tell me what you see is wrong with it?
Main code:
int maxBalls = 20;
Ball[] ballArray;
int ballCount; // No of balls being created
//Background colour variables
float a = 0;
float b = 0;
float c = 0;
float d = 102;
float e = 204;
float f = 255;
//controls
int edge = 56;
int radius = 0;
int radicont = 1;
void setup() {
size(750, 750);
smooth();
// Create an array of balls
ballArray = new Ball[maxBalls];
}
void background1()
{
background(color(d+a,e+b,f+c));
//Change the background colours
a = (random(-1,1)) + a;
b = (random(-1,1)) + b;
c = (random(-1,1)) + c;
//black border
fill(0);
rect(0,0,edge,height);
rect(0,0,width,edge);
rect(0,height-edge,width,height);
rect(width-edge,0,width,height);
noFill();
}
void draw() {
background1();
// Display the balls and update the positions
for (int i = 0; i < ballCount-1; i++) {
ballArray[i].display();
ballArray[i].update();
ballArray[i].mouse();
}
}
class Ball {
float x, y; // Position of the ball
float speedX, speedY; // Speed of the ball
float radius; // Radius of the ball
color ball_color = color(0,random(0,250)); // Color of the ball
int resizeControl = 0;
OK so i was wondering how to get more than one ball to spawn using arrays. I still don't fully grasp the concept of arrays at the moment and i want to be able to understand them.
I want this code to have the ball stop following the mouse. I also want to click and another ball appears. I have set up an array with 12 spaces but i can't remember what to do next.