Add corner textures, and redo the folder layout. Doesnt work yet though.
BIN
assets/graphics/connected_lines/corner/left_bottom.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
assets/graphics/connected_lines/corner/left_top.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
assets/graphics/connected_lines/corner/right_bottom.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
assets/graphics/connected_lines/corner/right_top.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 170 B |
BIN
assets/graphics/connected_lines/line/horizontal.png
Normal file
|
After Width: | Height: | Size: 203 B |
BIN
assets/graphics/connected_lines/line/vertical.png
Normal file
|
After Width: | Height: | Size: 187 B |
|
Before Width: | Height: | Size: 163 B |
BIN
assets/graphics/unconnected_lines/corner/left_bottom.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
assets/graphics/unconnected_lines/corner/left_top.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
assets/graphics/unconnected_lines/corner/right_bottom.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
assets/graphics/unconnected_lines/corner/right_top.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 158 B |
BIN
assets/graphics/unconnected_lines/line/horizontal.png
Normal file
|
After Width: | Height: | Size: 191 B |
BIN
assets/graphics/unconnected_lines/line/vertical.png
Normal file
|
After Width: | Height: | Size: 181 B |
|
Before Width: | Height: | Size: 159 B |
16
game/play.py
@@ -1,4 +1,4 @@
|
|||||||
import arcade, arcade.gui
|
import arcade, arcade.gui, random
|
||||||
|
|
||||||
from utils.constants import button_style
|
from utils.constants import button_style
|
||||||
from utils.preload import button_texture, button_hovered_texture
|
from utils.preload import button_texture, button_hovered_texture
|
||||||
@@ -13,6 +13,7 @@ class Game(arcade.gui.UIView):
|
|||||||
self.pypresence_client.update(state='In Game', start=self.pypresence_client.start_time)
|
self.pypresence_client.update(state='In Game', start=self.pypresence_client.start_time)
|
||||||
|
|
||||||
self.difficulty = difficulty
|
self.difficulty = difficulty
|
||||||
|
self.power_lines = []
|
||||||
|
|
||||||
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
||||||
self.grid_size = list(map(int, difficulty.split("x")))
|
self.grid_size = list(map(int, difficulty.split("x")))
|
||||||
@@ -26,8 +27,19 @@ class Game(arcade.gui.UIView):
|
|||||||
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
|
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
|
||||||
|
|
||||||
for row in range(self.grid_size[0]):
|
for row in range(self.grid_size[0]):
|
||||||
|
self.power_lines.append([])
|
||||||
for col in range(self.grid_size[1]):
|
for col in range(self.grid_size[1]):
|
||||||
self.power_grid.add(PowerLine(), row=row, column=col)
|
left_neighbor = self.power_lines[row][col - 1] if col > 0 else None
|
||||||
|
top_neighbor = self.power_lines[row - 1][col] if row > 0 else None
|
||||||
|
|
||||||
|
power_line = PowerLine(random.choice(["line", "corner"]), left_neighbor, top_neighbor)
|
||||||
|
self.power_grid.add(power_line, row=row, column=col)
|
||||||
|
self.power_lines[row].append(power_line)
|
||||||
|
|
||||||
|
if left_neighbor:
|
||||||
|
left_neighbor.right_neighbor = power_line
|
||||||
|
if top_neighbor:
|
||||||
|
top_neighbor.bottom_neighbor = power_line
|
||||||
|
|
||||||
def main_exit(self):
|
def main_exit(self):
|
||||||
from menus.main import Main
|
from menus.main import Main
|
||||||
|
|||||||
@@ -1,26 +1,81 @@
|
|||||||
import arcade, arcade.gui
|
import arcade, arcade.gui
|
||||||
|
|
||||||
from utils.preload import vertical_connected, vertical_unconnected, horizontal_connected, horizontal_unconnected
|
from utils.preload import *
|
||||||
|
|
||||||
from typing import Literal
|
TEXTURE_MAP = {
|
||||||
|
("vertical", True): vertical_connected,
|
||||||
|
("vertical", False): vertical_unconnected,
|
||||||
|
|
||||||
|
("horizontal", True): horizontal_connected,
|
||||||
|
("horizontal", False): horizontal_unconnected,
|
||||||
|
|
||||||
|
("left_bottom", True): left_bottom_connected,
|
||||||
|
("left_bottom", False): left_bottom_unconnected,
|
||||||
|
|
||||||
|
("left_top", True): left_top_connected,
|
||||||
|
("left_top", False): left_top_unconnected,
|
||||||
|
|
||||||
|
("right_bottom", True): right_bottom_connected,
|
||||||
|
("right_bottom", False): right_bottom_unconnected,
|
||||||
|
|
||||||
|
("right_top", True): right_top_connected,
|
||||||
|
("right_top", False): right_top_unconnected,
|
||||||
|
}
|
||||||
|
|
||||||
|
ROTATIONS = {
|
||||||
|
"line": ["vertical", "horizontal"],
|
||||||
|
"corner": ["left_top", "right_top", "right_bottom", "left_bottom"]
|
||||||
|
}
|
||||||
|
|
||||||
|
NEIGHBOURS = {
|
||||||
|
"vertical": lambda l, r, t, b: bool((b and b.connected) or (t and t.connected)),
|
||||||
|
"horizontal": lambda l, r, t, b: bool((l and l.connected) or (r and r.connected)),
|
||||||
|
"left_bottom": lambda l, r, t, b: bool(((l and l.connected) or (b and b.connected))),
|
||||||
|
"right_bottom": lambda l, r, t, b: bool(((r and r.connected) or (b and b.connected))),
|
||||||
|
"left_top": lambda l, r, t, b: bool(((l and l.connected) or (t and t.connected))),
|
||||||
|
"right_top": lambda l, r, t, b: bool(((r and r.connected) or (t and t.connected)))
|
||||||
|
}
|
||||||
|
|
||||||
class PowerLine(arcade.gui.UITextureButton):
|
class PowerLine(arcade.gui.UITextureButton):
|
||||||
def __init__(self):
|
def __init__(self, line_type, left_neighbor, top_neighbour):
|
||||||
super().__init__(texture=vertical_unconnected)
|
super().__init__(texture=TEXTURE_MAP[ROTATIONS[line_type][0], False])
|
||||||
|
|
||||||
self.rotation: Literal["vertical", "horizontal"] = "vertical"
|
self.line_type = line_type
|
||||||
|
self.rotation = ROTATIONS[line_type][0]
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
|
self.left_neighbour, self.top_neighbour = left_neighbor, top_neighbour
|
||||||
|
self.right_neighbour, self.bottom_neighbour = None, None
|
||||||
|
|
||||||
self.on_click = lambda e: self.next_rotation()
|
self.on_click = lambda e: self.next_rotation()
|
||||||
|
|
||||||
def next_rotation(self):
|
self.update()
|
||||||
if self.rotation == "vertical":
|
|
||||||
self.rotation = "horizontal"
|
|
||||||
self.texture = horizontal_connected if self.connected else horizontal_unconnected
|
|
||||||
self.texture_hovered = horizontal_connected if self.connected else horizontal_unconnected
|
|
||||||
elif self.rotation == "horizontal":
|
|
||||||
self.rotation = "vertical"
|
|
||||||
self.texture = vertical_connected if self.connected else vertical_unconnected
|
|
||||||
self.texture_hovered = vertical_connected if self.connected else vertical_unconnected
|
|
||||||
|
|
||||||
|
def next_rotation(self):
|
||||||
|
current_index = ROTATIONS[self.line_type].index(self.rotation)
|
||||||
|
|
||||||
|
if current_index + 1 == len(ROTATIONS[self.line_type]) - 1:
|
||||||
|
self.rotation = ROTATIONS[self.line_type][0]
|
||||||
|
else:
|
||||||
|
self.rotation = ROTATIONS[self.line_type][current_index + 1]
|
||||||
|
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def update_neighbours(self):
|
||||||
|
if self.rotation == "horizontal":
|
||||||
|
self.left_neighbour.update() if self.left_neighbour else None
|
||||||
|
self.right_neighbour.update() if self.right_neighbour else None
|
||||||
|
elif self.rotation == "vertical":
|
||||||
|
self.top_neighbour.update() if self.top_neighbour else None
|
||||||
|
self.bottom_neighbour.update() if self.bottom_neighbour else None
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
if not self.connected:
|
||||||
|
old_connected = self.connected
|
||||||
|
self.connected = NEIGHBOURS[self.rotation](self.left_neighbour, self.right_neighbour, self.top_neighbour, self.bottom_neighbour)
|
||||||
|
if self.connected != old_connected:
|
||||||
|
self.update_neighbours()
|
||||||
|
|
||||||
|
self.texture = TEXTURE_MAP[(self.rotation, self.connected)]
|
||||||
|
self.texture_hovered = TEXTURE_MAP[(self.rotation, self.connected)]
|
||||||
self._requires_render = True
|
self._requires_render = True
|
||||||
@@ -3,8 +3,16 @@ 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_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"))
|
button_hovered_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button_hovered.png"))
|
||||||
|
|
||||||
vertical_connected = arcade.load_texture("assets/graphics/connected_lines/vertical.png")
|
vertical_connected = arcade.load_texture("assets/graphics/connected_lines/line/vertical.png")
|
||||||
horizontal_connected = arcade.load_texture("assets/graphics/connected_lines/horizontal.png")
|
horizontal_connected = arcade.load_texture("assets/graphics/connected_lines/line/horizontal.png")
|
||||||
|
left_bottom_connected = arcade.load_texture("assets/graphics/connected_lines/corner/left_bottom.png")
|
||||||
|
left_top_connected = arcade.load_texture("assets/graphics/connected_lines/corner/left_top.png")
|
||||||
|
right_bottom_connected = arcade.load_texture("assets/graphics/connected_lines/corner/right_bottom.png")
|
||||||
|
right_top_connected = arcade.load_texture("assets/graphics/connected_lines/corner/right_top.png")
|
||||||
|
|
||||||
vertical_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/vertical.png")
|
vertical_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/line/vertical.png")
|
||||||
horizontal_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/horizontal.png")
|
horizontal_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/line/horizontal.png")
|
||||||
|
left_bottom_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/corner/left_bottom.png")
|
||||||
|
left_top_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/corner/left_top.png")
|
||||||
|
right_bottom_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/corner/right_bottom.png")
|
||||||
|
right_top_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/corner/right_top.png")
|
||||||