Please, when pasting code, use the little </> icon to format it with monospace and all that fancy stuff to make it more readable and stuff
.
You might want to keep in mind that I wrote this without looking at the example itself, as I can’t seem to find the exact sketch that looks like this one. The closest match is this one, but it’s called “Bouncing Ball with Vectors” and seems to be pretty different to what you have: https://www.processing.org/examples/bouncingball.html
The problem here is how you use these functions.
displayBall(...)
expects coordinates of the ball, and in draw()
you use it as displayBall(0,0);
, where both zeroes are constant and never change. So, displayBall(...);
always draws the ball at (0,0);
and never anywhere else.
Next, moveBall(...)
also expects coordinates of a ball, and then uses xspeed
and yspeed
to add to them. Same problem.
Moreso, it creates its own values called circleX
and circleY
, which refer to the input that the function gets and not to the actual circleX
and circleY
values themselves, and adds speed values to them - which are then immediately discarded as soon as the function ends as they are not needed.
The problem is that when you name arguments of a function with the same name as some variable, this function will always use its argument and not that variable, so real, global circleX
and circleY
variables get ignored by it.
Function checkEdges()
is made properly and operates on global values, but since no other function changes circleX
and circleY
in any way, it’s practically doing the same calculations with same numbers every time its run.
And even if you were to fix all of that up, the code would still be faulty, as all 3 functions will still operate on same circleX
, circleY
, xspeed
and yspeed
variables, which only correspond to a single ball. So, at best, you would be calculating same math on one ball data twice.
For such a thing, I suggest to learn arrays, and how to make your own objects and put functions in them - this way, you can just create a new variable Ball[]
, which is an array of any number of variables Ball
, where each Ball
will have its own circleX
, circleY
, xspeed
and yspeed
variables and functions that work on these variables.
Or, if you don’t want to do that yet, I suggest instead dialing it back to 1 ball, making sure that it works, and then create new circleX2
, circleY2
, xspeed2
and yspeed2
variables and copies of these functions that work on these variables, and then run them inside of draw()
independently.
Sorry if I bombarded you with information and explanations, it’s 3:03 AM here in Russia and I drank too much coffee.