Browse Source

realtime

master
whiteline 1 month ago
parent
commit
096fd91378
1 changed files with 19 additions and 1 deletions
  1. +19
    -1
      rougelike.py

+ 19
- 1
rougelike.py View File

@@ -3,6 +3,7 @@ import collections as cl
import networkx as nx
import curses as c
import random
from time import sleep
from grid import Grid, bresenhams
from fov import fieldOfView

@@ -58,6 +59,7 @@ class Player(Behaviour):
self.msgbuffer = cl.deque([], 200)
self.messaged = False
self.messaged_last = False
self.realtime = False

def message(self, msg):
if len(self.msgbuffer) > 0 and msg == self.msgbuffer[0][1] and self.messaged_last:
@@ -95,7 +97,15 @@ class Player(Behaviour):
self.world.window.refresh()

# this is the one gameplay input point.
key = self.world.window.getkey()
if self.realtime:
sleep(0.2)
try:
key = self.world.window.getkey()
except c.error:
key = ""
c.flushinp()
else:
key = self.world.window.getkey()
match key:
case 'w':
if not self.body.move((0, -1)):
@@ -121,6 +131,13 @@ class Player(Behaviour):
self.message("You see nothing here to close.")
case 'q':
self.world.run = False
case 'r':
if self.realtime:
self.realtime = False
self.world.window.nodelay(False)
else:
self.realtime = True
self.world.window.nodelay(True)
# case _: self.world.message(key)

class Drunkard(Behaviour):
@@ -236,6 +253,7 @@ door_open = Tile(',', "open door", "an unremarkable door", solid=False, transpar
w = c.initscr()
c.curs_set(0)
c.raw()
c.echo(False)

wld = World(w, 80, 23, floor)



Loading…
Cancel
Save