0

I'm creating a game where the players character always stays in the centre of the screen and the surrounding walls change position instead, like many top-down games.

My issue is that I have a list of the walls pygame.Rects but i cannot figure out a way to make the collisions works correctly with the static player. I have variables like so

walls = [pygame.Rect([0, 0, 20, 20]), ...]
player = pygame.Rect([100, 100, 20, 20])

where walls contains all the walls of the current level. How do I make it so when the player collides with one of these rects it adjusts correctly and stops all the other walls from moving as well. The position of the players rect never changes and hence must always be [100, 100] but the walls positions do change.

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
adammoyle
  • 199
  • 1
  • 13

1 Answers1

2

Don't move the walls. Move the player. Then when you draw all your game objects, just subtract the coordinates of the player and add (100, 100) to give it the appearance of the player not moving. Your game model should always represent the actual state of your game, and rendering considerations should generally occur at render time only. .

Blake O'Hare
  • 1,863
  • 12
  • 16