mirror of
https://github.com/csd4ni3l/logical-signals.git
synced 2026-01-01 12:33:46 +01:00
Add tutorial, back buttons, different placement for inputs, outputs and others, level evaluations(no gui yet), small fixes
This commit is contained in:
64
game/play.py
64
game/play.py
@@ -1,7 +1,8 @@
|
|||||||
import arcade, arcade.gui, random, datetime
|
import arcade, arcade.gui, random, datetime
|
||||||
|
|
||||||
from utils.utils import cubic_bezier_points, get_gate_port_position, generate_task_text
|
from utils.utils import cubic_bezier_points, get_gate_port_position, generate_task_text
|
||||||
from utils.constants import dropdown_style, LOGICAL_GATES, LEVELS
|
from utils.constants import button_style, dropdown_style, LOGICAL_GATES, LEVELS
|
||||||
|
from utils.preload import button_texture, button_hovered_texture
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -66,24 +67,32 @@ class Game(arcade.gui.UIView):
|
|||||||
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.tools_box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=5), anchor_x="right", anchor_y="bottom", align_x=-5, align_y=20)
|
self.tools_box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=5), anchor_x="right", anchor_y="bottom", align_x=-5, align_y=20)
|
||||||
|
|
||||||
gate_names = list(LOGICAL_GATES.keys())
|
|
||||||
|
|
||||||
if not level_num == -1:
|
if not level_num == -1:
|
||||||
self.task_label = self.anchor.add(arcade.gui.UILabel(text=generate_task_text(LEVELS[level_num]), font_size=20, multiline=True), anchor_x="center", anchor_y="top")
|
self.task_label = self.anchor.add(arcade.gui.UILabel(text=generate_task_text(LEVELS[level_num]), font_size=20, multiline=True), anchor_x="center", anchor_y="top")
|
||||||
for requirement in LEVELS[level_num]:
|
for requirement in LEVELS[level_num]:
|
||||||
if requirement[1] == "INPUT":
|
if requirement[1] == "INPUT":
|
||||||
for _ in range(requirement[0]):
|
for _ in range(requirement[0]):
|
||||||
self.add_gate(random.randint(0, self.window.width - 300), random.randint(200, self.window.height - 100), "INPUT", requirement[2])
|
self.add_gate(random.randint(0, 200), random.randint(200, self.window.height - 100), "INPUT", requirement[2])
|
||||||
elif requirement[1] == "OUTPUT":
|
elif requirement[1] == "OUTPUT":
|
||||||
for _ in range(requirement[0]):
|
for _ in range(requirement[0]):
|
||||||
self.add_gate(random.randint(0, self.window.width - 300), random.randint(200, self.window.height - 100), "OUTPUT")
|
self.add_gate(random.randint(self.window.width - 500, self.window.width - 200), random.randint(200, self.window.height - 100), "OUTPUT", requirement[2])
|
||||||
|
else:
|
||||||
|
for _ in range(requirement[0]):
|
||||||
|
self.add_gate(random.randint(300, self.window.width - 600), random.randint(200, self.window.height - 100), requirement[1])
|
||||||
else:
|
else:
|
||||||
self.task_label = self.anchor.add(arcade.gui.UILabel(text="Task: Have fun! Do whatever you want!", font_size=20), anchor_x="center", anchor_y="top")
|
self.task_label = self.anchor.add(arcade.gui.UILabel(text="Task: Have fun! Do whatever you want!", font_size=20), anchor_x="center", anchor_y="top")
|
||||||
gate_names.extend(["INPUT 0", "INPUT 1", "OUTPUT"])
|
|
||||||
|
|
||||||
for gate in gate_names:
|
for gate in list(LOGICAL_GATES.keys()) + ["INPUT 0", "INPUT 1", "OUTPUT"]:
|
||||||
button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text=f"Create {gate} gate", style=dropdown_style))
|
button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text=f"Create {gate} gate", style=dropdown_style))
|
||||||
button.on_click = lambda event, gate=gate: self.add_gate(random.randint(0, self.window.width - 300), random.randint(200, self.window.height - 100), gate)
|
|
||||||
|
if "INPUT" in gate:
|
||||||
|
func = lambda: (random.randint(0, 200), random.randint(200, self.window.height - 100))
|
||||||
|
elif gate == "OUTPUT":
|
||||||
|
func = lambda: (random.randint(self.window.width - 500, self.window.width - 200), random.randint(200, self.window.height - 100))
|
||||||
|
else:
|
||||||
|
func = lambda: (random.randint(300, self.window.width - 600), random.randint(200, self.window.height - 100))
|
||||||
|
|
||||||
|
button.on_click = lambda event, func=func, gate=gate: self.add_gate(*func(), gate)
|
||||||
|
|
||||||
screenshot_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Screenshot", style=dropdown_style))
|
screenshot_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Screenshot", style=dropdown_style))
|
||||||
screenshot_button.on_click = lambda event: self.screenshot()
|
screenshot_button.on_click = lambda event: self.screenshot()
|
||||||
@@ -91,6 +100,10 @@ class Game(arcade.gui.UIView):
|
|||||||
hide_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Hide", style=dropdown_style))
|
hide_button = self.tools_box.add(arcade.gui.UIFlatButton(width=self.window.width * 0.1, height=self.window.height * 0.075, text="Hide", style=dropdown_style))
|
||||||
hide_button.on_click = lambda event: self.hide_show_panel()
|
hide_button.on_click = lambda event: self.hide_show_panel()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
def screenshot(self):
|
def screenshot(self):
|
||||||
self.tools_box.visible = False
|
self.tools_box.visible = False
|
||||||
self.tools_box._requires_render = True
|
self.tools_box._requires_render = True
|
||||||
@@ -127,10 +140,36 @@ class Game(arcade.gui.UIView):
|
|||||||
hide_button.text = "Show"
|
hide_button.text = "Show"
|
||||||
|
|
||||||
def evaluate(self):
|
def evaluate(self):
|
||||||
|
process_nodes = []
|
||||||
|
outputs = []
|
||||||
|
|
||||||
for gate in self.gates:
|
for gate in self.gates:
|
||||||
if not gate.output:
|
if not gate.output:
|
||||||
gate.calculate_value()
|
gate.calculate_value()
|
||||||
|
|
||||||
|
if gate.gate_type == "OUTPUT" and gate.input:
|
||||||
|
outputs.append(gate.value)
|
||||||
|
|
||||||
|
if not gate.gate_type in ["INPUT", "OUTPUT"] and gate.input and gate.output:
|
||||||
|
process_nodes.append(gate.gate_type)
|
||||||
|
|
||||||
|
for requirement in LEVELS[self.level_num]:
|
||||||
|
if requirement[1] == "INPUT":
|
||||||
|
continue
|
||||||
|
|
||||||
|
if requirement[1] == "OUTPUT":
|
||||||
|
for _ in range(requirement[0]):
|
||||||
|
if not requirement[2] in outputs:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
outputs.remove(requirement[2])
|
||||||
|
else:
|
||||||
|
for _ in range(requirement[0]):
|
||||||
|
if not requirement[1] in process_nodes:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
process_nodes.remove(requirement[1])
|
||||||
|
|
||||||
def select_output(self, gate_id):
|
def select_output(self, gate_id):
|
||||||
if self.gates[gate_id].output:
|
if self.gates[gate_id].output:
|
||||||
return
|
return
|
||||||
@@ -190,10 +229,13 @@ class Game(arcade.gui.UIView):
|
|||||||
def on_mouse_release(self, x, y, button, modifiers):
|
def on_mouse_release(self, x, y, button, modifiers):
|
||||||
self.dragged_gate = None
|
self.dragged_gate = None
|
||||||
|
|
||||||
|
def main_exit(self):
|
||||||
|
from menus.main import Main
|
||||||
|
self.window.show_view(Main(self.pypresence_client))
|
||||||
|
|
||||||
def on_key_press(self, symbol, modifiers):
|
def on_key_press(self, symbol, modifiers):
|
||||||
if symbol == arcade.key.ESCAPE:
|
if symbol == arcade.key.ESCAPE:
|
||||||
from menus.main import Main
|
self.main_exit()
|
||||||
self.window.show_view(Main(self.pypresence_client))
|
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
super().on_draw()
|
super().on_draw()
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class LevelSelector(arcade.gui.UIView):
|
|||||||
|
|
||||||
row, col = (n + 1) // 5, (n + 1) % 5
|
row, col = (n + 1) // 5, (n + 1) % 5
|
||||||
|
|
||||||
diy_button = self.grid.add(arcade.gui.UITextureButton(width=self.window.width / 8, height=self.window.height / 8, text=f"DIY", texture=button_texture, texture_hovered=button_hovered_texture, style=button_style), row=row, column=col)
|
diy_button = self.anchor.add(arcade.gui.UITextureButton(width=self.window.width / 2, height=self.window.height / 8, text=f"DIY", texture=button_texture, texture_hovered=button_hovered_texture, style=button_style), anchor_x="center", anchor_y="bottom", align_y=20)
|
||||||
diy_button.on_click = lambda event: self.play(-1)
|
diy_button.on_click = lambda event: self.play(-1)
|
||||||
|
|
||||||
self.grid._trigger_size_hint_update()
|
self.grid._trigger_size_hint_update()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import arcade, arcade.gui, asyncio, pypresence, time, copy, json
|
import arcade, arcade.gui, asyncio, pypresence, time, copy, json
|
||||||
|
|
||||||
from utils.preload import button_texture, button_hovered_texture
|
from utils.preload import button_texture, button_hovered_texture
|
||||||
from utils.constants import big_button_style, discord_presence_id
|
from utils.constants import big_button_style, discord_presence_id
|
||||||
from utils.utils import FakePyPresence
|
from utils.utils import FakePyPresence
|
||||||
@@ -55,9 +56,16 @@ 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 / 8, style=big_button_style))
|
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 / 8, style=big_button_style))
|
||||||
self.play_button.on_click = lambda event: self.play()
|
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 / 8, 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 / 8, style=big_button_style))
|
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 / 8, style=big_button_style))
|
||||||
self.settings_button.on_click = lambda event: self.settings()
|
self.settings_button.on_click = lambda event: self.settings()
|
||||||
|
|
||||||
|
def tutorial(self):
|
||||||
|
from menus.tutorial import Tutorial
|
||||||
|
self.window.show_view(Tutorial(self.pypresence_client))
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
from menus.level_selector import LevelSelector
|
from menus.level_selector import LevelSelector
|
||||||
self.window.show_view(LevelSelector(self.pypresence_client))
|
self.window.show_view(LevelSelector(self.pypresence_client))
|
||||||
|
|||||||
41
menus/tutorial.py
Normal file
41
menus/tutorial.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import arcade, arcade.gui
|
||||||
|
|
||||||
|
from utils.constants import button_style
|
||||||
|
from utils.preload import button_texture, button_hovered_texture
|
||||||
|
|
||||||
|
class Tutorial(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.title_label = self.anchor.add(arcade.gui.UILabel(text="Tutorial", font_size=40), anchor_x="center", anchor_y="top")
|
||||||
|
|
||||||
|
self.instructions_label = self.anchor.add(arcade.gui.UILabel(text="""How to play:
|
||||||
|
- You can move gates by dragging their buttons (not the plus ones)
|
||||||
|
- To create connections, click on the + buttons, left is the input, right is the output
|
||||||
|
- A node has to have 2 inputs(Except the OUTPUT node), but only 1 output
|
||||||
|
- You have to connect the nodes in a way to meet the required result
|
||||||
|
|
||||||
|
Logical Gates explanation:
|
||||||
|
- AND: Returns 1 if both inputs are 1, otherwise 0
|
||||||
|
- OR: Returns 1 if any inputs are 1, otherwise 0
|
||||||
|
- NAND: Returns 1 if any inputs are 0, otherwise 0
|
||||||
|
- NOR: Returns 1 if both inputs are 0, otherwise 0
|
||||||
|
- XOR: Returns 1 if inputs are different, otherwise 0
|
||||||
|
- XNOR: Returns 1 if inputs are the same, otherwise 0
|
||||||
|
""", multiline=True, font_size=24), anchor_x="center", anchor_y="center")
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def main_exit(self):
|
||||||
|
from menus.main import Main
|
||||||
|
self.window.show_view(Main(self.pypresence_client))
|
||||||
|
|
||||||
|
def on_key_press(self, symbol, modifiers):
|
||||||
|
if symbol == arcade.key.ESCAPE:
|
||||||
|
self.main_exit()
|
||||||
@@ -28,7 +28,7 @@ LEVELS = [
|
|||||||
[1, "INPUT", 1],
|
[1, "INPUT", 1],
|
||||||
[1, "INPUT", 0],
|
[1, "INPUT", 0],
|
||||||
[1, "OR"],
|
[1, "OR"],
|
||||||
[1, "OUTPUT", 0]
|
[1, "OUTPUT", 1]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[2, "INPUT", 1],
|
[2, "INPUT", 1],
|
||||||
|
|||||||
Reference in New Issue
Block a user