def initialize(self): logger.debug('Initializing pygame graphics') pygame.display.init() pygame.font.init() screen = Screen() entity_registry.add(screen) entity_registry.add(PygameRenderer2d())
def __init__(self, explosion_size, position, color, **kwargs): super(ExplosionPlaceholder, self).__init__(60, 1, **kwargs) self.explosion_size = explosion_size self.position = position self._explosion_climax_frame = 10.0 self._last_frame = float(self._frames_count - 1) self._placeholder = Placeholder(color=color) entity_registry.add(self._placeholder)
def _handle_death(self): entity_registry.add( ExplosionPlaceholder(20, color=self.color, position=self.position.copy(), playing=True, cycle=False, destroy_on_completion=True, speed=2.0)) entity_registry.remove(self)
def shoot(self): if self._game_time.now - self._last_shot_time < self.fire_cooldown: return center = self.position + (self.size / 2) projectile_spawn_position = (self.position + get_vec_fact().vector2( self.size.x + 1, self.size.y / 2)).rotated_around( self.rotation, center) projectile_direction = self._calc_normalized_projectile_direction( projectile_spawn_position) entity_registry.add( Projectile(projectile_spawn_position, projectile_direction * 1000, (0, 0, 255), velocity=projectile_direction * 300, mass=1, z=self.z, collision_category=self.projectile_collision_category)) self._last_shot_time = self._game_time.now
def register_mouse(self): already_registered = len(entity_registry.get_by_class(PygameMouse)) > 0 if not already_registered: entity_registry.add(PygameMouse())
def register_keyboard(self): already_registered = len( entity_registry.get_by_class(PygameKeyboard)) > 0 if not already_registered: entity_registry.add(PygameKeyboard())
def initialize(self): key_mapping = KeyMapping({ FmPlayer.ACT_MOVE_RIGHT: [(Keyboard, KEYS.d)], FmPlayer.ACT_MOVE_LEFT: [(Keyboard, KEYS.a)], FmPlayer.ACT_MOVE_UP: [(Keyboard, KEYS.w)], FmPlayer.ACT_MOVE_DOWN: [(Keyboard, KEYS.s)], FmPlayer.ACT_EXIT: [(Keyboard, KEYS.esc)], FmPlayer.ACT_FIRE: [(Keyboard, KEYS.space), (Mouse, MBUTTONS.lmb)], }) keyboard = entity_registry.get_by_class(Keyboard)[0] mouse = entity_registry.get_by_class(Mouse)[0] self._player = FmPlayer( PlayerInput([keyboard, mouse], key_mapping), get_vec_fact().vector2(1, 200), z=1, collision_category=self.COLLSION_CAT_PLAYER, projectile_collision_category=self.COLLSION_CAT_PLAYER_PROJECTILE) entity_registry.add(self._player) entity_registry.add( Wall(get_vec_fact().vector2(-1, -1), get_vec_fact().vector2(1000, 1000), (200, 200, 255), z=2, collision_category=self.COLLSION_CAT_BACKGROUND)) entity_registry.add( DummyEnemy(get_vec_fact().vector2(300, 300), 1000, 2, z=1, collision_category=self.COLLSION_CAT_ENEMY, color=(255, 0, 0))) physics = SpacecraftPhysics() physics.set_collidable_categories(self.COLLSION_CAT_BACKGROUND, []) physics.set_collidable_categories(self.COLLSION_CAT_PLAYER, []) physics.set_collidable_categories(self.COLLSION_CAT_PLAYER_PROJECTILE, [self.COLLSION_CAT_ENEMY]) entity_registry.add(physics) entity_registry.add(ActorDriver(20)) entity_registry.add(FpsCounter()) screen = entity_registry.get_by_class(Screen)[0] screen.set_resolution(400, 500) renderer = entity_registry.get_by_class(Renderer2d)[0] viewport = renderer.create_viewport((0, 0, 400, 500), (0, 0, 400, 500)) entity_registry.add(viewport) mouse.set_viewport(viewport) entity_registry.add( Hud(get_vec_fact().vector2(0, 0), get_vec_fact().vector2(400, 100), self._player)) self._game_time = entity_registry.get_by_class(GameTime)[0]
'': { 'handlers': ['stdout'], 'level': 'DEBUG', }, } }) def initialize_subsystems(): subsystems = entity_registry.get_by_class(Subsystem) for subsystem in subsystems: subsystem.initialize() if __name__ == '__main__': # TODO: move core stuff initialization somewhere entity_registry.add(DefaultVectorFactory()) entity_registry.add(GameTime(1.0 / 60.0)) entity_registry.add(PygameSubsystem()) entity_registry.add(PygameGraphicsSubsystem()) entity_registry.add(PygameInputSubsystem()) initialize_subsystems() game_rules = FmGameRules() entity_registry.add(game_rules) game_rules.initialize() world = World() world.run()
def initialize(self): logger.debug('Initializing pygame') # pygame.init() entity_registry.add(PygameEventPumper())