Advertisement
moseechev

Untitled

Jan 20th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. from tkinter import *
  2. import random
  3.  
  4. #Globals
  5. WIDTH = 800
  6. HEIGHT = 600
  7. SEG_SIZE = 20
  8. IN_GAME = True
  9.  
  10. def create_block():
  11. global BLOCK
  12. posx=SEG_SIZE*random.randint(1,(WIDTH-SEG_SIZE)/SEG_SIZE)
  13. posy=SEG_SIZE*random.randint(1,(HEIGHT-SEG_SIZE)/SEG_SIZE)
  14. BLOCK=c.create_oval(posx,posy, posx+SEG_SIZE,posy+SEG_SIZE, fill='red')
  15.  
  16. class Snake(object):
  17. def __init__(self,segments):
  18. self.segments=segments
  19. self.mapping={"Down":(0,1),
  20. "Right":(1,0),
  21. "Left":(-1,0),
  22. "Up":(0,1)}
  23. self.vector=self.mapping["Right"]
  24. class Segment(object):
  25. def __init__(self,x,y):
  26. self.instance=c.create_rectangle(x,y, x+SEG_SIZE,y+SEG_SIZE,fill="white")
  27.  
  28. #Setting up window
  29. root=Tk()
  30. root.title("Snake")
  31. c=Canvas(root,width=WIDTH,height=HEIGHT,bg="#003300")
  32. c.grid()
  33. # catch keypressing
  34. c.focus_set()
  35. segments=[Segment(SEG_SIZE,SEG_SIZE),
  36. Segment(SEG_SIZE*2,SEG_SIZE),
  37. Segment(SEG_SIZE*3,SEG_SIZE)]
  38. create_block()
  39. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement