Make a modular BaseGame class that all Games are based on to decrease bloat, add Diaunay simulation and fix some stuff in README

This commit is contained in:
csd4ni3l
2025-09-28 21:20:15 +02:00
parent 195a429ff5
commit 311d3607f2
14 changed files with 242 additions and 407 deletions

View File

@@ -1,35 +1,20 @@
import arcade, arcade.gui, json, os, math
from game.base import BaseGame
from utils.constants import button_style
from utils.preload import button_texture, button_hovered_texture
class Game(arcade.gui.UIView):
class Game(BaseGame):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Playing a simulator", details="Spirograph Simulator")
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.settings_box = self.anchor.add(arcade.gui.UIBoxLayout(align="center", size_hint=(0.2, 1)).with_background(color=arcade.color.GRAY), anchor_x="right", anchor_y="bottom")
self.settings_label = self.settings_box.add(arcade.gui.UILabel(text="Settings", font_size=24))
if os.path.exists("data.json"):
with open("data.json", "r") as file:
self.settings = json.load(file)
else:
self.settings = {}
if not "spirograph_simulator" in self.settings:
self.settings["spirograph_simulator"] = {
super().__init__(pypresence_client, "Spirograph Simulator", "spirograph_simulator", {
"big_radius": 220,
"small_radius": 65,
"pen_distance": 100,
"step_size": 0.01,
"trail_size": 2000,
"mode": "inside"
}
})
self.center_points = [[self.window.width * 0.4, self.window.height / 2, 0, []]]
@@ -38,8 +23,6 @@ class Game(arcade.gui.UIView):
def on_show_view(self):
super().on_show_view()
self.settings_box.add(arcade.gui.UISpace(height=self.window.height / 75))
self.add_setting("Big Radius: {value}", 10, 500, 10, "big_radius")
self.add_setting("Small Radius: {value}", 5, 140, 5, "small_radius")
self.add_setting("Pen Distance: {value}", 0, 250, 10, "pen_distance")
@@ -63,18 +46,6 @@ class Game(arcade.gui.UIView):
self.mode_button.text = f"Change to {mode} mode"
def add_setting(self, text, min_value, max_value, step, settings_key):
label = self.settings_box.add(arcade.gui.UILabel(text.format(value=self.settings["spirograph_simulator"][settings_key])))
slider = self.settings_box.add(arcade.gui.UISlider(value=self.settings["spirograph_simulator"][settings_key], min_value=min_value, max_value=max_value, step=step))
slider._render_steps = lambda surface: None
slider.on_change = lambda event, label=label: self.change_value(label, text, settings_key, event.new_value)
def change_value(self, label, text, settings_key, value):
label.text = text.format(value=value)
self.settings["spirograph_simulator"][settings_key] = value
def on_draw(self):
super().on_draw()
@@ -123,14 +94,9 @@ class Game(arcade.gui.UIView):
self.center_points[n][3].pop(0)
def on_key_press(self, symbol, modifiers):
if symbol == arcade.key.ESCAPE:
with open("data.json", "w") as file:
file.write(json.dumps(self.settings, indent=4))
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))
super().on_key_press(symbol, modifiers)
elif symbol == arcade.key.C:
if symbol == arcade.key.C:
self.center_points = [[self.window.width * 0.4, self.window.height / 2, 0, []]]
elif symbol == arcade.key.SPACE: