Add rotation change sound effect, add tutorial and also add it to README, fix window title, add statistics label, add custom difficulty

This commit is contained in:
2025-11-08 20:53:25 +01:00
parent 5973d1143f
commit d1b238b239
13 changed files with 146 additions and 17 deletions

View File

@@ -0,0 +1,41 @@
import arcade, arcade.gui
from utils.constants import CUSTOM_DIFFICULTY_SETTINGS, slider_style, button_style
from utils.preload import button_texture, button_hovered_texture
class CustomDifficulty(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(size_between=self.window.height / 10), anchor_x="center", anchor_y="top")
self.custom_settings = {}
self.custom_setting_labels = {}
def set_custom_setting(self, key, value):
value = int(value)
self.custom_settings[key] = value
self.custom_setting_labels[key].text = f"{next(setting_list[1] for setting_list in CUSTOM_DIFFICULTY_SETTINGS if setting_list[0] == key)}: {value}"
def on_show_view(self):
super().on_show_view()
self.box.add(arcade.gui.UILabel(text="Custom Difficulty Selector", font_size=32))
self.box.add(arcade.gui.UISpace(height=self.window.height / 20))
for custom_setting_key, custom_setting_name, min_value, max_value in CUSTOM_DIFFICULTY_SETTINGS:
self.custom_settings[custom_setting_key] = int((max_value - min_value) / 2)
self.custom_setting_labels[custom_setting_key] = self.box.add(arcade.gui.UILabel(text=f"{custom_setting_name}: {int((max_value - min_value) / 2)}", font_size=28))
slider = self.box.add(arcade.gui.UISlider(step=1, min_value=min_value, max_value=max_value, value=int((max_value - min_value) / 2), style=slider_style, width=self.window.width / 2, height=self.window.height / 15))
slider._render_steps = lambda surface: None
slider.on_change = lambda event, key=custom_setting_key: self.set_custom_setting(key, event.new_value)
self.play_button = self.anchor.add(arcade.gui.UITextureButton(text="Play", style=button_style, texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10), anchor_x="center", anchor_y="bottom")
self.play_button.on_click = lambda event: self.play()
def play(self):
from game.play import Game
self.window.show_view(Game(self.pypresence_client, self.custom_settings["size"], self.custom_settings["source_count"], self.custom_settings["house_count"]))

View File

@@ -22,9 +22,17 @@ class DifficultySelector(arcade.gui.UIView):
self.box.add(arcade.gui.UILabel(text="Difficulty Selector", font_size=32))
for difficulty in ["7x7", "8x8", "9x9", "10x10", "12x12"]:
for difficulty in ["7x7", "8x8", "9x9", "10x10", "11x11", "12x12", "Custom"]:
button = self.box.add(arcade.gui.UITextureButton(text=difficulty, width=self.window.width / 2, height=self.window.height / 10, texture=button_texture, texture_hovered=button_hovered_texture, style=big_button_style))
button.on_click = lambda e, difficulty=difficulty: self.play(difficulty)
if not difficulty == "Custom":
button.on_click = lambda e, difficulty=difficulty: self.play(int(difficulty.split("x")[0]))
else:
button.on_click = lambda e: self.custom_difficulty()
def custom_difficulty(self):
from menus.custom_difficulty import CustomDifficulty
self.window.show_view(CustomDifficulty(self.pypresence_client))
def play(self, difficulty):
from game.play import Game

View File

@@ -55,6 +55,9 @@ class Main(arcade.gui.UIView):
self.play_button = self.box.add(arcade.gui.UITextureButton(text="Play", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.play_button.on_click = lambda event: self.play()
self.tutorial_button = self.box.add(arcade.gui.UITextureButton(text="Tutorial", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.tutorial_button.on_click = lambda event: self.tutorial()
self.settings_button = self.box.add(arcade.gui.UITextureButton(text="Settings", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.settings_button.on_click = lambda event: self.settings()
@@ -62,6 +65,10 @@ class Main(arcade.gui.UIView):
from menus.difficulty_selector import DifficultySelector
self.window.show_view(DifficultySelector(self.pypresence_client))
def tutorial(self):
from menus.tutorial import Tutorial
self.window.show_view(Tutorial(self.pypresence_client))
def settings(self):
from menus.settings import Settings
self.window.show_view(Settings(self.pypresence_client))

37
menus/tutorial.py Normal file
View File

@@ -0,0 +1,37 @@
import arcade, arcade.gui
from utils.preload import button_texture, button_hovered_texture
from utils.constants import button_style
TUTORIAL_TEXT = """
In Connect the Current, you have to rotate power lines so power reaches to all of the houses.
- Every line has to be connected on all of it's sides.
- When needed, you might have to create loops of power or branches with no house linked to them.
(This is also because it's randomly generated and i couldn't find a way to generate maps with no meaningless branches)
- To rotate a line, just click on it and it will change its rotation.
- Maps are randomly generated, difficulty(size, source count, house count) depends on what you pick and grows exponentially.
"""
class Tutorial(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Checking Tutorial")
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=20), anchor_x="center", anchor_y="top")
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))
def on_show_view(self):
super().on_show_view()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
self.box.add(arcade.gui.UILabel(text="CTC Tutorial", font_size=40))
self.box.add(arcade.gui.UILabel(text=TUTORIAL_TEXT, font_size=20, multiline=True))