commit 9656f8c2b6c46c90c8aa8c5b3ca0391786c818a5
parent e743774876c8ce577b52c6a561ce0e1f00b9567b
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Mon, 7 Dec 2020 16:55:00 -0600
Added highscores
Diffstat:
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/hs.json b/hs.json
@@ -0,0 +1 @@
+{"SCORES": [20, 500, 1000]}+
\ No newline at end of file
diff --git a/src/constants.py b/src/constants.py
@@ -1,4 +1,4 @@
-import pygame, os, enum
+import pygame, os, enum, json
# KEYS
TURN_LEFT_KEY = pygame.K_a
@@ -9,6 +9,9 @@ THRUST_KEY = pygame.K_w
REPAIR_KEY = pygame.K_e
BURST_KEY = pygame.K_k
+# HIGHSCORE
+with open("hs.json") as j: HIGHSCORES = json.load(j)
+
SCREEN_DIM = (1024, 768)
FRAMERATE = 60
COLORKEY = (255, 0, 255)
diff --git a/src/game.py b/src/game.py
@@ -299,6 +299,8 @@ class Game(object):
if self.transition_timer > 0:
self.transition_timer -= 1
else:
+ HIGHSCORES["SCORES"].append(self.score)
+ HIGHSCORES["SCORES"].sort()
self.change_mode(MODES.Menu)
def spawn_asteroids(self):
@@ -339,4 +341,6 @@ class Game(object):
self.update_logic()
self.update_screen()
+ # Write highscores and quit
+ with open("hs.json", "w") as j: json.dump(HIGHSCORES, j)
pygame.quit()