Exemplo n.º 1
0
    def __init__(self,
                 animations_owner: ResourceManager.AnimationsOwners,
                 animations_name,
                 animations_dims="original",
                 x=0,
                 y=0,
                 sprite_state="Default"):

        self.x = x  # px
        self.y = y  # px
        self._animations_owner = animations_owner
        self._animations_name = animations_name
        self.animations = ResourceManager.get_animations_for(
            animations_owner, self._animations_name)
        if animations_dims != "original":
            self.animations = ResourceManager.rescale_animations(
                self.animations, animations_dims)
            """Dictionary of lists of animation frames."""
        self.width = 0
        self.height = 0
        self.sprite_size = self.animations["Default"][0].get_rect().width
        self._animations_elapsed_time_counter = 0
        self._animations_period = Constants.ANIMATION_PERIOD
        # HACK:
        self.current_state = sprite_state

        self.sprite_states = list(self.animations.keys())
        self._counter_upper_limit = len(
            self.animations[self.current_state]) - 1
        self.counter = 0
Exemplo n.º 2
0
 def copy(self):
     """Returns a shallow copy of Ghost object. Use with caution!!!!!"""
     return Ghost(self.x, self.y, self.initial_location, self.width,
                  self.height, self.velocity, self.direction, self.form,
                  ResourceManager.copy_sprite(self.mapobject_hitbox),
                  ResourceManager.copy_sprite(self.creature_hitbox),
                  self.animations, self.is_chasing)
Exemplo n.º 3
0
 def copy(self):
     """Returns a shallow copy of PacMan object. Use with caution!!!!!"""
     return PacMan(self.x, self.y, self.initial_location, self.width,
                   self.height, self.velocity, self.direction, self.form,
                   ResourceManager.copy_sprite(self.mapobject_hitbox),
                   ResourceManager.copy_sprite(self.creature_hitbox),
                   self.animations, self.cooldown, self.mana, self.score,
                   self.lives, self.ghosts_eaten)
Exemplo n.º 4
0
 def _restretch_sprite(self):
     self._width = int(self.current_value * self.sprite_size)
     self._height = self.sprite_size
     self.animations[self.current_state][self.counter] = \
         pygame.transform.scale(
             ResourceManager.get_animations_for(self._animations_owner, self._animations_name)
             [self.current_state][self.counter],
             (self._width, self._height))
Exemplo n.º 5
0
 def sprite_size(self, value):
     if int(value) >= 0:
         self.animations = ResourceManager.rescale_animations(
             self.animations, (int(value), int(value)))
         self._sprite_size = int(value)
         self.width = self._sprite_size
         self.height = self._sprite_size
     else:
         raise ValueError("Cannot assign sprite_size to " + str(value))
Exemplo n.º 6
0
    def __init__(self,
                 x,
                 y,
                 initial_location,
                 width,
                 height,
                 velocity,
                 direction="left",
                 form="random",
                 mapobject_hitbox=None,
                 creature_hitbox=None,
                 animations=None,
                 cooldown=5,
                 mana=Constants.pacman_mana,
                 score=Constants.pacman_score,
                 lives=Constants.pacman_lives,
                 ghosts_eaten=0):

        if mapobject_hitbox is None:
            mapobject_hitbox = ResourceManager.get_hitbox_of(
                Constants.PACMAN_MAPOBJECT_HITBOX_PATH, (width, height))

        if creature_hitbox is None:
            creature_hitbox = ResourceManager.get_hitbox_of(
                Constants.PACMAN_CREATURE_HITBOX_PATH, (width, height))

        form = Constants.forms[random.randint(0,
                                              2)] if form == "random" else form

        if animations is None:
            animations = ResourceManager.get_animations_for(
                ResourceManager.AnimationsOwners.PacMan, form)

        super().__init__(x, y, initial_location, width, height, velocity,
                         direction, form, mapobject_hitbox, creature_hitbox,
                         animations)

        self.form = self.form
        self.cooldown = cooldown
        self.mana = mana
        self.score = score
        self.lives = lives
        self.ghosts_eaten = ghosts_eaten
Exemplo n.º 7
0
    def __init__(self,
                 x,
                 y,
                 initial_location,
                 width,
                 height,
                 velocity,
                 direction="up",
                 form="random",
                 mapobject_hitbox=None,
                 creature_hitbox=None,
                 animations=None,
                 is_chasing=Constants.ghost_is_chasing,
                 target_coord=None,
                 previous_target_coord=None):

        if mapobject_hitbox is None:
            mapobject_hitbox = ResourceManager.get_hitbox_of(
                Constants.GHOST_MAPOBJECT_HITBOX_PATH, (width, height))

        form = Constants.forms[random.randint(0,
                                              2)] if form == "random" else form

        if creature_hitbox is None:
            creature_hitbox = ResourceManager.get_hitbox_of(
                Constants.GHOST_CREATURE_HITBOX_PATH, (width, height))

        if animations is None:
            animations = ResourceManager.get_animations_for(
                ResourceManager.AnimationsOwners.Ghost, form)

        super().__init__(x, y, initial_location, width, height, velocity,
                         direction, form, mapobject_hitbox, creature_hitbox,
                         animations)
        self.is_chasing = is_chasing
        self.form = self.form
        self.target_coord = target_coord
        self.previous_target_coord = previous_target_coord
Exemplo n.º 8
0
    def _fit_icons_into_boundrect(self):

        # If icons width is greater than width of boundrect..
        icons_width = self._n * self.box_size
        if icons_width > self.boundrect.width:

            # ..then make every icon smaller and change its x position
            correction_ratio = self.boundrect.width / icons_width
            self.icons_size = int(self.icons_size * correction_ratio)
            self.box_size = int(self.box_size * correction_ratio)

            for i, icon in enumerate(self.icons):
                icon.animations = ResourceManager.rescale_animations(
                    icon.animations, (self.icons_size, self.icons_size))
                icon.x = self.boundrect.x + i * self.box_size
                icon.y = self.boundrect.y + (self.boundrect.height -
                                             self.icons_size) / 4
Exemplo n.º 9
0
 def form(self, value: str):
     if value in Constants.forms and isinstance(value, str):
         self._form = value
         self.animations = ResourceManager.get_animations_for(
             ResourceManager.AnimationsOwners.Ghost, value)
         return