Add score to main screen

main
Elijah Voigt 3 months ago
parent 3de04ab758
commit 0cdf95ae72

@ -187,23 +187,13 @@ fn init_obstacles(
)
};
let hitbox = {
let material = MeshMaterial2d(materials.add(ColorMaterial {
color: PINK.into(),
..default()
}));
let mesh = Mesh2d(meshes.add(Rectangle::new(0.1, 10.0)));
let physics = (RigidBody::Static, Collider::rectangle(1.0, 10.0));
let physics = (RigidBody::Static, Collider::rectangle(1.0, 10.0), Sensor, CollisionEventsEnabled);
let name = Name::new("hitbox");
(
material.clone(),
mesh.clone(),
name.clone(),
physics.clone(),
Sensor,
Hitbox,
CollisionEventsEnabled,
)
};
@ -273,7 +263,6 @@ fn init_ui(mut commands: Commands) {
..default()
},
).with_children(|parent| {
parent
.spawn((
Node {
@ -295,6 +284,18 @@ fn init_ui(mut commands: Commands) {
))
.observe(flap_button);
});
commands.spawn((
Node {
align_self: AlignSelf::Start,
justify_self: JustifySelf::Center,
..default()
},
BackgroundColor(WHITE.into()),
SyncResource::<Score>::default(),
Text::default(),
TextLayout::new_with_justify(JustifyText::Center)
));
}
fn start_rewind(_trigger: Trigger<Pointer<Pressed>>, mut next: ResMut<NextState<PlayerState>>) {
@ -514,6 +515,7 @@ impl Display for Deaths {
}
}
// TODO: Scoring is bugged, need to make it correct.
fn scoring(
mut events: EventReader<CollisionEnded>,
state: Res<State<PlayerState>>,
@ -528,7 +530,7 @@ fn scoring(
match state.get() {
PlayerState::Alive => score.0 = score.0.saturating_add(1),
PlayerState::Rewind => score.0 = score.0.saturating_sub(1),
_ => panic!("How are you scoring at a time like this??"),
PlayerState::Pause | PlayerState::Stasis => (),
}
})

Loading…
Cancel
Save