Exemplo n.º 1
0
    def __init__(self, game):
        InteractionEntity.__init__(self, game)
        self.name = "shop_entity"
        self.debug = True

        self.sprite = Sprite()
        self.sprite.material = game.loader.get_image("pikachu")
        self.sprite.crop = (32, 96, 32, 32)
        self.resize(64, 64)

        self.collision_body.set_position(0, 8)

        self.border = InvisibleWall(self.game)
        self.border.resize(32, 32)
        self.border.set_position(16, 24)
        self.border.name = self.name + "_fake_wall"

        self.game.get_scene().add(self.border)
Exemplo n.º 2
0
    def __init__(self, game):
        Entity.__init__(self, game)
        self.properties.append(Property.CAN_PUSH)
        self.sprite = default_sprite()
        self.pusher = None
        self.debug = True

        self.border = InvisibleWall(self.game)
        self.border.resize(56, 56)
        self.border.set_position(2, 2)
        self.border.name = self.name + "_fake_wall"
        self.border.ignore.append(self)

        self.game.get_scene().add(self.border)
        self.border.scale(0.5, 0.5)
        self.scale(0.5, 0.5)

        self.allow_pull = False
Exemplo n.º 3
0
class Shop(InteractionEntity):
    def __init__(self, game):
        InteractionEntity.__init__(self, game)
        self.name = "shop_entity"
        self.debug = True

        self.sprite = Sprite()
        self.sprite.material = game.loader.get_image("pikachu")
        self.sprite.crop = (32, 96, 32, 32)
        self.resize(64, 64)

        self.collision_body.set_position(0, 8)

        self.border = InvisibleWall(self.game)
        self.border.resize(32, 32)
        self.border.set_position(16, 24)
        self.border.name = self.name + "_fake_wall"

        self.game.get_scene().add(self.border)

    def set_position(self, x, y):
        dx, dy = x - self.x, y - self.y
        InteractionEntity.set_position(self, x, y)
        self.border.set_position(self.border.x + dx, self.border.y + dy)

    def interact(self, obj):
        self.log("Interacted with ", obj.name)

    def update(self):
        pass
        #self.log(self.border.x, self.border.y)

    def on_created(self):
        self.parent.add(self.border)
Exemplo n.º 4
0
class PushableEntity(Entity):
    def __init__(self, game):
        Entity.__init__(self, game)
        self.properties.append(Property.CAN_PUSH)
        self.sprite = default_sprite()
        self.pusher = None
        self.debug = True

        self.border = InvisibleWall(self.game)
        self.border.resize(56, 56)
        self.border.set_position(2, 2)
        self.border.name = self.name + "_fake_wall"
        self.border.ignore.append(self)

        self.game.get_scene().add(self.border)
        self.border.scale(0.5, 0.5)
        self.scale(0.5, 0.5)

        self.allow_pull = False

    def on_collision(self, obj):
        #self.log(obj)
        if obj.has_property(Property.CAN_PUSH):
            test_x = lambda o: o.collision_body.center_of_mass().x + o.x
            test_y = lambda o: o.collision_body.center_of_mass().y + o.y
            sgn = lambda x: 1 if x > 0 else -1 if x < 0 else 0
            #print("%s == %s = %s", (sgn(self.v_y), sgn(test_y(self) - test_y(obj)), (sgn(self.v_y) == sgn(test_y(self) - test_y(obj)))))
            if (sgn(obj.v_x)
                    == sgn(test_x(self) - test_x(obj))) or self.allow_pull:
                self.pusher = obj
                self.v_x = self.pusher.v_x
            if (sgn(obj.v_y)
                    == sgn(test_y(self) - test_y(obj))) or self.allow_pull:
                self.pusher = obj
                self.v_y = self.pusher.v_y

    def set_position(self, x, y):
        dx, dy = x - self.x, y - self.y
        self.log("Moving %s, %s" % (x, y))
        Entity.set_position(self, x, y)
        self.border.set_position(self.border.x + dx, self.border.y + dy)

    def on_collision_end(self, obj):
        if obj == self.pusher:
            self.pusher = None
            self.v_x = 0
            self.v_y = 0

    def on_created(self):
        self.parent.add(self.border)
Exemplo n.º 5
0
 def add_wall(self, x, y, w, h, scene):
     wall_x, wall_y = self.room_axis_to_global(x, y)
     wall = InvisibleWall(self.game)
     wall.set_position(wall_x, wall_y)
     wall.resize(w, h)
     self.compiled_walls.append(wall)
     scene.add(wall)
     self.log("Added", wall)
Exemplo n.º 6
0
    def _setup_walls(self, scene):
        # TODO: Add walls in initalization to room, then listen for an entered_scene event to actually create walls
        wall1 = InvisibleWall(self.game)
        wall1.set_position(65, 92)
        wall1.resize(128, 20)
        self.walls.append(wall1)
        scene.add(wall1)

        wall2 = InvisibleWall(self.game)
        wall2.set_position(32, 112)
        wall2.resize(32, 208)
        self.walls.append(wall2)
        scene.add(wall2)

        self.add_wall(128, 188, 96, 54, scene)
        self.add_wall(289, 92, 95, 54, scene)
        self.add_wall(63, 316, 129, 34, scene)

        portal = Portal(self.game)
        portal.set_position(224, 80)
        portal.resize(33, 14)
        portal.target_x, portal.target_y = 260, 160
        self.walls.append(portal)
        scene.add(portal)

        self.resize(768 * 3, 909 * 3)