Hello PsychoPy Discourse community!
Forgive my spaghetti code. Hopefully not too annoying.
I’m coding a game where I am a character trying to dodge obstacles. I want to remove all of the randomly placed obstacles upon my collision with any one of them and replace these with newly positioned obstacles.
Right now I have a messy for loop embedded within a while loop that, upon registering an overlap/collision, draws new obstacles without discarding the old ones. How did I fix this?
Snip-it of my existing code (only most relevant parts included):
me_y = -600 # my initial vertical position while True: for i in range(len(obs_pos)): # indexes all x,y coordinates of obstacle positions obs_circle.pos = [obs_pos[i], obs_pos[i]] # updates position of obstacle obs_circle.draw() if me_circle.overlaps(obs_circle): # if I interact with any of the obstacles me_y = -600 # put my character back to start new_positions() # call the function that creates new positions for obstacles # ... code in between that does other stuff... # me_circle.draw() win.flip()
So as you can see, I don’t have a way to remove the old obstacles from the screen. I’m not fully there to understand how I can fix this, which is why I am reaching out to you lovely folks. Let me know if you have the answer! Much appreciates