run_quwi
This commit is contained in:
parent
7aec7a36a7
commit
cb157cbdfa
16
src/main.rs
16
src/main.rs
@ -22,7 +22,7 @@ struct Velocity(f64, f64);
|
|||||||
struct VelocitySystem;
|
struct VelocitySystem;
|
||||||
impl System for VelocitySystem {
|
impl System for VelocitySystem {
|
||||||
fn on_update(&self, ctx: &mut engine::Context, delta: f64) -> Result<(), engine::Error> {
|
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 vel = ctx.entity_component::<Velocity>(id).clone();
|
||||||
let Position(x, y) = ctx.entity_component::<Position>(id);
|
let Position(x, y) = ctx.entity_component::<Position>(id);
|
||||||
*x += vel.0 * delta;
|
*x += vel.0 * delta;
|
||||||
@ -38,7 +38,7 @@ struct Gravity;
|
|||||||
struct GravitySystem;
|
struct GravitySystem;
|
||||||
impl System for GravitySystem {
|
impl System for GravitySystem {
|
||||||
fn on_update(&self, ctx: &mut engine::Context, delta: f64) -> Result<(), engine::Error> {
|
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);
|
let Velocity(_, y) = ctx.entity_component::<Velocity>(id);
|
||||||
*y = if *y < 800.0 { *y + 400.0 * delta } else { *y };
|
*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);
|
let Velocity(x, _) = ctx.entity_component::<Velocity>(id);
|
||||||
*x = if *x < 200.0 { *x + 200.0 * delta } else { *x };
|
*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);
|
let Position(x, _) = ctx.entity_component::<Position>(id);
|
||||||
if *x > 1400.0 {
|
if *x > 1400.0 {
|
||||||
ctx.despawn(id);
|
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;
|
struct SpriteRenderer;
|
||||||
impl System for SpriteRenderer {
|
impl System for SpriteRenderer {
|
||||||
fn on_update(&self, ctx: &mut engine::Context, _delta: f64) -> Result<(), engine::Error> {
|
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 &mut Position(x, y) = ctx.entity_component::<Position>(id);
|
||||||
let sprite = ctx.entity_component::<Sprite>(id).sprite;
|
let sprite = ctx.entity_component::<Sprite>(id).sprite;
|
||||||
|
|
||||||
@ -98,7 +102,7 @@ struct PlayerMovement;
|
|||||||
struct PlayerMovementSystem;
|
struct PlayerMovementSystem;
|
||||||
impl System for PlayerMovementSystem {
|
impl System for PlayerMovementSystem {
|
||||||
fn on_update(&self, ctx: &mut engine::Context, _delta: f64) -> Result<(), engine::Error> {
|
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 d_down = ctx.key_pressed(engine::Keycode::D);
|
||||||
let a_down = ctx.key_pressed(engine::Keycode::A);
|
let a_down = ctx.key_pressed(engine::Keycode::A);
|
||||||
let Velocity(x, _) = ctx.entity_component::<Velocity>(id);
|
let Velocity(x, _) = ctx.entity_component::<Velocity>(id);
|
||||||
|
Loading…
Reference in New Issue
Block a user