Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_basic_run_and_jump.py
- # multi-key action not supported?
- from Tkinter import *
- from random import randint
- count = 0
- size = 32
- ground = 600
- displ_obst = 10
- pos = [96, 568]
- square_pos = [pos[0]-size, pos[1], pos[0]+size, pos[1]]
- jump = [0,0]
- randomized = randint(1286, 1768)
- pos_obst = [randomized, 536, randomized + randint(16, 64), 600]
- def move(event):
- global buffer, square_pos, pos_obst
- if (event.char == "z"):
- square_pos[0] -= displ_obst
- if (event.char == "x"):
- square_pos[0] += displ_obst
- if (event.char == "c") and (square_pos[1] >= 600-size):
- jump[1] = -12
- def display():
- global square_pos, size, charac, buffer, pos_obst, count
- liste = [square_pos[0], square_pos[1], square_pos[2], square_pos[3]]
- jump[1] += 0.3
- if (square_pos[1] > ground-size):
- square_pos[1] = ground-size
- jump[1] = 0
- else:
- square_pos[1] += jump[1]
- charac.destroy()
- charac = Canvas(root, width = 1280, height = 720, bg = "cyan", highlightthickness = "0")
- charac.create_rectangle(square_pos[0], square_pos[1], square_pos[0]+size, square_pos[1]+size, fill ="white")
- charac.create_rectangle(0, 720, 1280, 600, fill ="brown")
- charac.grid()
- root.after(20, display)
- root = Tk()
- root.geometry("1280x720+0+0")
- ground = 600
- x = 0
- root.bind('<Key>', move)
- charac = Canvas(root, width = 1280, height = 720, bg = "cyan")
- display()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement