Gigoteur / PX8
- понедельник, 24 апреля 2017 г. в 03:11:43
Rust
Open source Fantasy Console in Rust (with Python and Lua)
PX8 is an Open Source Fantasy Console (128x128 pixels) in Rust, by using a cartridge that contains the code/gfx/music. The code could be in Python/Lua, or you could create directly everything in pure Rust by using it as a library.
It is still in development, but it is usable and the main features are:
It works on all platforms (Linux/OSX/Windows), in the browser (via Emscripten), and on tiny hardware like Raspberry Pi 2/3.
The console is inspired from the awesome Pico-8, so there is a compatibility mode (not 100%) available with Pico-8 console and cartridges (P8/PNG).
The time for each frame is slow (10ms) in the GIF, and doesn't correspond to the speed of the game.
Editor mode:
More advanced examples:
Advanced Micro Platformer - Starter Kit http://www.lexaloffle.com/bbs/?tid=28793 in Python https://github.com/Gigoteur/PX8/tree/master/games/amp
2D Terrain Generation (http://www.lexaloffle.com/bbs/?uid=12213) in Python https://github.com/Gigoteur/PX8/tree/master/games/terrain
Voxel framework (http://www.lexaloffle.com/bbs/?tid=28308) in Python https://github.com/Gigoteur/PX8/tree/master/demos/voxel
You can get directly the latest version via git:
git clone https://github.com/Gigoteur/PX8.git
cd PX8
Or you can get binaries for multiples platforms directly on itch.io:
You will need multiple things:
Packages:
Please enable the GL Driver (7 - Advanced Options -> Ac - GL Driver -> Yes) via:
sudo raspi-config
You could build PX8 with cargo directly, in release mode for example, with the support of Python and Lua.
cargo build --features="cpython lua" --release
By default the resolution will 128x128 but you can change the default values by specifying the values of the env variables PX8_SCREEN_WIDTH + PX8_SCREEN_HEIGHT during the compulation:
PX8_SCREEN_WIDTH=256 PX8_SCREEN_HEIGHT=256
Example:
PX8_SCREEN_WIDTH=256 PX8_SCREEN_HEIGHT=256 cargo build --release
If you want to use the gfx_rs renderer (WIP):
cargo build --features="gfx_rs_renderer" --release
You can force opengl with SDL via the '-o' option:
./target/release/px8 -o ./games/ski/ski.px8
You must follow the following guide to install Emscripten.
You can see example of PX8 + Emscripten in the demos repository. You could also see live example from your browser:
Each pixel can be access from 0 to 128 (or the new defined width/height) :
Player 1:
Player 2:
System shortcut:
You should be able to run it directly by providing the path of the cartridge:
./target/release/px8 ./games/ski/ski.px8
You could run the API demos:
./target/release/px8 -s 4 ./demos/api_demos.py
or some fancy demos:
./target/release/px8 -s 4 ./demos/demos.py
./target/release/px8 -s 4 ./demos/voxel/voxel.px8
./target/release/px8 -s 4 ./demos/pong/pong.px8
You can edit the GFX in the cartridge by using the specific '-e' option, and alternate between the run mode and the editor with 'F6':
./target/release/px8 -s 4 -e ./games/ski/ski.px8
and you can save the GFX with 'F5'.
With the '-s' option you can change the size of the console, so you can increase it (2/4/8/10).
You can also use the fullscreen option by using '-f' option.
You can add the '-o' option to force SDL to use OpenGL
You could load a PICO8 cartridge file by using the '-m pico8' option to convert the Lua code.
PX8 will call 3 functions, at startup or during the runtime:
After that you can use the API to do your game. There is no limitation of what you can do in Python or Lua languages.
By default I don't do any modification in the Python or Lua interpreter, so you are free to create threads, load native files, etc
You will be able to find more technical documentation in the wiki
You can create a classical Python program, all you need is to define the previous functions (_init, _update, _draw), and you can import any packages.
def _init():
px8_print("INIT")
def _update():
px8_print("UPDATE")
def _draw():
px8_print("DRAW")
function _init()
print("INIT")
end
function _update()
print("UPDATE")
end
function _draw()
print("DRAW")
end
Format | Read | Write |
---|---|---|
P8 | ||
P8.PNG | ||
PX8 |
API | Rust | Python | Lua |
---|---|---|---|
camera | |||
circ | |||
circfill | |||
clip | |||
cls | |||
color | |||
cursor | |||
ellipse | |||
ellipsefill | |||
fget | |||
flip | |||
fset | |||
line | |||
pal | |||
palt | |||
pget | |||
pset | |||
rect | |||
rectfill | |||
sget | |||
spr | |||
sset | |||
sspr | |||
trigon | |||
trigonfill | |||
btn | |||
btnp | |||
map | |||
mget | |||
mset |
More details here about each function with the arguments: API