Exemplo n.º 1
0
class NPC(GameObject):
    def __init__(self, scene, name, x, y, filename="", **kwargs):
        super(NPC, self).__init__(scene, name, x, y, **kwargs)
        self.sprite = AnimSprite(self, assets.getSpriteAnim("anims/npc.json"), "stand", offset_y = 11, layer=0)
        self.collider = SpriteCollide(self, -26, 20, 64+52, 76)
        self.filename = filename

    def init(self):
        """Initiation code."""
        self.collider.addToGroup(self.obj_mgr.interactive)
        self.obj_mgr.normal_update.append(self)

    def destroy(self):
        """Clean up code."""
        self.sprite.destroy()
        self.collider.removeFromGroup(self.obj_mgr.interactive)
        self.obj_mgr.normal_update.remove(self)

    def update(self, td):
        self.sprite.updateAnim(td)

    def spriteCollide(self, gameobject, collider):
        pass

    def interact(self, obj):
        statemgr.switch("dialog", self.filename)
        return True

    def debug_draw(self, surface, camera_x, camera_y):
        super(NPC, self).debug_draw(surface, camera_x, camera_y)
        self.sprite.debug_draw(surface, camera_x, camera_y)
        self.collider.debug_draw(surface, camera_x, camera_y)
class SideTravel(GameObject):
    def __init__(self, scene, name, x, y, mapfile="", spawnpoint="", side="left", width=0, height=0, **kwargs):
        super(SideTravel, self).__init__(scene, name, x, y, **kwargs)
        self.mapfile = mapfile
        self.spawnpoint = spawnpoint
        self.side = side
        self.width = int(width)
        self.height = int(height)
        self.collider = SpriteCollide(self, 0, 0, self.width, self.height)

    def init(self):
        """Initiation code."""
        self.collider.addToGroup(self.obj_mgr.player_touchable)

    def destroy(self):
        """Clean up code."""
        self.collider.removeFromGroup(self.obj_mgr.player_touchable)

    def spawnPlayer(self):
        """Create a player object"""
        if self.side == "left":
            player = self.obj_mgr.create("Player", "player", self.x - 48, self.y+self.height - 62)
        else:
            player = self.obj_mgr.create("Player", "player", self.x + self.width + 48, self.y+self.height-62)
        player.spawn(self.side)

    def spriteCollide(self, gameobject, collider):
        gameobject.call("sideTravel", self.side, self.mapfile, self.spawnpoint)

    def debug_draw(self, surface, camera_x, camera_y):
        super(SideTravel, self).debug_draw(surface, camera_x, camera_y)
        self.collider.debug_draw(surface, camera_x, camera_y)
Exemplo n.º 3
0
class Sign(GameObject):
    def __init__(self, scene, name, x, y, filename="", **kwargs):
        super(Sign, self).__init__(scene, name, x, y, **kwargs)
        self.sprite = StaticSprite(self, assets.getImage("graphics/sign.png"), layer=0)
        self.collider = SpriteCollide(self, 16, 0, 32, 64)
        self.filename = filename

    def init(self):
        """Initiation code."""
        self.collider.addToGroup(self.obj_mgr.interactive)

    def destroy(self):
        """Clean up code."""
        self.sprite.destroy()
        self.collider.removeFromGroup(self.obj_mgr.interactive)

    def spriteCollide(self, gameobject, collider):
        pass

    def interact(self, obj):
        statemgr.switch("dialog", self.filename)
        return True

    def debug_draw(self, surface, camera_x, camera_y):
        super(Sign, self).debug_draw(surface, camera_x, camera_y)
        self.sprite.debug_draw(surface, camera_x, camera_y)
        self.collider.debug_draw(surface, camera_x, camera_y)
Exemplo n.º 4
0
class Cave(GameObject):
    def __init__(self, scene, name, x, y, mapfile="", spawnpoint="", cavetype="entrance", **kwargs):
        super(Cave, self).__init__(scene, name, x, y, **kwargs)
        self.mapfile = mapfile
        self.spawnpoint = spawnpoint

        if cavetype == "entrance":
            self.sprite = StaticSprite(self, assets.getImage("graphics/cave_entrance.png"), offset_y=-13, layer=0)
        if cavetype == "exit":
            self.sprite = StaticSprite(self, assets.getImage("graphics/cave_exit.png"),  offset_y=-13, layer=0)
        self.collider = SpriteCollide(self, 64, 32, 32, 96)
        if cavetype == "exitinv":
            self.sprite = StaticSprite(self, assets.getImage("graphics/fish.png"),  offset_y=0, layer=0)
        self.collider = SpriteCollide(self, 0, 0, 32, 32)

    def init(self):
        """Initiation code."""
        self.collider.addToGroup(self.obj_mgr.interactive)

    def destroy(self):
        """Clean up code."""
        self.sprite.destroy()
        self.collider.removeFromGroup(self.obj_mgr.interactive)

    def spawnPlayer(self):
        """Create a player object"""
        player = self.obj_mgr.create("Player", "player", self.x+64+16, self.y+65)
        player.spawn("door")

    def spriteCollide(self, gameobject, collider):
        pass

    def interact(self, obj):
        obj.call("enterDoor", self.mapfile, self.spawnpoint)

    def debug_draw(self, surface, camera_x, camera_y):
        super(Cave, self).debug_draw(surface, camera_x, camera_y)
        self.sprite.debug_draw(surface, camera_x, camera_y)
        self.collider.debug_draw(surface, camera_x, camera_y)