feat(save_level): now displays a alert with filename #6

Merged
bedohswe merged 2 commits from n3tael/p3he:main into main 2024-04-04 21:08:47 +00:00
8 changed files with 31 additions and 26 deletions
Showing only changes of commit 43b2d31980 - Show all commits

View File

@ -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

17
draw.py
View File

@ -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
@ -23,10 +23,13 @@ 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)
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

View File

@ -18,8 +18,8 @@ def parse_level_from_string(string):
level.append(
Segment(
bool(raw_segment[0]),
float(raw_segment[1]),
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(', ')))
)

View File

@ -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):

29
main.py
View File

@ -2,11 +2,13 @@
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 +22,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)
@ -39,6 +33,10 @@ 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)
display = pygame.display.set_mode((1280,720))
@ -55,6 +53,12 @@ def mainLoop():
alerts.append(alert)
alert.start_hide_thread(alerts, delay)
try:
leveltoparse = open_level(sys.argv[1])
except IndexError:
leveltoparse = open_level("maps/squareroom.p3hel")
level = parse_level_from_string(leveltoparse)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
@ -80,11 +84,6 @@ def mainLoop():
alert_append(alert, 5)
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]:
gPlayer.rotate(ROT)
@ -105,7 +104,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((nonzerocap(i.dist)) * 360),8,int((1 -nonzerocap(i.dist)) * 1280)))
n += 4
gPlayer.normalize()
if debugInfo:

1
maps/cross.p3hel Normal file
View File

@ -0,0 +1 @@
False/1/0/(255, 0, 0 |False/1j/0/(0, 255, 0

1
maps/empty.p3hel Normal file
View File

@ -0,0 +1 @@
True/0/0/(0, 0, 0

1
maps/squareroom.p3hel Normal file
View File

@ -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)