Skip to content

Python-Ninja-Hebi/python-pygame-ping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pygame-ping - simple ball game with python and pygame

I made a simple game with python and pygame

A classic table tennis game















From pygame to the browser

You can convert a python pygame into an webassembly and play it in the browser.

Install pygbag https://github.com/pygame-web/pygbag

pip install pygbag

You have to rename your game to main.py and make its loop async aware.

import pygame, asyncio

FRAMES_PER_SECOND = 30


class Ping:
...

    async def game_loop(self):
        while True:
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE) \
                        or (event.type == pygame.QUIT):
                    return

            self.update()
            self.draw()
            await asyncio.sleep(0)

...

async def main():
    ping = Ping()
    await ping.game_loop()

asyncio.run(main())

Compile to webassembly

pygbag ./folder

You can play it. Chrome should work. Use keyboard.

https://hebi-python-ninja.itch.io/ping-from-pygame-to-the-web

About

Simple Table Tennis Game with Python and Pygame

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published