@loserprogramist
i allaways want to create good code but i cant

Почему у меня ошибка в коде моей игры?

у меня возникает ошибка при заупеске программы
Traceback (most recent call last):
  File "F:/Python/KolfBloodC/game3d.py", line 24, in <module>
    drawing.world(player.pos, player.angle)
  File "F:\Python\KolfBloodC\drawing.py", line 19, in world
    ray_casting(self.sc, player_pos, player_angle, self.textures)
  File "F:\Python\KolfBloodC\raycasting.py", line 43, in ray_casting
    depth, offset, texture= (depth_v,yv , texture_v) if depth_v < depth_h else (depth_h , xh, texture_h)
UnboundLocalError: local variable 'texture_v' referenced before assignment

вот мой код:
import pygame
from settings import *
from map import world_map


def mapping(a, b):
    return (a // TILE) * TILE, (b // TILE) * TILE


def ray_casting(sc, player_pos, player_angle,textures):
    ox, oy = player_pos
    xm, ym = mapping(ox, oy)
    cur_angle = player_angle - HALF_FOV
    for ray in range(NUM_RAYS):
        sin_a = math.sin(cur_angle)
        cos_a = math.cos(cur_angle)
        sin_a = sin_a if sin_a else 0.000001
        cos_a = cos_a if cos_a else 0.000001

        # verticals
        x, dx = (xm + TILE, 1) if cos_a >= 0 else (xm, -1)
        for i in range(0, WIDTH, TILE):
            depth_v = (x - ox) / cos_a
            yv = oy + depth_v * sin_a
            tile_v = mapping(x + dx , yv)
            if tile_v in world_map:
                texture_v = world_map[tile_v]
                break
            x += dx * TILE

        # horizontals
        y, dy = (ym + TILE, 1) if sin_a >= 0 else (ym, -1)
        for i in range(0, HEIGHT, TILE):
            depth_h = (y - oy) / sin_a
            xh = ox + depth_h * cos_a
            tile_h = mapping(xh , y + dy)
            if tile_h in world_map:
                texture_h = world_map[tile_h]
                break
            y += dy * TILE

        # projection
        depth, offset, texture= (depth_v,yv , texture_v) if depth_v < depth_h else (depth_h , xh, texture_h)
        offset = int(offset) % TILE
        depth *= math.cos(player_angle - cur_angle)
        depth =  max(depth , 0.00001)
        proj_height = min(int(PROJ_COEFF / depth),2 * HEIGHT)

        wall_column = texture[textures].subsurface(offset * TEXTURE_SCALE, 0, TEXTURE_SCALE, TEXTURE_HEIGHT)
        wall_column = pygame.transform.scale(wall_column, (SCALE, proj_height))
        sc.blit(wall_column, (ray * SCALE, HALF_HEIGHT - proj_height // 2))

        cur_angle += DELTA_ANGLE
  • Вопрос задан
  • 141 просмотр
Пригласить эксперта
Ответы на вопрос 1
SoreMix
@SoreMix Куратор тега Python
yellow
Ну собственно, как и написано, texture_v не определена. Условие if tile_v in world_map не выполнено
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 17:06
15000 руб./за проект
19 апр. 2024, в 16:53
1000 руб./за проект
19 апр. 2024, в 16:45
5000 руб./за проект