[Tutor] Livewires questions

Tonu Mikk tmikk at umn.edu
Thu Jul 26 03:07:16 CEST 2007

Thanks for offering to help!  I am following the Livewires exercise 
(attached file "5-robots.pdf").  I have gotten as far as page 7.  
Attached is also my code so far in robotsarecoming-teleport.py. 

Question 1.  I was checking for collision of a robot and player first in 
this way:

def check_collisions():
    if player_x == robot_x+0.5 and player_y == robot_y+0.5:
       print 'You have been caught'

This was working fine.  I then tried to create a definition like this:
def collided():
    player_x == robot_x+0.5 and player_y == robot_y+0.5

and then check for collisions in this way (as in my code):
def check_collisions():
    if collided() == 1:
        print 'You have been caught'

But this isn't printing out anything when the player and robot collide.  
I think I need to pass a variable of collided somehow, but I am not sure 
how.  I also tried following:
def check_collisions():
    if collided()
       print 'You have been caught'
but this isn't working either.

Question 2.  I created a if statement to check if the "t" key is pressed 
on a keyboard.  If it is, I want the player to be placed on another 
location on the grid.  However nothing happens when I press the "t" 
key.  I am not sure why.

Question 3.  I think there is something strange about how I check that 
my player is within the boundaries of the grid.  When it gets close to 
the edges of the grid, it can sometimes disappear past it even though I 
thought I had prevented this from happening.

Thank you again for looking at this.  The attached bit of code has taken 
a long time to create.  I admire all who can program :-).



-------------- next part --------------
A non-text attachment was scrubbed...
Name: 5-robots.pdf
Type: application/pdf
Size: 89939 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070725/75d75458/attachment-0001.pdf 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: robotsarecoming-teleport.py
Url: http://mail.python.org/pipermail/tutor/attachments/20070725/75d75458/attachment.asc 

More information about the Tutor mailing list