Python

Moderators: None (Apply to moderate this forum)
Number of threads: 477
Number of posts: 1160

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Game Help! Pygame! Posted by Polofiesta on 19 Jan 2011 at 1:47 PM
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:



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



http://www.photoshop.com/users/polofiesta/assets/469c4ec09e9e49e39fac9e98df050ade
Attachment: Traffic Rush.py (2638 Bytes | downloaded 107 times)
Report
Re: Game Help! Pygame! Posted by alextigernick on 25 Mar 2011 at 10:49 AM
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.
Report
Re: Game Help! Pygame! Posted by Proga on 10 May 2011 at 2:37 PM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.