April 6th, 2005, 09:01 AM
im creating a snake game in python, having trouble with a fish.gif collision detection:
here is my function, the problem i am having is the last if statement (if rat_count > 0) the collidepoint is being run despite whether the coords match or not, so the collision detection is not working. any ideas?
def display_rat(screen, back):
rat_pos = 
global rect, X_random, Y_random, rat_count
if (rat_count < 1 ):
X_random = random.randint(0,640)
Y_random = random.randint(0,480)
rect = screen.blit(RAT, [X_random,Y_random]) # draw a random rat.
rat_pos.append(rect) #remember rat position for loop.
rat_count =+ 1 #this is created to ensure the computers know there is a rat
#this is done straight away after the rat is created - while a rat is there this not
#repeted - this is to get around the randomizing of the X and Y variables, this way they
if rat_count > 0:
for rect in rat_pos:
screen.blit(back, rect, rect) # cover up the rect from the corresponding bit of the background
print "fish hit"
rat_count = 0
April 6th, 2005, 08:53 PM
Your problem is exemplified by the following code:
Originally Posted by punkboii
You can fix the bug if you read the documentation for the if statement.
if x < 1:
print "x is now less than 1"
x = 1
if x > 0:
print "x is now greater than 0"
x = 0