From 4d69851438952829cf88b059666099646e9cf12f Mon Sep 17 00:00:00 2001 From: senicko Date: Sun, 5 Feb 2023 16:58:47 +0100 Subject: [PATCH 1/3] Create boost plugin --- assets/img/boost.png | Bin 0 -> 1268 bytes src/assets.rs | 2 ++ src/boost.rs | 82 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 5 +-- 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 assets/img/boost.png create mode 100644 src/boost.rs diff --git a/assets/img/boost.png b/assets/img/boost.png new file mode 100644 index 0000000000000000000000000000000000000000..3b058e460ebeb71255c737fd6136d7f276b79ecd GIT binary patch literal 1268 zcmVPx(u1Q2eRCt{2TU%=zM;JY0-E8%z*pmE|M~9L=v>_#=p^%0=goLCGp@o)0AS7<> z-UuxvrA-@hAtdBNahpIwX`lTIvb**l$%CYoWTp?Zvls1cb}qY8;sdfq%V;&{n=|Lk zYGpEhb%5dx#zNHts2ckPsCocZqtpV>?cFjzP6+j~K8SAbf~+n3ulN4jVGY6_B-BPu zn-GE|gwHPuVmbx(UhJUu{t9dV6OgVQUcuhKI}vh3umDL#kRcD0P=LvEM!FC=fj+!V z2$3cal(7UT1wg?53cjU4Uvf~MJYcv0lV^^{go%uLv_!~pS&9}y7DiK`eyqco_zwzD zPZWZWtiB6xuPBevNC9}{%)7lXDK96ewjplg%k?;8w5xd49tQ;N}jCw1deWRt`94P`*t1j*VmM)&N{olI_&M-0(IZg!4k-s&3+*Bcy6~JRE zd4~0<0q`!YpuZ4G3UF`P-dP|JYx>jx0@OdyQwX&bC=_el@{#HO!bt&O@|3A!^30K@ zAguuR4?A<_%2Wd&uLyYsC~a~ytAPe;C<>_p41cqg1{*Czw7<$OQf5g=ErH>$wl?Vo zZ6e&iaUziWc+1ILZh1RO4d6`Vv;lwJV$wyms&#>o!GPaHHp ziW8h{IjDaqZiuDc9CdHmTD)QW*zu!~UySkRBIJP*3*g?28>ehi_+PpJ{%tYY+he5^ z!2LZvHHxaCamt%v3XC7gZ-6+A-y3vq*h2j%(ytMkr#l$kwY7g8&oggW{4ANM3A0Os zasdWEScPM4@$;U_M{0$V2MoTqGOyW}zU=wyeesJPBVPKoXEvl2(Em1&eOjz7T}qzm zG9{h|DFyU5t(c?7X8%$z^{273LLQJ%K!1a8a*(>oS-LzsYdjBy6wv?bWh~R%S9@_a z%n^hOK(}|%-dJU%zwQNv0NAlBK_U9zSy`u=DF`hAzLxpg?XSNC2+-bG^$o4R8DARh zE3>~83Y#F^-bH(J6_m0iLDrVpvGpF>>wya9fjl5kfa%EMgx}&tSPzQ8-r)JdoFMmF zAn7|dzfFPmH>*>}=F0_hJ%B4, #[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..89fbeee --- /dev/null +++ b/src/boost.rs @@ -0,0 +1,82 @@ +use crate::{assets::TextureAssets, paddle::Paddle, GameState}; +use bevy::prelude::*; +use bevy::sprite::collide_aabb::collide; +use bevy_rapier2d::prelude::*; + +// This could be but inside of a boost or a boost type later. +pub const DEFAULT_BOOST_SPEED: f32 = 150.; + +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) + .with_system(boost_picker), + ); + } +} + +#[derive(Component)] +pub struct Boost; + +#[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, + 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 boost_query: Query<&mut Transform, With>, time: Res