Skip to content

Commit

Permalink
added rocket example for showcase #17
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Aug 28, 2024
1 parent 8ed7da1 commit 56def94
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 32 deletions.
Binary file added img/bg-space-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/vh-rocket-1ut.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 3 additions & 26 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 2 additions & 1 deletion test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 1 addition & 5 deletions turtleps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -1478,11 +1479,6 @@ async def say(self, text, seconds, dx=0, dy=65):









"""
screen = Screen()
Expand Down

0 comments on commit 56def94

Please sign in to comment.