feat: Implement background shader and visual effects
- Added a new WGSL shader for background rendering with volumetric fog effects. - Created components for game entities including Circle, Velocity, Explosion, and ChainReaction. - Introduced game state management with GameState enum and LevelState resource. - Implemented event system for explosion requests and circle destruction notifications. - Developed plugins for game logic, input handling, movement, reactions, scoring, and UI. - Configured game settings through GameConfig resource with adjustable parameters. - Enhanced UI with configuration options and game over screens. - Integrated spatial grid for efficient collision detection and explosion handling.
This commit is contained in:
127
src/components.rs
Normal file
127
src/components.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
use bevy::{platform::collections::HashMap, prelude::*};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Circle {
|
||||
pub radius: f32,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(pub Vec2);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Explosion {
|
||||
pub timer: Timer,
|
||||
pub radius: f32,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct ChainReaction {
|
||||
pub delay: Timer,
|
||||
pub next_radius: f32,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Score {
|
||||
pub total: u32,
|
||||
pub multiplier: u32,
|
||||
pub combo_timer: Timer,
|
||||
}
|
||||
|
||||
#[derive(States, Default, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum GameState {
|
||||
#[default]
|
||||
Menu,
|
||||
Playing,
|
||||
GameOver,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct SpatialGrid {
|
||||
pub cells: HashMap<IVec2, Vec<Entity>>,
|
||||
pub cell_size: f32,
|
||||
}
|
||||
|
||||
impl SpatialGrid {
|
||||
pub fn pos_to_cell(&self, pos: Vec2) -> IVec2 {
|
||||
IVec2::new(
|
||||
(pos.x / self.cell_size).floor() as i32,
|
||||
(pos.y / self.cell_size).floor() as i32,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.cells.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct MainCamera;
|
||||
|
||||
#[derive(Resource, Clone, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
pub struct GameConfig {
|
||||
pub circle_count_min: u32,
|
||||
pub circle_count_max: u32,
|
||||
pub circle_radius_min: f32,
|
||||
pub circle_radius_max: f32,
|
||||
pub max_velocity: f32,
|
||||
|
||||
pub explosion_radius: f32,
|
||||
pub explosion_duration: f32,
|
||||
pub chain_reaction_delay: f32,
|
||||
pub secondary_explosion_factor: f32,
|
||||
|
||||
pub base_score: u32,
|
||||
pub combo_window: f32,
|
||||
|
||||
pub cell_size: f32,
|
||||
pub manual_explosion_limit: u32,
|
||||
}
|
||||
|
||||
impl Default for GameConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
circle_count_min: 1000,
|
||||
circle_count_max: 5000,
|
||||
circle_radius_min: 10.0,
|
||||
circle_radius_max: 50.0,
|
||||
max_velocity: 1000.0,
|
||||
explosion_radius: 100.0,
|
||||
explosion_duration: 0.5,
|
||||
chain_reaction_delay: 0.1,
|
||||
secondary_explosion_factor: 0.5,
|
||||
base_score: 10,
|
||||
combo_window: 0.5,
|
||||
cell_size: 100.0,
|
||||
manual_explosion_limit: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum LevelStatus {
|
||||
#[default]
|
||||
Playing,
|
||||
Victory,
|
||||
Defeat(usize),
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct LevelState {
|
||||
pub explosions_left: u32,
|
||||
pub settle_timer: Timer,
|
||||
pub status: LevelStatus,
|
||||
}
|
||||
|
||||
impl Default for LevelState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
explosions_left: 1,
|
||||
settle_timer: Timer::from_seconds(1.25, TimerMode::Once),
|
||||
status: LevelStatus::Playing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct GameEntity;
|
||||
Reference in New Issue
Block a user