๐ Pick the language #
Firefly Zero supports lots of programming languages. For simple apps and games, it’s a good idea to stick to what you already know. But if you’re ready to learn something new for a better results, there are some recommendations:
- (โ Coming soon) โก๏ธ Zig is simple and gives the best performance but you need to be careful to avoid bugs and memory leaks.
- ๐ฆ Rust gives performance close to Zig and it’s hard to use it wrong, but it’s also the most difficult language to learn on the list.
- ๐ Go is slower than Rust or Zig but very simple to use and doesn’t have memory leaks.
- (โ Coming soon) More languages.
Subjective comparison:
Language | Simplicity | Performance | Safety |
---|---|---|---|
โก๏ธ Zig | ๐ป 3/5 | ๐ 5/5 | ๐ 2/5 |
๐ฆ Rust | ๐ฌ 1/5 | ๐ 5/5 | ๐ 5/5 |
๐ Go | ๐จ 4/5 | ๐ 4/5 | ๐ 4/5 |
๐ฅ Install tools #
- Install rust and cargo:
curl https://sh.rustup.rs -sSf | sh
- Install firefly-cli:
cargo install firefly_cli
- Download emulator binary and put it into
$PATH
- Install WebAssembly compiler for your language:
rustup target add wasm32-unknown-unknown
๐ป Create the project #
Create an empty project:
cargo new hello-world
cd hello-world
cargo add firefly_rust
mkdir hello-world
cd hello-world
go mod init hello-world
go get github.com/firefly-zero/firefly-go
echo "package main\n\nfunc main() {}" > main.go
Create firefly.toml
config:
author_id = "joearms"
app_id = "hello-world"
author_name = "Joe Armstrong"
app_name = "Hello World"
Write some code:
#![no_std]
#![no_main]
use firefly_rust::*;
#[no_mangle]
extern fn render() {
draw_triangle(
Point { x: 60, y: 10 },
Point { x: 40, y: 40 },
Point { x: 80, y: 40 },
Style {
fill_color: Color::LightGray,
stroke_color: Color::DarkBlue,
stroke_width: 1,
},
);
}
package main
import "github.com/firefly-zero/firefly-go/firefly"
func init() {
firefly.Render = render
}
func render() {
firefly.DrawTriangle(
firefly.Point{X: 60, Y: 10},
firefly.Point{X: 40, Y: 40},
firefly.Point{X: 80, Y: 40},
firefly.Style{
FillColor: firefly.ColorDarkBlue,
StrokeColor: firefly.ColorBlue,
StrokeWidth: 1,
},
)
}
const ff = @import("firefly");
pub export fn render() void {
ff.drawTriangle(
ff.Point{ .x = 60, .y = 10 },
ff.Point{ .x = 40, .y = 40 },
ff.Point{ .x = 80, .y = 40 },
ff.Style{
.fill_color = ff.Color.light_gray,
.stroke_color = ff.Color.dark_blue,
.stroke_width = 1,
},
);
}
๐ Build and run #
- Build and install the app:
firefly_cli build
- Run the last built app:
firefly_emulator
Have troubles using emulator? Check out the emulator user guide.
๐ฆ Distribute #
-
Create a file for an installed app:
firefly_cli export --author joearms --app hello-world
-
Publish the file anywhere you like. For open-source projects, a good option is Github Releases.
-
People then can download and install the app:
firefly_cli import ./joearms.hello-world.zip
-
Optional: add your app into the catalog: catalog.fireflyzero.com.
๐ง Further reading #
There are several things you should know to make a game:
- How the runtime works in general. Start by reading about firefly.toml and then go through all other pages in this documentation in order.
- What functions the SDK for the programming language that you choose provides:
- How to make games and what patterns make it easier. We recommend reading Game Programming Patterns.