From 24dbe030e75c717c8ab17600044a077e1d4eff4c Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 7 Mar 2023 23:11:31 -0500 Subject: [PATCH] [+] Move function with bounds --- tngame/telnet.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tngame/telnet.py b/tngame/telnet.py index 8fa50a0..5f117d5 100644 --- a/tngame/telnet.py +++ b/tngame/telnet.py @@ -68,6 +68,14 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): # Draw the cat print_ascii(ASCII_CAT, x, y) + # Move the cat along the x-axis + async def move(delta: int): + nonlocal x + orig = x + x = min(max(x + delta, 0), width - ASCII_WIDTH) + if x != orig: + await update() + # Update frame function async def update(): while True: @@ -88,13 +96,9 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): # Switch case match inp: case '\x1b[C': # Right - x += 1 + await move(1) case '\x1b[D': # Left - x -= 1 - # case '\x1b[A': # Up - # y -= 1 - # case '\x1b[B': # Down - # y += 1 + await move(-1) case '\x1b': # Escape writer.write('\r\nBye!\r\n') writer.close()