|
|
|
@ -41,7 +41,7 @@ pub fn SetupECS(reg: *ecs.Registry) !void {
|
|
|
|
|
reg.add(player, EnSysTypes.Sprite{.image = rl.loadTexture("src/Images/9k.png")});
|
|
|
|
|
}
|
|
|
|
|
pub fn DrawSystem(reg: *ecs.Registry) !void {
|
|
|
|
|
var view = reg.*.view(.{EnSysTypes.Transform, EnSysTypes.Sprite}, .{});
|
|
|
|
|
var view = reg.view(.{EnSysTypes.Transform, EnSysTypes.Sprite}, .{});
|
|
|
|
|
var iter = view.entityIterator();
|
|
|
|
|
while(iter.next())|entity|{
|
|
|
|
|
const Transform = view.getConst(EnSysTypes.Transform, entity);
|
|
|
|
@ -50,17 +50,17 @@ pub fn DrawSystem(reg: *ecs.Registry) !void {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn PhysicsSystem(reg: *ecs.Registry, deltaTime: f32) !void {
|
|
|
|
|
var view = reg.*.view(.{EnSysTypes.Transform, EnSysTypes.Rigidbody, EnSysTypes.Gravity}, .{});
|
|
|
|
|
var view = reg.view(.{EnSysTypes.Transform, EnSysTypes.Rigidbody, EnSysTypes.Gravity}, .{});
|
|
|
|
|
var iter = view.entityIterator();
|
|
|
|
|
while(iter.next())|entity|{
|
|
|
|
|
var Rigidbody = view.get(EnSysTypes.Rigidbody, entity);
|
|
|
|
|
var Transform = view.get(EnSysTypes.Transform, entity);
|
|
|
|
|
const Gravity = view.getConst(EnSysTypes.Gravity, entity);
|
|
|
|
|
|
|
|
|
|
Rigidbody.*.vel.x += Gravity.vel.x;
|
|
|
|
|
Rigidbody.*.vel.y += Gravity.vel.y;
|
|
|
|
|
Transform.*.pos.x += Rigidbody.*.vel.x / deltaTime;
|
|
|
|
|
Transform.*.pos.y += Rigidbody.*.vel.y / deltaTime;
|
|
|
|
|
Rigidbody.vel.x += Gravity.vel.x;
|
|
|
|
|
Rigidbody.vel.y += Gravity.vel.y;
|
|
|
|
|
Transform.pos.x += Rigidbody.vel.x / deltaTime;
|
|
|
|
|
Transform.pos.y += Rigidbody.vel.y / deltaTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|