Irányítás
This commit is contained in:
38
src/controls.py
Normal file
38
src/controls.py
Normal 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
|
||||||
@@ -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()
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import arcade
|
import arcade
|
||||||
import assets
|
import assets
|
||||||
|
import controls
|
||||||
import text
|
import text
|
||||||
import renderers
|
import renderers
|
||||||
|
|
||||||
@@ -7,11 +8,16 @@ text = text.TextRenderer(6, 186, 210)
|
|||||||
panel = renderers.NineSlicesPanel(0,100,230,100)
|
panel = renderers.NineSlicesPanel(0,100,230,100)
|
||||||
|
|
||||||
def switch():
|
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.")
|
pass
|
||||||
text.type_all()
|
|
||||||
|
|
||||||
def update(dt):
|
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):
|
def draw(game):
|
||||||
arcade.draw_rect_filled(
|
arcade.draw_rect_filled(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import arcade
|
|||||||
import assets
|
import assets
|
||||||
import gamestate
|
import gamestate
|
||||||
import renderers
|
import renderers
|
||||||
|
import controls
|
||||||
import text
|
import text
|
||||||
|
|
||||||
SCREEN_WIDTH = 256
|
SCREEN_WIDTH = 256
|
||||||
@@ -33,6 +34,13 @@ class Game(arcade.Window):
|
|||||||
|
|
||||||
def on_update(self, dt):
|
def on_update(self, dt):
|
||||||
gamestate.update(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):
|
def on_draw(self):
|
||||||
self.framebuffer.use()
|
self.framebuffer.use()
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class TextRenderer:
|
|||||||
self.text = text
|
self.text = text
|
||||||
self.textptr = 0
|
self.textptr = 0
|
||||||
self.sprites = []
|
self.sprites = []
|
||||||
|
self.x = self.base_x
|
||||||
|
self.y = self.base_y
|
||||||
|
|
||||||
def amend(self, text):
|
def amend(self, text):
|
||||||
self.text = self.text + text
|
self.text = self.text + text
|
||||||
|
|||||||
Reference in New Issue
Block a user