I'm making a game with Pygame, and now I have two problems:
- don't know how to make for objects looping back to the right edge when hitting the left edge
- I don't understand how to write collides between objects correctly(now its work incorrect)
Here is my code: It's a simple Scrolling Game where a player tries to avoid "harm" and collect "benefit". The Player stands at the left side and can move up and down, "harm" and "benefit" objects move from the right to the left
here I think the problem with loop back to the right edge
if len(enemies) == 0:
wave_length += 1
for i in range(wave_length):
enemy = Enemy(random.randrange(500, 700), random.randrange(0, HEIGHT-100), random.choice(["1","2","3"]))
enemies.append(enemy)
if len(fruits) == 0:
wave_length += 1
for i in range(wave_length):
food = Food(random.randrange(500, 700), random.randrange(100, HEIGHT-100), random.choice(["one","two","three"]))
fruits.append(food)
here is problems with crushing objects
for enemy in enemies[:]:
enemy.move(enemy_val)
if enemy.x + enemy.get_width() == player.x + player.get_width():
lives -=1
enemies.remove(enemy)
for food in fruits[:]:
food.move(food_val)
if food.x + food.get_width() == player.x + player.get_width():
score += 1
fruits.remove(food)