Ejemplo n.º 1
0
class TavernModal(Interface, CascadeElement):
    def __init__(self, father, tavern):
        CascadeElement.__init__(self)
        self.bg = SimpleSprite('helpmodal.png')
        self.bg.rect.x, self.bg.rect.y = 262, 200
        self.text = TextSprite('Enter a word or two about your inquiry',
                               '#ffffff', 274, 250)
        self.question = TextSprite('', '#ffffff', 274, 300)
        self.word = ''
        self.tavern = tavern
        self.subsprites = [self.bg, self.text, self.question]
        Interface.__init__(self,
                           father,
                           keys=[
                               (K_ESCAPE, lambda x: self.done()),
                               ('[a-z ]', self.typing),
                               (K_BACKSPACE, self.erase),
                               (K_RETURN, self.validate),
                           ])

    def typing(self, code):
        self.word += code
        self.question.set_text(self.word)

    def erase(self, _):
        self.word = self.word[:-1]
        self.question.set_text(self.word)

    def validate(self, _):
        self.tavern.inquiry(self.word)
        self.done()

    def update(self, mouse_pos):
        self.display()
Ejemplo n.º 2
0
    def __init__(self, father):
        CascadeElement.__init__(self)
        self.bg = SimpleSprite('helpmodal.png')
        self.bg.rect.x, self.bg.rect.y = 302, 200
        self.text = TextSprite('Items to buy. [Esc] to leave.', '#ffffff', 330,
                               250)
        self.items = []
        self.item_texts = []
        father.desactivate()
        for i in range(3):
            choice = random.choice(list(items.ITEMS.keys()))
            item_class = items.ITEMS[choice][0]
            item_args = items.ITEMS[choice][1]
            item = item_class(*item_args)
            self.items.append(item)
            self.item_texts.append(
                TextSprite(
                    "[%d]: %s - %d gold" % (i + 1, item.name, item.shop_price),
                    "#ffffff", 368, 304 + 40 * i))

        Interface.__init__(self,
                           father,
                           keys=[
                               (K_ESCAPE, self.leave),
                               ('[1-3]', self.buy),
                           ])
Ejemplo n.º 3
0
class TeammateDisplay(CascadeElement):
    def __init__(self, creature, basex, basey):
        super().__init__()
        self.basex, self.basey = basex, basey
        self.pc = creature
        self.pc.rect.x, self.pc.rect.y = basex, basey
        self.health_stat = TextSprite('', '#ffffff', basex + 38, basey + 4)
        self.inventory = [
            SimpleSprite('icons/icon-blank.png'),
            SimpleSprite('icons/icon-blank.png'),
            SimpleSprite('icons/icon-blank.png'),
        ]
        for i, sprite in enumerate(self.inventory):
            sprite.rect.x, sprite.rect.y = basex + 120 + 32 * i, basey
        for i, item in enumerate(self.pc.items):
            item.rect.x, item.rect.y = self.inventory[
                i].rect.x, self.inventory[i].rect.y
        self.subsprites = [self.pc, self.health_stat
                           ] + self.inventory + self.pc.items

    def update(self):
        if self.pc.health < 0:
            self.must_show = False
        self.pc.rect.x, self.pc.rect.y = self.basex, self.basey
        self.health_stat.set_text("%s/%s" %
                                  (self.pc.health, self.pc.maxhealth))
        for item in self.pc.items:
            if item not in self.subsprites:
                self.subsprites.append(item)
        for item in self.subsprites[5:]:
            if item not in self.pc.items:
                self.subsprites.remove(item)
        for i, item in enumerate(self.pc.items):
            item.rect.x, item.rect.y = self.inventory[
                i].rect.x, self.inventory[i].rect.y
Ejemplo n.º 4
0
 def __init__(self, father, tavern):
     CascadeElement.__init__(self)
     self.bg = SimpleSprite('helpmodal.png')
     self.bg.rect.x, self.bg.rect.y = 262, 200
     self.text = TextSprite('Enter a word or two about your inquiry',
                            '#ffffff', 274, 250)
     self.question = TextSprite('', '#ffffff', 274, 300)
     self.word = ''
     self.tavern = tavern
     self.subsprites = [self.bg, self.text, self.question]
     Interface.__init__(self,
                        father,
                        keys=[
                            (K_ESCAPE, lambda x: self.done()),
                            ('[a-z ]', self.typing),
                            (K_BACKSPACE, self.erase),
                            (K_RETURN, self.validate),
                        ])
Ejemplo n.º 5
0
 def update(self, mouse_pos):
     for i, item in enumerate(self.items):
         item.rect.x, item.rect.y = 330, 300 + 40 * i
         self.item_texts[i] = TextSprite(
             "[%d]: %s - %d gold" % (i + 1, item.name, item.shop_price),
             "#ffffff", 368, 304 + 40 * i)
     self.subsprites = [self.bg, self.text] + self.items + self.item_texts
     self.father.update(mouse_pos)
     self.display()
Ejemplo n.º 6
0
 def __init__(self, creature, basex, basey):
     super().__init__()
     self.basex, self.basey = basex, basey
     self.pc = creature
     self.pc.rect.x, self.pc.rect.y = basex, basey
     self.health_stat = TextSprite('', '#ffffff', basex + 38, basey + 4)
     self.inventory = [
         SimpleSprite('icons/icon-blank.png'),
         SimpleSprite('icons/icon-blank.png'),
         SimpleSprite('icons/icon-blank.png'),
     ]
     for i, sprite in enumerate(self.inventory):
         sprite.rect.x, sprite.rect.y = basex + 120 + 32 * i, basey
     for i, item in enumerate(self.pc.items):
         item.rect.x, item.rect.y = self.inventory[
             i].rect.x, self.inventory[i].rect.y
     self.subsprites = [self.pc, self.health_stat
                        ] + self.inventory + self.pc.items
Ejemplo n.º 7
0
 def __init__(self, father, item):
     CascadeElement.__init__(self)
     self.item = item
     self.bg = SimpleSprite('helpmodal.png')
     self.bg.rect.x, self.bg.rect.y = 302, 200
     self.text = TextSprite(
         'Apply to adventurer with [1-5]. [Esc] to cancel.',
         '#ffffff',
         330,
         250,
         maxlen=350)
     self.stats = TextSprite(str(item), '#ffffff', 330, 220, maxlen=350)
     self.subsprites = [self.bg, self.stats, self.text]
     Interface.__init__(self,
                        father,
                        keys=[
                            (K_ESCAPE, lambda x: self.done()),
                            ('[1-5]', self.equip),
                        ])
Ejemplo n.º 8
0
class StatusDisplay(CascadeElement):
    def __init__(self, worldinterface):
        super().__init__()
        self.worldinterface = worldinterface
        self.gold_icon = SimpleSprite('icons/gold.png')
        self.gold_icon.rect.x, self.gold_icon.rect.y = 20, 50
        self.gold_stat = TextSprite('', '#ffffff', 58, 54)
        self.food_icon = SimpleSprite('icons/apple.png')
        self.food_icon.rect.x, self.food_icon.rect.y = 92, 50
        self.food_stat = TextSprite('', '#ffffff', 130, 54)
        self.day_text = TextSprite('', '#ffffff', 20, 90)
        self.inventory = []
        self.items = []
        for i in range(10):
            self.inventory.append(SimpleSprite('icons/icon-blank.png'))
            self.inventory[i].rect.x, self.inventory[i].rect.y = 50 + (
                i % 5) * 32, 380 + (i // 5) * 32
        self.subsprites = [
            self.gold_icon, self.gold_stat, self.food_icon, self.food_stat,
            self.day_text
        ] + self.inventory
        self.teammates = []

    def update(self, mouse_pos):
        if not self.teammates:
            for i, pc in enumerate(self.worldinterface.pc_list):
                self.teammates.append(TeammateDisplay(pc, 20, 158 + 40 * i))
        self.gold_stat.set_text(str(self.worldinterface.party_gold))
        self.food_stat.set_text(str(self.worldinterface.party_food))
        self.day_text.set_text("Level %d" % self.worldinterface.level)

        for pc in self.teammates:
            pc.update()

        for i, item in enumerate(self.worldinterface.inventory):
            item.rect.x, item.rect.y = self.inventory[
                i].rect.x, self.inventory[i].rect.y
            self.items.append(item)
        for item in self.items.copy():
            if item not in self.worldinterface.inventory:
                self.items.remove(item)
        self.subsprites = [
            self.gold_icon, self.gold_stat, self.day_text, self.food_icon,
            self.food_stat
        ] + self.inventory + self.teammates + self.items

    def on_click(self, mouse_pos):
        for sprite in self.worldinterface.inventory:
            if sprite.rect.collidepoint(mouse_pos):
                ei = EquipInterface(self.worldinterface, sprite)
                ei.activate()
                ei.display()
                self.worldinterface.desactivate()
                return

        for pc in self.worldinterface.pc_list:
            for item in pc.items:
                if item.rect.collidepoint(mouse_pos):
                    item.unequip()
                    self.worldinterface.inventory.append(item)
Ejemplo n.º 9
0
 def __init__(self):
     CascadeElement.__init__(self)
     self.bg = SimpleSprite('menu.png')
     self.hello = TextSprite('Choose a save slot with keys 1-3', '#ffffff',
                             320, 280)
     self.slots = []
     for i in range(3):
         try:
             slotname = 'Day %d' % json.load(open('save%d.json' %
                                                  (i + 1)))['level']
         except FileNotFoundError:
             slotname = 'Empty'
         self.slots.append(
             TextSprite('[%d] Slot - %s' % (i + 1, slotname), '#ffffff',
                        320, 300 + 20 * i))
     self.subsprites = [self.bg, self.hello] + self.slots
     Interface.__init__(self,
                        None,
                        keys=[
                            (K_ESCAPE, lambda x: self.done()),
                            ('[1-3]', self.start),
                        ])
Ejemplo n.º 10
0
 def __init__(self, father):
     CascadeElement.__init__(self)
     Interface.__init__(self,
                        father,
                        keys=[(K_ESCAPE, self.cancel),
                              (K_RETURN, self.cancel)])
     self.basex, self.basey = 302, 200
     self.bg = SimpleSprite('helpmodal.png')
     self.bg.rect.move_ip(self.basex, self.basey)
     self.text = TextSprite('Your party is dead. Game Over.',
                            '#ffffff',
                            330,
                            250,
                            maxlen=350)
     self.subsprites = [self.bg, self.text]
     self.display()
Ejemplo n.º 11
0
 def __init__(self, worldinterface):
     super().__init__()
     self.worldinterface = worldinterface
     self.gold_icon = SimpleSprite('icons/gold.png')
     self.gold_icon.rect.x, self.gold_icon.rect.y = 20, 50
     self.gold_stat = TextSprite('', '#ffffff', 58, 54)
     self.food_icon = SimpleSprite('icons/apple.png')
     self.food_icon.rect.x, self.food_icon.rect.y = 92, 50
     self.food_stat = TextSprite('', '#ffffff', 130, 54)
     self.day_text = TextSprite('', '#ffffff', 20, 90)
     self.inventory = []
     self.items = []
     for i in range(10):
         self.inventory.append(SimpleSprite('icons/icon-blank.png'))
         self.inventory[i].rect.x, self.inventory[i].rect.y = 50 + (
             i % 5) * 32, 380 + (i // 5) * 32
     self.subsprites = [
         self.gold_icon, self.gold_stat, self.food_icon, self.food_stat,
         self.day_text
     ] + self.inventory
     self.teammates = []