Advertisement
here2share

# Tk_basic_run_and_jump.py

Jul 24th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # Tk_basic_run_and_jump.py
  2.  
  3. # multi-key action not supported?
  4.  
  5. from Tkinter import *
  6. from random import randint
  7.  
  8. count = 0
  9. size = 32
  10. ground = 600
  11. displ_obst = 10
  12. pos = [96, 568]
  13. square_pos = [pos[0]-size, pos[1], pos[0]+size, pos[1]]
  14. jump = [0,0]
  15. randomized = randint(1286, 1768)
  16. pos_obst = [randomized, 536, randomized + randint(16, 64), 600]
  17.  
  18.  
  19. def move(event):
  20.     global buffer, square_pos, pos_obst
  21.  
  22.     if (event.char == "z"):
  23.         square_pos[0] -= displ_obst
  24.  
  25.     if (event.char == "x"):
  26.         square_pos[0] += displ_obst
  27.  
  28.     if (event.char == "c") and (square_pos[1] >= 600-size):
  29.         jump[1] = -12
  30.  
  31. def display():
  32.     global square_pos, size, charac, buffer, pos_obst, count
  33.  
  34.     liste = [square_pos[0], square_pos[1], square_pos[2], square_pos[3]]
  35.  
  36.     jump[1] += 0.3
  37.  
  38.     if (square_pos[1] > ground-size):
  39.         square_pos[1] = ground-size
  40.         jump[1] = 0
  41.     else:
  42.         square_pos[1] += jump[1]
  43.  
  44.     charac.destroy()
  45.     charac = Canvas(root, width = 1280, height = 720, bg = "cyan", highlightthickness = "0")
  46.     charac.create_rectangle(square_pos[0], square_pos[1], square_pos[0]+size, square_pos[1]+size, fill ="white")
  47.     charac.create_rectangle(0, 720, 1280, 600, fill ="brown")
  48.     charac.grid()
  49.  
  50.     root.after(20, display)
  51.  
  52.  
  53.  
  54.  
  55. root = Tk()
  56. root.geometry("1280x720+0+0")
  57. ground = 600
  58. x = 0
  59.  
  60.  
  61. root.bind('<Key>', move)
  62.  
  63. charac = Canvas(root, width = 1280, height = 720, bg = "cyan")
  64.  
  65.  
  66. display()
  67.  
  68. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement