Skip to content

Quick Start

This guide walks you through creating a simple game with labelle.

Terminal window
labelle init my-first-game
cd my-first-game

Edit scenes/main.zon:

.{
.name = "main",
.entities = .{
.{
.id = "player",
.components = .{
.Position = .{ .x = 400, .y = 300 },
.Sprite = .{ .name = "player.png", .pivot = .center },
},
},
.{
.components = .{
.Position = .{ .x = 200, .y = 200 },
.Shape = .{ .type = .circle, .radius = 25, .color = .{ .r = 255 } },
},
},
},
}

Create scripts/movement.zig:

const engine = @import("labelle-engine");
pub fn update(game: *engine.Game, scene: *engine.Scene, dt: f32) void {
const input = game.getInput();
if (scene.getEntityByName("player")) |player| {
var pos = game.getPosition(player);
const speed: f32 = 200;
if (input.isKeyDown(.w)) pos.y -= speed * dt;
if (input.isKeyDown(.s)) pos.y += speed * dt;
if (input.isKeyDown(.a)) pos.x -= speed * dt;
if (input.isKeyDown(.d)) pos.x += speed * dt;
game.setPosition(player, pos.x, pos.y);
}
}

Update scenes/main.zon to include the script:

.{
.name = "main",
.scripts = .{"movement"},
.entities = .{
// ... entities
},
}
Terminal window
labelle run

Use WASD to move the player around.