示例#1
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setObjectName("miniMapDock")
        self.mMiniMap = MiniMap(self)
        self.setWidget(self.mMiniMap)
        self.retranslateUi()
示例#2
0
文件: main.py 项目: ncd2dq/3dsimple
def main(env_array, env_string, texture_map, wall='#'):
    last_key = None

    # If resolution is 12, each 3D column will be 12 units long
    env_index_width = len(env_array[0])
    env_index_height = len(env_array)
    screen_width_resolution = 12
    screen_height_resolution = 12
    screen_width = env_index_width * screen_width_resolution
    screen_height = env_index_height * screen_height_resolution

    # Player Attributes (Angles in Degrees)
    player = Player(24.0, 12.0, 0)
    map = MiniMap(env_array)

    while last_key != 'QUIT':
        new_key = get_keys()
        player.key_input(new_key)

        #
        # RAY TRACING
        #
        # Determine distances to objects in player field
        # each distance until ray touched an object will determine 1 full column drawn
        distances = []
        ray_count = 140
        ray_angle_incrementation = player.visual_field_degrees / ray_count
        ray_distance_incrementation = 2
        ray_max_dist = screen_width
        for ray_num in range(ray_count):
            ray_x = player.x
            ray_y = player.y
            ray_angle = (player.angle - (player.visual_field_degrees / 2) +
                         (ray_angle_incrementation * ray_num))

            # Increment the rays length until a collision
            ray_distance = 0
            while True:
                ray_index_x = int(ray_x // screen_width_resolution)
                ray_index_y = int(ray_y // screen_height_resolution)
                # If we hit a wall, determine distance we traveled

                if ray_index_x >= env_index_width:
                    ray_index_x = env_index_width - 1
                if ray_index_y >= env_index_height:
                    ray_index_y = env_index_height - 1

                if ray_distance >= ray_max_dist:
                    distances.append(ray_max_dist)
                    break
                elif env_array[ray_index_y][ray_index_x] == wall:
                    distances.append(ray_distance)
                    break
                else:
                    ray_distance += ray_distance_incrementation
                    ray_angle_radians = math.radians(ray_angle)
                    ray_x += math.cos(ray_angle_radians) * ray_distance
                    ray_y += math.sin(ray_angle_radians) * ray_distance

        #
        # SCREEN RENDERING
        #
        # Now we have an array of distances (@array distances) for each array
        # each distance in the array represents a column
        player_vision = generate_player_vision(distances, texture_map,
                                               ray_max_dist,
                                               screen_height_resolution,
                                               screen_height)
        last_key = new_key
        try:
            # Widnows
            os.system('cls')
        except Exception as e:
            # Mac
            os.system('clear')

        # Display player on map
        player_cord_x, player_cord_y = player.get_index(
            screen_width_resolution, screen_height_resolution)
        map_bytes = map.get_minimap(player_cord_x, player_cord_y, player.angle)

        player_vision += map_bytes
        player_vision += bytes(str(map.arrow_angle), 'utf-8')

        sys.stdout.buffer.write(player_vision)
        sys.stdout.flush()
示例#3
0
 def addMiniMap(self):
     self.miniMap = MiniMap(self, 160, 120)
     self.addSprite(self.miniMap)