53 lines
1.4 KiB
Zig
53 lines
1.4 KiB
Zig
const Pawn = @This();
|
|
|
|
const std = @import("std");
|
|
const Entity = @import("Entity.zig");
|
|
const Scene = @import("Scene.zig");
|
|
const Camera = @import("Camera.zig");
|
|
const Terrain = @import("Terrain.zig");
|
|
const Tag = @import("Tag.zig");
|
|
const Vec2i = @import("geometry/Vec2i.zig");
|
|
const assets = @import("assets.zig");
|
|
const Layer = @import("Layer.zig");
|
|
const Color = @import("Color.zig");
|
|
var prng = std.rand.DefaultPrng.init(0);
|
|
|
|
camera: *const Camera = undefined,
|
|
position: Vec2i = Vec2i.ZERO,
|
|
|
|
pub fn random() !*Pawn {
|
|
var self: Pawn = Pawn {};
|
|
self.position = Vec2i.create(
|
|
@intFromFloat(@floor(prng.random().float(f32) * @as(f32, @floatFromInt(Terrain.CHUNK_SIZE)))),
|
|
@intFromFloat(@floor(prng.random().float(f32) * @as(f32, @floatFromInt(Terrain.CHUNK_SIZE))))
|
|
);
|
|
return try Scene.EntityPool.allocate(self);
|
|
}
|
|
|
|
pub fn create() !*Pawn {
|
|
const self: Pawn = Pawn {};
|
|
return try Scene.allocate(self);
|
|
}
|
|
|
|
pub fn start(self: *Pawn, scene: *const Scene) void {
|
|
self.camera = scene.get(Camera.TAG, Camera);
|
|
}
|
|
|
|
pub fn destroy(self: *const Pawn) void {
|
|
Scene.EntityPool.deallocate(self);
|
|
}
|
|
|
|
pub fn entity(self: *Pawn) Entity {
|
|
return Entity.init(self, .{});
|
|
}
|
|
|
|
// pub fn tile(self: *Pawn) Tile {
|
|
// return Tile.init(.{
|
|
// .solid = true
|
|
// });
|
|
// }
|
|
|
|
pub fn draw(self: *const Pawn) void {
|
|
self.camera.draw_sprite_i(assets.pawn, self.position.to_unit_recti(), Layer.ENTITIES, Color.WHITE);
|
|
}
|