This commit is contained in:
Theis Pieter Hollebeek 2024-04-10 09:32:45 +02:00
parent 7aec7a36a7
commit cb157cbdfa

View File

@ -22,7 +22,7 @@ struct Velocity(f64, f64);
struct VelocitySystem;
impl System for VelocitySystem {
fn on_update(&self, ctx: &mut engine::Context, delta: f64) -> Result<(), engine::Error> {
for id in engine::Quwi::<(Velocity, Position)>::new().run(&ctx) {
for id in run_quwi::<Velocity, Position>(ctx) {
let vel = ctx.entity_component::<Velocity>(id).clone();
let Position(x, y) = ctx.entity_component::<Position>(id);
*x += vel.0 * delta;
@ -38,7 +38,7 @@ struct Gravity;
struct GravitySystem;
impl System for GravitySystem {
fn on_update(&self, ctx: &mut engine::Context, delta: f64) -> Result<(), engine::Error> {
for id in engine::Quwi::<(Gravity, Velocity)>::new().run(&ctx) {
for id in run_quwi::<Gravity, Velocity>(ctx) {
let Velocity(_, y) = ctx.entity_component::<Velocity>(id);
*y = if *y < 800.0 { *y + 400.0 * delta } else { *y };
}
@ -64,12 +64,12 @@ impl System for CloudSystem {
]);
}
for id in engine::Quwi::<(Cloud, Velocity)>::new().run(&ctx) {
for id in run_quwi::<Cloud, Velocity>(ctx) {
let Velocity(x, _) = ctx.entity_component::<Velocity>(id);
*x = if *x < 200.0 { *x + 200.0 * delta } else { *x };
}
for id in engine::Quwi::<(Cloud, Position)>::new().run(&ctx) {
for id in run_quwi::<Cloud, Velocity>(ctx) {
let Position(x, _) = ctx.entity_component::<Position>(id);
if *x > 1400.0 {
ctx.despawn(id);
@ -79,10 +79,14 @@ impl System for CloudSystem {
}
}
fn run_quwi<A: 'static + Component, B: 'static + Component>(ctx: &mut engine::Context) -> Vec<u64> {
engine::Quwi::<(A, B)>::new().run(&ctx)
}
struct SpriteRenderer;
impl System for SpriteRenderer {
fn on_update(&self, ctx: &mut engine::Context, _delta: f64) -> Result<(), engine::Error> {
for id in engine::Quwi::<(Sprite, Position)>::new().run(&ctx) {
for id in run_quwi::<Sprite, Position>(ctx) {
let &mut Position(x, y) = ctx.entity_component::<Position>(id);
let sprite = ctx.entity_component::<Sprite>(id).sprite;
@ -98,7 +102,7 @@ struct PlayerMovement;
struct PlayerMovementSystem;
impl System for PlayerMovementSystem {
fn on_update(&self, ctx: &mut engine::Context, _delta: f64) -> Result<(), engine::Error> {
for id in engine::Quwi::<(PlayerMovement, Velocity)>::new().run(&ctx) {
for id in run_quwi::<PlayerMovement, Velocity>(ctx) {
let d_down = ctx.key_pressed(engine::Keycode::D);
let a_down = ctx.key_pressed(engine::Keycode::A);
let Velocity(x, _) = ctx.entity_component::<Velocity>(id);