Closed streetartist closed 3 years ago
Pygame Zero is LGPL so you're welcome to do that as long as your new engine is licensed LGPL also.
The thing you are looking for is coroutines. I've already done a lot of work on coroutines in Wasabi2d: https://wasabi2d.readthedocs.io/en/latest/coros.html (these docs are lagging where the engine is, it is on my to-do list to write new docs).
I have been trying to work out whether coroutines belong in Pygame Zero. I think the fact that they are in Scratch is in the plus column, but I think the syntax and mental model to use them in Python might be too much complexity for complete programming beginners (and their teachers).
I think your approach is a bit limited if the only way you can create a coroutine here is as the main() method of one of these objects (Sprite, Scene, Game etc). You can generalise this to allow any method or function to be a coroutine:
class Cat(Sprite):
def __init__(self):
self.image = "cat.png"
async def main(self):
self.start(self.listen_broadcast())
while True:
self.move(10)
await sleep(1)
self.clone()
async def listen_broadcast(self):
while True:
await listen('event')
self.clone()
class Main(Game):
async def main():
self.start(Cat().main())
while True:
await sleep(0.5)
broadcast('event')
Main().run()
I Want to use the code of pgzero to make a new engine named Scrawl.
The engine is more similar to Scratch than pgzero.
I Am here to
A Scrawl project is like this(I Think the code is easy to understand)
I Use yield to make the muilttask, you can use while true, and make clone, broadcast function.