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, 53)
- robot_y = randint(0, 57)
- robot_shape = Box ((5, 5), 5, 5)
- 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 -= 4
- elif key == 'j' and robot_y < 47:
- robot_y -= 4
- elif key == 'k' and robot_y > 0:
- robot_y += 4
- elif key == 'l' and robot_x < 63:
- robot_x += 4
- # 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 check_collisions():
- if player_x == robot_x and player_y == robot_y:
- print('you have been caught!')
- begin_graphics()
- finished = False
- place_robot()
- place_player()
- while not finished:
- move_player()
- move_robot()
- check_collisions()
- end_graphics()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement