8 # FX is the abstract base class for all "effects" objects. They have two
11 # 1) The FX base class sets up self.screen so that you can draw to the
12 # screen. It is then important to call FX.__init__(self) in your
14 # 2) Each FX object has a draw(self,t) method that draws itself to the
15 # screen (possibly with appearance based on the current time).
19 self.screen = pygame.display.get_surface()
26 self.screen.fill((0,0,0))
31 def __init__(self,file,location=(0,0)):
33 self.surface = pygame.image.load(file).convert_alpha()
34 self.location = location
37 if self.align == ALIGN_RIGHT:
38 rl = (self.location[0] - self.surface.get_width(),self.location[1])
39 self.screen.blit(self.surface,rl)
41 self.screen.blit(self.surface,self.location)
44 def __init__(self,text,font,size,location=(0,0),color=(255,255,255)):
46 self.font = pygame.font.Font(font,size)
47 self.location = location
51 def settext(self,text):
52 f = self.font.render(text,True,(0,0,0))
53 self.surface = pygame.surface.Surface((f.get_width()+2,f.get_height()+2)).convert_alpha()
54 self.surface.fill((0,0,0,0))
55 self.surface.blit(f,(2,2))
56 f = self.font.render(text,True,self.color)
57 self.surface.blit(f,(0,0))
62 def __init__(self,location=(0,0),glyphdir='gfx/glyph'):
65 l = os.listdir(glyphdir)
68 textglyphs[c] = pygame.image.load(os.path.join(glyphdir,g)).convert_alpha()
69 self.location = location
72 def settext(self,str):
78 if textglyphs.has_key(c):
79 self.screen.blit(textglyphs[c],(x,y))
80 x += textglyphs[c].get_width()
85 def __init__(self, pointlist, color, period, maxwidth = 8, minwidth = 1):
90 self.maxwidth = maxwidth
92 self.minwidth = minwidth
93 self.pointlist = pointlist
97 w = (self.maxwidth - 1) * math.exp(self.r * (t % self.period)) + self.minwidth
98 pl = map(lambda x: (x[0] + self.location[0],x[1] + self.location[1]),self.pointlist)
99 pygame.draw.lines(self.screen,self.color, 0, pl, int(w))
101 class ColumnPulse(FX):
104 def __init__(self,rect,color):
113 s = pygame.Surface(self.rect.size).convert_alpha()
116 for n in range(0,self.rect.height):
117 c = (self.color[0],self.color[1],self.color[2],float(n) / self.rect.height * a * 255.0)
118 w = (self.rect.width / 2) * (1.0 - a)
119 pygame.draw.line(s,c,(w,n),(self.rect.width-w,n))
120 #s.fill(c,(0,n,self.rect.width,1))
124 a = math.exp(self.r * t)
132 self.st = pygame.time.get_ticks()
136 dt = pygame.time.get_ticks() - self.st
138 self.screen.blit(self.surf[0],self.rect)
141 if n > len(self.surf) - 1:
143 self.screen.blit(self.surf[n],self.rect)
145 class PlaneScroll(FX):
148 def __init__(self,file,direction,zoom=1.0,alpha=1.0):
150 ts = pygame.image.load(file)
152 ts = pygame.transform.rotozoom(ts, 0.0, zoom)
153 self.surface = ts.convert()
155 if alpha < 1.0 and alpha >= 0.0:
156 self.surface.set_alpha(int(alpha * 255))
157 self.direction = direction
160 w = self.surface.get_width()
161 h = self.surface.get_height()
162 location = self.surface.get_rect()
163 location.size = (640,480)
164 location.move_ip((t * self.direction[0]) % w, (t * self.direction[1]) % h)
165 self.screen.blit(self.surface,(0,0),location)
166 if location.right > w:
167 x = 640 - (location.right - w)
168 self.screen.blit(self.surface,(x,0),(0,location.top,640,480))
169 if location.bottom > h:
170 y = 480 - (location.bottom - h)
171 self.screen.blit(self.surface,(0,y),(location.left,0,640,480))
172 if location.bottom > h and location.right > w:
173 # x and y must be calculated from above two tests
174 self.screen.blit(self.surface,(x,y),(0,0,640,480))