def __init__(self, sprite_sheet, height, width, delay, speed): """delay is the time (in frames) spent on each image sprite_sheet is the filename of the sprites height, width are the dimensions of the sprite """ AnimatedFacingSprite.__init__(self, sprite_sheet, height, width, delay, speed)
class SpinningBase(State): """State 2: Spins in place for a period of time. In the original game the base should continue to move as in MovingBase, but currently it becomes stationary for simplicity reasons. SpinningBase should not be followable by the shield. Note:SpinningBase.sprite is an AnimatedFacingSprite that only faces NORTH """ def __init__(self, manager, position, target, sprite_sheet, height, width, delay, targ_time, shoot_time): """manager is the root EnemyBase object position is the sprite's rect.center coordinates (taken from the moving state) sprite_sheet, etc are AnimatedFacingSprite args targ_time is the frame (from start) when target direction is taken shoot_time is the frame (from start) when spinner becomes shooter and begins movement """ State.__init__(self, manager) self.sprite = AnimatedFacingSprite(sprite_sheet, height, width, delay, 0) self.sprite.rect.center = position self.target = target self.targ_time = targ_time self.shoot_time = shoot_time self.tick = 0 self.STATE_NUMBER = manager.SPINNING self.IS_FOLLOWABLE = False def update(self): self.sprite.update() self.tick += 1 if self.tick == self.targ_time: self.target_direction = vector.normalize( vector.get_direction(self.sprite.rect.center, self.target.rect.center)) if self.tick == self.shoot_time: self.transition_to(self.manager.SHOOTING) def transition_to(self, new_state_number): if new_state_number == self.manager.SHOOTING: self.manager.start_shooter(self.sprite.rect.center, self.target_direction) return False
class SpinningBase(State): """State 2: Spins in place for a period of time. In the original game the base should continue to move as in MovingBase, but currently it becomes stationary for simplicity reasons. SpinningBase should not be followable by the shield. Note:SpinningBase.sprite is an AnimatedFacingSprite that only faces NORTH """ def __init__(self, manager, position, target, sprite_sheet, height, width, delay, targ_time, shoot_time): """manager is the root EnemyBase object position is the sprite's rect.center coordinates (taken from the moving state) sprite_sheet, etc are AnimatedFacingSprite args targ_time is the frame (from start) when target direction is taken shoot_time is the frame (from start) when spinner becomes shooter and begins movement """ State.__init__(self, manager) self.sprite = AnimatedFacingSprite(sprite_sheet, height, width, delay, 0) self.sprite.rect.center = position self.target = target self.targ_time = targ_time self.shoot_time = shoot_time self.tick = 0 self.STATE_NUMBER = manager.SPINNING self.IS_FOLLOWABLE = False def update(self): self.sprite.update() self.tick += 1 if self.tick == self.targ_time: self.target_direction = vector.normalize(vector.get_direction(self.sprite.rect.center, self.target.rect.center)) if self.tick == self.shoot_time: self.transition_to(self.manager.SHOOTING) def transition_to(self, new_state_number): if new_state_number == self.manager.SHOOTING: self.manager.start_shooter(self.sprite.rect.center, self.target_direction) return False
def __init__(self, manager, position, direction, sprite_sheet, height, width, delay, speed): """manager is the base EnemyBase object position is the rect.center coordinates (taken from the spinning state) direction is a vector """ State.__init__(self, manager) self.sprite = AnimatedFacingSprite(sprite_sheet, height, width, delay, speed) self.sprite.rect.center = position self.direction = direction self.STATE_NUMBER = manager.SHOOTING self.IS_FOLLOWABLE = False
def move(self, direction): """can't move off left or right edges and loops around top and bottom otherwise moves same as AnimatedFacingSprite """ AnimatedFacingSprite.move(self, direction) #if ship is off left or right edges, "nudge" back to the edge if self.rect.left < 0: self.rect.left = 0 if self.rect.right > options.width: self.rect.right = options.width #if ship is off top or bottom edges, teleport to opposite edge if self.rect.top < 0: self.rect.bottom = options.height if self.rect.bottom > options.height: self.rect.top = 0
class ShootingBase(State): """State 3: Moves ("shoots") in the given direction until offscreen. ShootingBase should not be followable by the shield. Note:ShootingBase.sprite is an AnimatedFacingSprite that only faces NORTH """ def __init__(self, manager, position, direction, sprite_sheet, height, width, delay, speed): """manager is the base EnemyBase object position is the rect.center coordinates (taken from the spinning state) direction is a vector """ State.__init__(self, manager) self.sprite = AnimatedFacingSprite(sprite_sheet, height, width, delay, speed) self.sprite.rect.center = position self.direction = direction self.STATE_NUMBER = manager.SHOOTING self.IS_FOLLOWABLE = False def update(self): self.sprite.update() ASprite.move(self.sprite, self.direction) rect = self.sprite.rect if rect.left <= 0 or rect.top <= 0 or rect.bottom >= options.height: self.transition_to(self.manager.MOVING) def transition_to(self, new_state_number): if new_state_number == self.manager.MOVING: self.manager.resume_mover_state() return True if new_state_number == self.manager.SPINNING: self.manager.start_spinner(self.sprite.rect.center) return False
def __init__(self, manager, position, target, sprite_sheet, height, width, delay, targ_time, shoot_time): """manager is the root EnemyBase object position is the sprite's rect.center coordinates (taken from the moving state) sprite_sheet, etc are AnimatedFacingSprite args targ_time is the frame (from start) when target direction is taken shoot_time is the frame (from start) when spinner becomes shooter and begins movement """ State.__init__(self, manager) self.sprite = AnimatedFacingSprite(sprite_sheet, height, width, delay, 0) self.sprite.rect.center = position self.target = target self.targ_time = targ_time self.shoot_time = shoot_time self.tick = 0 self.STATE_NUMBER = manager.SPINNING self.IS_FOLLOWABLE = False