Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | Source Code | 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.     if key == 'h' and player_x > 0:
  19.         player_x -= 1
  20.     elif key == 'j' and player_y < 47:
  21.         player_y -= 1
  22.     elif key == 'k' and player_y > 0:
  23.         player_y += 1
  24.     elif key == 'l' and player_x < 63:
  25.         player_x += 1
  26.  
  27.     move_to(player_shape, (10 * player_x + 5, 10 * player_y + 5))
  28.  
  29.  
  30. begin_graphics()
  31. finished = False
  32.  
  33. place_player()
  34.  
  35. while not finished:
  36.     move_player()
  37.  
  38. end_graphics()
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement