Practical Rust Projects by Shing Lyu

Practical Rust Projects by Shing Lyu

Author:Shing Lyu
Language: eng
Format: epub
ISBN: 9781484255995
Publisher: Apress


// ...

impl<'s> System<'s> for BounceSystem {

// ...

fn run(

&mut self,

(mut balls, players, transforms): Self::SystemData

) {

for (ball, transform) in (&mut balls, &transforms).join() {

// ...

// Bounce at the players.

for (player, player_transform) in

(&players, &transforms).join() {

let player_x = player_transform

.translation().x - (player.width * 0.5);

let player_y = player_transform

.translation().y - (player.height * 0.5);

if point_in_rect(

ball_x,

ball_y,

player_x - ball.radius,

player_y - ball.radius,

player_x + player.width + ball.radius,

player_y + player.height + ball.radius,

) {

if ball.velocity[1] < 0.0 {

// Only bounce when ball is falling

ball.velocity[1] = -ball.velocity[1];



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.