class Brick(Sprite): sprite = load_sprite(brick) SHAPE = sprite.shape def __init__(self, scene, *args, **kwargs): super(Brick, self).__init__(self.sprite, scene, *args, **kwargs) self.fill_foreground((255, 0, 0)) self.alpha = True def hit(self, ball): if ball.thru: self.deactivate()
class Alien(StatefulMixin, Sprite): sprite = load_sprite(alien[1]) SHAPE = sprite.shape def __init__(self, scene, *args, **kwargs): state = { 'done': 0, 'color': [255, 255, 66] } kwargs['state'] = state super(Alien, self).__init__(self.sprite, scene, *args, **kwargs) self.fill_foreground(self.state['color']) def update_sprite(self): self.fill_foreground(self.state['color']) def hit(self, targeet): self.state['color'][1] -= 20 if self.state['color'][1] < 200 and self.state['done'] == 0: self.scene.add_layer() self.state['done'] += 1 elif self.state['color'][1] < 100 and self.state['done'] == 1: self.scene.add_layer() self.state['done'] += 1 elif self.state['color'] <= 0: self.deactivate() self.update_sprite() def update(self, timestamp): for target in self.scene.iter_balls(): if (target.top == self.bottom or collides(target, self) and target.vy < 0) \ or (target.bottom == self.top or collides(target, self) and target.vy > 0): if target.left > self.left - 1 and target.right < self.right + 2: self.hit(target) target.switch_y() elif target.left == self.left - 1 and target.vx > 0: self.hit(target) target.switch_x() target.switch_y() elif target.left == self.right + 1 and target.vx < 0: self.hit(target) target.switch_x() target.switch_y() elif (target.left == self.right or collides(target, self) and target.vx < 0) or \ (target.right == self.left or collides(target, self) and target.vx > 0): if self.top <= target.top <= self.bottom: self.hit(target) target.switch_x() if timestamp % 50 == 0: self.scene.add_alien_bullet(Pos([self.bottom, self.left + self.width // 2]), Vel([1, 0]))
class AlienBullet(Bullet): sprite = load_sprite(bullet[0]) SHAPE = sprite.shape def __init__(self, *args, **kwargs): super(AlienBullet, self).__init__(*args, **kwargs) self.vel = Vel([1, 0]) def update(self, timestamp): if self.bottom == self.scene.paddle.top and \ self.scene.paddle.left <= self.left <= self.scene.paddle.right: self.scene.game.lives -= 1 self.move(self.vel)
class PaddleBullet(Bullet): sprite = load_sprite(bullet[1]) SHAPE = sprite.shape def __init__(self, *args, **kwargs): super(PaddleBullet, self).__init__(*args, **kwargs) self.vel = Vel([-1, 0]) def update(self, timestamp): for target in self.scene.iter_bricks(): if self.top == target.bottom: self.deactivate() return self.move(self.vel)
class SpeedBall(BallPowerUp): sprite = load_sprite(powerup['mul']) SHAPE = sprite.shape def mutate(self, ball, timestamp): ball.set_mul(timestamp)
class ThruBall(BallPowerUp): sprite = load_sprite(powerup['thru']) SHAPE = sprite.shape def mutate(self, ball, timestamp): ball.set_thru(timestamp)
class ShootPaddle(PaddlePowerUp): sprite = load_sprite(powerup['shoot']) SHAPE = sprite.shape def mutate(self, paddle, timestamp): paddle.set_shoot(timestamp)
class GrabPaddle(PaddlePowerUp): sprite = load_sprite(powerup['grab']) SHAPE = sprite.shape def mutate(self, paddle, timestamp): paddle.set_grab(timestamp)
class LongPaddle(PaddlePowerUp): sprite = load_sprite(powerup['long']) SHAPE = sprite.shape def mutate(self, paddle, timestamp): paddle.set_long(timestamp)
def __init__(self, scene, message, *args, **kwargs): self.sprite = load_sprite(message) super(TextMessage, self).__init__(self.sprite, scene, *args, **kwargs) self.fill_foreground((255, 255, 255)) self.alpha = True