0

My game is like cars are coming from above and player has to dodge it by moving left or right,

  • (x,y) is players postion
  • (enemy_startx,enemy_starty) is enemys position

other variables are obvious

#These are also the crash conditions for the game.
    if y < enemy_starty+enemy_height:
        if x > enemy_startx  and x < enemy_startx + enemy_width or x+(car_width+5) > enemy_startx and x + (car_width+5) < enemy_startx+enemy_width:
             crash()
furas
  • 134,197
  • 12
  • 106
  • 148
CapsLock
  • 9
  • 3
  • 1
    BTW: `pygame` has `pygame.Rect()` to keep object size and position and it has functions to check collisions - `one_rect.colliderect(other_rect)`, `one_rect.collidepoint(mouse_pos)` or `one_rect.collidepoint(other_rect.topleft)` – furas Dec 27 '16 at 00:25
  • pygame doc: [pygame.Rect()](http://pygame.org/docs/ref/rect.html). BTW: [pygame.sprite](http://pygame.org/docs/ref/sprite.html) also has methods to check collisions. – furas Dec 27 '16 at 00:33
  • BTW: [Pygame: Collision by Sides of Sprite](http://stackoverflow.com/questions/20180594/pygame-collision-by-sides-of-sprite) – furas Dec 27 '16 at 00:35
  • Actually i am totally new to this whole programming stuff. Though i get what you are saying but i am not too familiar with sprite and some other basic stuff in pygame. I made this game with nothing but simple functions.Can i send you with email my code and you help me improve it.? Plz. – CapsLock Dec 27 '16 at 04:36
  • you can put code on GitHub on pastebin.org and then put link. You can add email in code. – furas Dec 27 '16 at 06:42

0 Answers0