https://github.com/python-ninja-hebi/python-pygame-ping
Simple Table Tennis Game with Python and Pygame
https://github.com/python-ninja-hebi/python-pygame-ping
game game-development pygame python
Last synced: 2 months ago
JSON representation
Simple Table Tennis Game with Python and Pygame
- Host: GitHub
- URL: https://github.com/python-ninja-hebi/python-pygame-ping
- Owner: Python-Ninja-Hebi
- License: mit
- Created: 2022-12-19T10:20:41.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T13:47:25.000Z (over 2 years ago)
- Last Synced: 2025-01-14T10:33:37.815Z (11 months ago)
- Topics: game, game-development, pygame, python
- Language: HTML
- Homepage:
- Size: 1.57 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.ipynb
- License: LICENSE
Awesome Lists containing this project
README
{
"cells": [
{
"cell_type": "markdown",
"id": "f4169895-9110-4d6a-8552-3ee0d49d8270",
"metadata": {},
"source": [
"# pygame-ping - simple ball game with python and pygame"
]
},
{
"cell_type": "markdown",
"id": "e5363834-a363-4313-9ba8-73a15855c68a",
"metadata": {},
"source": [
"I made a simple game with python and pygame\n",
"\n",
"A classic table tennis game"
]
},
{
"cell_type": "markdown",
"id": "1a3ce75c-ed7c-483f-a295-716fc6205037",
"metadata": {},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"id": "2106a9bb-7055-4725-a2f7-cc06c3c70dbe",
"metadata": {},
"source": [
"## From pygame to the browser"
]
},
{
"cell_type": "markdown",
"id": "3dd18b8a-beff-4a4d-b217-379350c7c46f",
"metadata": {},
"source": [
"You can convert a python pygame into an webassembly and play it in the browser."
]
},
{
"cell_type": "markdown",
"id": "e629058f-b87d-4baf-8c83-12b7448a9d37",
"metadata": {},
"source": [
"Install pygbag https://github.com/pygame-web/pygbag"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df33cbec-11d4-4fbb-bbdf-8a764682db3d",
"metadata": {},
"outputs": [],
"source": [
"pip install pygbag"
]
},
{
"cell_type": "markdown",
"id": "a04bb914-82c6-4eb1-8665-b5f14738a63d",
"metadata": {},
"source": [
"You have to rename your game to main.py and make its loop async aware."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e748e315-fb25-40c2-9c6e-9338fcf06c31",
"metadata": {},
"outputs": [],
"source": [
"import pygame, asyncio\n",
"\n",
"FRAMES_PER_SECOND = 30\n",
"\n",
"\n",
"class Ping:\n",
"...\n",
"\n",
" async def game_loop(self):\n",
" while True:\n",
" for event in pygame.event.get():\n",
" if (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE) \\\n",
" or (event.type == pygame.QUIT):\n",
" return\n",
"\n",
" self.update()\n",
" self.draw()\n",
" await asyncio.sleep(0)\n",
"\n",
"...\n",
"\n",
"async def main():\n",
" ping = Ping()\n",
" await ping.game_loop()\n",
"\n",
"asyncio.run(main())"
]
},
{
"cell_type": "markdown",
"id": "359968c1-1422-4ddc-984e-3adae372d63e",
"metadata": {},
"source": [
"Compile to webassembly"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4dae1af5-5436-4e06-a917-b9cc592e598d",
"metadata": {},
"outputs": [],
"source": [
"pygbag ./folder"
]
},
{
"cell_type": "markdown",
"id": "50e49198-d3f6-406d-b08d-334ba26eac81",
"metadata": {},
"source": [
"You can play it.\n",
"Chrome should work. Use keyboard.\n",
"\n",
"https://hebi-python-ninja.itch.io/ping-from-pygame-to-the-web"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c775a9e-bae4-4c99-86ad-1d5d6e294421",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Rust",
"language": "rust",
"name": "rust"
},
"language_info": {
"codemirror_mode": "rust",
"file_extension": ".rs",
"mimetype": "text/rust",
"name": "Rust",
"pygment_lexer": "rust",
"version": ""
}
},
"nbformat": 4,
"nbformat_minor": 5
}