▶️ Getting started

▶️ Getting started #

👉 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:

  1. (⌛ Coming soon) ⚡️ Zig is simple and gives the best performance but you need to be careful to avoid bugs and memory leaks.
  2. 🦀 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.
  3. 🐹 Go is slower than Rust or Zig but very simple to use and doesn’t have memory leaks.
  4. (⌛ 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 #

  1. Install rust and cargo: curl https://sh.rustup.rs -sSf | sh
  2. Install firefly-cli: cargo install firefly_cli
  3. Download emulator binary and put it into $PATH
  4. 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,
        },
    )
}

🏃 Build and run #

  1. Build and install the app: firefly_cli build
  2. Run the last built app: firefly_emulator

Have troubles using emulator? Check out the emulator user guide.

📦 Distribute #

  1. Create a file for an installed app:

    firefly_cli export --author joearms --app hello-world
    
  2. Publish the file anywhere you like. For open-source projects, a good option is Github Releases.

  3. People then can download and install the app:

    firefly_cli import ./joearms.hello-world.zip
    
  4. Optional: add your app into the catalog: catalog.fireflyzero.com.

🧠 Further reading #

There are several things you should know to make a game:

  1. How the runtime works in general. Start by reading about Callbacks and then go through all other pages in this documentation in order.
  2. What functions the SDK for the programming language that you choose provides:
    1. 🦀 Rust
    2. 🏃 Go
  3. How to make games and what patterns make it easier. We recommend reading Game Programming Patterns.
➡️ firefly.toml