|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
from random import *
|
|
|
|
|
import sys,os,math,shutil,json
|
|
|
|
|
import sys,os,configparser
|
|
|
|
|
|
|
|
|
|
def drawcenter(game,surface,posx,posy):
|
|
|
|
|
# Draw a surface in its center
|
|
|
|
@ -68,3 +68,64 @@ class Timer():
|
|
|
|
|
self.timer+=amount
|
|
|
|
|
self.maxcount+=amount
|
|
|
|
|
|
|
|
|
|
def get_save_dir(dirname):
|
|
|
|
|
path = ""
|
|
|
|
|
p = sys.platform
|
|
|
|
|
if p=="linux":
|
|
|
|
|
path = os.environ["HOME"]+"/.local/share/"+dirname
|
|
|
|
|
if p=="win32":
|
|
|
|
|
path = os.getenv('APPDATA')+"\\"+dirname
|
|
|
|
|
|
|
|
|
|
# Create folder if non-existant
|
|
|
|
|
try:
|
|
|
|
|
os.mkdir(path)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
|
def loadscore(dirname,filename="highscore.ini"):
|
|
|
|
|
filepath = os.path.join(dirname,filename)
|
|
|
|
|
highscore = 0
|
|
|
|
|
try:
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
config.read(filepath)
|
|
|
|
|
if "highscore" in config.sections():
|
|
|
|
|
highscore = int(config["highscore"].get("score",0))
|
|
|
|
|
except:
|
|
|
|
|
# Save file corrupted, reset it
|
|
|
|
|
os.remove(filepath)
|
|
|
|
|
|
|
|
|
|
return highscore
|
|
|
|
|
|
|
|
|
|
def loadsettings(dirname,filename="settings.ini"):
|
|
|
|
|
filepath = os.path.join(dirname,filename)
|
|
|
|
|
sfx = 100
|
|
|
|
|
bgm = 100
|
|
|
|
|
try:
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
config.read(filepath)
|
|
|
|
|
if "settings" in config.sections():
|
|
|
|
|
bgm = int(config["settings"].get("bgm",100))
|
|
|
|
|
sfx = int(config["settings"].get("sfx",100))
|
|
|
|
|
except:
|
|
|
|
|
# Save file corrupted, reset it
|
|
|
|
|
os.remove(filepath)
|
|
|
|
|
return bgm,sfx
|
|
|
|
|
|
|
|
|
|
def savescore(dirname,highscore=0,filename="highscore.ini"):
|
|
|
|
|
filepath = os.path.join(dirname,filename)
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
config["highscore"] = {"score":highscore}
|
|
|
|
|
|
|
|
|
|
with open(filepath,'w') as configfile:
|
|
|
|
|
config.write(configfile)
|
|
|
|
|
|
|
|
|
|
def savesettings(dirname,bgm=1,sfx=1,filename="settings.ini"):
|
|
|
|
|
filepath = os.path.join(dirname,filename)
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
bgm,sfx = round(bgm*100),round(sfx*100)
|
|
|
|
|
config["settings"] = {"bgm":bgm,"sfx":sfx}
|
|
|
|
|
|
|
|
|
|
with open(filepath,'w') as configfile:
|
|
|
|
|
config.write(configfile)
|
|
|
|
|