Spawning score and lives UI elements, no logic
I have basic UI elements! They can't be updated, yet, and there's still no game logic to allow the player to affect it on their own.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "asteroids"
|
name = "asteroids"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
84
src/lib.rs
84
src/lib.rs
@@ -9,20 +9,25 @@ pub struct AsteroidPlugin;
|
|||||||
|
|
||||||
impl Plugin for AsteroidPlugin {
|
impl Plugin for AsteroidPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, (spawn_camera, spawn_player))
|
app.add_systems(
|
||||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
Startup,
|
||||||
.insert_resource(WorldSize {
|
(spawn_camera, spawn_player, spawn_ui),
|
||||||
width: WINDOW_SIZE.x,
|
)
|
||||||
height: WINDOW_SIZE.y,
|
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||||
})
|
.insert_resource(WorldSize {
|
||||||
.add_systems(
|
width: WINDOW_SIZE.x,
|
||||||
FixedUpdate,
|
height: WINDOW_SIZE.y,
|
||||||
(input_ship_thruster, input_ship_rotation, wrap_entities),
|
})
|
||||||
)
|
.insert_resource(Lives(3))
|
||||||
.add_systems(
|
.insert_resource(Score(0))
|
||||||
FixedPostUpdate,
|
.add_systems(
|
||||||
(integrate_velocity, update_positions, apply_rotation_to_mesh),
|
FixedUpdate,
|
||||||
);
|
(input_ship_thruster, input_ship_rotation, wrap_entities),
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
FixedPostUpdate,
|
||||||
|
(integrate_velocity, update_positions, apply_rotation_to_mesh),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +49,24 @@ struct Ship;
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct ThrusterColors(Handle<ColorMaterial>, Handle<ColorMaterial>);
|
struct ThrusterColors(Handle<ColorMaterial>, Handle<ColorMaterial>);
|
||||||
|
|
||||||
|
#[derive(Resource, Debug, Deref, Clone, Copy)]
|
||||||
|
struct Score(i32);
|
||||||
|
|
||||||
|
impl From<Score> for String {
|
||||||
|
fn from(value: Score) -> Self {
|
||||||
|
value.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Debug, Deref, Clone, Copy)]
|
||||||
|
struct Lives(i32);
|
||||||
|
|
||||||
|
impl From<Lives> for String {
|
||||||
|
fn from(value: Lives) -> Self {
|
||||||
|
value.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct WorldSize {
|
struct WorldSize {
|
||||||
width: f32,
|
width: f32,
|
||||||
@@ -187,3 +210,36 @@ fn wrap_entities(mut query: Query<&mut Position>, world_size: Res<WorldSize>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn_ui(mut commands: Commands, score: Res<Score>, lives: Res<Lives>) {
|
||||||
|
commands.spawn(TextBundle::from_sections([
|
||||||
|
TextSection::new(
|
||||||
|
"Score: ",
|
||||||
|
TextStyle {
|
||||||
|
font_size: 25.0,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSection::new(
|
||||||
|
*score,
|
||||||
|
TextStyle {
|
||||||
|
font_size: 25.0,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSection::new(
|
||||||
|
" | Lives: ",
|
||||||
|
TextStyle {
|
||||||
|
font_size: 25.0,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSection::new(
|
||||||
|
*lives,
|
||||||
|
TextStyle {
|
||||||
|
font_size: 25.0,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user