2024-05-29 19:27:02 +01:00
|
|
|
const coral = @import("coral");
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
const ona = @import("ona");
|
|
|
|
|
|
|
|
const Actors = struct {
|
2024-06-04 23:05:57 +01:00
|
|
|
instances: coral.stack.Sequential(ona.gfx.Point2D) = .{.allocator = coral.heap.allocator},
|
2024-06-23 02:16:04 +01:00
|
|
|
quad_mesh_2d: ona.gfx.Handle = .none,
|
2024-06-04 23:05:57 +01:00
|
|
|
body_texture: ona.gfx.Handle = .none,
|
2024-05-30 22:43:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const Player = struct {
|
2024-05-29 19:27:02 +01:00
|
|
|
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},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-20 21:54:00 +01:00
|
|
|
fn load(display: coral.Write(ona.gfx.Display), actors: coral.Write(Actors), assets: coral.Write(ona.gfx.Assets)) !void {
|
|
|
|
display.res.width, display.res.height = .{1280, 720};
|
|
|
|
actors.res.body_texture = try assets.res.open_file("actor.bmp");
|
2024-06-23 02:16:04 +01:00
|
|
|
actors.res.quad_mesh_2d = try assets.res.open_quad_mesh_2d(@splat(1));
|
2024-05-29 19:27:02 +01:00
|
|
|
|
2024-06-20 21:54:00 +01:00
|
|
|
try actors.res.instances.push_grow(.{0, 0});
|
2024-05-29 19:27:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn exit(actors: coral.Write(Actors)) void {
|
|
|
|
actors.res.instances.deinit();
|
|
|
|
}
|
|
|
|
|
2024-06-23 02:16:04 +01:00
|
|
|
fn render(queue: ona.gfx.Queue, actors: coral.Write(Actors)) !void {
|
2024-06-04 23:05:57 +01:00
|
|
|
for (actors.res.instances.values) |instance| {
|
2024-06-20 21:54:00 +01:00
|
|
|
try queue.commands.append(.{
|
2024-06-04 23:05:57 +01:00
|
|
|
.instance_2d = .{
|
2024-06-23 02:16:04 +01:00
|
|
|
.mesh_2d = actors.res.quad_mesh_2d,
|
2024-06-04 23:05:57 +01:00
|
|
|
.texture = actors.res.body_texture,
|
|
|
|
|
|
|
|
.transform = .{
|
|
|
|
.origin = instance,
|
2024-06-20 21:54:00 +01:00
|
|
|
.xbasis = .{64, 0},
|
|
|
|
.ybasis = .{0, 64},
|
2024-06-04 23:05:57 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2024-05-29 19:27:02 +01:00
|
|
|
}
|
|
|
|
|
2024-05-30 22:43:45 +01:00
|
|
|
fn update(player: coral.Read(Player), actors: coral.Write(Actors), mapping: coral.Read(ona.act.Mapping)) !void {
|
2024-06-04 23:05:57 +01:00
|
|
|
actors.res.instances.values[0] += .{
|
2024-05-30 22:43:45 +01:00
|
|
|
mapping.res.axis_strength(player.res.move_x),
|
|
|
|
mapping.res.axis_strength(player.res.move_y),
|
2024-05-29 19:27:02 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(world: *coral.World, events: ona.App.Events) !void {
|
|
|
|
try world.set_resource(.none, Actors{});
|
2024-05-30 22:43:45 +01:00
|
|
|
try world.set_resource(.none, Player{});
|
2024-05-29 19:27:02 +01:00
|
|
|
|
|
|
|
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"});
|
|
|
|
}
|