Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- from random import randint
- bub_speed=list()
- min_bub_r=10
- max_bub_r=30
- max_bub_spd=10
- gop=100
- HEIGHT=500
- WIDTH=800
- fereastra=Tk()
- fereastra.title('Distrugatorul de bule')
- plansa=Canvas(fereastra,width=WIDTH,height=HEIGHT,bg='darkblue')
- plansa.pack()
- ship_id=plansa.create_polygon(5,5,5,25,30,15,fill='red')
- ship_id2=plansa.create_oval(0,0,30,30,outline='red')
- ship_r=15
- mid_x=WIDTH/2
- mid_y=HEIGHT/2
- plansa.move(ship_id,mid_x,mid_y)
- plansa.move(ship_id2,mid_x,mid_y)
- ship_dist=10
- def move_ship(event):
- if event.keysym=='Up':
- plansa.move(ship_id,0,-ship_dist)
- plansa.move(ship_id2,0,-ship_dist)
- elif event.keysym=='Down':
- plansa.move(ship_id,0,ship_dist)
- plansa.move(ship_id2,0,ship_dist)
- elif event.keysym=='Left':
- plansa.move(ship_id,-ship_dist,0)
- plansa.move(ship_id2,-ship_dist,0)
- elif event.keysym=="Right":
- plansa.move(ship_id,ship_dist,0)
- plansa.move(ship_id2,ship_dist,0)
- plansa.bind_all('<Key>',move_ship)
- def create_buble():
- x=WIDTH+gap
- y=randint(0,height)
- r=randint(min_bub_r,max_bub_r)
- id1=plansa.create_oval(x-r,y-r,x+r,y+r,outline='white')
- bub_id.append(id1)
- bub_r.append(r)
- bub_speed.append(randint(1,max_bub_spd))
- def move_bubbles():
- for i in range(len(bub_id)):
- plansa.move(bub_id[i],-bub_speed[i],0)
- from time import sleep,time
- bub_chance=10
- while True:
- if randint(1,bub_chance)==1:
- create_bubble()
- move_bubbles()
- fereastra.update()
- sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement