diff --git a/assets/img/boost.png b/assets/img/boost.png new file mode 100644 index 0000000..3b058e4 Binary files /dev/null and b/assets/img/boost.png differ diff --git a/src/assets.rs b/src/assets.rs index 6759ce5..88ed173 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -34,4 +34,6 @@ pub struct TextureAssets { pub ball: Handle, #[asset(path = "img/block.png")] pub block: Handle, + #[asset(path = "img/boost.png")] + pub boost: Handle, } diff --git a/src/boost.rs b/src/boost.rs new file mode 100644 index 0000000..bdd3eda --- /dev/null +++ b/src/boost.rs @@ -0,0 +1,82 @@ +use crate::{assets::TextureAssets, paddle::Paddle, GameState}; +use bevy::prelude::*; +use bevy_rapier2d::prelude::*; + +pub struct BoostPlugin; + +impl Plugin for BoostPlugin { + fn build(&self, app: &mut App) { + app.add_system_set(SystemSet::on_enter(GameState::Playing).with_system(boost_setup)) + .add_system_set(SystemSet::on_update(GameState::Playing).with_system(boost_movement)); + } +} + +#[derive(Component)] +pub struct Boost { + pub name: String, + pub speed: f32, +} + +#[derive(Bundle)] +pub struct BoostBundle { + boost: Boost, + collider: Collider, + #[bundle] + sprite: SpriteBundle, +} + +impl BoostBundle { + fn new(texture: Handle, boost_size: &Vec2) -> Self { + Self { + boost: Boost { + name: "test".to_string(), + speed: 150., + }, + sprite: SpriteBundle { + texture, + transform: Transform::from_translation(Vec3::new(0., 200., 0.)), + ..default() + }, + collider: Collider::cuboid(boost_size.x / 2., boost_size.y / 2.), + } + } +} + +fn boost_setup(mut commands: Commands, textures: Res, images: Res>) { + let boost_image = images + .get(&textures.boost) + .expect("Boost texture is not loaded"); + + commands.spawn(BoostBundle::new( + textures.boost.clone(), + &boost_image.size(), + )); +} + +fn boost_movement( + mut commands: Commands, + mut boost_query: Query<(&mut Transform, &Boost)>, + time: Res