alien-cake-addict example: ensure the cake doesn't spawn on the player (#1713)

fixes #1707 

In the game, it makes sense to never spawn the cake on the player.
This commit is contained in:
François 2021-03-22 19:07:15 +00:00
parent 2dd2e5e9fe
commit 94f45586ce

View file

@ -307,8 +307,15 @@ fn spawn_bonus(
return; return;
} }
} }
// ensure bonus doesn't spawn on the player
loop {
game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I); game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J); game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
if game.bonus.i != game.player.i || game.bonus.j != game.player.j {
break;
}
}
game.bonus.entity = commands game.bonus.entity = commands
.spawn(( .spawn((
Transform { Transform {