โ–ถ๏ธ 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,
        },
    )
}
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 #

  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 firefly.toml 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