Irányítás

This commit is contained in:
markojozsef
2026-09-16 12:30:05 +02:00
parent 4eaf0dbd98
commit bbdead0b2e
5 changed files with 59 additions and 20 deletions

38
src/controls.py Normal file
View File

@@ -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

View File

@@ -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()

View File

@@ -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(

View File

@@ -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()

View File

@@ -26,6 +26,8 @@ class TextRenderer:
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