Game Help! Pygame! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Game Help! Pygame!

PolofiestaPolofiesta Posts: 1Member
Hey, I am programming a game called Traffic Rush and I am a begginer programmer that started not to long ago. The game is with pygame and just an intersection with four cars or animations riding across it over and over. When you press your key up the car going up will move much faster to the end etc. I was wondering how to make my program detect collisions with these images. I have searched all over the internet with things such as "Sprites" which I dont know what that is. There are many algorithms I see but I am confused.I figured out the concept where you draw a rectangle around your image and go on from there. But I do not know how to execute this? Please help. I want the car to go to its original postition if the cars hit eachother. Here are my pictures:

[img=image]

http://www.photoshop.com/users/polofiesta/assets/68d36bf184704b67ace0e826db99e2f9

[img=http://www.photoshop.com/users/polofiesta/assets/469c4ec09e9e49e39fac9e98df050ade]

http://www.photoshop.com/users/polofiesta/assets/469c4ec09e9e49e39fac9e98df050ade

Comments

  • alextigernickalextigernick Posts: 2Member
    Its real easy you're not looking in the right place look on pygame website under rect rect.collide and things like that the rect has the image not the sprite.
  • ProgaProga Posts: 1Member
    Hello! (I am new here so don't flame me please!)

    This is a problem I my self just solved.
    There a few things you have to do first:
    1:) first make the image a "rect" by doing the following:
    a:) make your image
    b:) make a new variable and set it as IMAGE_rect = image.get_rect()
    that will make your image a rect! [almost all physics in pygame have to do with rect]


    Type in the following:

    if IMAGE1.colliderect(IMAGE2) == True:
    speed[0] = -speed[0]
    if IMAGE2.colliderect(IMAGE2) == True:
    speed2[0] = -speed[0]

    so basically if IMAGE1 collides with the image in the () [if it's "True"] do something. In this case, move backwards.

    There you go! (If I really suck at teaching look at this page: http://www.pygame.org/docs/tut/intro/intro.html and this one: http://www.pygame.org/docs/ref/rect.html)


    Hope this helps!

    -Proga
Sign In or Register to comment.