80 lines
2.2 KiB
Zig
80 lines
2.2 KiB
Zig
const coral = @import("coral");
|
|
|
|
const std = @import("std");
|
|
|
|
const ona = @import("ona");
|
|
|
|
const Actors = struct {
|
|
instances: coral.stack.Sequential(ona.gfx.Queue.Instance2D) = .{.allocator = coral.heap.allocator},
|
|
body_texture: ona.gfx.Queue.Handle = .none,
|
|
};
|
|
|
|
const Player = struct {
|
|
move_x: ona.act.Axis = .{.keys = .{.a, .d}},
|
|
move_y: ona.act.Axis = .{.keys = .{.w, .s}},
|
|
};
|
|
|
|
pub fn main() !void {
|
|
try ona.start_app(setup, .{
|
|
.tick_rate = 60,
|
|
.execution = .{.thread_share = 0.1},
|
|
});
|
|
}
|
|
|
|
fn load(display: coral.ReadBlocking(ona.gfx.Display), actors: coral.Write(Actors), gfx: ona.gfx.Queue) !void {
|
|
display.res.resize(1280, 720);
|
|
|
|
try actors.res.instances.push_many(800, .{
|
|
.origin = .{75, 75},
|
|
.xbasis = .{100, 0},
|
|
.ybasis = .{0, 100},
|
|
});
|
|
|
|
const crap = [_]u32{
|
|
0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000,
|
|
0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF,
|
|
0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF, 0xFF000000,
|
|
0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFFFFFF,
|
|
};
|
|
|
|
actors.res.body_texture = try gfx.buffer.open(.{
|
|
.resource = .{
|
|
.texture = .{
|
|
.data = coral.io.bytes_of(&crap),
|
|
.width = 4,
|
|
.access = .static,
|
|
.format = .bgra8888,
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
fn exit(actors: coral.Write(Actors)) void {
|
|
actors.res.instances.deinit();
|
|
}
|
|
|
|
fn render(gfx: ona.gfx.Queue, actors: coral.Write(Actors)) !void {
|
|
try gfx.buffer.draw_2d(.{
|
|
.mesh_2d = gfx.primitives.quad_mesh,
|
|
.instances = actors.res.instances.values,
|
|
.texture = actors.res.body_texture,
|
|
});
|
|
}
|
|
|
|
fn update(player: coral.Read(Player), actors: coral.Write(Actors), mapping: coral.Read(ona.act.Mapping)) !void {
|
|
actors.res.instances.values[0].origin += .{
|
|
mapping.res.axis_strength(player.res.move_x),
|
|
mapping.res.axis_strength(player.res.move_y),
|
|
};
|
|
}
|
|
|
|
fn setup(world: *coral.World, events: ona.App.Events) !void {
|
|
try world.set_resource(.none, Actors{});
|
|
try world.set_resource(.none, Player{});
|
|
|
|
try world.on_event(events.load, coral.system_fn(load), .{.label = "load"});
|
|
try world.on_event(events.update, coral.system_fn(update), .{.label = "update"});
|
|
try world.on_event(events.exit, coral.system_fn(exit), .{.label = "exit"});
|
|
try world.on_event(events.render, coral.system_fn(render), .{.label = "render actors"});
|
|
}
|