Skip to content

Commit

Permalink
Initial attempt at a speedometer.
Browse files Browse the repository at this point in the history
This is really pretty hacky and needs to be refactored into a bundle.
However let's checkpoint at this point because it does, in fact, work!
  • Loading branch information
daniel-thompson committed Jan 16, 2024
1 parent 9e49764 commit bbadc4b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ impl bevy::prelude::Plugin for Plugin {
embedded_asset!(app, p, "level1.tmx");
embedded_asset!(app, p, "level2.tmx");

embedded_asset!(app, p, "speeddial.png");
embedded_asset!(app, p, "speedneedle.png");

embedded_asset!(app, p, "kenney_racing-pack/PNG/Cars/car_red_5.png");
embedded_asset!(app, p, "kenney_racing-pack/PNG/Cars/car_blue_1.png");
embedded_asset!(app, p, "kenney_racing-pack/PNG/Cars/car_yellow_3.png");
Expand Down
Binary file added src/assets/speeddial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/speedneedle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 58 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ fn main() {
#[derive(Component, Debug)]
struct Player;

#[derive(Component, Debug)]
struct Speedometer;

#[derive(Component, Debug)]
struct SpeedoNeedle;

#[derive(Component, Debug, Default)]
struct Racer {
penalty: f32,
Expand Down Expand Up @@ -270,6 +276,36 @@ fn spawn_player(
..default()
},
));

let handle = asset_server.load("embedded://tdr2024/assets/speeddial.png");
let atlas = TextureAtlas::from_grid(handle, Vec2::new(196., 196.), 1, 1, None, None);
commands.spawn((
Speedometer,
SpriteSheetBundle {
texture_atlas: texture_atlas.add(atlas),
transform: Transform {
translation: Vec3::new(0.0, -200.0, 3.0),
scale: Vec3::splat(1.),
..default()
},
..default()
},
));

let handle = asset_server.load("embedded://tdr2024/assets/speedneedle.png");
let atlas = TextureAtlas::from_grid(handle, Vec2::new(196., 196.), 1, 1, None, None);
commands.spawn((
SpeedoNeedle,
SpriteSheetBundle {
texture_atlas: texture_atlas.add(atlas),
transform: Transform {
translation: Vec3::new(0.0, -200.0, 4.0),
scale: Vec3::splat(1.),
..default()
},
..default()
},
));
}

fn spawn_ai_players(
Expand Down Expand Up @@ -628,10 +664,30 @@ fn handle_ai_players(
}

fn track_player(
player: Query<(&Transform, With<Player>)>,
player: Query<(&Transform, &Velocity, With<Player>)>,
mut speedo: Query<(
&mut Transform,
With<Speedometer>,
Without<SpeedoNeedle>,
Without<Camera>,
Without<Player>,
)>,
mut needle: Query<(
&mut Transform,
With<SpeedoNeedle>,
Without<Speedometer>,
Without<Camera>,
Without<Player>,
)>,
mut camera: Query<(&mut Transform, With<Camera>, Without<Player>)>,
) {
let (txp, _) = player.single();
let (txp, v, _) = player.single();
let (mut speedo, _, _, _, _) = speedo.single_mut();
let (mut needle, _, _, _, _) = needle.single_mut();

speedo.translation = txp.translation + vec3(-800.0, -400.0, 3.0);
needle.translation = txp.translation + vec3(-800.0, -400.0, 4.0);
needle.rotation = Quat::from_rotation_z(v.0.length() / -100.0);

for (mut txc, _, _) in camera.iter_mut() {
txc.translation.x = txp.translation.x;
Expand Down

0 comments on commit bbadc4b

Please sign in to comment.