import asyncio
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
pygame.display.set_caption("My WASM Game")
async def main():
running = True
color_toggle = False
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
color_toggle = not color_toggle
# Fill screen (Blue or Red on click)
if color_toggle:
screen.fill((255, 0, 0))
else:
screen.fill((0, 0, 255))
pygame.display.flip()
# THIS LINE IS MANDATORY FOR BROWSER GAMES
await asyncio.sleep(0)
# Run the async loop
asyncio.ensure_future(main())