jelkner

ForThomas2022-10-15

Oct 15th, 2022
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | Fixit | 0 0
  1. from gasp import *
  2. from random import randint
  3.  
  4.  
  5. def place_player():
  6.     global player_x, player_y, player_shape
  7.  
  8.     player_x =  randint(0, 63)
  9.     player_y =  randint(0, 47)
  10.     player_shape = Circle((10 * player_x + 5, 10 * player_y + 5), 5)
  11.  
  12.  
  13. def move_player():
  14.     global player_x, player_y, player_shape
  15.  
  16.     key = update_when('key_pressed')
  17.  
  18.     # Use vim keys for left, down, up, and right
  19.     if key == 'h' and player_x > 0:
  20.         player_x -= 1
  21.     elif key == 'j' and player_y > 0:
  22.         player_y -= 1
  23.     elif key == 'k' and player_y < 47:
  24.             player_y += 1
  25.     elif key == 'i':                   # move right and up
  26.         if player_x < 63:
  27.             player_x += 1
  28.         if player_y < 47:
  29.             player_y += 1
  30.     elif key == 'n':                   # move left and down
  31.         if player_x > 0:
  32.             player_x -= 1
  33.         if player_y > 0:
  34.             player_y -= 1
  35.     elif key == 'm':                   # move right and down
  36.         if player_x < 63:
  37.             player_x += 1
  38.         if player_y > 0:
  39.             player_y -= 1
  40.  
  41.     move_to(player_shape, (10 * player_x + 5, 10 * player_y + 5))
  42.     move_robot()
  43.  
  44.  
  45. def place_robot():
  46.     global robot_x, robot_y, robot_shape
  47.  
  48.     robot_x =  randint(0, 63)
  49.     robot_y =  randint(0, 47)
  50.     robot_shape = Box((10 * robot_x, 10 * robot_y), 10, 10)
  51.  
  52.  
  53. def move_robot():
  54.     global robot_x, robot_y, robot_shape, player_x, player_y
  55.  
  56.     # print(f"robot_x: {robot_x}  player_x: {player_x}")
  57.     # if robot_x > player_x:
  58.     #    robot_x += 1
  59.     print(f"robot_x: {robot_x}")
  60.     if robot_x > 63:
  61.         robot_x = 0
  62.     else:
  63.         robot_x += 1
  64.  
  65.     move_to(robot_shape, (10 * robot_x, 10 * robot_y))
  66.  
  67.  
  68. begin_graphics()
  69. finished = False
  70.  
  71. place_player()
  72. place_robot()
  73.  
  74. while not finished:
  75.     move_player()
  76.  
  77. end_graphics()
  78.  
Advertisement
Add Comment
Please, Sign In to add comment