Hello! Can you remove comments, and make room procedural generated? (And add here please…
- User
Hello! Can you remove comments, and make room procedural generated? (And add here please minimap) Also, can you make for borderless full screen window?
import pygame import math import numpy as np
pygame.init()
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720 FOV = math.pi / 3 HALF_FOV = FOV / 2 NUM_RAYS = SCREEN_WIDTH // 2 MAX_DEPTH = 800 CELL_SIZE = 64 PLAYER_SIZE = 10 FLOOR_COLOR = (30, 30, 30) CEILING_COLOR = (50, 50, 80) TEXTURE_SIZE = 64
WALL_TEXTURES = { 1: np.array([[(int((i ^ j) % 2) * 255) for i in range(TEXTURE_SIZE)] for j in range(TEXTURE_SIZE)], dtype=np.uint8), 2: np.array([[(int((i * j) % 32) * 8) for i in range(TEXTURE_SIZE)] for j in range(TEXTURE_SIZE)], dtype=np.uint8), 3: np.array([[int(abs(127 - i) * 2) for i in range(TEXTURE_SIZE)] for j in range(TEXTURE_SIZE)], dtype=np.uint8) }
MAP = [ [1, 1, 1, 2, 2, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 3, 0, 2, 0, 0, 2], [2, 0, 0, 0, 0, 3, 0, 1], [2, 0, 2, 0, 0, 0, 0, 1], [1, 0, 3, 0, 2, 0, 0, 2], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 2, 1, 1, 2, 1, 1] ]
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.RESIZABLE) pygame.display.set_caption('2.5D Raycaster')
Add mouse control variables
pygame.mouse.set_visible(False) pygame.event.set_grab(True) MOUSE_SENSITIVITY = 0.002
player_x = CELL_SIZE * 1.5 player_y = CELL_SIZE * 1.5 player_angle = 0 player_speed = 150 rotation_speed = 2
class TextureCache: def init(self): self.wall_textures = {} self._generate_textures()
def _generate_textures(self): for wall_type, pattern in WALL_TEXTURES.items(): surface = pygame.Surface((TEXTURE_SIZE, TEXTURE_SIZE)) pygame.surfarray.blit_array(surface, np.stack([pattern]*3, axis=-1)) self.wall_textures[wall_type] = surface.convert()texture_cache = TextureCache()
def cast_ray(angle): sin_a = math.sin(angle) cos_a = math.cos(angle)
EPSILON = 1e-10 if abs(sin_a) < EPSILON: sin_a = EPSILON if abs(cos_a) < EPSILON: cos_a = EPSILON player_cell_x = int(player_x / CELL_SIZE) player_cell_y = int(player_y / CELL_SIZE) delta_dist_x = abs(CELL_SIZE / cos_a) delta_dist_y = abs(CELL_SIZE / sin_a) step_x = 1 if cos_a >= 0 else -1 step_y = 1 if sin_a >= 0 else -1 side_dist_x = ((player_cell_x + 1) * CELL_SIZE - player_x) / cos_a if cos_a >= 0 else (player_x - player_cell_x * CELL_SIZE) / -cos_a side_dist_y = ((player_cell_y + 1) * CELL_SIZE - player_y) / sin_a if sin_a >= 0 else (player_y - player_cell_y * CELL_SIZE) / -sin_a distance = 0 map_width = len(MAP[0]) map_height = len(MAP) while distance < MAX_DEPTH: if side_dist_x < side_dist_y: side_dist_x += delta_dist_x player_cell_x += step_x side = 0 else: side_dist_y += delta_dist_y player_cell_y += step_y side = 1 if 0 <= player_cell_x < map_width and 0 <= player_cell_y < map_height: wall_type = MAP[player_cell_y][player_cell_x] if wall_type > 0: if side == 0: distance = (player_cell_x * CELL_SIZE - player_x + (1 - step_x) * CELL_SIZE / 2) / cos_a texture_pos = (player_y + distance * sin_a) % CELL_SIZE / CELL_SIZE else: distance = (player_cell_y * CELL_SIZE - player_y + (1 - step_y) * CELL_SIZE / 2) / sin_a texture_pos = (player_x + distance * cos_a) % CELL_SIZE / CELL_SIZE return distance, angle, wall_type, texture_pos else: return MAX_DEPTH, angle, 0, 0 return MAX_DEPTH, angle, 0, 0 - Assistant