Compare commits
3 Commits
adf47220c7
...
c79b5b2b5b
Author | SHA1 | Date | |
---|---|---|---|
c79b5b2b5b | |||
35e7819818 | |||
4208597ed3 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
__pycache__/
|
||||
levels/
|
30
levels.py
Normal file
30
levels.py
Normal file
@ -0,0 +1,30 @@
|
||||
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,8 +6,11 @@ from cmath import exp, pi
|
||||
from math import acos, copysign
|
||||
import pygame
|
||||
import pygame.freetype
|
||||
from os import makedirs
|
||||
from time import time
|
||||
from gyro import *
|
||||
from lines import *
|
||||
from levels import *
|
||||
|
||||
def deg2rad(rA): return rA/180*PI
|
||||
|
||||
@ -93,6 +96,22 @@ def make_wall(wall_buffer):
|
||||
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():
|
||||
gPlayer = GyroVector(0,1)
|
||||
display = pygame.display.set_mode((1280,720))
|
||||
@ -120,6 +139,12 @@ def mainLoop():
|
||||
wall_buffer.clear()
|
||||
else:
|
||||
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]:
|
||||
|
Loading…
Reference in New Issue
Block a user