From d1b238b239c07e96da92bd07393e6cb7c3372e08 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Sat, 8 Nov 2025 20:53:25 +0100 Subject: [PATCH] Add rotation change sound effect, add tutorial and also add it to README, fix window title, add statistics label, add custom difficulty --- CREDITS | 3 +++ README.md | 10 ++++++++- assets/sound/wire.mp3 | Bin 0 -> 4365 bytes game/cell.py | 7 ++++-- game/level_generator.py | 7 +++--- game/play.py | 27 +++++++++++++++++------ menus/custom_difficulty.py | 41 +++++++++++++++++++++++++++++++++++ menus/difficulty_selector.py | 12 ++++++++-- menus/main.py | 7 ++++++ menus/tutorial.py | 37 +++++++++++++++++++++++++++++++ run.py | 4 ++-- utils/constants.py | 6 +++++ utils/preload.py | 2 ++ 13 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 assets/sound/wire.mp3 create mode 100644 menus/custom_difficulty.py create mode 100644 menus/tutorial.py diff --git a/CREDITS b/CREDITS index 015b4a1..ac6e134 100644 --- a/CREDITS +++ b/CREDITS @@ -1,3 +1,6 @@ +Sound Effect by freesound_community from Pixabay (cut to the important part) +https://pixabay.com/sound-effects/cutting-clipping-wire-copper-80373/ + The Roboto Black font used in this project is licensed under the Open Font License. Read assets/fonts/OFL.txt for more information. Huge Thanks to Python for being the programming language used in this game. diff --git a/README.md b/README.md index 16c9fbe..2a392ec 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -CTC: Connect The Current is a game where you have a power source, and you have to direct the power lines to houses by rotating them into the correct direction. \ No newline at end of file +CTC: Connect The Current is a game where you have a power source, and you have to direct the power lines to houses by rotating them into the correct direction. + +Tutorial: +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. \ No newline at end of file diff --git a/assets/sound/wire.mp3 b/assets/sound/wire.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..53999f820bb1a2885cdd33a5a34a92936ef95549 GIT binary patch literal 4365 zcmeHJe^e89wx9eYArWSP{D4Ir!jA$8aRS03`fNf2^3$SFI#R4d2v}TpmDIIM*VRk{ z8c3`ZA@anBY%oAIwTY#>Xx%!21o;uI3%aLnySpGt)!J?!9QUcK%$vAdA7@YBIq&`R z-uvU-naut1z4QIvJD+>+Nv=AD0r)Apq_{YX;=$CfpkhyTYPvibkt-0yzxa0|7jAtg z{s+(fN%c-j^S{Rd0B{;eUqY`ep}M8?&JsGclrAly*`-7-A^++AApQLN37kG2&YAfB zwg0#NCtrZVS9?G08&ME=`92K*7&$aO0O%35M_m+r57EB~08$zP4KJrDW~PAUNWhzG zGZZtk8GEFWvS1+qY+yUrZ?EhIL-Zk)vymC8?%A~~6tlMe;8W+Nr$x4pj|RBk+2HQF zeGaMlMSctpfdpsk*|hyzFCYCpaY?2tapDI)h2_FS_^7 ze4Jt1Uia%)j%WX2|HDgEDLlRpG#SLXKVn4 z0>FMEz6l`7dq~fU9)Y7M9b{qv@P6;BY?=lC=sqjxzV-jz{x zu)?}=4hj_?msI}tZbK$86Q&KJNod{2-LPP>vW|NQ$2ZZM8>{J{z?e70hB)rHW~3jJAKrIwk@x+j#9?F}`?N!7f5~;=y_hOV-pk8b*YSgjoj70z;eh zm|6@W`r{FxjO#0a5K|{fP5?%xAs=WZV%&hisWLZuF@rPL+&IEv)^{~}^||N^etgL_ z_d*L1-?vl={0(0pK$8gz($^}k-oK<|1OWxR*CI1t%mhsZ9V`Gc5YAV=a=Db*Zoc4# zPblh2#`}6ifL0(zLkHNMafzbd_<5 zn)k@!F;m|Wfnq95E|k%(-F^9S7g_uPSvS{S1{Ji8=U-S#p` zK2={YP!(pS_$Swr+4DW(0+YdFY_0Tari5*Q&WM{sUmB)=b_gg0_W$m~)+;xrGUUb8 zwezn&*t7rfA&FDzsxfaYD+yF~!%p#_Q(jh-fSb*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oN+}dh#kMM8tRUOg+TL$bN6Xga`KmS0 zv+zY$W);4Yv@-Xh5S8IR_8~B0wepR3aoY%A4P~>N#ENHz-x{IJc((~Rb$fO-BN{{_ zTNVO0zi5PpVs}+2D{_!NP8(am4&$`51$cV`TQFS}NTYa|F|Z<}1L+szh{>c@OX8qV zBlFaAe3$g>|A5Hp(t75&W!h=GcH|vSP&h*DmdRL+^dVdWg41dJ&Haw%4~}j4dHQDE zTMwS*xq;w=KmaXu&*^)s!Nle}j%L$)i>OitM+9=qxL4u!ZYx+wV}9`D4#fg4vw*8b z>qZV-&Z%|meBw+iU5!S}yKJrx!(Iy8?Bc8PzLbW!)|jHuE{z{wQ{oP;7~7fpd_MDT zYs5AoOOd5uNkI?zW#|O`5o*`8Hl$)M9{dQ{DU=nSBnfW=@SpOSD8 zMz}^`5TP`Tc%eb*5;P98hB@8k>1NZQ+4PAhNODsqX&KxF@^}ZJx-i~BUL#Z|fK(#W zU^C_TD~T;pwCtu_Vp|2NgyfT~9sf)C{&!1AM*AVQarncxRoQ`4;q>)Afx1*CoPPC{ zHKlCj*tWU+m>q`~+P~TM-q1I-{m`n@+S*ewdM)E^3xi{9A+3Rec4>TR$$0xhJT+DF z{u=qSKcb0fJQ`o>#}|$H@mE4%$L^8u`ghR7m4YZV2j^lhw>QlbdPFY<5hkC;-~a@O z(ey)64a!*Ma1(lrd$N$}$TJG`!wdnpzrCsZm=R!udnEv-!i@~}ZV710jAC$*L-4p! zIul_`nEq*ZGEQ;gZVuv*l!QkHttm?W4e{3voWC&MDWP=(dL$yP^8A`xSR0|rJ zyD$r1d13}y$>w~!aIkIN!+PUbaD2V-@9j~=@XXotw+cEpcKV3*)SU0hZfaF1_+;#;oN I@m0Kk2hyXLod5s; literal 0 HcmV?d00001 diff --git a/game/cell.py b/game/cell.py index 5e1dd5f..0620781 100644 --- a/game/cell.py +++ b/game/cell.py @@ -1,7 +1,7 @@ import arcade, arcade.gui from utils.constants import ROTATIONS, NEIGHBOURS -from utils.preload import TEXTURE_MAP +from utils.preload import TEXTURE_MAP, wire_sound_effect def get_opposite(direction): if direction == "l": @@ -46,7 +46,10 @@ class Cell(arcade.Sprite): def update_visual(self): self.texture = TEXTURE_MAP[(self.cell_type, self.rotation, self.powered)] - def next_rotation(self): + def next_rotation(self, sfx, sfx_volume): + if sfx: + wire_sound_effect.play(volume=sfx_volume / 50) + current_index = ROTATIONS[self.cell_type].index(self.rotation) if current_index + 1 == len(ROTATIONS[self.cell_type]): diff --git a/game/level_generator.py b/game/level_generator.py index 09148b2..730abc1 100644 --- a/game/level_generator.py +++ b/game/level_generator.py @@ -1,6 +1,5 @@ import random from utils.constants import ROTATIONS, NEIGHBOURS, DIRECTIONS -from collections import deque def in_bounds(x, y, size): return 0 <= x < size and 0 <= y < size @@ -41,8 +40,10 @@ def add_cycles(conns, num_cycles): def pick_random_cells(size, count, avoid=None): all_cells = [(x, y) for y in range(size) for x in range(size)] + if avoid: all_cells = [c for c in all_cells if c not in avoid] + random.shuffle(all_cells) return all_cells[:count] @@ -110,14 +111,14 @@ def generate_map(size, source_count, house_count, cycles=15): conns = add_cycles(conns, cycles) houses = dead_ends[:house_count] - available_cells = [(x, y) for y in range(size) for x in range(size) - if (x, y) not in houses] + available_cells = [(x, y) for y in range(size) for x in range(size) if (x, y) not in houses] random.shuffle(available_cells) sources = available_cells[:source_count] grid = [] for y in range(size): grid.append([]) + for x in range(size): if (x, y) in sources: grid[-1].append("power_source") diff --git a/game/play.py b/game/play.py index be9632d..6c8f3a4 100644 --- a/game/play.py +++ b/game/play.py @@ -1,4 +1,4 @@ -import arcade, arcade.gui +import arcade, arcade.gui, json, time from utils.constants import button_style, NEIGHBOURS from utils.preload import button_texture, button_hovered_texture @@ -9,23 +9,30 @@ from game.level_generator import generate_map from game.cells import * class Game(arcade.gui.UIView): - def __init__(self, pypresence_client, difficulty): + def __init__(self, pypresence_client, grid_size, source_count=None, house_count=None): super().__init__() self.pypresence_client = pypresence_client self.pypresence_client.update(state='In Game', start=self.pypresence_client.start_time) - self.difficulty = difficulty + self.grid_size = grid_size + self.source_count = source_count + self.house_count = house_count + + self.start = time.perf_counter() + self.wire_rotations = 0 self.cells = [] self.power_sources = [] self.houses = [] self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1))) - self.grid_size = int(difficulty.split("x")[0]) - self.map = generate_map(self.grid_size, int((self.grid_size * self.grid_size) / 10), int((self.grid_size * self.grid_size) / 5)) + self.map = generate_map(self.grid_size, int((self.grid_size * self.grid_size) / 10) if not source_count else source_count, int((self.grid_size * self.grid_size) / 5) if not house_count else house_count) self.spritelist = arcade.SpriteList() + with open("settings.json", "r") as file: + self.settings = json.load(file) + def on_show_view(self): super().on_show_view() @@ -36,12 +43,14 @@ class Game(arcade.gui.UIView): self.won_label = self.anchor.add(arcade.gui.UILabel(text="You won!", font_size=48), anchor_x="center", anchor_y="center") self.won_label.visible = False + self.info_label = self.anchor.add(arcade.gui.UILabel("Time spent: 0s Wire Rotations: 0", font_size=24), anchor_x="center", anchor_y="top") + x = (self.window.width / 2) - (self.grid_size * 64) / 2 y = (self.window.height / 2) + (self.grid_size * 64) / 2 for row in range(self.grid_size): self.cells.append([]) - + for col in range(self.grid_size): left_neighbour = self.cells[row][col - 1] if col > 0 else None top_neighbour = self.cells[row - 1][col] if row > 0 else None @@ -126,12 +135,16 @@ class Game(arcade.gui.UIView): continue if cell.rect.point_in_rect((x, y)): - cell.next_rotation() + self.wire_rotations += 1 + cell.next_rotation(self.settings["sfx"], self.settings.get("sfx_volume", 50)) def on_draw(self): super().on_draw() self.spritelist.draw() + def on_update(self, delta_time): + self.info_label.text = f"Time left: {int(time.perf_counter() - self.start)}s Wire Rotations: {self.wire_rotations}" + def main_exit(self): from menus.main import Main self.window.show_view(Main(self.pypresence_client)) \ No newline at end of file diff --git a/menus/custom_difficulty.py b/menus/custom_difficulty.py new file mode 100644 index 0000000..1141b6b --- /dev/null +++ b/menus/custom_difficulty.py @@ -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"])) diff --git a/menus/difficulty_selector.py b/menus/difficulty_selector.py index 1be2dc9..e8a5a2f 100644 --- a/menus/difficulty_selector.py +++ b/menus/difficulty_selector.py @@ -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 diff --git a/menus/main.py b/menus/main.py index a15ce0e..f7bf635 100644 --- a/menus/main.py +++ b/menus/main.py @@ -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)) diff --git a/menus/tutorial.py b/menus/tutorial.py new file mode 100644 index 0000000..3f71d04 --- /dev/null +++ b/menus/tutorial.py @@ -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)) \ No newline at end of file diff --git a/run.py b/run.py index 87ff882..dcc4d23 100644 --- a/run.py +++ b/run.py @@ -90,10 +90,10 @@ else: # theme_sound.play(volume=settings.get("music_volume", 50) / 100, loop=True) try: - window = ControllerWindow(width=resolution[0], height=resolution[1], title='Game Of Life', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False) + window = ControllerWindow(width=resolution[0], height=resolution[1], title='Connect the Current', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False) except (FileNotFoundError, PermissionError) as e: logging.warning(f"Controller support unavailable: {e}. Falling back to regular window.") - window = arcade.Window(width=resolution[0], height=resolution[1], title='Game Of Life', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False) + window = arcade.Window(width=resolution[0], height=resolution[1], title='Connect the Current', samples=antialiasing, antialiasing=antialiasing > 0, fullscreen=fullscreen, vsync=vsync, resizable=False, style=style, visible=False) if vsync: window.set_vsync(True) diff --git a/utils/constants.py b/utils/constants.py index d4a3334..571ec6f 100644 --- a/utils/constants.py +++ b/utils/constants.py @@ -3,6 +3,12 @@ from arcade.types import Color from arcade.gui.widgets.buttons import UITextureButtonStyle, UIFlatButtonStyle from arcade.gui.widgets.slider import UISliderStyle +CUSTOM_DIFFICULTY_SETTINGS = [ + ["source_count", "Source Count", 1, 20], + ["house_count", "House Count", 1, 20], + ["size", "Size", 3, 30] +] + ROTATIONS = { "line": ["vertical", "horizontal"], "corner": ["right_bottom", "left_bottom", "left_top", "right_top"], diff --git a/utils/preload.py b/utils/preload.py index a7fd095..87dc6cf 100644 --- a/utils/preload.py +++ b/utils/preload.py @@ -3,6 +3,8 @@ import arcade.gui, arcade button_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button.png")) button_hovered_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button_hovered.png")) +wire_sound_effect = arcade.Sound("assets/sound/wire.mp3") + TEXTURE_MAP = { ("line", "vertical", True): arcade.load_texture("assets/graphics/powered_lines/line/vertical.png"), ("line", "vertical", False): arcade.load_texture("assets/graphics/unpowered_lines/line/vertical.png"),