Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gasp import *
- from random import randint
- def place_robot():
- global robot_x, robot_y, robot_shape
- robot_x = randint(0, 47)
- robot_y = randint(0, 63)
- robot_shape = Box((5, 5), 10, 10 )
- def place_player():
- global player_x, player_y, player_shape
- player_x = randint(0, 63)
- player_y = randint(0, 47)
- player_shape = Circle((10 * player_x + 5, 10 * player_y + 5), 5, filled = True)
- def move_player():
- global player_x, player_y, Player_shape
- key = update_when('key_pressed')
- if key == 'h' and player_x > 0:
- player_x -= 1
- elif key == 'j' and player_y < 47:
- player_y -= 1
- elif key == 'k' and player_y > 0:
- player_y += 1
- elif key == 'l' and player_x < 63:
- player_x += 1
- # Custom diagonal keys for laptops without numeric keypad
- elif key == 'u': # move left and up
- if player_x > 0:
- player_x -= 1
- if player_y < 47:
- player_y += 1
- elif key == 'i': # move right and up
- if player_x < 63:
- player_x += 1
- if player_y < 47:
- player_y += 1
- elif key == 'n': # move left and down
- if player_x > 0:
- player_x -= 1
- if player_y > 0:
- player_y -= 1
- elif key == 'm': # move right and down
- if player_x < 63:
- player_x += 1
- if player_y > 0:
- player_y += 1
- move_to( player_shape, (10 * player_x + 5, 10 * player_y + 5))
- def move_robot():
- global robot_x, robot_y, robot_shape
- key = update_when('key_pressed')
- if key == 'h' and robot_x > 0:
- robot_x += 1
- elif key == 'j' and robot_y < 47:
- robot_y += 1
- elif key == 'k' and robot_y > 0:
- robot_y -= 1
- elif key == 'l' and robot_x < 63:
- robot_x -= 1
- # Custom diagonal keys for laptops without numeric keypad
- elif key == 'u': # move left and up
- if robot_x > 0:
- robot_x += 1
- if robot_y < 47:
- robot_y -= 1
- elif key == 'i': # move right and up
- if robot_x < 63:
- robot_x += 1
- if robot_y < 47:
- robot_y -= 1
- elif key == 'n': # move left and down
- if robot_x > 0:
- robot_x -= 1
- if robot_y > 0:
- robot_y -= 1
- elif key == 'm': # move right and down
- if robot_x < 63:
- robot_x -= 1
- if robot_y > 0:
- robot_y -=1
- move_to( robot_shape, (10 * robot_x + 5, 10 * robot_y + 5))
- def collided():
- if player_x == robot_x and player_y == robot_y:
- key = 'you have been caught'
- key_text = Text (key, (320, 240), size=28)
- sleep(30)
- while player and robot != collided:
- place_player = randint(0, 96)
- def safely_place_player():
- place_player()
- while collided():
- place_player()
- begin_graphics()
- finished = False
- place_player()
- place_robot()
- while not finished:
- move_robot()
- move_player()
- collided()
- end_graphics()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement