Exemple #1
0
    def load(self, filename):
        file = open(Scene.path + filename)
        data = file.read().splitlines()

        ground_height = 0
        self.cursor = Sprite(0, 0, 'cursor.png', False)
        self.sprites = []
        self.warps = []

        self.ui_top = UiGroup()
        panel = UiPanel(0, 0, 800, 110)
        button = UiButton(10, 10, 90, 90, "banana")
        self.ui_top.add_element(panel)
        self.ui_top.add_element(button)

        for line in data:
            cell = line.split(";")
            # Ground
            if (cell[0] == "ground"):
                self.ground = Sprite(0, 0, cell[1] + ".png", False)
                _, screen_h = pygame.display.get_surface().get_size()
                ground_height = screen_h - self.ground.surface.get_height()
                self.ground.y = ground_height
            # Background
            elif (cell[0] == "background"):
                self.background = Sprite(0, 0, cell[1] + ".png", False)
            # Player
            elif (cell[0] == "player"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                self.player = SpriteControlled(int(cell[2]), height,
                                               cell[1] + ".png", True,
                                               int(cell[4]))
            # Sprites
            elif (cell[0] == "sprite"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                sprite = Sprite(int(cell[2]), height, cell[1] + ".png", True)
                self.sprites.append(sprite)
            # Warps
            elif (cell[0] == "warp"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                warp = Warp(int(cell[2]), height, cell[1] + ".png", False,
                            eval(cell[4]))
                self.warps.append(warp)

        # Set heights
        if (self.player.y == -1):
            self.player.y = ground_height
        for s in self.sprites:
            if (s.y == -1):
                s.y = ground_height
        for w in self.warps:
            if (w.y == -1):
                w.y = ground_height - w.surface.get_height() / 2
Exemple #2
0
 def update_inventory_ui(self):
     i = 0
     for item in self.inventory:
         x = i * 95 + 10
         y = 10
         w = 90
         h = 90
         self.ui_top.add_element(UiButton(x, y, w, h, item))
         i = i + 1