From 3b2522b12b172af461ba391ea5f4673c9e1fda84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 00:40:37 +0500 Subject: [PATCH 01/11] Implement level loading. --- levels.py | 2 +- main.py | 16 +++++++--------- maps/cuberoom.p3hel | 1 + 3 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 maps/cuberoom.p3hel diff --git a/levels.py b/levels.py index 395ab92..560258b 100644 --- a/levels.py +++ b/levels.py @@ -19,7 +19,7 @@ def parse_level_from_string(string): level.append( Segment( bool(raw_segment[0]), - float(raw_segment[1]), + complex(raw_segment[1]), complex(raw_segment[2]), tuple(map(int, raw_segment[3][1:len(raw_segment[3])-1].split(', '))) ) diff --git a/main.py b/main.py index 88dfd9e..6cf93d5 100755 --- a/main.py +++ b/main.py @@ -3,11 +3,12 @@ from numba import jit from math import copysign, pi, acos from time import time +import sys import pygame import pygame.freetype -from levels import Segment +from levels import Segment, open_level, parse_level_from_string from gyro import * from levels import * from constants import * @@ -20,14 +21,6 @@ gOrigin = GyroVector(0,1) SKY = (127,127,255) GROUND = (102, 51, 0) -level = [ - Segment(True,.6,I*.6,(255,0,0)), - Segment(True,.6,-I*.6,(0,255,0)), - Segment(True,-.6,-I*.6,(0,0,255)), - Segment(True,-.6,I*.6,(255,255,0)) - ] - - def renderDebugInfo(gPlayer, clock, fontSize = 18): font = pygame.freetype.Font(None, fontSize) font_fg = (255, 255, 255) @@ -49,6 +42,11 @@ def mainLoop(): debugInfo = True wall_buffer = [] + try: + level = parse_level_from_string(open_level(sys.argv[1])) + except IndexError: + level = parse_level_from_string(open_level("maps/cuberoom.p3hel")) + while True: for event in pygame.event.get(): if event.type == pygame.QUIT: diff --git a/maps/cuberoom.p3hel b/maps/cuberoom.p3hel new file mode 100644 index 0000000..a586296 --- /dev/null +++ b/maps/cuberoom.p3hel @@ -0,0 +1 @@ +True/0.6/0.6j/(255, 0, 0)|True/0.6/-0.6j/(0, 255, 0)|True/-0.6/-0.6j/(0, 0, 255)|True/-0.6/0.6j/(255, 255, 0) \ No newline at end of file From 1845425c16dc8bdd3b9846e3f7ecdc974ee170a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 00:52:39 +0500 Subject: [PATCH 02/11] Fix level loading and add an empty level. --- main.py | 7 ++++--- maps/empty.p3hel | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 maps/empty.p3hel diff --git a/main.py b/main.py index 6cf93d5..f1e3729 100755 --- a/main.py +++ b/main.py @@ -41,11 +41,12 @@ def mainLoop(): fontSize = 18 debugInfo = True wall_buffer = [] - + try: - level = parse_level_from_string(open_level(sys.argv[1])) + leveltoparse = open_level(sys.argv[1]) except IndexError: - level = parse_level_from_string(open_level("maps/cuberoom.p3hel")) + leveltoparse = open_level("maps/cuberoom.p3hel") + level = parse_level_from_string(leveltoparse) while True: for event in pygame.event.get(): diff --git a/maps/empty.p3hel b/maps/empty.p3hel new file mode 100644 index 0000000..07c6a6d --- /dev/null +++ b/maps/empty.p3hel @@ -0,0 +1 @@ +True/0/0/(0, 0, 0 From 181492cc68c32e784098caf16ade0bf3228f9c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 00:53:56 +0500 Subject: [PATCH 03/11] Rename "cuberoom" into "squareroom". --- main.py | 2 +- maps/{cuberoom.p3hel => squareroot.p3hel} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename maps/{cuberoom.p3hel => squareroot.p3hel} (100%) diff --git a/main.py b/main.py index f1e3729..abf7b57 100755 --- a/main.py +++ b/main.py @@ -45,7 +45,7 @@ def mainLoop(): try: leveltoparse = open_level(sys.argv[1]) except IndexError: - leveltoparse = open_level("maps/cuberoom.p3hel") + leveltoparse = open_level("maps/squareroot.p3hel") level = parse_level_from_string(leveltoparse) while True: diff --git a/maps/cuberoom.p3hel b/maps/squareroot.p3hel similarity index 100% rename from maps/cuberoom.p3hel rename to maps/squareroot.p3hel From 9121959b2596a3ef0e737d5a9f933668cf065721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:00:08 +0500 Subject: [PATCH 04/11] Fix rendering a bit. --- lines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lines.py b/lines.py index 4f064c1..71ffb0d 100644 --- a/lines.py +++ b/lines.py @@ -13,7 +13,7 @@ def cLineIntersection(cA0, cA1, cB0, cB1): @jit def Between(rA,rB,rN): - return (rA < rN and rN < rB) or (rB < rN and rN < rA) + return (rA <= rN and rN <= rB) or (rB <= rN and rN <= rA) @jit def cBetween(cA,cB,cN): From bd0aea17288cf0df5c262fc2ef64eb4d91c96004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:04:37 +0500 Subject: [PATCH 05/11] Fix a typo. --- main.py | 2 +- maps/{squareroot.p3hel => squareroom.p3hel} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename maps/{squareroot.p3hel => squareroom.p3hel} (100%) diff --git a/main.py b/main.py index abf7b57..70b8d27 100755 --- a/main.py +++ b/main.py @@ -45,7 +45,7 @@ def mainLoop(): try: leveltoparse = open_level(sys.argv[1]) except IndexError: - leveltoparse = open_level("maps/squareroot.p3hel") + leveltoparse = open_level("maps/squareroom.p3hel") level = parse_level_from_string(leveltoparse) while True: diff --git a/maps/squareroot.p3hel b/maps/squareroom.p3hel similarity index 100% rename from maps/squareroot.p3hel rename to maps/squareroom.p3hel From 18e4dec8211b5737347f66480ceead9fd86895b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:08:01 +0500 Subject: [PATCH 06/11] Nope. --- main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.py b/main.py index 70b8d27..02a5e4b 100755 --- a/main.py +++ b/main.py @@ -69,10 +69,6 @@ def mainLoop(): wall_buffer.append(gPlayer.cPos) if event.key == pygame.K_F5: save_level(level) - if event.key == pygame.K_F9: - # TODO: @bedohswe make open file dialog - # open_level(path) - pass keys = pygame.key.get_pressed() if keys[pygame.K_d]: From 7f1799acfe57e658fbab3be85d7c94bfcfc10f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:31:01 +0500 Subject: [PATCH 07/11] Fix level loading. --- levels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/levels.py b/levels.py index 560258b..111bfe4 100644 --- a/levels.py +++ b/levels.py @@ -18,7 +18,7 @@ def parse_level_from_string(string): level.append( Segment( - bool(raw_segment[0]), + raw_segment[0] == "True", complex(raw_segment[1]), complex(raw_segment[2]), tuple(map(int, raw_segment[3][1:len(raw_segment[3])-1].split(', '))) From 04f0f7329cd6f0b42b9cc0d67538ac8c9765272a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:31:27 +0500 Subject: [PATCH 08/11] . --- draw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draw.py b/draw.py index b9af465..7290441 100644 --- a/draw.py +++ b/draw.py @@ -23,7 +23,7 @@ def draw(level,gPlayer,fov,res): if cDot(rot,MobiusAdd(cInt,-gPlayer.cPos)) > 0: continue rDist = MobiusDist(cInt,gPlayer.cPos)*1.1 - if not (j.isFinite and cBetween(j.pointA,j.pointB,cInt)): + if j.isFinite and not cBetween(j.pointA,j.pointB,cInt): continue if (1 - m.height) > rDist: m = DrawnSegment(1-rDist,j.color) From 53ecde3e0c85d4702842d359c4f0992307e48d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:33:15 +0500 Subject: [PATCH 09/11] Add a map. --- maps/cross.p3hel | 1 + 1 file changed, 1 insertion(+) create mode 100644 maps/cross.p3hel diff --git a/maps/cross.p3hel b/maps/cross.p3hel new file mode 100644 index 0000000..db796f0 --- /dev/null +++ b/maps/cross.p3hel @@ -0,0 +1 @@ +False/1/0/(255, 0, 0 |False/1j/0/(0, 255, 0 From d54377e3d65f2abb5559a836cde39eafa83ecc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:46:39 +0500 Subject: [PATCH 10/11] Change rendering a bit. --- draw.py | 15 +++++++++------ main.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/draw.py b/draw.py index 7290441..399c788 100644 --- a/draw.py +++ b/draw.py @@ -4,8 +4,8 @@ from gyro import * from lines import * class DrawnSegment: - def __init__(self,height,color): - self.height = height + def __init__(self,dist,color): + self.dist = dist self.color = color def draw(level,gPlayer,fov,res): @@ -13,7 +13,7 @@ def draw(level,gPlayer,fov,res): irot = exp(fov/res*I) iprot = gPlayer.cRot for i in range(res): - m = DrawnSegment(0,BLACK) + m = None rot = irot**(i-(res/2)) * iprot for j in level: try: # Function "LineIntersection" faults from time to time @@ -25,8 +25,11 @@ def draw(level,gPlayer,fov,res): rDist = MobiusDist(cInt,gPlayer.cPos)*1.1 if j.isFinite and not cBetween(j.pointA,j.pointB,cInt): continue - if (1 - m.height) > rDist: - m = DrawnSegment(1-rDist,j.color) - drawn.append(m) + if m is None: + m = DrawnSegment(rDist,j.color) + continue + if m.dist > rDist: + m = DrawnSegment(rDist,j.color) + drawn.append(m if m is not None else DrawnSegment(0, BLACK)) return drawn diff --git a/main.py b/main.py index 02a5e4b..5dc7f37 100755 --- a/main.py +++ b/main.py @@ -90,7 +90,7 @@ def mainLoop(): pygame.draw.rect(display,GROUND, (0,360,1280,360)) n = 0 for i in drawn: - pygame.draw.rect(display,i.color, (n,int((1 - cap(i.height)) * 360),8,int(cap(i.height) * 1280))) + pygame.draw.rect(display,i.color, (n,int((cap(i.dist)) * 360),8,int(cap(1 - i.dist) * 1280))) n += 4 gPlayer.normalize() if debugInfo: From 9ebde906c28bc7be39c8a640bb985239c6235f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Fri, 5 Apr 2024 01:51:26 +0500 Subject: [PATCH 11/11] Slow down a bit. --- constants.py | 2 +- main.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/constants.py b/constants.py index 391f0b6..7e03d7a 100644 --- a/constants.py +++ b/constants.py @@ -3,6 +3,6 @@ from cmath import exp I = complex(0,1) WHITE = (255,255,255) BLACK = (0,0,0) -OFFSET = 0.015625 +OFFSET = 0.0078125 ROT = cNorm(exp(deg2rad(2)*I)) IROT = 1/ROT diff --git a/main.py b/main.py index 5dc7f37..d69ab27 100755 --- a/main.py +++ b/main.py @@ -32,7 +32,9 @@ def renderDebugInfo(gPlayer, clock, fontSize = 18): return fps_surf, cPos_surf, cRot_surf - +def nonzerocap(n): + if n <= 0: return 1 + return n def mainLoop(): gPlayer = GyroVector(0,1) @@ -90,7 +92,7 @@ def mainLoop(): pygame.draw.rect(display,GROUND, (0,360,1280,360)) n = 0 for i in drawn: - pygame.draw.rect(display,i.color, (n,int((cap(i.dist)) * 360),8,int(cap(1 - i.dist) * 1280))) + pygame.draw.rect(display,i.color, (n,int((nonzerocap(i.dist)) * 360),8,int((1 -nonzerocap(i.dist)) * 1280))) n += 4 gPlayer.normalize() if debugInfo: