Skip to content

Commit e200044

Browse files
authored
Merge pull request #16 from wade-cheng/main
Overhaul docs
2 parents 4fde406 + 4cbf490 commit e200044

File tree

13 files changed

+259
-311
lines changed

13 files changed

+259
-311
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
/.idea
1+
/.idea
2+
3+
# for local testing
4+
Gemfile.lock
5+
Gemfile
6+
.jekyll-metadata
7+
_site

README.md

Lines changed: 2 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -1,207 +1,10 @@
11
# pygame-web.github.io
22

3-
This is the CDN root used by [Pygbag](https://pypi.org/project/pygbag/) ([Source code](https://github.com/pygame-web/pygbag)/[Old runtimes](https://github.com/pygame-web/archives)) and the site of its [wiki](https://pygame-web.github.io/wiki/pygbag).
3+
This is the CDN root used by [Pygbag](https://pypi.org/project/pygbag/) ([Source code](https://github.com/pygame-web/pygbag)/[Old runtimes](https://github.com/pygame-web/archives)) and the site of its [wiki](/wiki/).
44

55
Pygbag does not track usage at all, not even for statistical purposes. If you like it, please [star](https://github.com/pygame-web/pygbag/stargazers) the repository!
66

7-
Check out some [demos](#demos-on-itchio) before you start!
8-
9-
## Important points
10-
11-
Read Pygbag's [project description](https://pypi.org/project/pygbag/) for a more detailed overview. A full packaging guide can be found [here](https://pygame-web.github.io/wiki/pygbag/).
12-
13-
**<ins>Also, read the page on [making your code compatible with browser game loop](https://pygame-web.github.io/wiki/python-wasm). You will probably have to change some of your code.</ins>**
14-
15-
### All operating systems
16-
17-
- Name your main game script `main.py` and put it in the root folder of your game.
18-
- Make your main loop async-aware and use `asyncio.sleep(0)` every iteration to give control back to the main thread.
19-
- Add `--template noctx.tmpl` to pygbag command line if using 3D/WebGL.
20-
- Put the import statements of complex packages in order (but numpy first) at the top of `main.py`.
21-
- Avoid using CPython's standard library for web operations, GUI (like tkinter), or I/O as it is very synchronous/platform-specific and will probably stay that way. In terms of GUI alternatives, [pygame_gui](https://pypi.org/project/pygame_gui) works on top of [pygame-ce](https://pyga.me), [Panda3D](https://www.panda3d.org/) provides [directgui](https://docs.panda3d.org/1.10/python/programming/gui/directgui/index) and Harfang3D provides imgui. They are all cross-platform.
22-
- You can add a square image file named `favicon.png` in your game's root folder to make Pygbag use it as the web package's favicon.
23-
- Make sure all audio files are in OGG format, and all files are compressed. (that is, not in WAV/AIFF)
24-
- Avoid raw formats like BMP for your image assets, they are too big for web use; use PNG/WEBP or JPG instead.
25-
26-
- Do not use filenames like `*-pygbag.*` that pattern is reserved for pygbag internal use (optimizing pass).
27-
28-
Before packaging, adapt your code this way if you still want WAV/MP3 format on desktop:
29-
```py
30-
if sys.platform == "emscripten":
31-
snd = pygame.mixer.Sound("sound.ogg")
32-
else:
33-
snd = pygame.mixer.Sound("sound.wav") # or .WAV, .mp3, .MP3, etc.
34-
```
35-
36-
if you have heightmaps in your assets use `--no_opt` to prevent png recompression.
37-
38-
if you want to keep pixelated look whatever the device screen size is use:
39-
```py
40-
import sys, platform
41-
if sys.platform == "emscripten":
42-
platform.window.canvas.style.imageRendering = "pixelated"
43-
```
44-
45-
### Windows
46-
47-
- Use Python that was downloaded from python.org rather than the Windows Store. You can check installed version(s) with the `py --list` command.
48-
- Use `/` instead of `\​` as a path separator (e.g. `img/my_image.png` instead of `img\my_image.png`). The path should still be valid on newer Windows versions.
49-
50-
### MacOS
51-
52-
- If you get a SSL error, use the file `Install Certificates.command` in `Applications/Python 3.XX`.
53-
54-
### Linux
55-
56-
- When using webusb ftdi serial emulation, use `sudo rmmod ftdi_sio` after plugging devices.
57-
58-
## Template
59-
60-
There is actually none, because Python-WASM is just a web-friendly version of CPython REPL with [some added facilities](https://discuss.python.org/t/status-of-wasm-in-cpythons-main-branch/15542/12?u=pmp-p). Most desktop code will run (and continue to run) with only a few changes.
61-
62-
Basic structure of a game (available [here](https://github.com/pygame-web/pygbag/tree/main/test)):
63-
```
64-
test
65-
├── img
66-
│   ├── pygc.bmp
67-
│   ├── pygc.png
68-
│   └── tiger.svg
69-
├── main.py
70-
└── sfx
71-
└── beep.ogg
72-
```
73-
74-
Useful .gitignore additions:
75-
```
76-
*.wav
77-
*.mp3
78-
*.pyc
79-
*.egg-info
80-
*-pygbag.???
81-
/build
82-
/dist
83-
```
84-
85-
## Coding
86-
87-
- [General Python-WASM](https://pygame-web.github.io/wiki/python-wasm/)
88-
- [With Pygbag specifically](https://pygame-web.github.io/wiki/pygbag-code/)
89-
- [Pygbag code examples](https://pygame-web.github.io/wiki/pygbag-code/#pygbag-code-specifics-samples-)
90-
91-
## Adding modules
92-
93-
- [List of available wheels](https://pygame-web.github.io/wiki/pkg/)
94-
- [requesting modules](https://github.com/pygame-web/pkg-porting-wasm/issues)
95-
96-
When importing complex packages (for example, numpy or matplotlib), you must put their import statements at top of `main.py`. You should also add a metadata header as specified by [PEP 723](https://peps.python.org/pep-0723/), for example:
97-
```
98-
# /// script
99-
# dependencies = [
100-
# "six",
101-
# "bs4",
102-
# "markdown-it-py",
103-
# "pygments",
104-
# "rich",
105-
# "mdurl",
106-
# "textual",
107-
# ]
108-
# ///
109-
```
110-
111-
If using pygame-zero (mostly untested), put `#!pgzrun` near the top of main.py. (2nd line is perfect if the file already has a shebang)
112-
113-
## Debugging / Desktop Simulator
114-
115-
- [How to enter debug mode](https://pygame-web.github.io/wiki/pygbag-debug/)
116-
- While working, you can access the simulator of the web loop by replacing `import asyncio` by `import pygbag.aio as asyncio` at top of main.py and run the program from the folder containing it.
117-
- TODO: Android remote debugging via [chromium browsers series](https://developer.chrome.com/docs/devtools/remote-debugging/).
118-
- TODO: Universal remote debugging via IRC Client or websocket using pygbag.net.
119-
120-
## Running
121-
122-
- [Pygbag-script](https://pygame-web.github.io/wiki/pygame-script/) (WIP)
123-
- [REPL](https://pygame-web.github.io/showroom/python.html?-i-&-X-dev#https://gist.githubusercontent.com/pmp-p/cfd398c75608504293d21f2642e87968/raw/773022eef4a2cc676ab0475890577a2b5e79e429/hello.py)
124-
- [CPython test suite](https://pygame-web.github.io/showroom/pythondev.html?-d#src/testsuite.py%20all) (WIP)
125-
126-
## Publishing
127-
128-
- [Github Pages](https://pygame-web.github.io/wiki/pygbag/github.io/)
129-
- [Itch.io](https://pygame-web.github.io/wiki/pygbag/itch.io/)
130-
131-
## Demos
132-
133-
### Demos on itch.io
134-
135-
- [Games using Python-WASM](https://itch.io/c/2563651/pygame-wasm) (Expected to be stable)
136-
- [Panda3D demos](https://itch.io/c/3724091/panda3d-wasm) (Experimental)
137-
138-
### Demos on Github Pages
139-
140-
These are provided for testing purposes only, and might not always work since they use development versions of Pygbag.
141-
142-
#### Heavy CPU load, not for low-end devices
143-
144-
- [Perfect Rain](https://pmp-p.github.io/pygame-perfect-rain-wasm/)
145-
- [Alien Dimension](https://pmp-p.github.io/pygame-alien-dimension-wasm/)
146-
147-
#### Light CPU load
148-
149-
- [Breakout](https://pmp-p.github.io/pygame-breakout-wasm/index.html)
150-
- [PyChess](https://pmp-p.github.io/pygame-pychess-wasm/index.html)
151-
- [Penguins Can't Fly!](https://pmp-p.github.io/pygame-PenguinsCantFly-wasm/)
152-
- [John's Adventure](https://pmp-p.github.io/pygame-JohnsAdventure-wasm/)
153-
- [3D Tic-Tac-Toe](https://pmp-p.github.io/pygame-ttt-3d-wasm/)
154-
- [Arachnoids](https://pmp-p.github.io/pygame-arachnoids-wasm/)
155-
- [Sudoku Solver](https://www.pete-j-matthews.com/Sudoku-Solver/)
156-
157-
Source code for these games can be found [here](https://github.com/pmp-p?tab=repositories&q=pygame-.-wasm&sort=name). You can tag your Github repositories with [[pygame-wasm]](https://github.com/topics/pygame-wasm).
158-
159-
### Script demos
160-
161-
The code is read-only, so you should right-click then open in a new window.
162-
163-
- [i18n bidi, complex scripts](/showroom/pypad_git.html?-i#src/test_hb.py)
164-
- [Camera](/showroom/pypad_git.html?-i#src/test_vidcap.py)
165-
- [Panda3D](/showroom/pypad_dev.html?-i#src/test_panda3d_cube.py)
166-
- [Audio Record/Play](/showroom/pypad_dev.html?-i#src/test_audio.py)
167-
- [HTML output](/showroom/pypad_dev.html?-i#src/test_html.py)
168-
169-
## Technology
170-
171-
- [Initial discussion](https://github.com/pygame/pygame/issues/718)
172-
- [Discussion at pygame-ce repo](https://github.com/pygame-community/pygame-ce/issues/540)
173-
- [Python-WASM explained by core dev Christian Heimes (video)](https://www.youtube.com/watch?v=oa2LllRZUlU)
174-
175-
### Early demos from above talk, may not work as intended :)
176-
177-
- [Pygame tech demo PyCon DE & PyData Berlin 2022](https://pmp-p.github.io/pygame-wasm/)
178-
- [Galaxy Attack](https://pmp-p.github.io/pygame-galaxy-attack-wasm/)
179-
180-
Python WebAssembly at PyCon FR 2023 (in French):
181-
[Pour quoi, pour qui et comment](https://harfang3d.github.io/pyconfr2023/#1)
182-
183-
## Status
184-
185-
- [Current issues](https://github.com/pygame-web/pygbag/issues)
186-
- [Package porting](https://github.com/pygame-web/pkg-porting-wasm/issues)
187-
- [PyPI stats](https://pepy.tech/project/pygbag)
188-
189-
## Other Pythons in browser
190-
191-
- [Pyodide/Pyscript](https://github.com/pyodide/pyodide) ( py3.12+ not suitable for heavy games, music or 3D )
192-
- [Micropython/Pyscript](https://www.npmjs.com/package/@micropython/micropython-webassembly-pyscript) ( py3.4, no pygame, but pysdl2/javascript libraries possible )
193-
- PocketPy, not any Python spec compliant but sometimes close. Can make Terminal/raylib based games.
194-
195-
## Support
196-
197-
- [Pygame Community](https://pyga.me/)
198-
199-
## Connect
200-
201-
- [Pygame Community Discord Server](https://discord.gg/p7RjnVNTcM)
202-
- [WebAssembly/Python Discord Server](https://discord.gg/MCTM4xFDMK)
203-
204-
Thanks for reading and supporting pygame-ce and pygbag. These tools could not have existed without your support.
7+
Visit the [wiki](/wiki/) to get started!
2058

2069
**Work in progress, pull requests welcomed. Feel free to propose links to games or tutorials. Please contribute!!!**
20710

wiki/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Check out some [demos](#demos-on-itchio) before you start!
2+
3+
## Using Pygbag
4+
- Visit [this page](/wiki/pygbag/) on how to use Pygbag to make web games with Python.
5+
- Visit [this page](/wiki/pygbag-code/) for useful Pygbag code snippets and a Pygbag FAQ.
6+
7+
## Debugging / Desktop Simulator
8+
9+
- [How to enter debug mode](/wiki/pygbag-debug/)
10+
- While working, you can access the simulator of the web loop by replacing `import asyncio` by `import pygbag.aio as asyncio` at top of main.py and run the program from the folder containing it.
11+
- TODO: Android remote debugging via [chromium browsers series](https://developer.chrome.com/docs/devtools/remote-debugging/).
12+
- TODO: Universal remote debugging via IRC Client or websocket using pygbag.net.
13+
14+
## Running
15+
16+
- [Pygbag-script](/wiki/pygbag-script/) (WIP)
17+
- [REPL](https://pygame-web.github.io/showroom/python.html?-i-&-X-dev#https://gist.githubusercontent.com/pmp-p/cfd398c75608504293d21f2642e87968/raw/773022eef4a2cc676ab0475890577a2b5e79e429/hello.py)
18+
- [CPython test suite](https://pygame-web.github.io/showroom/pythondev.html?-d#src/testsuite.py%20all) (WIP)
19+
20+
## Publishing
21+
22+
- [Github Pages](/wiki/publishing/github.io/)
23+
- [Itch.io](/wiki/publishing/itch.io/)
24+
25+
## Demos
26+
27+
### Demos on itch.io
28+
29+
- [Games using Python-WASM](https://itch.io/c/2563651/pygame-wasm) (Expected to be stable)
30+
- [Panda3D demos](https://itch.io/c/3724091/panda3d-wasm) (Experimental)
31+
32+
### Demos on Github Pages
33+
34+
These are provided for testing purposes only, and might not always work since they use development versions of Pygbag.
35+
36+
#### Heavy CPU load, not for low-end devices
37+
38+
- [Perfect Rain](https://pmp-p.github.io/pygame-perfect-rain-wasm/)
39+
- [Alien Dimension](https://pmp-p.github.io/pygame-alien-dimension-wasm/)
40+
41+
#### Light CPU load
42+
43+
- [Breakout](https://pmp-p.github.io/pygame-breakout-wasm/index.html)
44+
- [PyChess](https://pmp-p.github.io/pygame-pychess-wasm/index.html)
45+
- [Penguins Can't Fly!](https://pmp-p.github.io/pygame-PenguinsCantFly-wasm/)
46+
- [John's Adventure](https://pmp-p.github.io/pygame-JohnsAdventure-wasm/)
47+
- [3D Tic-Tac-Toe](https://pmp-p.github.io/pygame-ttt-3d-wasm/)
48+
- [Arachnoids](https://pmp-p.github.io/pygame-arachnoids-wasm/)
49+
- [Sudoku Solver](https://www.pete-j-matthews.com/Sudoku-Solver/)
50+
51+
Source code for these games can be found [here](https://github.com/pmp-p?tab=repositories&q=pygame-.-wasm&sort=name). You can tag your Github repositories with [[pygame-wasm]](https://github.com/topics/pygame-wasm).
52+
53+
### Script demos
54+
55+
The code is read-only, so you should right-click then open in a new window.
56+
57+
- [i18n bidi, complex scripts](https://pygame-web.github.io/showroom/pypad_git.html?-i#src/test_hb.py)
58+
- [Camera](https://pygame-web.github.io/showroom/pypad_git.html?-i#src/test_vidcap.py)
59+
- [Panda3D](https://pygame-web.github.io/showroom/pypad_dev.html?-i#src/test_panda3d_cube.py)
60+
- [Audio Record/Play](https://pygame-web.github.io/showroom/pypad_dev.html?-i#src/test_audio.py)
61+
- [HTML output](https://pygame-web.github.io/showroom/pypad_dev.html?-i#src/test_html.py)
62+
63+
## Technology
64+
65+
- [Initial discussion](https://github.com/pygame/pygame/issues/718)
66+
- [Discussion at pygame-ce repo](https://github.com/pygame-community/pygame-ce/issues/540)
67+
- [Python-WASM explained by core dev Christian Heimes (video)](https://www.youtube.com/watch?v=oa2LllRZUlU)
68+
69+
### Early demos from above talk, may not work as intended :)
70+
71+
- [Pygame tech demo PyCon DE & PyData Berlin 2022](https://pmp-p.github.io/pygame-wasm/)
72+
- [Galaxy Attack](https://pmp-p.github.io/pygame-galaxy-attack-wasm/)
73+
74+
Python WebAssembly at PyCon FR 2023 (in French):
75+
[Pour quoi, pour qui et comment](https://harfang3d.github.io/pyconfr2023/#1)
76+
77+
## Status
78+
79+
- [Current issues](https://github.com/pygame-web/pygbag/issues)
80+
- [Package porting](https://github.com/pygame-web/pkg-porting-wasm/issues)
81+
- [PyPI stats](https://pepy.tech/project/pygbag)
82+
83+
## Other Pythons in browser
84+
85+
- [Pyodide/Pyscript](https://github.com/pyodide/pyodide) ( py3.12+ not suitable for heavy games, music or 3D )
86+
- [Micropython/Pyscript](https://www.npmjs.com/package/@micropython/micropython-webassembly-pyscript) ( py3.4, no pygame, but pysdl2/javascript libraries possible )
87+
- PocketPy, not any Python spec compliant but sometimes close. Can make Terminal/raylib based games.
88+
89+
## Support
90+
91+
- [Pygame Community](https://pyga.me/)
92+
93+
## Connect
94+
95+
- [Pygame Community Discord Server](https://discord.gg/p7RjnVNTcM)
96+
- [WebAssembly/Python Discord Server](https://discord.gg/MCTM4xFDMK)
97+
98+
Thanks for reading and supporting pygame-ce and pygbag. These tools could not have existed without your support.

wiki/pkg/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ documented modified packages :
2929

3030

3131
- [pygame] Starting with 0.7 pygbag runtime will use [pygame-ce](https://github.com/pygame-community/pygame-ce) codebase.
32-
- [nurses_2](https://pygame-web.github.io/wiki/pkg/nurses_2/)
32+
- [nurses_2](/wiki/pkg/nurses_2/)
3333
- [harfang] from [vendored pygbag](https://github.com/harfang3d/harfang-wasm)
34-
- [panda3d](https://pygame-web.github.io/wiki/pkg/panda3d/) from [Panda3D wasm branch](https://github.com/panda3d/panda3d/tree/webgl-port) + [vendored pygbag](https://github.com/pmp-p/panda3d-wasm)
34+
- [panda3d](/wiki/pkg/panda3d/) from [Panda3D wasm branch](https://github.com/panda3d/panda3d/tree/webgl-port) + [vendored pygbag](https://github.com/pmp-p/panda3d-wasm)
3535

3636

3737
[edit this page](https://github.com/pygame-web/pygame-web.github.io/edit/main/wiki/pkg/README.md)
File renamed without changes.
File renamed without changes.
File renamed without changes.

wiki/pygbag/itch.io/README.md renamed to wiki/publishing/itch.io/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ To set up the project:
2525
4. Select `This file will be played in the browser`
2626
5. Then save your project
2727

28-
After following these step, if you view your game page and set it to public, then you would be able to see your game.
28+
More information can be found [here](https://itch.io/docs/creators/html5). After following these steps, if you view your game page, you would be able to see your game. If you update your games frequently, you can use [butler](https://itch.io/docs/butler/), a command-line tool made by the developers of itch.
2929

30-
Thought, if your are unable to do so, you can ask for help in the [pygame discord server](https://discord.gg/s6Hhrh77aq)
30+
After following these steps, if you view your game page and set it to public, then you would be able to see your game.
31+
32+
Though, if you are unable to do so, you can ask for help in the [pygame discord server](https://discord.gg/s6Hhrh77aq)
3133

3234

3335

0 commit comments

Comments
 (0)