Commit from game template + added basic power line and difficulty selector

This commit is contained in:
csd4ni3l
2025-11-05 19:34:57 +01:00
commit f37c6619d2
22 changed files with 2012 additions and 0 deletions

26
game/play.py Normal file
View File

@@ -0,0 +1,26 @@
import arcade, arcade.gui, pyglet
from utils.constants import button_style
from utils.preload import button_texture, button_hovered_texture
from game.power_line import PowerLine
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client, difficulty):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="In Game")
self.difficulty = difficulty
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.grid_size = list(map(int, difficulty.split("x")))
self.power_grid = self.anchor.add(arcade.gui.UIGridLayout(horizontal_spacing=0, vertical_spacing=0, row_count=self.grid_size[0], column_count=self.grid_size[1]))
def on_show_view(self):
super().on_show_view()
for row in range(self.grid_size[0]):
for col in range(self.grid_size[1]):
self.power_grid.add(PowerLine(), row=row, column=col)

33
game/power_line.py Normal file
View File

@@ -0,0 +1,33 @@
import arcade, arcade.gui
from utils.preload import button_texture, button_hovered_texture
from utils.constants import button_style
from typing import Literal
ROTATIONS = ["right", "down", "left", "up"]
class PowerLine(arcade.gui.UITextureButton):
def __init__(self):
super().__init__(text="--->", style=button_style, texture=button_texture, texture_hovered=button_hovered_texture)
self.rotation: Literal["right", "down", "left", "up"] = "right"
self.on_click = lambda e: self.next_rotation()
def next_rotation(self):
current_index = ROTATIONS.index(self.rotation)
if current_index + 1 == len(ROTATIONS):
self.rotation = ROTATIONS[0]
else:
self.rotation = ROTATIONS[current_index + 1]
if self.rotation == "up":
self.text = "^"
elif self.rotation == "down":
self.text = "ˇ"
elif self.rotation == "left":
self.text = "<---"
elif self.rotation == "right":
self.text = "--->"