waves
All checks were successful
Build Bevy Game (Linux + Windows) / build-windows (push) Successful in 18m50s
Build Bevy Game (Linux + Windows) / build-linux (push) Successful in 18m38s

This commit is contained in:
Crizomb 2026-01-04 00:25:35 +01:00
parent 751d8097d2
commit 4b9101ad2c
7 changed files with 143 additions and 29 deletions

97
src/core/wave.rs Normal file
View file

@ -0,0 +1,97 @@
use std::thread::panicking;
use bevy::prelude::*;
use rand::distr::slice::Empty;
use crate::{
core::bubble::{Bubble, bubble_spawn_wave},
map::map::{BOTTOM, LEFT, RIGHT, TOP},
};
pub struct BubbleType {
pub color: Color,
pub move_force: f32,
pub max_life: f32,
}
pub struct BubbleSplash {
pub bubble_type: BubbleType,
pub center: Vec2,
pub radius: f32,
pub nb_bubbles: u32,
}
impl BubbleSplash {
fn new(bubble_type: BubbleType, center: Vec2, radius: f32, nb_bubbles: u32) -> Self {
BubbleSplash { bubble_type, center, radius, nb_bubbles }
}
}
const BASE_MOVE_FORCE: f32 = 3000.0;
const BASE_LIFE: f32 = 10.0;
const NORMAL_BUBBLE: BubbleType = BubbleType {
color: Color::linear_rgb(1.0, 1.0, 1.0),
move_force: BASE_MOVE_FORCE * 1.0,
max_life: BASE_LIFE * 1.0,
};
const RED_BUBBLE: BubbleType = BubbleType {
color: Color::linear_rgb(1.0, 0.0, 0.0),
move_force: BASE_MOVE_FORCE * 2.0,
max_life: BASE_LIFE * 0.5,
};
const GREEN_BUBBLE: BubbleType = BubbleType {
color: Color::linear_rgb(1.0, 0.0, 0.0),
move_force: BASE_MOVE_FORCE * 0.5,
max_life: BASE_LIFE * 2.0,
};
#[derive(Resource)]
pub struct BubbleWaves {
pub waves: Vec<Vec<BubbleSplash>>,
pub current_wave: usize,
}
fn get_bubble_waves() -> BubbleWaves {
BubbleWaves {
waves: vec![
vec![BubbleSplash::new(NORMAL_BUBBLE, RIGHT, 10.0, 10)],
vec![BubbleSplash::new(NORMAL_BUBBLE, RIGHT, 10.0, 10), BubbleSplash::new(NORMAL_BUBBLE, TOP, 10.0, 10)],
vec![BubbleSplash::new(NORMAL_BUBBLE, RIGHT, 10.0, 100), BubbleSplash::new(NORMAL_BUBBLE, TOP, 10.0, 100)],
vec![
BubbleSplash::new(NORMAL_BUBBLE, RIGHT, 10.0, 100),
BubbleSplash::new(NORMAL_BUBBLE, TOP, 10.0, 100),
BubbleSplash::new(RED_BUBBLE, BOTTOM, 10.0, 20),
],
vec![
BubbleSplash::new(NORMAL_BUBBLE, RIGHT, 10.0, 200),
BubbleSplash::new(RED_BUBBLE, RIGHT, 10.0, 100),
BubbleSplash::new(RED_BUBBLE, LEFT, 10.0, 100),
],
],
current_wave: 0,
}
}
fn no_ennemy_left(bubble_query: Query<(), With<Bubble>>) -> bool {
bubble_query.is_empty()
}
fn change_wave(mut bubble_wave: ResMut<BubbleWaves>, mut commands: Commands, asset_server: Res<AssetServer>) {
let max_bubble_wave = bubble_wave.waves.len();
bubble_wave.current_wave += 1;
if bubble_wave.current_wave >= max_bubble_wave {
panic!("GG you win");
}
bubble_spawn_wave(&mut commands, &asset_server, bubble_wave.waves[bubble_wave.current_wave].as_slice());
}
pub struct WavePlugin;
impl Plugin for WavePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(get_bubble_waves()).add_systems(Update, change_wave.run_if(no_ennemy_left));
}
}