Score
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::camera::CameraPlugin;
|
|||||||
use crate::collision::CollisionPlugin;
|
use crate::collision::CollisionPlugin;
|
||||||
use crate::obstacle::ObstaclePlugin;
|
use crate::obstacle::ObstaclePlugin;
|
||||||
use crate::player::PlayerPlugin;
|
use crate::player::PlayerPlugin;
|
||||||
|
use crate::score::ScorePlugin;
|
||||||
|
|
||||||
mod background;
|
mod background;
|
||||||
mod bounds;
|
mod bounds;
|
||||||
@@ -32,5 +33,6 @@ fn main() {
|
|||||||
.add_plugins(CollisionPlugin) // Collisions
|
.add_plugins(CollisionPlugin) // Collisions
|
||||||
.add_plugins(ObstaclePlugin) // Obstacles
|
.add_plugins(ObstaclePlugin) // Obstacles
|
||||||
.add_plugins(BoundsPlugin) // Bound player
|
.add_plugins(BoundsPlugin) // Bound player
|
||||||
|
.add_plugins(ScorePlugin) // Score
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-6
@@ -1,18 +1,55 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::player::{Player, START_POSITION};
|
use crate::player::{Player, START_POSITION, move_player};
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Default)]
|
||||||
pub struct Depth(pub f32);
|
pub struct Depth(pub f32);
|
||||||
|
|
||||||
|
// Update depth of the player
|
||||||
fn update_depth(mut depth: ResMut<Depth>, player: Single<&Transform, With<Player>>) {
|
fn update_depth(mut depth: ResMut<Depth>, player: Single<&Transform, With<Player>>) {
|
||||||
depth.0 = START_POSITION.y - player.translation.y;
|
depth.0 = START_POSITION.y - player.translation.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_depth_text() {
|
#[derive(Component)]
|
||||||
todo!()
|
pub struct DepthText;
|
||||||
|
|
||||||
|
// Display the initial text of the depth (Score)
|
||||||
|
fn spawn_depth_text(mut commands: Commands) {
|
||||||
|
commands.spawn((
|
||||||
|
Text::new("0"),
|
||||||
|
TextFont {
|
||||||
|
font_size: FontSize::Px(50.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
TextColor(Color::WHITE),
|
||||||
|
Node {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
top: Val::Px(20.0),
|
||||||
|
left: Val::Px(20.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
DepthText,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_depth_text() {
|
// Update depth score text
|
||||||
todo!()
|
fn update_depth_text(
|
||||||
|
mut commands: Commands,
|
||||||
|
depth: Res<Depth>,
|
||||||
|
mut texts: Query<&mut Text, With<DepthText>>,
|
||||||
|
) {
|
||||||
|
for mut text in texts {
|
||||||
|
text.0 = format!("Score: {}", depth.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ScorePlugin;
|
||||||
|
|
||||||
|
impl Plugin for ScorePlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Startup, spawn_depth_text)
|
||||||
|
.init_resource::<Depth>()
|
||||||
|
.add_systems(Update, update_depth.after(move_player))
|
||||||
|
.add_systems(Update, update_depth_text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user