Beispiel #1
0
 def __init__(self, game, position):
     super().__init__(game, position)
     self.main_texture = load_texture('not_a_flower/main.png')
     self.hit_texture = load_texture('not_a_flower/hit.png')
     self.image = self.main_texture
     self.update_rect()
     self.movement_vector = Vector2D(1, 1).normalized() * self.speed
Beispiel #2
0
 def __init__(self, game, position):
     super().__init__(game)
     self.full_texture = load_texture('heart/full.png')
     self.empty_texture = load_texture('heart/empty.png')
     self._is_full = True
     self.position = position
     self.image = self.full_texture
     self.update_rect()
 def __init__(self, game, position):
     super().__init__(game, position)
     self.main_texture = load_texture('player/main.png')
     self.hit_texture = load_texture('player/hit.png')
     self.image = self.main_texture
     self.update_rect()
     self.hit_timeout = 0.0
     self.control_disabled_for = 0.0
     self.weapon = Gun(game=self.game, holder=self)
Beispiel #4
0
 def __init__(self, game, position):
     super().__init__(game, position)
     self.main_texture = load_texture('deadline/main.png')
     self.hit_texture = load_texture('deadline/hit.png')
     self.image = self.main_texture
     self.weapon = Gun(
         game=game,
         holder=self,
         BulletClass=DeadlineBullet,
         cooldown_period=self.trait_fire_delay,
     )
     self.update_rect()
 def __init__(self, game, position):
     super().__init__(game, position)
     self.main_texture = load_texture('ivr/main.png')
     self.hit_texture = load_texture('ivr/hit.png')
     self.image = self.main_texture
     self.weapon = Gun(
         game=game,
         holder=self,
         BulletClass=IVRBullet,
         cooldown_period=0,
     )
     self.update_rect()
     self.before_attack = 5.0
Beispiel #6
0
 def get_level_entry_overlay(level_name):
     try:
         return load_texture('overlay.png',
                             root=os.path.join('assets', 'levels',
                                               level_name))
     except Exception as e:
         raise LevelLoadError(
             'Failed to load entry overlay image for level `{}`: {}'.format(
                 level_name, str(e))) from e
Beispiel #7
0
    def load_level(self, level_name, reward=None):
        logger.info('Loading level `{}`'.format(level_name))
        self.level_switch_timer = 0.0
        self.health_osd = None
        self.sprites.empty()
        self.mobs.empty()
        self.enemies.empty()
        if self.player is None:
            self.player = Player(game=self,
                                 position=self.surface.get_rect().center)
        self.level_name = level_name
        try:
            try:
                level = self.read_level(level_name)
            except LevelLoadError:
                if self.level_exists(level_name):
                    raise
                self.has_player_died = 'final'
                self.final_overlay_image = load_texture('final.png',
                                                        root='assets')
                self.fps = 5
                return
            player_position_info = level['player']['position']
            #self.player = Player(
            #    game = self,
            #    position = self.to_absolute_position(player_position_info['x'], player_position_info['y']),
            #)
            self.player.position = self.to_absolute_position(
                player_position_info['x'], player_position_info['y'])
            self.add_sprite(self.player)
            for ent in level['entities']:
                name = ent['name']
                position = self.to_absolute_position(*ent['position'])
                if name not in entities:
                    raise LevelLoadError(
                        'Unknown entity name: `{}`'.format(name))
                Entity = entities[name]

                entity = Entity(game=self, position=position)
                if ent['is_enemy']:
                    self.enemies.add(entity)
                self.add_sprite(entity)
            self.is_showing_level_overlay = True
            self.level_transition_overlay = LevelTransitionOverlay(
                game=self,
                image=self.get_level_entry_overlay(level_name),
                powerup_image=None if reward is None else reward.image,
            )
            if reward is not None:
                reward.apply(self.player)
            self.level_transition_overlay.update(0.0)
            self.health_osd = HealthOSD(game=self)
        except Exception as e:
            raise LevelLoadError('Failed to load level `{}`: {}'.format(
                level_name, str(e))) from e
Beispiel #8
0
 def __init__(self, game, position, direction):
     super().__init__(game, position)
     self.direction = direction.normalized()
     self.main_texture = load_texture(self.trait_texture_filename)
     if self.trait_should_rotate:
         self.main_texture = pygame.transform.rotate(
             self.main_texture,
             direction.azimuth() * 180 / math.pi,
         )
     self.image = self.main_texture
     self.update_rect()
Beispiel #9
0
 def run(self):
     logger.info('Initializing Pygame-related objects')
     pygame.display.set_mode((800, 600))
     self.surface = pygame.display.get_surface()
     self.clock = pygame.time.Clock()
     self.init()
     logger.info('Entering main loop')
     try:
         while True:
             try:
                 millisecs = self.clock.tick(self.fps)
                 secs = millisecs / 1000.0
                 self.draw()
                 self.update(secs)
                 self.process_events()
                 self.frame_counter += 1
                 self.time_counter += secs
                 if self.frame_counter >= 10:
                     self.average_fps = self.frame_counter / self.time_counter
                     self.frame_counter = 0
                     self.time_counter = 0
                 if not self.is_showing_level_overlay and self.should_switch_level(
                 ):
                     self.load_level(self.get_next_level_name(),
                                     reward=self.get_random_powerup())
             except PlayerDied as e:
                 logger.info('Player died')
                 self.fps = 5
                 self.has_player_died = True
                 self.death_overlay_image = self.surface.copy()
                 texture = load_texture('death_screen.png',
                                        root='assets/overlays').convert(24)
                 texture.set_alpha(200)
                 self.death_overlay_image.blit(texture, (0, 0))
     except GameExited:
         logger.info('Game exited')
         return
Beispiel #10
0
 def __init__(self, game, position):
     super().__init__(game, position)
     self.main_texture = load_texture('s_me/main.png')
     self.hit_texture = load_texture('s_me/main.png')    # TODO: actually draw hit texture
     self.image = self.main_texture
     self.update_rect()