Hi, I am relatively new to processing.py and I’ve been stuck on my code for a few days now. Basically I’m trying to make a bunch of boxes bounce around the screen and bounce off of each other if they collide. I’ve written a bit of the code which I’ll share below, but I have no clue were to begin with the collision, boundaries and adding more boxes to my list.
def setup():
global boxes, numBoxes
global canvasWidth, canvasHeight
global i
i = 6
size(800,600)
background(0)
boxes = [[6, 6], [787,11]]
numBoxes = len(boxes)
canvasWidth = 799
canvasHeight = 599
def draw():
global boxes, numBoxes
background(0)
rect(378,250,100,100)
global canvasWidth, canvasHeight
for i in range(0,1):
boxes[i][0] += 3
boxes[i][1] += 2
rect(boxes[i][0], boxes[i][1], 100, 100)
Any help or advice would be greatly appreciated, thank you!
Yeah I added all of my boxes to a nested list and then I just looped through the list (using a for loop), and if they collided from any of the sides then they would move the opposite direction. I implemented the code that tabreturn sent to my code.