Example #1
0
    def __init__(self, **kwargs):
        self._structure_id = kwargs['id']
        self._name = kwargs['name']
        self._tile_requirements = kwargs.get('requires_tile', {})
        self._build_requirements = kwargs.get('requires', {})
        self._produces = kwargs.get('produces', {})
        self._consumes = kwargs.get('consumes', {})
        self._environment = kwargs.get('environment', {})
        self._image = get_image(kwargs['image'])
        self._width = kwargs['width']
        self._height = kwargs['height']
        self._hit_box_width = kwargs.get('hit_box_width', None)
        self._hit_box_height = kwargs.get('hit_box_height', None)
        self._animation_speed = kwargs.get('animation_speed', 3)
        self._animation = kwargs.get('animations', {
            'idle':1
        })

        self._animation_sequences = {}
        y = len(self._animation) - 1
        # y is in reverse order, frames are read from bottom to top
        for name, frames in self._animation.items():
            self._animation_sequences[name] = ChainableAnimation.from_image_sequence(
                ANIM_LOOP, [
                    self._image.get_region(
                        self._width*x,
                        self._height*y,
                        self._width,
                        self._height
                    ) for x in range(0, frames)
                ], self._animation_speed)
            y -= 1
Example #2
0
    def __init__(self, *args, **kwargs):
        self._width = 32
        self._height = 32
        self.frame_size = (self._width, self._height)
        frame_period = 0.024
        sequences = {
            'idle': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(12*self.frame_size[0], 0, self.frame_size[0], self.frame_size[1]), ], frame_period),
            'walk_sw': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 0, self.frame_size[1], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_w': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_nw': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 2*self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_n': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 3*self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_ne': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 4*self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_e': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 5*self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_se': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 6*self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
            'walk_s': ChainableAnimation.from_image_sequence(ANIM_LOOP, [image.get_region(i*self.frame_size[0], 7*self.frame_size[1], self.frame_size[0], self.frame_size[1]) for i in range(0,16)], frame_period),
        }
        super(Mech, self).__init__(sequences, *args, **kwargs)

        self.collides_with = [Human,Structure,]
        self._collision_modifier = 5