from common import * class Enemy: def __init__(self, text, x, y): self.x = x self.y = y self.text = text self.matched = 0 def draw(self): txt = font.render(self.text[0:self.matched], True, (255, 0, 0)) txtRest = font.render(self.text[self.matched:], True, (255, 255, 255)) width = txt.get_width() + txtRest.get_width() screen.blit(txt, (self.x - width / 2, self.y)) screen.blit(txtRest, (self.x - width / 2 + txt.get_width(), self.y)) def update(self): self.y += 1 if self.y > height: objects.remove(self) def typed(self, key): if not self.text: return if self.text[self.matched] != key: self.matched = 0 if self.text[self.matched] == key: self.matched += 1 if self.matched == len(self.text): self.text = "" shoot(self, self.x, self.y) return True def hit(self): objects.remove(self) explode(self.x, self.y, (255, 0, 0), 30) class Fighter(Enemy): def __init__(self, text, x, y): super().__init__(text, x, y) def draw(self): if self.y < 0: return super().draw() pygame.draw.lines(screen, (0, 255, 0), True, ((self.x, self.y), (self.x + 10, self.y - 20), (self.x - 10, self.y - 20), )) class Boss(Enemy): def __init__(self, text, x, y): super().__init__(text, x, y) def draw(self): if self.y < 0: return super().draw() pygame.draw.lines(screen, (0, 255, 0), True, ((self.x - 20, self.y - 20), (self.x - 10, self.y), (self.x , self.y - 20), (self.x + 10, self.y), (self.x + 20, self.y - 20), ))