We cannot speed up updating the display, but we can limit the updates to once a second, and take two steps per second.
This commit is contained in:
parent
e583bb5691
commit
8aeeac62ef
1 changed files with 7 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
import random
|
||||
from datetime import datetime, timedelta
|
||||
from time import sleep
|
||||
|
||||
from buba.bubaanimation import BubaAnimation
|
||||
|
@ -46,6 +47,7 @@ class SnakeAnimation(BubaAnimation):
|
|||
self.body = [(x, y)]
|
||||
self.render()
|
||||
iterations = 0
|
||||
last_update = datetime.now()
|
||||
while True:
|
||||
if self.is_blocked(x, y, d):
|
||||
end = True
|
||||
|
@ -71,8 +73,11 @@ class SnakeAnimation(BubaAnimation):
|
|||
self.grid[ty][tx] = 0
|
||||
(tx, ty) = self.body[0]
|
||||
self.grid[ty][tx] = 11
|
||||
if datetime.now() - last_update > timedelta(seconds=1):
|
||||
last_update = datetime.now()
|
||||
self.render()
|
||||
sleep(1)
|
||||
else:
|
||||
sleep(.5)
|
||||
sleep(5)
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue