Skip to content

Commit

Permalink
add high scores, make music longer
Browse files Browse the repository at this point in the history
  • Loading branch information
ShakyaMajumdar committed Sep 26, 2021
1 parent 13174e9 commit 00a81dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ venv
.idea
.vscode
__pycache__/
hs.txt
Binary file modified models/Guitar-Mayhem-3.wav
Binary file not shown.
15 changes: 13 additions & 2 deletions tracks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import sys
from functools import partial
from pathlib import Path
from textwrap import dedent
from typing import Set

Expand Down Expand Up @@ -29,6 +30,11 @@
from track_generation import Track, TrackCollectionGenerator, TrackList
from menu import Menu

HIGH_SCORE_FILE = Path("hs.txt")
if not HIGH_SCORE_FILE.exists():
with open(HIGH_SCORE_FILE, "w") as f:
f.write("0")


class Game(ShowBase):
def __init__(self):
Expand All @@ -37,7 +43,8 @@ def __init__(self):
props.set_title("Infinity Coaster")
props.icon_filename = "models/logo.ico"
base.win.requestProperties(props)

with open(HIGH_SCORE_FILE) as f:
self.high_score = int(f.read())
cube_map = self.loader.loadCubeMap("models/sky_#.png")
self.sky_box = self.loader.loadModel("models/coaster.bam")
self.sky_box.setScale(50)
Expand Down Expand Up @@ -252,6 +259,10 @@ def unpause(self):

def die(self, cause: str):
self.death_sound.play()
if self.current_track_index > self.high_score:
self.high_score = self.current_track_index
with open(HIGH_SCORE_FILE, "w") as f:
f.write(str(self.high_score))
self.pause(show_resume=False)
for track in self.tracks:
track.node_path.removeNode()
Expand All @@ -268,7 +279,7 @@ def die(self, cause: str):
scale=0.1,
)
t2 = OnscreenText(
text=f"Final Score: {self.current_track_index}",
text=f"Final Score: {self.current_track_index} \n High Score: {self.high_score}",
pos=(0, 0.3, 0),
bg=(0, 0, 0, 0),
fg=(0, 0.7, 1, 1),
Expand Down

0 comments on commit 00a81dd

Please sign in to comment.