Skip to content

Commit

Permalink
Added more settings compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
xSqne committed Jun 11, 2021
1 parent fb9e15a commit a1ce729
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
36 changes: 18 additions & 18 deletions menus/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,42 @@ class Game:
def __init__(self):
pygame.init()

# Setting Variables
# Default settings
self.fps = 240
self.fullscreen = False
self.accuracy = 100
self.speed = 1

# Setting resolution
self.width, self.height = 1280, 720
self.screen = pygame.display.set_mode((self.width, self.height))

# Clock & fps
self.clock = pygame.time.Clock()
self.clock.tick(self.fps)

# Background & Font & Color
self.titlefont = pygame.font.Font(os.path.join('./resources', 'fonts', 'Aller_Bd.ttf'), 48)
self.textfont = pygame.font.Font(os.path.join('./resources', 'fonts', 'Aller_Lt.ttf'), 32)
self.background_image = pygame.image.load(os.path.join('./resources', 'img', 'background.jpg')).convert()
self.color = (0, 128, 255)

# Try to read configuration file
try:
with open('./settings.yml', "r") as f:
parsed = yaml.safe_load(f)
self.fps = parsed.get("fps")
self.fullscreen = parsed.get("fullscreen")
self.speed = parsed.get("speed")

# Catch FileNotFound error
except FileNotFoundError:
pass

# Setting resolution
self.width, self.height = 1280, 720
self.screen = pygame.display.set_mode((self.width, self.height))

# Fullscreen
if self.fullscreen:
pygame.display.toggle_fullscreen()

# Clock & fps
self.clock = pygame.time.Clock()
self.clock.tick(self.fps)

# Background & Font & Color
self.titlefont = pygame.font.Font(os.path.join('./resources', 'fonts', 'Aller_Bd.ttf'), 48)
self.textfont = pygame.font.Font(os.path.join('./resources', 'fonts', 'Aller_Lt.ttf'), 32)
self.background_image = pygame.image.load(os.path.join('./resources', 'img', 'background.jpg')).convert()
self.color = (0, 128, 255)

# Instantiating menu classes
self.mm = mainmenu.MainMenu(self)
self.ss = songselect.SongSelect(self)
Expand All @@ -54,9 +57,6 @@ def __init__(self):
# Set state to Main Menu
self.currentstate = "Main Menu"

# Define accuracy
self.accuracy = 100

# Function for handling events
def events(self):
for event in pygame.event.get():
Expand Down
19 changes: 15 additions & 4 deletions menus/mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,33 @@ def play(self):
self.game.songselect_handler()

def settings(self):
# TODO: Add other OS compatibility & Create GUI
# Check if settings file exist
if not os.path.exists('./settings.txt'):
default = {
"fullscreen": False,
"fps": 60
"fps": 60,
"speed": 1
}

# Create new one
with open('./settings.yml', "w") as f:
f.write("# This is a YAML config file. Make sure to follow the format or the program will break!\n"
"# If you somehow misconfigure it, you can delete this file to generate a new one.\n"
"# For the changes to apply, please restart your game!\n\n")
yaml.dump(default, f, indent=4, sort_keys=True)

subprocess.run(["notepad", "./settings.json"])
# Catch Errors just in case
try:
subprocess.run(["notepad", "./settings.json"])
except Exception as e:
print("An execption has occured. Please report this on our GitHub\n Execption:")
print(e)
else:
subprocess.run(["notepad", "./settings.json"])
try:
subprocess.run(["notepad", "./settings.json"])
except Exception as e:
print("An execption has occured. Please report this on our GitHub\n Execption:")
print(e)

def tutorial(self):
# Tutorial
Expand Down
10 changes: 9 additions & 1 deletion menus/stagerandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, game):
self.note_list = []
self.note_coords = []
for a in range(100):
notes = note.Note(self)
notes = note.Note(self, game)
pygame.sprite.spritecollide(notes, self.note_group, True)

self.note_group.add(notes)
Expand Down Expand Up @@ -86,6 +86,14 @@ def render(self, event):
# Update Display
pygame.display.flip()

# If escape key is detected, leave
if event == "esc":
# Change game state
self.game.currentstate = "Song Select"

# Reset
self.__init__(self.game)

# When all the notes are killed
if not self.note_group.sprites():
# Calculate Accuracy
Expand Down
5 changes: 3 additions & 2 deletions sprites/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class Note(pygame.sprite.Sprite):
def __init__(self, ps):
def __init__(self, ps, game):
super().__init__()
self.game = game
self.ps = ps
self.random_x = [510, 575, 640, 705]
self.random_y = []
Expand All @@ -25,7 +26,7 @@ def __init__(self, ps):

def update(self):
# Move the note down
self.rect.topleft = (self.rect.x, self.rect.y + 1)
self.rect.topleft = (self.rect.x, self.rect.y + self.game.speed)

# When notes reach the end of the screen
if self.rect.y > 720:
Expand Down

0 comments on commit a1ce729

Please sign in to comment.