Exemple #1
0
def _rendering_zone_to_v2f(z: Zone):
    bottom_left = z.bottom_left
    bottom_right = v2(z.top_right.x, z.bottom_left.y)
    top_right = z.top_right
    top_left = v2(z.bottom_left.x, z.top_right.y)

    return _rendering_v2_to_tup(bottom_left, bottom_right, top_right, top_left)
Exemple #2
0
    def generate(self) -> World:
        _log.info("Starting world generation...")
        zones = []
        zones_left = self.count

        while zones_left > 0:
            if not zones:
                gen_bottom_left = v2(
                    _worldgen_round(-self.min_size.x * 0.75, self.round_to),
                    _worldgen_round(-self.min_size.y * 0.75, self.round_to))
                gen_top_right = v2(
                    _worldgen_round(self.min_size.x * 0.75, self.round_to),
                    _worldgen_round(self.min_size.y * 0.75, self.round_to))
                generated_zone = Zone("starting-room", gen_bottom_left,
                                      gen_top_right)
            else:
                gen_width = _worldgen_round(
                    randint(self.min_size.x, self.max_size.x), self.round_to)
                gen_height = _worldgen_round(
                    randint(self.min_size.y, self.max_size.y), self.round_to)
                # legacy docs below: pypy doesn't have a 3.6 version, so choices() doesn't exist
                # choices() allows weighting
                # by default, k=1, so choices() will only have 1 element (safe to just use [0])
                # the weighting I chose to use was just using the amount of open neighbors to the 10th
                # why to the 10th? I want a significantly less chance of it picking a zone with 3 neighbors as opposed
                # to one with just 1 neighbor. obviously, I should probably just use squared or something
                # but I really _really_ don't want 4-way corridors.
                random_parent_zone = choice(zones)
                open_directions = random_parent_zone.get_open_directions()
                if not open_directions:
                    continue
                random_direction = choice(open_directions)
                offset_func = choice(_WORLDGEN_OFFSET[random_direction])
                bottom_left, top_right = offset_func(random_parent_zone,
                                                     gen_width, gen_height, 0)

                generated_zone = Zone("zone-%d" % (self.count - zones_left),
                                      bottom_left, top_right)
                # if we generated an overlap, just discard it and generate another one
                if _worldgen_has_collision(zones, generated_zone):
                    continue
                random_parent_zone.neighbors[random_direction] = generated_zone
                generated_zone.neighbors[
                    ~random_direction] = random_parent_zone

            zones.append(generated_zone)
            zones_left -= 1

        _log.info("Finished world generation!")
        return World(zones)
Exemple #3
0
def _worldgen_offset_n_r(z: Zone, new_width: int, new_height: int,
                         offset: int):
    return v2(z.bottom_left.x + z.width() - new_width, z.top_right.y - offset), \
           v2(z.bottom_left.x + z.width(), z.top_right.y + new_height - offset)
Exemple #4
0
def _worldgen_offset_n_m(z: Zone, new_width: int, new_height: int,
                         offset: int):
    return v2(z.bottom_left.x + (z.width() / 2) - (new_width / 2), z.top_right.y - offset), \
           v2(z.bottom_left.x + (z.width() / 2) + (new_width / 2), z.top_right.y + new_height - offset)
Exemple #5
0
def _worldgen_offset_w_b(z: Zone, new_width: int, new_height: int,
                         offset: int):
    return v2(z.bottom_left.x + offset, z.top_right.y - z.height()), \
           v2(z.bottom_left.x - new_width + offset, z.top_right.y - z.height() + new_height)
Exemple #6
0
def _worldgen_offset_w_m(z: Zone, new_width: int, new_height: int,
                         offset: int):
    return v2(z.bottom_left.x + offset, z.top_right.y - (z.height() / 2) + (new_height / 2)), \
           v2(z.bottom_left.x - new_width + offset, z.top_right.y - (z.height() / 2) - (new_height / 2))
Exemple #7
0
def _worldgen_offset_s_l(z: Zone, new_width: int, new_height: int,
                         offset: int):
    return v2(z.bottom_left.x, z.top_right.y - z.height() + offset), \
           v2(z.bottom_left.x + new_width, z.top_right.y - z.height() - new_height  + offset)
Exemple #8
0
def _worldgen_offset_e_t(z: Zone, new_width: int, new_height: int,
                         offset: int):
    return v2(z.bottom_left.x + z.width() - offset, z.top_right.y), \
           v2(z.bottom_left.x + z.width() + new_width - offset, z.top_right.y - new_height)
Exemple #9
0
camera_look_direction = v3(0, 0, 1, 1)

fov = 60

fps = 0

camera_movement_speed = 4
yaw = 0

#'''  Unit cube:

cube = Mesh(
    (

        # SOUTH
        Triangle(v3(0, 0, 0, 1), v3(0, 1, 0, 1), v3(1, 1, 0, 1), v2(0, 1),
                 v2(0, 0), v2(1, 0)),
        Triangle(v3(0, 0, 0, 1), v3(1, 1, 0, 1), v3(1, 0, 0, 1), v2(0, 1),
                 v2(1, 0), v2(1, 1)),

        # EAST
        Triangle(v3(1, 0, 0, 1), v3(1, 1, 0, 1), v3(1, 1, 1, 1), v2(0, 1),
                 v2(0, 0), v2(1, 0)),
        Triangle(v3(1, 0, 0, 1), v3(1, 1, 1, 1), v3(1, 0, 1, 1), v2(0, 1),
                 v2(1, 0), v2(1, 1)),

        # NORTH
        Triangle(v3(1, 0, 1, 1), v3(1, 1, 1, 1), v3(0, 1, 1, 1), v2(0, 1),
                 v2(0, 0), v2(1, 0)),
        Triangle(v3(1, 0, 1, 1), v3(0, 1, 1, 1), v3(0, 0, 1, 1), v2(0, 1),
                 v2(1, 0), v2(1, 1)),