Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
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")
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)