Пример #1
0
 def update(self, dt):
     directions = self._available_dir()
     if self.enum_next_direction in directions:
         self.direction = movement.get_direction(self.enum_next_direction)
         self.sprite.image = assets.get_pacman(self.direction.current)
         self.enum_next_direction = None
     Player.update(self, dt)
Пример #2
0
 def _get_closest_direction(self, enum_directions):
     closest = None
     for d in enum_directions:
         dist = distance(np.array(self.get_pos_in_map()) + np.array(movement.get_direction(d).direction),
                         np.array([self.y_target, self.x_target]))
         if closest is None or closest[0] > dist:
             closest = (dist, d)
     if closest is None:
         return EnumDirection.STOP
     return closest[1]
Пример #3
0
 def _make_decision(self):
     enum_directions = self._available_dir()
     if len(enum_directions) == 1:
         self.direction = movement.get_direction(enum_directions[0])
     # players are not allowed to turn around
     if self.direction.opposite in enum_directions:
         enum_directions.remove(self.direction.opposite)
     # if locked remove direction up
     if self.locked and EnumDirection.UP in enum_directions:
         enum_directions.remove(EnumDirection.UP)
     # if not locked but in spawn and can go up, go up
     if not self.locked \
             and self.get_pos_in_map() == (self.bit_map.shape[0] // 2, self.bit_map.shape[1] // 2) \
             and EnumDirection.UP in enum_directions:
         self.direction = movement.get_direction(EnumDirection.UP)
     # if scared but not dead move randomly
     elif self.scared and not self.dead:
         self.direction = movement.get_direction(random.choice(enum_directions))
     # else go to square closest to target
     else:
         self.direction = movement.get_direction(self._get_closest_direction(enum_directions))
Пример #4
0
    def __init__(self, bit_map, sp_texture, start_x, start_y, x_offset=None, y_offset=None):

        self.normal_speed = 1
        self.dead = False
        self.previous_dead = self.dead
        if x_offset is None:
            x_offset = 0
        if y_offset is None:
            y_offset = 0
        self.bit_map = bit_map
        self.x_offset = x_offset
        self.y_offset = y_offset
        y, x = self._translate_cord_to_screen(start_y, start_x)
        self.sprite = pyglet.sprite.Sprite(sp_texture,
                                           x=settings.BLOCK_SIZE * x + self.x_offset,
                                           y=settings.BLOCK_SIZE * y + self.y_offset)
        self.sprite.scale = settings.BLOCK_SIZE / self.sprite.height
        self.direction = movement.get_direction(EnumDirection.STOP)
Пример #5
0
    def scare(self, time):
        if time < 1.5:
            time = 1.5

        def warn():
            self.warn = True
            self.scare_timer = Timer(1.5, unscare)
            self.scare_timer.start()

        def unscare():
            self.scared = False
            self.warn = True

        self.scared = True
        self.sprite.image = assets.get_scared(False)
        self.direction = movement.get_direction(self.direction.opposite)
        if self.scare_timer is not None:
            self.scare_timer.cancel()
        self.scare_timer = Timer(time - 1.5, warn)
        self.scare_timer.start()
Пример #6
0
 def respawn(self):
     self.dead = False
     self.scared = False
     self.direction = movement.get_direction(self.direction.opposite)
     self.sprite.image = assets.get_ghost(self.direction.current, self.texture)