Beispiel #1
0
    def __init__(self):
        # Initialization
        libtcodpy.console_set_custom_font('src/arial10x10.png', libtcodpy.FONT_TYPE_GREYSCALE | libtcodpy.FONT_LAYOUT_TCOD)
        libtcodpy.console_init_root(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT, 'ROGuelike TUTorial', False)
        libtcodpy.sys_set_fps(settings.LIMIT_FPS)
        self.con = libtcodpy.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT)

        self.game_map = GameMap(self.con)
        player_x, player_y = self.game_map.get_staring_position()
        # game objects
        self.player = Player(
            'Player',
            self.con,
            player_x, player_y, '@',
            fighter=Fighter(hp=15, defense=5, power=5, death_function=player_death))

        npc_x, npc_y = self.game_map.get_ending_position()
        self.npc = Npc('Trader', self.con, npc_x, npc_y, '@')
        self.objects = [self.npc, self.player]

        self.npcs = [self.npc]
        for monster in self.game_map.place_monsters():
            self.objects.append(monster)

            if hasattr(monster, 'is_selfmoving') and monster.is_selfmoving:
                self.npcs.append(monster)

        self.game_state = 'playing'
        self.player_action = None
Beispiel #2
0
    def place_monsters(self):
        for room in self._rooms:
            #choose random number of monsters
            num_monsters = libtcodpy.random_get_int(0, 0,
                                                    settings.MAX_ROOM_MONSTERS)

            for i in range(num_monsters):
                #choose random spot for this monster
                x = libtcodpy.random_get_int(0, room.x1, room.x2)
                y = libtcodpy.random_get_int(0, room.y1, room.y2)

                if libtcodpy.random_get_int(
                        0, 0, 100) < 80:  #80% chance of getting an orc
                    #create an orc
                    monster = Orc('Uguk',
                                  self.con,
                                  x,
                                  y,
                                  'o',
                                  fighter=Fighter(
                                      hp=10,
                                      defense=0,
                                      power=3,
                                      death_function=monster_death),
                                  ai=SelfMovingBasicMonster())
                else:
                    #create a troll
                    monster = Troll('Ogg',
                                    self.con,
                                    x,
                                    y,
                                    'T',
                                    fighter=Fighter(
                                        hp=20,
                                        defense=5,
                                        power=7,
                                        death_function=monster_death),
                                    ai=ImmovableBasicMonster())

                yield monster
Beispiel #3
0
def gen_monster_troll(coords):

    x, y = coords

    fighter_comp = Fighter(hp=16,
                           defense=1,
                           power=4,
                           death_function=gf.monster_death)

    ai_comp = BasicMonster()

    monster = GameObject(g.settings,
                         "Troll",
                         x,
                         y,
                         color=colors.darker_green,
                         blocks=True,
                         fighter=fighter_comp,
                         ai=ai_comp,
                         img=r.troll)

    return monster
Beispiel #4
0
def gen_monster_zombie(coords):

    x, y = coords

    fighter_comp = Fighter(hp=10,
                           defense=0,
                           power=3,
                           death_function=gf.monster_death)

    ai_comp = BasicMonster()

    monster = GameObject(g.settings,
                         "Zombie",
                         x,
                         y,
                         color=colors.darker_violet,
                         blocks=True,
                         fighter=fighter_comp,
                         ai=ai_comp,
                         img=r.zombie)

    return monster
Beispiel #5
0
def run_game():
    #Initialize game and create a screen object.
    pygame.init()
    settings = Settings()
    g.settings = Settings()

    g.settings_g = Settings()

    pygame.display.set_caption(settings.title)

    # Initialize Map
    grid = Grid(settings)
    g.tiles = Group()

    # Map Matrix initialisieren und Tiles hinzufügen
    tiles_init(settings, g.tiles)

    #Player
    fighter_comp = Fighter(hp=30,
                           defense=2,
                           power=5,
                           death_function=gf.player_death)
    g.player = GameObject(settings,
                          "player",
                          1,
                          1,
                          colors.gold,
                          img=r.player,
                          blocks=True,
                          fighter=fighter_comp)

    # Create Random Map
    make_map()

    # Initialize GUI and Inventory
    g.gui_elements = GUI(settings)
    g.inventory_menu = InventoryMenu(settings)

    #Print Welcome Message
    print_message("Welcome to the BEIDL", colors.black, colors.dark_red)

    #Initialize groups
    g.monster_group = Group()
    g.item_group = Group()
    g.dead_group = Group()
    g.inventory = Group()
    g.graphics_group = Group()
    """F**K AROUND"""
    #vvvvvvvvvvv#

    for i in range(10):
        testi_place_objects('item')

    for i in range(50):
        testi_place_objects('enemy')

    # """Test: Dummy Walls"""
    # g.map_matrix[4][5].blocked = True
    # g.map_matrix[4][5].block_sight = True
    # g.map_matrix[4][6].blocked = True
    # g.map_matrix[4][6].block_sight = True
    #
    # g.map_matrix[15][21].blocked = True
    # g.map_matrix[15][21].block_sight = True
    # g.map_matrix[16][21].blocked = True
    # g.map_matrix[16][21].block_sight = True

    #^^^^^^^^^#
    """F**K AROUND"""

    # Start the main loop for the game.
    while True:
        """MENU"""
        # Menu Screen
        #while settings.game_state == "menu":
        #gf.check_events_menu(settings, all_groups)
        #gf.update_screen_menu(settings, all_groups)
        """GAME"""
        #while g.game_state == "playing":
        while True:

            g.clock.tick(FPS)
            # ticks = pygame.time.get_ticks()

            gf.update_screen(settings)

            # Check game_state for Contol Setup
            # TODO game state control handling like this?
            if g.game_state == 'inventory':
                player_action = gf.controls_inventory(settings)
            else:
                player_action = gf.controls(settings, g.player)

            # Let Enemys take turns
            if g.game_state == 'playing' and player_action != "noturn":
                for obj in g.monster_group:
                    if obj.ai:
                        obj.ai.take_turn()

            # TODO Turn for using inventory item, redundant, use in game state?
            if player_action == "turn":
                for obj in g.monster_group:
                    if obj.ai:
                        obj.ai.take_turn()