def alien_factory(initial_x: int, initial_y: int) -> ecs.Entity: alien = dict() alien["GraphicComponent"] = ecs.GraphicComponent(alien_surface, initial_x, initial_y) alien["AnimationCycleComponent"] = ecs.AnimationCycleComponent(cyc_surfaces, ALIEN_ANIMATION_INTERVAL_LENGTH) alien["VelocityComponent"] = ecs.VelocityComponent(ALIEN_VELOCITY[0], ALIEN_VELOCITY[1]) entities_manager.register_and_enlist_entity(alien, "aliens") return alien
def register_afv(afv_surface: pygame.Surface, entities_manager: ecs.EntitiesManager, afv: ecs.Entity) -> None: afv["GraphicComponent"] = ecs.GraphicComponent(afv_surface, AFV_INITIAL_POSITION[0], AFV_INITIAL_POSITION[1]) afv["HorizontalOrientationComponent"] = ecs.HorizontalOrientationComponent(afv_surface, pygame.transform.flip(afv_surface, True, False)) afv["VelocityComponent"] = ecs.VelocityComponent(AFV_VELOCITY[0], AFV_VELOCITY[1]) entities_manager.register_entity(afv)
def explosion_factory(initial_x: int, initial_y: int) -> ecs.Entity: explosion = dict() explosion["GraphicComponent"] = ecs.GraphicComponent(explosion_surface, initial_x, initial_y) explosion["LifeTimeComponent"] = ecs.LifeTimeComponent(EXPLOSION_LIFE_TIME) explosion["AudioComponent"] = ecs.AudioComponent(explosion_sound) explosion["AudioComponent"].sound.play() entities_manager.register_and_enlist_entity(explosion, "explosions") return explosion
def shot_factory(initial_x: int, initial_y: int) -> ecs.Entity: shot = dict() shot["GraphicComponent"] = ecs.GraphicComponent(shot_surface, initial_x, initial_y) shot["VelocityComponent"] = ecs.VelocityComponent(SHOT_VELOCITY[0], SHOT_VELOCITY[1]) shot["AudioComponent"] = ecs.AudioComponent(shot_sound) shot["AudioComponent"].sound.play() entities_manager.register_and_enlist_entity(shot, "shots") return shot
def register_and_enlist_alien(images: List[pygame.Surface], entities_manager: ecs.EntitiesManager) -> None: alien = dict() alien["GraphicComponent"] = ecs.GraphicComponent(images[ImgsIndices.alien1], ALIEN_INITIAL_POSITION[0], ALIEN_INITIAL_POSITION[1]) alien["AnimationCycleComponent"] = ecs.AnimationCycleComponent((images[ImgsIndices.alien1], images[ImgsIndices.alien2], images[ImgsIndices.alien3]), ALIEN_ANIMATION_INTERVAL_LENGTH) alien["VelocityComponent"] = ecs.VelocityComponent(ALIEN_VELOCITY[0], ALIEN_VELOCITY[1]) entities_manager.register_and_enlist_entity(alien, "aliens")
def bomb_factory(initial_x: int, initial_y: int) -> ecs.Entity: bomb = dict() bomb["GraphicComponent"] = ecs.GraphicComponent(bomb_surface, initial_x, initial_y) bomb["VelocityComponent"] = ecs.VelocityComponent(BOMB_VELOCITY[0], BOMB_VELOCITY[1]) entities_manager.register_and_enlist_entity(bomb, "bombs") return bomb
def register_score(entities_manager: ecs.EntitiesManager, score: ecs.Entity) -> None: score["TextComponent"] = ecs.TextComponent("Score: {}".format(INITIAL_PLAYER_SCORE), SCORE_TEXT_SIZE, SCORE_TEXT_COLOR) score_surface = score["TextComponent"].font.render(score["TextComponent"].text, False, score["TextComponent"].color) score["GraphicComponent"] = ecs.GraphicComponent(score_surface, SCORE_POSITION[0], SCORE_POSITION[1]) entities_manager.register_entity(score)
def register_lives(entities_manager: ecs.EntitiesManager, lives: ecs.Entity) -> None: lives["TextComponent"] = ecs.TextComponent("Lives: {}".format(INITIAL_PLAYER_LIFE), LIVES_TEXT_SIZE, LIVES_TEXT_COLOR) lives_surface = lives["TextComponent"].font.render(lives["TextComponent"].text, False, lives["TextComponent"].color) lives["GraphicComponent"] = ecs.GraphicComponent(lives_surface, LIVES_POSITION[0], LIVES_POSITION[1]) entities_manager.register_entity(lives)