Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. from tkinter import*
  2. from random import randint
  3. bub_speed=list()
  4. min_bub_r=10
  5. max_bub_r=30
  6. max_bub_spd=10
  7. gop=100
  8. HEIGHT=500
  9. WIDTH=800
  10. fereastra=Tk()
  11. fereastra.title('Distrugatorul de bule')
  12. plansa=Canvas(fereastra,width=WIDTH,height=HEIGHT,bg='darkblue')
  13. plansa.pack()
  14.  
  15. ship_id=plansa.create_polygon(5,5,5,25,30,15,fill='red')
  16. ship_id2=plansa.create_oval(0,0,30,30,outline='red')
  17. ship_r=15
  18. mid_x=WIDTH/2
  19. mid_y=HEIGHT/2
  20. plansa.move(ship_id,mid_x,mid_y)
  21. plansa.move(ship_id2,mid_x,mid_y)
  22.  
  23. ship_dist=10
  24. def move_ship(event):
  25. if event.keysym=='Up':
  26. plansa.move(ship_id,0,-ship_dist)
  27. plansa.move(ship_id2,0,-ship_dist)
  28. elif event.keysym=='Down':
  29. plansa.move(ship_id,0,ship_dist)
  30. plansa.move(ship_id2,0,ship_dist)
  31. elif event.keysym=='Left':
  32. plansa.move(ship_id,-ship_dist,0)
  33. plansa.move(ship_id2,-ship_dist,0)
  34. elif event.keysym=="Right":
  35. plansa.move(ship_id,ship_dist,0)
  36. plansa.move(ship_id2,ship_dist,0)
  37. plansa.bind_all('<Key>',move_ship)
  38.  
  39. def create_buble():
  40. x=WIDTH+gap
  41. y=randint(0,height)
  42. r=randint(min_bub_r,max_bub_r)
  43. id1=plansa.create_oval(x-r,y-r,x+r,y+r,outline='white')
  44. bub_id.append(id1)
  45. bub_r.append(r)
  46. bub_speed.append(randint(1,max_bub_spd))
  47.  
  48. def move_bubbles():
  49. for i in range(len(bub_id)):
  50. plansa.move(bub_id[i],-bub_speed[i],0)
  51.  
  52. from time import sleep,time
  53. bub_chance=10
  54. while True:
  55. if randint(1,bub_chance)==1:
  56. create_bubble()
  57. move_bubbles()
  58. fereastra.update()
  59. sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement