import pygame class Tower(): def __init__(self,x,y,grid,ttype='null',elem=0): self.x,self.y,self.grid=x,y,grid self.type=ttype self.elem=elem self.target=Mouse() def draw(self,screen): x,y,s=self.grid.cell_to_real(self.x,self.y) sprites.get(self.type,'null')(screen,x,y,s,self) def update(self,events): self.target.update(events) if self.target: self.tx,self.ty=self.target.x,self.target.y class Mouse(): def update(self,events): self.x,self.y=pygame.mouse.get_pos() shots={} def mkshot(funky): shots[funky.__name__]=funky return funky sprites={} def mksprite(funky): sprites[funky.__name__]=funky return funky @mksprite def null(screen,x,y,s,t): pygame.draw.rect(screen, (90,90,90), (x,y,s,s)) @mkshot def null(*args): pass @mksprite def cannon(screen,x,y,s,t): pygame.draw.rect(screen, (90+165*(t.elem==0),90+165*(t.elem==1),90+165*(t.elem==2)), (x,y,s,s)) pygame.draw.line(screen, (255,0,0), (x+s/2,y+s/2),(t.tx,t.ty)) @mkshot def cannon(*args): pass