mirror of
https://github.com/neogeek23/rust_pong.git
synced 2026-02-04 10:58:20 +00:00
26 lines
725 B
Rust
26 lines
725 B
Rust
use amethyst::{
|
|
core::timing::Time,
|
|
core::transform::Transform,
|
|
ecs::prelude::{Join, Read, ReadStorage, System, WriteStorage},
|
|
};
|
|
|
|
use crate::pong::Ball;
|
|
|
|
pub struct MoveBallsSystem;
|
|
|
|
impl<'s> System<'s> for MoveBallsSystem {
|
|
type SystemData = (
|
|
ReadStorage<'s, Ball>,
|
|
WriteStorage<'s, Transform>,
|
|
Read<'s, Time>,
|
|
);
|
|
|
|
fn run(&mut self, (balls, mut locals, time): Self::SystemData) {
|
|
// Move every ball according to its speed, and the time passed.
|
|
for (ball, local) in (&balls, &mut locals).join() {
|
|
local.translate_x(ball.velocity[0] * time.delta_seconds());
|
|
local.translate_y(ball.velocity[1] * time.delta_seconds());
|
|
}
|
|
}
|
|
}
|