Compare commits
No commits in common. "c79b5b2b5bc488072bb547583095604f0ec83db5" and "adf47220c7b4db6f641674e996bb9c6ac556cccb" have entirely different histories.
c79b5b2b5b
...
adf47220c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
levels/
|
|
30
levels.py
30
levels.py
@ -1,30 +0,0 @@
|
|||||||
from main import Segment
|
|
||||||
|
|
||||||
def parse_level_from_string(string):
|
|
||||||
level = []
|
|
||||||
|
|
||||||
raw_segments = string.split('|')
|
|
||||||
|
|
||||||
for segment in raw_segments:
|
|
||||||
raw_segment = segment.split('/')
|
|
||||||
|
|
||||||
level.append(
|
|
||||||
Segment(
|
|
||||||
bool(raw_segment[0]),
|
|
||||||
float(raw_segment[1]),
|
|
||||||
complex(raw_segment[2]),
|
|
||||||
tuple(map(int, raw_segment[3][1:len(raw_segment[3])-1].split(', ')))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return level
|
|
||||||
|
|
||||||
def save_level_to_string(level):
|
|
||||||
string_level = ""
|
|
||||||
|
|
||||||
for segment in level:
|
|
||||||
string_level += f'{segment.isFinite}/{segment.pointA}/{segment.pointB}/{segment.color}'
|
|
||||||
if segment != level[len(level) - 1]:
|
|
||||||
string_level += '|'
|
|
||||||
|
|
||||||
return string_level
|
|
25
main.py
25
main.py
@ -6,11 +6,8 @@ from cmath import exp, pi
|
|||||||
from math import acos, copysign
|
from math import acos, copysign
|
||||||
import pygame
|
import pygame
|
||||||
import pygame.freetype
|
import pygame.freetype
|
||||||
from os import makedirs
|
|
||||||
from time import time
|
|
||||||
from gyro import *
|
from gyro import *
|
||||||
from lines import *
|
from lines import *
|
||||||
from levels import *
|
|
||||||
|
|
||||||
def deg2rad(rA): return rA/180*PI
|
def deg2rad(rA): return rA/180*PI
|
||||||
|
|
||||||
@ -96,22 +93,6 @@ def make_wall(wall_buffer):
|
|||||||
Segment(True, wall_buffer[0], wall_buffer[1], (23,74,183))
|
Segment(True, wall_buffer[0], wall_buffer[1], (23,74,183))
|
||||||
)
|
)
|
||||||
|
|
||||||
def save_level(level):
|
|
||||||
makedirs("./levels/", exist_ok=True)
|
|
||||||
|
|
||||||
level_save = save_level_to_string(level)
|
|
||||||
|
|
||||||
unix_timestamp = int(time())
|
|
||||||
save = open(f"./levels/{unix_timestamp}.p3hel", "w")
|
|
||||||
save.write(level_save)
|
|
||||||
save.close()
|
|
||||||
|
|
||||||
def open_level(path):
|
|
||||||
save = open(path, "r")
|
|
||||||
level = save.read() # don't know it working
|
|
||||||
|
|
||||||
save.close()
|
|
||||||
|
|
||||||
def mainLoop():
|
def mainLoop():
|
||||||
gPlayer = GyroVector(0,1)
|
gPlayer = GyroVector(0,1)
|
||||||
display = pygame.display.set_mode((1280,720))
|
display = pygame.display.set_mode((1280,720))
|
||||||
@ -139,12 +120,6 @@ def mainLoop():
|
|||||||
wall_buffer.clear()
|
wall_buffer.clear()
|
||||||
else:
|
else:
|
||||||
wall_buffer.append(gPlayer.cPos)
|
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()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_d]:
|
if keys[pygame.K_d]:
|
||||||
|
Loading…
Reference in New Issue
Block a user