Exemplo n.º 1
0
    def __init__(self, movement=Vec2.zero(), rotation=0):
        """
            Create AutoComponent

            This Component is here to add auto movement (direction, rotation) to entity
            Required Components : If movement != Vec2.zero() PositionComponent
                                  If rotation != 0 SpriteComponent

            :param movement: Vector of Automatic Movement
            :param rotation: Number of Automatic Rotation
        """
        super(AutoComponent, self).__init__()
        self.movement = movement
        self.rotation = rotation

        if self.movement != Vec2.zero():
            self.required_components.add(PositionComponent)
        if self.rotation != 0:
            self.required_components.add(SpriteComponent)
Exemplo n.º 2
0
    def update(self):
        """
            Update values

            .. note:: You may not use this method. Entity make it for you
        """
        if self.movement != Vec2.zero():
            pos = self.entity.get_component(PositionComponent).position()
            pos.x += self.movement.x
            pos.y += self.movement.y

            if self.entity.has_component(CollisionComponent):
                if self.entity.get_component(CollisionComponent).can_go(
                        pos.x, pos.y, "AUTOCOMPONENT"):
                    self.entity.get_component(PositionComponent).set_position(
                        pos.x, pos.y)
            else:
                self.entity.get_component(PositionComponent).set_position(
                    pos.x, pos.y)

        if self.rotation != 0:
            self.entity.get_component(
                SpriteComponent).rotation += self.rotation
            self.entity.get_component(SpriteComponent).update_image()