Esempio n. 1
0
def encounter(hero):
    monster = chars.Mob(hero.lvl)
    util.log("Executing a(n) {} {}!".format(monster.adjective, monster.name))
    util.debug_log("lvl:{} exp:{} sc:{}".format(monster.lvl, monster.exp, monster.shitcoins))
    tui.run_progress_bar(config.TURN_SPEED / util.modifier(hero.lvl, monster.lvl))
    
    hero.exp = int(monster.exp + hero.exp)
    util.debug_log("Earned {} experience.".format(monster.exp))
    if (hero.exp >= hero.exp_next_lvl):
        util.log("Level up! {} -> {}".format(hero.lvl, hero.next_lvl))
        hero.level_up()
    tui.update_stats_panel(hero)
    
    util.log("Looting corpse.")
    tui.run_progress_bar(config.TURN_SPEED / 3)
    hero.shitcoins = monster.shitcoins + hero.shitcoins
    tui.update_inventory_panel(hero)
    util.debug_log("- {} shitcoins".format(monster.shitcoins))
    for i in range(monster.loot_amount):
        loot = objects.Item(monster.lvl)
        if loot.type == "item":
            hero.inventory.append(loot)
        if equip(hero, loot) is False:
            hero.inventory.append(loot)

        tui.update_equipped_panel(hero)
        tui.update_inventory_panel(hero)
        util.debug_log("- {} {} lvl:{} val:{} type:{}".format(loot.adjective, loot.name, loot.lvl, loot.value, loot.type))
        util.debug_log("- Hero equipped {} ".format(hero.equipped))
 def on_char(self, char, x, y, layer):
     gx, gy = x, y
     x = x * self.tile_width
     y = y * self.tile_height
     if char == "GRS":
         objects.Scenery(self.game, x, y, "grass.png")
     if char == "WTR":
         objects.Scenery(self.game, x, y, "water.png")
     if char == "SND":
         objects.Scenery(self.game, x, y, "sand.png")
     if char == "TRT":
         self.set_tile(objects.Scenery(self.game, x, y, "tree-top.png"))
     if char == "TRM":
         self.set_tile(objects.Scenery(self.game, x, y, "tree-middle.png"))
     if char == "TRB":
         self.set_tile(objects.Scenery(self.game, x, y, "tree-bottom.png"))
     if char == "HLL":
         objects.Scenery(self.game, x, y, "hill.png")
     if char == "BRV":
         objects.Obstacle(self.game, x, y, "bridge-vertical.png").sides = [
             False, True, False, True
         ]
     if char == "BRH":
         objects.Obstacle(
             self.game, x, y,
             "bridge-horizontal.png").sides = [True, False, True, False]
     if char == "CSL":
         objects.Obstacle(self.game, x, y, "castle.png")
     if char == "MTN":
         objects.Obstacle(self.game, x, y, "mountain-center.png")
     if char == "MNT":
         objects.Obstacle(self.game, x, y, "mountain-top.png")
     if char == "MNB":
         objects.Obstacle(self.game, x, y, "mountain-bottom.png")
     if char == "MNL":
         objects.Obstacle(self.game, x, y, "mountain-left.png")
     if char == "MNR":
         objects.Obstacle(self.game, x, y, "mountain-right.png")
     if char == "MTL":
         objects.Obstacle(self.game, x, y, "mountain-topleft.png")
     if char == "MTR":
         objects.Obstacle(self.game, x, y, "mountain-topright.png")
     if char == "MBL":
         objects.Obstacle(self.game, x, y, "mountain-bottomleft.png")
     if char == "MBR":
         objects.Obstacle(self.game, x, y, "mountain-bottomright.png")
     if char == "SHT":
         objects.Obstacle(self.game, x, y, "shore-top.png")
     if char == "SHB":
         objects.Obstacle(self.game, x, y, "shore-bottom.png")
     if char == "SHL":
         objects.Obstacle(self.game, x, y, "shore-left.png")
     if char == "SHR":
         objects.Obstacle(self.game, x, y, "shore-right.png")
     if char == "STL":
         objects.Obstacle(self.game, x, y, "shore-topleft.png")
     if char == "STR":
         objects.Obstacle(self.game, x, y, "shore-topright.png")
     if char == "SBL":
         objects.Obstacle(self.game, x, y, "shore-bottomleft.png")
     if char == "SBR":
         objects.Obstacle(self.game, x, y, "shore-bottomright.png")
     if char == "CLB":
         objects.Obstacle(self.game, x, y, "cliff-bottom.png")
     if char == "CLL":
         objects.Obstacle(self.game, x, y, "cliff-left.png").sides = [
             False, True, False, False
         ]
     if char == "CLR":
         objects.Obstacle(self.game, x, y, "cliff-right.png").sides = [
             False, False, False, True
         ]
     if char == "CTL":
         objects.Obstacle(self.game, x, y, "cliff-topleft.png").sides = [
             True, True, False, False
         ]
     if char == "CTR":
         objects.Obstacle(self.game, x, y, "cliff-topright.png").sides = [
             True, False, False, True
         ]
     if char == "CLT":
         objects.Obstacle(self.game, x, y, "cliff-top.png").sides = [
             True, False, False, False
         ]
     if char.startswith("CH"):
         id = int(char[-1:])
         objects.Chest(self.game, x, y, id)
     if char.startswith("NP"):
         id = int(char[-1:])
         name = self.info.npcs[id][0]
         npc = objects.NPC(self.game, x, y, name)
         if npc.name in self.game.npc_cache:
             npc.set_pos_to(self.game.npc_cache[npc.name])
             self.game.npc_cache[npc.name] = npc
         else:
             self.game.npc_cache[npc.name] = npc
     if char.startswith("IT"):
         id = int(char[-1:])
         name, id = self.info.items[id]
         if name in self.game.inventory:
             if self.game.inventory[name][0] == id:
                 return
         objects.Item(self.game, x, y, name, id)
Esempio n. 3
0
    def place_objects(self, room):

        num_monsters = random.randint(0, self.max_room_monsters)
        monster_counter = 0

        for i in range(num_monsters):
            x = random.randint(room.x, room.x2)
            y = random.randint(room.y, room.y2)

            if not self.is_blocked_at(x, y):
                if random.randint(0, 100) < 80:
                    ai_component = game_ai.BasicMonster(20)
                    monster_fighter = objects.Fighter(
                        hp=10,
                        defense=0,
                        power=3,
                        recharge=20,
                        death_function=ai_component.monster_death)
                    monster = objects.GameObject(
                        'orc',
                        x,
                        y,
                        0xE101,
                        blocks=True,
                        fighter=monster_fighter,
                        ai=ai_component,
                        update_func=objects.update_monster)
                else:
                    ai_component = game_ai.BasicMonster(30)
                    monster_fighter = objects.Fighter(
                        hp=16,
                        defense=1,
                        power=4,
                        recharge=30,
                        death_function=ai_component.monster_death)
                    monster = objects.GameObject(
                        'troll',
                        x,
                        y,
                        0xE100,
                        blocks=True,
                        fighter=monster_fighter,
                        ai=ai_component,
                        update_func=objects.update_monster)

                monster.current_map = self
                self.objects.append(monster)

        num_items = random.randint(0, self.max_room_items)

        for i in range(num_items):
            x = random.randint(room.x + 1, room.x2 - 1)
            y = random.randint(room.y + 1, room.y2 - 1)

            if not self.is_blocked_at(x, y):
                item_component = objects.Item(use_function=effects.cast_heal)
                item = objects.GameObject('healing potion',
                                          x,
                                          y,
                                          0xE201,
                                          item=item_component,
                                          active=False)

                self.objects.append(item)
                item.current_map = self
                item.send_to_back()
Esempio n. 4
0
    def make_map(self, player):
        num_rooms = 0

        for r in range(self.max_rooms):
            w = random.randint(self.min_room_size, self.max_room_size)
            h = random.randint(self.min_room_size, self.max_room_size)

            x = random.randint(0, self.width - w - 1)
            y = random.randint(0, self.height - h - 1)

            new_room = Room(x, y, w, h)
            failed = False

            for other_room in self.rooms:
                if new_room.intersect(other_room):
                    failed = True
                    break

            if not failed:
                new_room.get_walls()
                self.draw_room(new_room)
                (new_x, new_y) = new_room.center()

                if num_rooms == 0:
                    player.x = new_x
                    player.y = new_y
                else:
                    (prev_x, prev_y) = self.rooms[num_rooms - 1].center()

                    if random.randint(0, 1):
                        self.create_h_tunnel(prev_x, new_x, prev_y)
                        self.create_v_tunnel(prev_y, new_y, new_x)
                    else:
                        self.create_v_tunnel(prev_y, new_y, prev_x)
                        self.create_h_tunnel(prev_x, new_x, new_y)

                #for wall in new_room.walls:
                #for x, y in wall:
                #self.tiles[x][y] = 2

                self.rooms.append(new_room)
                self.place_objects(new_room)
                num_rooms += 1

        # debug light casting
        torch_room = random.choice(self.rooms)
        torch_x = random.randint(torch_room.x + 1, torch_room.x2 - 1)
        torch_y = random.randint(torch_room.y + 1, torch_room.y2 - 1)
        print(torch_x, torch_y)
        torchlight = objects.LightSource(radius=2, color=colors.lighter_yellow)
        torch = objects.GameObject('torch',
                                   torch_x,
                                   torch_y,
                                   0xE200,
                                   light_source=torchlight,
                                   active=False)
        torch.current_map = self
        torch.light_source.cast_light()
        self.objects.append(torch)

        sword_item = objects.Item()
        sword_wpn = objects.Weapon(2, effects.sword_attack)
        sword = objects.GameObject('sword',
                                   player.x + 1,
                                   player.y + 1,
                                   0xE251,
                                   item=sword_item,
                                   weapon=sword_wpn,
                                   active=False)
        sword.current_map = self
        self.objects.append(sword)

        bow_item = objects.Item()
        bow_wpn = objects.Weapon(2,
                                 effects.bow_attack,
                                 ranged=True,
                                 radius=5,
                                 ammo_icons={
                                     'n': 0xE350,
                                     's': 0xE351,
                                     'w': 0xE352,
                                     'e': 0xE353,
                                     'ne': 0xE354,
                                     'nw': 0xE355,
                                     'se': 0xE356,
                                     'sw': 0xE357
                                 },
                                 ammo_name='arrow')
        bow = objects.GameObject('bow',
                                 player.x - 1,
                                 player.y - 1,
                                 0xE252,
                                 item=bow_item,
                                 weapon=bow_wpn,
                                 active=False)
        bow.current_map = self
        self.objects.append(bow)

        spear_item = objects.Item()
        spear_wpn = objects.Weapon(power=2,
                                   attack_function=effects.spear_attack,
                                   special=effects.push_back)
        spear = objects.GameObject('spear',
                                   player.x,
                                   player.y - 1,
                                   0xE253,
                                   item=spear_item,
                                   weapon=spear_wpn,
                                   active=False)
        spear.current_map = self
        self.objects.append(spear)

        axe_item = objects.Item()
        axe_wpn = objects.Weapon(power=2, attack_function=effects.axe_attack)
        axe = objects.GameObject('axe',
                                 player.x - 1,
                                 player.y + 1,
                                 0xE250,
                                 item=axe_item,
                                 weapon=axe_wpn,
                                 active=False)
        axe.current_map = self
        self.objects.append(axe)

        lb_item = objects.Item()
        lb_spell = objects.SpellEffect(name='Lightning',
                                       spell_range=5,
                                       damage=15,
                                       render_frames=3,
                                       icons={
                                           'n': 0xE370,
                                           's': 0xE370,
                                           'w': 0XE371,
                                           'e': 0xE371,
                                           'ne': 0xE372,
                                           'sw': 0xE372,
                                           'nw': 0xE373,
                                           'se': 0xE373,
                                           'hit': 0xE374
                                       },
                                       charges=5,
                                       aoe_function=effects.lightning_bolt)
        lb_book = objects.GameObject('Book of Lightning Bolt',
                                     player.x + 1,
                                     player.y,
                                     0xE360,
                                     item=lb_item,
                                     spell=lb_spell,
                                     active=False,
                                     update_func=objects.update_spell)
        lb_book.current_map = self
        self.objects.append(lb_book)

        fb_item = objects.Item()
        fb_spell = objects.SpellEffect(name='Fireball',
                                       spell_range=10,
                                       damage=10,
                                       render_frames=3,
                                       icons={
                                           'n': 0xE380,
                                           's': 0xE381,
                                           'w': 0xE382,
                                           'e': 0xE383,
                                           'ne': 0xE384,
                                           'nw': 0xE385,
                                           'se': 0xE386,
                                           'sw': 0xE387,
                                           'hit': 0xE388
                                       },
                                       charges=5,
                                       aoe_function=effects.fireball)
        fb_book = objects.GameObject('Book of Fireball',
                                     player.x - 1,
                                     player.y,
                                     0xE361,
                                     item=fb_item,
                                     spell=fb_spell,
                                     active=False,
                                     update_func=objects.update_spell)

        fb_book.current_map = self
        self.objects.append(fb_book)

        self.assign_object_ids()
Esempio n. 5
0
#!/usr/bin/python
import random
import objects

all_the_things = {
    "item1":
    objects.Item(key="item1",
                 name="Unknown entity",
                 symbol="$",
                 color=7,
                 description="You don't know about this, yet",
                 longdesc="You don't know about this yet, longer",
                 def_article="the ",
                 indef_article="a ",
                 xp=0,
                 defense={},
                 attacks={},
                 speed=60,
                 accuracy=100,
                 hidden=False,
                 inventory=[]),
    "item2":
    objects.Item(key="item2",
                 name="Testing Sword",
                 symbol="/",
                 color=7,
                 description="A sword that should be wielded",
                 longdesc="You don't know about this yet, longer",
                 def_article="the ",
                 indef_article="a ",
                 xp=0,