ℹ️
Notification
Pygame Web IDE
Loading Environment...
Editor
Save
Projects
Export
Pop Out
Stop
Run Code
main.py
import asyncio import pygame import sys import math # Initialize pygame.init() WIDTH, HEIGHT = 400, 400 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("My Web Pygame") clock = pygame.time.Clock() async def main(): running = True x, y = 200, 200 angle = 0 while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False return # Simple movement keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: x -= 5 if keys[pygame.K_RIGHT]: x += 5 if keys[pygame.K_UP]: y -= 5 if keys[pygame.K_DOWN]: y += 5 # Draw background and visual screen.fill((15, 23, 42)) # Slate 900 # Draw a pulsing circle radius = 20 + math.sin(angle) * 10 pygame.draw.circle(screen, (56, 189, 248), (x, y), radius) angle += 0.1 pygame.display.update() # CRITICAL: Yield to browser await asyncio.sleep(0) clock.tick(60) # Start the asyncio loop asyncio.ensure_future(main())
Console Output
Clear
Project Name
Created on
...
Share Link
Remix Code
Source Code
Comments
Loading comments...
Post Comment
Save Project Online
Enter a name for your Pygame project to save it to the public database.
Cancel
Publish
Community Projects
×
Click a project to view its page, run the code, and read comments.
Loading database...