Skip to main content
GameDev.net gamedev.net
🔒 Locked

Collect Grass

Started by LeafieTail Mar 29, 2011 at 2:32 AM 1 replies 950+ views
Original Post
LeafieTail
LeafieTail
Hello. I am working on a game in python which is based off a tutorial by Lusikkamage. I have almost finished it but when I try and use collision between the player and the grass it doesn't work. When you move the player with the mouse the grass scatters all over the screen. I imported random and tried to make it work but nothing is working. HELP PLEASE. P.S. I use pygame with python, here is the code. Thanks

if (playerRect.colliderect(grassRect)):
Gx = random.randint(1,640)
Gy = random.randint(1,480)

screen.blit(grass, (Gx, Gy))
Hodgman
Hodgman
There's not much for us to go on here.
I have almost finished it but when I try and use collision between the player and the grass it doesn't work.
I imported random and tried to make it work but nothing is working. HELP PLEASE. P.S. I use pygame with python, here is the code.
Are Gx/Gy local variables? Where do they come from? What is their value if the 'if' statement isn't entered? What does "doesn't work" mean? What is it supposed to do?
When you move the player with the mouse the grass scatters all over the screen.local? variable position = ???
if (player is colliding with grass):
position = random number
draw grass at position
[/quote]What is that code supposed to do? It looks like that code says:
If the player isn't touching the grass, draw it at it's default (?) position.
if the player is touching the grass, draw it at a random position (randomly chosen each frame).

I'm guessing that while the player is standing where the grass was, it 'scatters' to a new position every frame?
I'm guessing that you don't want it to continuously choose random positions? Is that the 'not working' bit? What's supposed to happen when the player collides with the grass?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.