Implement level loading.

This commit is contained in:
bʰedoh₂ swé 2024-04-05 00:40:37 +05:00
parent 371491a607
commit 3b2522b12b
3 changed files with 9 additions and 10 deletions

View File

@ -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(', ')))
)

16
main.py
View File

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

1
maps/cuberoom.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)