From 8527a216e11e9921a3a4e591d59c3e3d5d43af78 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 7 Mar 2023 23:48:39 -0500 Subject: [PATCH] [O] Calculate snow pos by dt --- tngame/telnet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tngame/telnet.py b/tngame/telnet.py index a40af0d..c3b28c3 100644 --- a/tngame/telnet.py +++ b/tngame/telnet.py @@ -79,7 +79,7 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): return snow # Update snow particles - def update_snow(): + def update_snow(dt: float): nonlocal snow # Erase snow particles for particle in snow: @@ -89,8 +89,8 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): # Update snow particles for particle in snow: # Update position - particle.x += particle.xv - particle.y += particle.yv + particle.x += particle.xv * dt + particle.y += particle.yv * dt # Wrap around the screen if particle.x >= width: @@ -148,7 +148,7 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): clear() # Update snow - update_snow() + update_snow(dt) # Move the cat print_ascii(ASCII_CAT, x, y) # Move the cursor to the bottom @@ -179,8 +179,8 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): async def listen_update(): while True: await update() - # Wait for 0.1s - await asyncio.sleep(0.1) + # 30 fps + await asyncio.sleep(1 / 30) # Listen input function async def listen_input():