Nov-23-2017, 10:43 AM
import tkinter,random,time class game(): def __init__(self): self.canvas= tkinter.Canvas( width=500, height=700, bg='white' ) self.canvas.pack() self.x=250 self.y=400 self.interval=0.01 self.z=800 self.x1=random.randint(0, 500) self.y1=random.randint(0, 800) self.r=random.randint(5, 16) self.canvas.bind_all('<Left>',self.moveleft) self.canvas.bind_all('<Right>',self.moveright) self.canvas.bind_all('<Up>',self.moveup) self.canvas.bind_all('<Down>',self.movedown) self.canvas.create_oval(self.x-7,self.y+300,self.x+7,self.y+270,tags='plane') self.canvas.create_oval(self.x-14,self.y+280,self.x+14,self.y+290,tags='plane') self.obstacles() self.cycle() self.canvas.mainloop() def obstacles(self): self.x2=random.randint(0, 500) self.y2=random.randint(0, 800) self.r1=random.randint(5, 16) self.canvas.create_rectangle(self.x2-self.r1,self.y2-self.z-self.r1,self.x2+self.r1,self.y2-self.z+self.r1,fill='red',tags='obs') self.canvas.after(200,self.obstacles) def cycle (self) : while True: time.sleep(self.interval) self.canvas.move('obs', 0, +2) tagged_objects = self.canvas.find_withtag('obs') overlapping_objects = self.canvas.find_overlapping(*self.canvas.coords('plane')) for item in overlapping_objects: if item in tagged_objects: return False self.canvas.update() def moveleft(self,event): self.canvas.move('plane', -15, 0) def moveright(self,event): self.canvas.move('plane', 15, 0) def movedown(self,event): self.canvas.move('plane', 0, 15) def moveup(self,event): self.canvas.move('plane', 0, -15) game()can u remake this so it will move to my mouse?