Beispiel #1
0
def random_unblocked_pos(objects, depth):
    pos = Point(randint(1, MAP_WIDTH - 1), randint(1, MAP_HEIGHT - 1), depth)

    existing_objects = [o for o in objects if o.position == pos]
    if not dungeon.is_blocked(pos) and len(existing_objects) == 0:
        return pos

    return random_unblocked_pos(objects, depth)
Beispiel #2
0
def move_player(dx, dy, dz):
    new_pos = player.position.add(Point(dx, dy, dz))

    monster = filter_by_pos(monsters, new_pos)
    if monster is not None:
        attack(player, monster)
    elif not dungeon.is_blocked(new_pos):
        player.position = new_pos
        player.update_fov(dungeon.is_blocked)
        dungeon.update_explored(player)
Beispiel #3
0
def take_turn_monster(monster):
    if monster.died:
        return

    # close enough, attack!
    if euclidean_distance(player.position, monster.position) < 2:
        attack(monster, player)
        return

    # if the monster sees the player, update its target position
    if player.is_in_fov(monster.position):
        monster.target_pos = player.position

    if monster.target_pos not in (None, monster.position):
        # move towards player if far away
        if euclidean_distance(monster.position, monster.target_pos) >= 2:
            path = dungeon.get_path(monster.position, monster.target_pos)
            if path is not None:
                new_pos = Point(path[0], path[1], monster.position.z)
                if not dungeon.is_blocked(new_pos) and filter_by_pos(monsters, new_pos) is None:
                    monster.position = new_pos