Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

buffer keys

more natural feel
  • Loading branch information...
commit 5f9e821c336036d99a709b1f18b9262afdf5cdbb 1 parent a95ba77
@ruggeri ruggeri authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 snake.py
View
13 snake.py
@@ -42,10 +42,19 @@ def put_char(pos, char):
def draw(obj):
obj.draw(CANVAS)
+KEY_BUFFER_MAX_SIZE = 4
+KEY_BUFFER = []
def m(keys):
direction = None
- if keys and keys[0] in KEY_TO_DIR:
- direction = KEY_TO_DIR[keys[0]]
+
+ for key in keys:
+ if len(KEY_BUFFER) == KEY_BUFFER_MAX_SIZE:
+ break
+ elif key in KEY_TO_DIR:
+ KEY_BUFFER.append(key)
+
+ if KEY_BUFFER:
+ direction = KEY_TO_DIR[KEY_BUFFER.pop(0)]
CANVAS.clear()
move(direction)
Please sign in to comment.
Something went wrong with that request. Please try again.