diff --git a/img/bg-space-1.gif b/img/bg-space-1.gif new file mode 100644 index 0000000..2672ec7 Binary files /dev/null and b/img/bg-space-1.gif differ diff --git a/img/vh-rocket-1ut.gif b/img/vh-rocket-1ut.gif new file mode 100644 index 0000000..09b4843 Binary files /dev/null and b/img/vh-rocket-1ut.gif differ diff --git a/main.py b/main.py index 2b5d2ae..4b349c2 100644 --- a/main.py +++ b/main.py @@ -1,31 +1,8 @@ from turtleps import * +from tests import * -screen = Screen() - - -hideturtle() - -ada = Sprite() - -ada.forward(100) - -init_engine() - -def update(): - - if pressed("ArrowRight"): - print("KEY_RIGHT") - ada.goto(ada.xcor() + 10, ada.ycor()) - - if pressed("ArrowLeft"): - print("KEY_LEFT") - ada.goto(ada.xcor() - 10, ada.ycor()) - - - - set_timeout(update, interval) - -update() +test_interactive_loop() +#test_storytelling() diff --git a/test_main.py b/test_main.py index fd91d32..21464d9 100644 --- a/test_main.py +++ b/test_main.py @@ -14,10 +14,11 @@ from pyodide.http import open_url from pyodide.ffi.wrappers import set_timeout from pyodide.ffi.wrappers import add_event_listener +import asyncio from turtleps import * -import asyncio + ctx = None diff --git a/tests.py b/tests.py index ea3ba29..e38b9f1 100644 --- a/tests.py +++ b/tests.py @@ -431,6 +431,49 @@ async def test_layers(): ada.to_background() +async def test_interactive_loop(): + + screen = Screen() + screen.bgpic("img/bg-space-1.gif") + screen.register_shape("img/bg-space-1.gif") + screen.register_shape("img/vh-rocket-1ut.gif") + + await asyncio.sleep(0.3) # TODO improve when we have proper awaiting register_shape + + rocket = Sprite() + rocket.shape("img/vh-rocket-1ut.gif") # rocket looks up + rocket.pencolor("yellow") + rocket.pensize(5) + + + rocket.tilt(-90) # fix image orientation - NOTE: original Python turtle doesn't allow this for images, only for polygons! + + await rocket.say("Are you ready?", 2) # outside main loop we can use await stuff for intro animations + await rocket.say("Use arrow keys!", 2) + + + init_engine() + + def update(): + + if pressed("ArrowUp"): + print("ArrowUp") + rocket.forward(5) + + if pressed("ArrowLeft"): + print("ArrowLeft") + rocket.left(6) + + if pressed("ArrowRight"): + print("ArrowRight") + rocket.right(6) + + set_timeout(update, interval) + + + update() + + """ #stop_button = pydom[".cdtn-stop-button"] diff --git a/turtleps.py b/turtleps.py index 69e5d54..8fe18d7 100644 --- a/turtleps.py +++ b/turtleps.py @@ -882,6 +882,7 @@ def _predict(self, length): def forward(self, length): self._position = self._predict(length) + self._track.append('{} {} {}'.format( 'L' if self._down else 'M', self._position[0] + self.screen._offset[0], @@ -1478,11 +1479,6 @@ async def say(self, text, seconds, dx=0, dy=65): - - - - - """ screen = Screen()