Lines 43-48
Link Here
|
43 |
|
43 |
|
44 |
zoom = 1 |
44 |
zoom = 1 |
45 |
|
45 |
|
|
|
46 |
# path to configfile (to save config in the homedir of the user who is running the game) |
47 |
configfile = None |
48 |
|
46 |
def init(): |
49 |
def init(): |
47 |
global popUpFont |
50 |
global popUpFont |
48 |
global titleFont |
51 |
global titleFont |
Lines 50-55
Link Here
|
50 |
global smallItemFont |
53 |
global smallItemFont |
51 |
global bigFont |
54 |
global bigFont |
52 |
global background |
55 |
global background |
|
|
56 |
global configfile |
53 |
|
57 |
|
54 |
try: |
58 |
try: |
55 |
popUpFont = pygame.font.Font(os.path.join("fonts", "arcade_pizzadude", "ARCADE.TTF"), int(24*zoom)) |
59 |
popUpFont = pygame.font.Font(os.path.join("fonts", "arcade_pizzadude", "ARCADE.TTF"), int(24*zoom)) |
Lines 63-68
Link Here
|
63 |
sys.exit(-1) |
67 |
sys.exit(-1) |
64 |
|
68 |
|
65 |
background = pygame.transform.scale(pygame.image.load(os.path.join("sprites", "background.png")).convert(), (int(1024*zoom), int(768*zoom))) |
69 |
background = pygame.transform.scale(pygame.image.load(os.path.join("sprites", "background.png")).convert(), (int(1024*zoom), int(768*zoom))) |
|
|
70 |
configfile = os.environ.get('HOME') + "/.pyRacerz.conf" |
66 |
|
71 |
|
67 |
def chrono2Str(chrono): |
72 |
def chrono2Str(chrono): |
68 |
return str(chrono/100.0).replace(".", "''") |
73 |
return str(chrono/100.0).replace(".", "''") |
Lines 152-172
Link Here
|
152 |
y = y - textRect.height |
157 |
y = y - textRect.height |
153 |
|
158 |
|
154 |
def addHiScore(track, player): |
159 |
def addHiScore(track, player): |
|
|
160 |
global configfile |
155 |
|
161 |
|
156 |
fileExist = 1 |
162 |
fileExist = 1 |
157 |
|
163 |
|
158 |
confFile=ConfigParser.SafeConfigParser() |
164 |
confFile=ConfigParser.SafeConfigParser() |
159 |
try: |
165 |
try: |
160 |
confFile.readfp(file(".pyRacerz.conf", "r")) |
166 |
confFile.readfp(file(configfile, "r")) |
161 |
except Exception: |
167 |
except Exception: |
162 |
fileExist = 0 |
168 |
fileExist = 0 |
163 |
|
169 |
|
164 |
# If the track is not represented, create it |
170 |
# If the track is not represented, create it |
165 |
if fileExist == 0 or not confFile.has_section("hi " + track.name): |
171 |
if fileExist == 0 or not confFile.has_section("hi " + track.name): |
166 |
fwrite = file(".pyRacerz.conf", "w+") |
172 |
fwrite = file(configfile, "w+") |
167 |
confFile.add_section("hi " + track.name) |
173 |
confFile.add_section("hi " + track.name) |
168 |
confFile.write(fwrite) |
174 |
confFile.write(fwrite) |
169 |
confFile.readfp(file(".pyRacerz.conf", "r")) |
175 |
confFile.readfp(file(configfile, "r")) |
170 |
|
176 |
|
171 |
# For the Inverse |
177 |
# For the Inverse |
172 |
if track.reverse == 0: |
178 |
if track.reverse == 0: |
Lines 180-186
Link Here
|
180 |
h.update(str("level" + str(level))) |
186 |
h.update(str("level" + str(level))) |
181 |
h.update(player.name) |
187 |
h.update(player.name) |
182 |
h.update(str(player.bestChrono)) |
188 |
h.update(str(player.bestChrono)) |
183 |
fwrite = file(".pyRacerz.conf", "w+") |
189 |
fwrite = file(configfile, "w+") |
184 |
confFile.set("hi " + track.name, "level" + str(level), player.name + " " + str(player.bestChrono) + " " + h.hexdigest()) |
190 |
confFile.set("hi " + track.name, "level" + str(level), player.name + " " + str(player.bestChrono) + " " + h.hexdigest()) |
185 |
confFile.write(fwrite) |
191 |
confFile.write(fwrite) |
186 |
return 1 |
192 |
return 1 |
Lines 196-202
Link Here
|
196 |
h.update(str("level" + str(level))) |
202 |
h.update(str("level" + str(level))) |
197 |
h.update(player.name) |
203 |
h.update(player.name) |
198 |
h.update(str(player.bestChrono)) |
204 |
h.update(str(player.bestChrono)) |
199 |
fwrite = file(".pyRacerz.conf", "w+") |
205 |
fwrite = file(configfile, "w+") |
200 |
confFile.set("hi " + track.name, "level" + str(level), player.name + " " + str(player.bestChrono) + " " + h.hexdigest()) |
206 |
confFile.set("hi " + track.name, "level" + str(level), player.name + " " + str(player.bestChrono) + " " + h.hexdigest()) |
201 |
confFile.write(fwrite) |
207 |
confFile.write(fwrite) |
202 |
return 1 |
208 |
return 1 |
Lines 208-223
Link Here
|
208 |
h.update(str("level" + str(level))) |
214 |
h.update(str("level" + str(level))) |
209 |
h.update(player.name) |
215 |
h.update(player.name) |
210 |
h.update(str(player.bestChrono)) |
216 |
h.update(str(player.bestChrono)) |
211 |
fwrite = file(".pyRacerz.conf", "w+") |
217 |
fwrite = file(configfile, "w+") |
212 |
confFile.set("hi " + track.name, "level" + str(level), player.name + " " + str(player.bestChrono) + " " + h.hexdigest()) |
218 |
confFile.set("hi " + track.name, "level" + str(level), player.name + " " + str(player.bestChrono) + " " + h.hexdigest()) |
213 |
confFile.write(fwrite) |
219 |
confFile.write(fwrite) |
214 |
return 1 |
220 |
return 1 |
215 |
|
221 |
|
216 |
def getUnlockLevel(): |
222 |
def getUnlockLevel(): |
|
|
223 |
global configfile |
217 |
|
224 |
|
218 |
confFile=ConfigParser.SafeConfigParser() |
225 |
confFile=ConfigParser.SafeConfigParser() |
219 |
try: |
226 |
try: |
220 |
confFile.readfp(file(".pyRacerz.conf", "r")) |
227 |
confFile.readfp(file(configfile, "r")) |
221 |
except Exception: |
228 |
except Exception: |
222 |
return 0 |
229 |
return 0 |
223 |
|
230 |
|
Lines 235-240
Link Here
|
235 |
return 0 |
242 |
return 0 |
236 |
|
243 |
|
237 |
def setUnlockLevel(lck): |
244 |
def setUnlockLevel(lck): |
|
|
245 |
global configfile |
238 |
|
246 |
|
239 |
# Only change the unlock level if it's better than the actual one |
247 |
# Only change the unlock level if it's better than the actual one |
240 |
if getUnlockLevel() >= lck: |
248 |
if getUnlockLevel() >= lck: |
Lines 244-262
Link Here
|
244 |
|
252 |
|
245 |
confFile=ConfigParser.SafeConfigParser() |
253 |
confFile=ConfigParser.SafeConfigParser() |
246 |
try: |
254 |
try: |
247 |
confFile.readfp(file(".pyRacerz.conf", "r")) |
255 |
confFile.readfp(file(configfile, "r")) |
248 |
except Exception: |
256 |
except Exception: |
249 |
fileExist = 0 |
257 |
fileExist = 0 |
250 |
|
258 |
|
251 |
if fileExist == 0 or not confFile.has_section("unlockLevel"): |
259 |
if fileExist == 0 or not confFile.has_section("unlockLevel"): |
252 |
fwrite = file(".pyRacerz.conf", "w+") |
260 |
fwrite = file(configfile, "w+") |
253 |
confFile.add_section("unlockLevel") |
261 |
confFile.add_section("unlockLevel") |
254 |
confFile.write(fwrite) |
262 |
confFile.write(fwrite) |
255 |
confFile.readfp(file(".pyRacerz.conf", "r")) |
263 |
confFile.readfp(file(configfile, "r")) |
256 |
|
264 |
|
257 |
h = sha.new("pyRacerz") |
265 |
h = sha.new("pyRacerz") |
258 |
h.update(str(lck)) |
266 |
h.update(str(lck)) |
259 |
fwrite = file(".pyRacerz.conf", "w+") |
267 |
fwrite = file(configfile, "w+") |
260 |
confFile.set("unlockLevel", "key", str(lck) + " " + h.hexdigest()) |
268 |
confFile.set("unlockLevel", "key", str(lck) + " " + h.hexdigest()) |
261 |
confFile.write(fwrite) |
269 |
confFile.write(fwrite) |