DKL9 GitList
Repositories
DKL9 home
voxels
Code
Commits
Branches
Tags
Search
Tree:
88576ad
Branches
Tags
master
voxels
src
main.py
Fix collisions, mapgen, and voxel-placing
dkl9
commited
88576ad
at 2025-183 20:12:05
main.py
Blame
History
Raw
from libs import * from display import init_display from mapgen import MapGen from player import Player def debug_mode(mg, cam): pass def in_view(wr, cam): rwrc = wr.pos + wr.r / 2 - cam.pos close = np.linalg.norm(rwrc) < VIEW_DIST ld = cam.looking() cv = rwrc + 8 * ld frust = np.dot(cv, ld) / np.linalg.norm(cv) > 0.5 return close and frust def main(): init_display() glUniform4fv(UNIFORMS["lightPos"][2], 1, vec([*LIGHT_POS, 100])) mg = MapGen() clock = pygame.time.Clock() cam = Player(speed=6/FPS) cam.pos = [4, 8, 4] cam.set_focus(True) while True: scene = list(filter(lambda wr: in_view(wr, cam), mg.regions.values())) for wr in scene: if wr.dirty: wr.remesh() for i in range(len(VERTEX_ATTRS)): update_attr(wr, i) for ev in pygame.event.get(): match ev.type: case pygame.QUIT: pygame.quit() return case pygame.KEYUP: match ev.unicode: case "q": pygame.quit() return case "d": debug_mode(mg, cam) cam.handle_event(ev, mg, scene) cam.update_motion(pygame.key.get_pressed(), mg) cam.update_pos() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) for ent in scene: cam.draw(ent) perf = clock.get_fps() / FPS cam.draw_hud(scene, perf) pygame.display.flip() clock.tick(FPS) main()