from Tkinter import *
# Faltenisz
class PApp
(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
Pack.config(self)
self.s=0 # Score
self.x=280 # Ball
self.y=5
self.vx=4 #Ball speed
self.vy=4 #Ball speed
self.px=250 #Player
self.py=0
self.w()
self.after(10, self.moveBall)
def w(self):
self.l=Canvas(self,bg='yellow', width="300",heigh="220")
self.l.pack()
self.m=Label(self,relief='groove', text="",anchor="w")
self.m.pack(side='top',fill="x")
self.player= self.l.create_rectangle(self.px, self.py, self.px + 7, self.py + 30,
{"fill" : 'black',"tags":"p1"})
self.ball = self.l.create_rectangle(280, 5, 290, 15,
{"fill":'red',"tags":"ball"})
self.bind_all("<Up>", self.fel)
self.bind_all("<Down>", self.le)
self.bind_all("<B1-Motion>",self.Move)
self.m.configure(text="Score : "+`self.s`)
def Move(self, event):
if CURRENT <> "ball":
self.l.move(CURRENT, 0, event.y-self.py)
self.py=event.y
def fel(self, event):
self.l.move("p1", 0,-10)
self.py=self.py-10
def le(self, event):
self.l.move("p1",0,10)
self.py=self.py+10
def moveBall(self,*args):
if (self.x+10 == self.px) and (self.vx < 0) and (self.py - 11 < self.y) and (self.py + 36 > self.y):
self.s=self.s+1
self.m.configure(text ="Score : "+`self.s`)
self.vx=self.vx * -1
if (self.x < 4 )or(self.x>288) :
self.vx=-1.0 * self.vx
if (self.y > 211) or (self.y < 4):
self.vy=-1.0 * self.vy
self.x=self.x - self.vx
self.y=self.y + self.vy
self.l.move("ball",-self.vx,self.vy )
self.after(10, self.moveBall)
if __name__=='__main__':
# root = Tk()
app = PApp()
app.mainloop()
Nincsenek megjegyzések:
Megjegyzés küldése