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
|
import random
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from buba.bubaanimation import BubaAnimation
|
from buba.bubaanimation import BubaAnimation
|
||||||
|
@ -46,6 +47,7 @@ class SnakeAnimation(BubaAnimation):
|
||||||
self.body = [(x, y)]
|
self.body = [(x, y)]
|
||||||
self.render()
|
self.render()
|
||||||
iterations = 0
|
iterations = 0
|
||||||
|
last_update = datetime.now()
|
||||||
while True:
|
while True:
|
||||||
if self.is_blocked(x, y, d):
|
if self.is_blocked(x, y, d):
|
||||||
end = True
|
end = True
|
||||||
|
@ -71,8 +73,11 @@ class SnakeAnimation(BubaAnimation):
|
||||||
self.grid[ty][tx] = 0
|
self.grid[ty][tx] = 0
|
||||||
(tx, ty) = self.body[0]
|
(tx, ty) = self.body[0]
|
||||||
self.grid[ty][tx] = 11
|
self.grid[ty][tx] = 11
|
||||||
self.render()
|
if datetime.now() - last_update > timedelta(seconds=1):
|
||||||
sleep(1)
|
last_update = datetime.now()
|
||||||
|
self.render()
|
||||||
|
else:
|
||||||
|
sleep(.5)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue