Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/boosts #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/img/boost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ pub struct TextureAssets {
pub ball: Handle<Image>,
#[asset(path = "img/block.png")]
pub block: Handle<Image>,
#[asset(path = "img/boost.png")]
pub boost: Handle<Image>,
}
82 changes: 82 additions & 0 deletions src/boost.rs
Original file line number Diff line number Diff line change
@@ -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<Image>, 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<TextureAssets>, images: Res<Assets<Image>>) {
let boost_image = images
.get(&textures.boost)
.expect("Boost texture is not loaded");

commands.spawn(BoostBundle::new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boosty mają się spawnić losowo po zniszczeniu bloczka

textures.boost.clone(),
&boost_image.size(),
));
}

fn boost_movement(
mut commands: Commands,
mut boost_query: Query<(&mut Transform, &Boost)>,
time: Res<Time>,
paddle_query: Query<(&Collider, &Transform), (With<Paddle>, Without<Boost>)>,
rapier_context: Res<RapierContext>,
) {
// Check for boost collision
let (paddle_collider, paddle_transform) = paddle_query.single();

if let Some((entity, _)) = rapier_context.cast_shape(
paddle_transform.translation.truncate(),
0.,
Vec2::new(0., -1.),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

castuj do miejsca w którym potem znajdzie się boost. proponuje dodać zmienną movement_vector o którą będziesz jednocześnie castował i poruszał boosta, tak jak to robimy w ball.rs

paddle_collider,
1.,
QueryFilter::default().predicate(&|entity| boost_query.get(entity).is_ok()),
) {
// TODO: apply boost effect or sth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zrób to od razu w tym PR. możesz tu wywoływać event, który będzie potem łapać paletka.

commands.entity(entity).despawn_recursive();
}

// Free fall
for (mut transform, boost) in boost_query.iter_mut() {
transform.translation.y -= time.delta_seconds() * boost.speed;
}
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use block::BlockPlugin;

mod actions;
mod assets;
mod ball;
mod block;
mod boost;
mod camera;
mod cursor;
mod menu;
Expand Down Expand Up @@ -43,7 +43,8 @@ impl Plugin for ArkanoidPlugin {
.add_plugin(paddle::PaddlePlugin)
.add_plugin(ball::BallPlugin)
.add_plugin(menu::MenuPlugin)
.add_plugin(BlockPlugin)
.add_plugin(block::BlockPlugin)
.add_plugin(boost::BoostPlugin)
.add_state(GameState::Loading);
}
}