mirror of
https://github.com/csd4ni3l/connect-the-current.git
synced 2026-03-10 09:09:18 +01:00
Add corner textures, and redo the folder layout. Doesnt work yet though.
This commit is contained in:
16
game/play.py
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.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.difficulty = difficulty
|
||||
self.power_lines = []
|
||||
|
||||
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
||||
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)
|
||||
|
||||
for row in range(self.grid_size[0]):
|
||||
self.power_lines.append([])
|
||||
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):
|
||||
from menus.main import Main
|
||||
|
||||
@@ -1,26 +1,81 @@
|
||||
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):
|
||||
def __init__(self):
|
||||
super().__init__(texture=vertical_unconnected)
|
||||
def __init__(self, line_type, left_neighbor, top_neighbour):
|
||||
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.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()
|
||||
|
||||
def next_rotation(self):
|
||||
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
|
||||
self.update()
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user