Advertisement
THOMASBOIMAH07778730

novawebdev

Oct 1st, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. from gasp import *
  2. from random import randint
  3.  
  4.  
  5. def place_robot():
  6.  
  7. global robot_x, robot_y, robot_shape
  8.  
  9. robot_x = randint(0, 53)
  10. robot_y = randint(0, 57)
  11. robot_shape = Box ((5, 5), 5, 5)
  12.  
  13. def place_player():
  14.  
  15. global player_x, player_y, player_shape
  16.  
  17. player_x = randint(0, 63)
  18. player_y = randint(0, 47)
  19. player_shape = Circle((10 * player_x + 5, 10 * player_y + 5), 5, filled=True)
  20.  
  21.  
  22.  
  23. def move_player():
  24. global player_x, player_y, player_shape
  25.  
  26. key = update_when('key_pressed')
  27.  
  28. if key =='h' and player_x > 0:
  29. player_x -=1
  30.  
  31. elif key == 'j' and player_y < 47:
  32. player_y -= 1
  33.  
  34. elif key == 'k' and player_y > 0:
  35. player_y += 1
  36.  
  37. elif key == 'l' and player_x < 63:
  38. player_x += 1
  39. # Custom diagonal keys for laptops without numeric keypad
  40. elif key == 'u': # move left and up
  41. if player_x > 0:
  42. player_x -= 1
  43. if player_y < 47:
  44. player_y += 1
  45. elif key == 'i': # move right and up
  46. if player_x < 63:
  47. player_x += 1
  48. if player_y < 47:
  49. player_y += 1
  50. elif key == 'n': # move left and down
  51. if player_x > 0:
  52. player_x -= 1
  53. if player_y > 0:
  54. player_y -= 1
  55. elif key == 'm': # move right and down
  56. if player_x < 63:
  57. player_x += 1
  58. if player_y > 0:
  59. player_y -= 1
  60. move_to(player_shape, (10 * player_x + 5, 10 *player_y + 5))
  61.  
  62. def move_robot():
  63. global robot_x, robot_y, robot_shape
  64.  
  65. key = update_when('key_pressed')
  66. if key == 'h' and robot_x > 0:
  67. robot_x -= 4
  68. elif key == 'j' and robot_y < 47:
  69. robot_y -= 4
  70. elif key == 'k' and robot_y > 0:
  71. robot_y += 4
  72. elif key == 'l' and robot_x < 63:
  73. robot_x += 4
  74. # Custom diagonal keys for laptops without numeric keypad
  75. elif key == 'u': # move left and up
  76. if robot_x > 0:
  77. robot_x -= 1
  78. if robot_y < 47:
  79. robot_y += 1
  80. elif key == 'i': # move right and up
  81. if robot_x < 63:
  82. robot_x += 1
  83. if robot_y < 47:
  84. robot_y += 1
  85. elif key == 'n': # move left and down
  86. if robot_x > 0:
  87. robot_x -= 1
  88. if robot_y > 0:
  89. robot_y -= 1
  90. elif key == 'm': # move right and down
  91. if robot_x < 63:
  92. robot_x += 1
  93. if robot_y > 0:
  94. robot_y -= 1
  95.  
  96. move_to( robot_shape, (10 * robot_x + 5, 10 * robot_y + 5))
  97.  
  98. def check_collisions():
  99. if player_x == robot_x and player_y == robot_y:
  100. print('you have been caught!')
  101.  
  102.  
  103.  
  104. begin_graphics()
  105. finished = False
  106.  
  107. place_robot()
  108. place_player()
  109.  
  110. while not finished:
  111. move_player()
  112. move_robot()
  113. check_collisions()
  114.  
  115.  
  116. end_graphics()
  117.  
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement