From bbdead0b2e44f0c5e809f5139af5d8fa756e8725 Mon Sep 17 00:00:00 2001 From: markojozsef Date: Wed, 16 Sep 2026 12:30:05 +0200 Subject: [PATCH] =?UTF-8?q?Ir=C3=A1ny=C3=ADt=C3=A1s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controls.py | 38 ++++++++++++++++++++++++++++++++++++++ src/gamestates/menu.py | 15 --------------- src/gamestates/title.py | 14 ++++++++++---- src/main.py | 8 ++++++++ src/text.py | 4 +++- 5 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 src/controls.py delete mode 100644 src/gamestates/menu.py diff --git a/src/controls.py b/src/controls.py new file mode 100644 index 0000000..027183c --- /dev/null +++ b/src/controls.py @@ -0,0 +1,38 @@ +import arcade + +class Control: + def __init__(self, key, label): + self.key = key + self.label = label + self.pressed = False + self.held = False + +controls = [ + Control(arcade.key.W, "Fel"), + Control(arcade.key.S, "Le"), + Control(arcade.key.A, "Bal"), + Control(arcade.key.D, "Jobb"), +] + +def key_press(key): + for c in controls: + if c.key == key: + c.pressed = True + +def key_release(key): + for c in controls: + if c.key == key: + c.pressed = False + c.held = False + +def update(): + for c in controls: + if c.pressed: + c.pressed = False + c.held = True + +def is_control_pressed(cid): + return controls[cid].pressed + +def is_control_held(cid): + return controls[cid].held \ No newline at end of file diff --git a/src/gamestates/menu.py b/src/gamestates/menu.py deleted file mode 100644 index 9243416..0000000 --- a/src/gamestates/menu.py +++ /dev/null @@ -1,15 +0,0 @@ -import arcade -import assets -import text - -text = text.TextRenderer(0, 100, 200) - -def switch(): - text.reset("●A bölcs, gyors, fürge róka zöld ágon ül, miközben egy tyúk csípős paprikát főz, és egy whiskyvel teli dobozt cipelő dzsesszzenész kvázi jókedvűen fütyörészik.") - text.type_all() - -def update(dt): - pass - -def draw(game): - text.render() diff --git a/src/gamestates/title.py b/src/gamestates/title.py index 28084ed..b79119b 100644 --- a/src/gamestates/title.py +++ b/src/gamestates/title.py @@ -1,5 +1,6 @@ import arcade import assets +import controls import text import renderers @@ -7,11 +8,16 @@ text = text.TextRenderer(6, 186, 210) panel = renderers.NineSlicesPanel(0,100,230,100) def switch(): - text.reset("●A bölcs, gyors, fürge róka zöld ágon ül, miközben egy tyúk csípős paprikát főz, és egy whiskyvel teli dobozt cipelő dzsesszzenész kvázi jókedvűen fütyörészik.") - text.type_all() + pass def update(dt): - pass + controltext = "" + + for c in controls.controls: + controltext += f"{c.label}: {c.pressed}-{c.held}\n" + + text.reset(controltext) + text.type_all() def draw(game): arcade.draw_rect_filled( @@ -20,4 +26,4 @@ def draw(game): ) panel.render() - text.render() + text.render() \ No newline at end of file diff --git a/src/main.py b/src/main.py index 5655542..06a7cb4 100644 --- a/src/main.py +++ b/src/main.py @@ -2,6 +2,7 @@ import arcade import assets import gamestate import renderers +import controls import text SCREEN_WIDTH = 256 @@ -33,6 +34,13 @@ class Game(arcade.Window): def on_update(self, dt): gamestate.update(dt) + controls.update() + + def on_key_press(self, symbol, modifiers): + controls.key_press(symbol) + + def on_key_release(self, symbol, modifiers): + controls.key_release(symbol) def on_draw(self): self.framebuffer.use() diff --git a/src/text.py b/src/text.py index f173d29..6a69455 100644 --- a/src/text.py +++ b/src/text.py @@ -23,9 +23,11 @@ class TextRenderer: self.y = y def reset(self, text): - self.text = text + self.text = text self.textptr = 0 self.sprites = [] + self.x = self.base_x + self.y = self.base_y def amend(self, text): self.text = self.text + text