Browse Source

simplified object data loading and removed unused data from savegame

JSON-implementation
Max Lange 7 years ago
parent
commit
920ca2b111
  1. 11
      saves/Debug.ini
  2. 11
      saves/default.ini
  3. 25
      src/objects.py
  4. 18
      src/settings.py

11
saves/Debug.ini

@ -1,11 +0,0 @@
[main]
fullscreen = False
screenx_current = 400
screeny_current = 300
debug = True
skip = True
posx = 0.949870958743
posy = 0.92354835789
volume = 0.0
highscore = 100000000

11
saves/default.ini

@ -1,11 +0,0 @@
[main]
fullscreen = False
screenx_current = 960
screeny_current = 540
debug = True
skip = True
posx = 283
posy = 497
volume = 0.5
debugscreen = False
debugmode = False

25
src/objects.py

@ -37,9 +37,6 @@ class stars():
# values between -1 and +1
self.relative_x = (random.random() * 2) - 1
self.relative_y = (random.random() * 2) - 1
# update determines absolute position
self.pointx = 0
self.pointy = 0
self.update(screenx / 1920.0)
def move(self, x, y):
@ -142,6 +139,7 @@ class target():
self.kill_entity = False
self.inscreen = True
self.move(settings.player.pos.x, settings.player.pos.y)
self.test = 0
def update(self):
"""Adjusts position according to screen size"""
@ -194,6 +192,13 @@ class target():
return True
return False
def unique_relevant_data(self):
data = {}
data["timer"] = self.timer
data["pos_yper"] = self.pos_yper
data["pos_xper"] = self.pos_xper
return data
class warp_station():
@ -254,14 +259,20 @@ class warp_station():
settings.right = False
while test_collide():
if settings.player.pos.center[0] < self.pos.center[0]:
settings.player.move_pix_ip(-20, 0)
settings.player.move_ip(-20, 0)
else:
settings.player.move_pix_ip(20, 0)
settings.player.move_ip(20, 0)
if settings.player.pos.center[1] < self.pos.center[1]:
settings.player.move_pix_ip(0, -20)
settings.player.move_ip(0, -20)
else:
settings.player.move_pix_ip(0, 20)
settings.player.move_ip(0, 20)
playerpos = settings.player.pos
def blit(self):
self.screen.blit(self.img, self.pos)
def unique_relevant_data(self):
data = {}
data["y_pos"] = self.y_pos
data["x_pos"] = self.x_pos
return data

18
src/settings.py

@ -309,20 +309,12 @@ class data():
if not os.path.isdir("./saves/%s/%s" % (name, world_name)):
os.makedirs("./saves/%s/%s" % (name, world_name))
all_world_data[world_name] = {}
all_world_data[world_name]["targets"] = []
all_world_data[world_name]["station"] = {}
all_world_data[world_name]["targets"] = list()
all_world_data[world_name]["station"] = dict()
for target in localmap[world_name].targets:
savable_vars = {}
for inst_var in target.__dict__:
if type(target.__dict__[inst_var]) in [list, str, int, float, bool]:
savable_vars[inst_var] = target.__dict__[inst_var]
all_world_data[world_name]["targets"].append(savable_vars)
savable_vars = {}
station_vars = localmap[world_name].warp1.__dict__
for inst_var in station_vars:
if type(station_vars[inst_var]) in [list, str, int, float, bool]:
savable_vars[inst_var] = station_vars[inst_var]
all_world_data[world_name]["station"] = (savable_vars)
all_world_data[world_name]["targets"].append(target.unique_relevant_data())
station_data = localmap[world_name].warp1.unique_relevant_data()
all_world_data[world_name]["station"] = station_data
world_image[world_name] = localmap[world_name].background
data = {"fullscreen": fullscreen,

Loading…
Cancel
Save