These code snippets are useful when running your game in a browser with Emscripten.
if sys.platform == "emscripten":
pass
if 'wasm' in __import__('platform').machine():
pass
import asyncio
import pygame
pygame.init()
def menu(events):
# draw
# check events
# change state
pass
def play(events):
# draw
# check events
# change state
pass
game_state = menu
async def main():
global game_state
# You can initialise pygame here as well
while game_state:
game_state(pygame.event.get())
pygame.display.update()
await asyncio.sleep(0) # do not forget that one, it must be called on every frame
# Closing the game (not strictly required)
pygame.quit()
sys.exit()
if __name__ == "__main__":
asyncio.run(main())
Everything else is probably specific to Pygbag. You can find more information/code here.