use sevenx_engine::{
input::InputHandler,
particles::{ParticleConfig, ParticleSystem},
world::World,
Engine, EngineConfig, GameState, KeyCode,
};
struct ParticlesDemo {
particle_system: ParticleSystem,
spawn_timer: f32,
}
impl GameState for ParticlesDemo {
fn new() -> Self {
ParticlesDemo {
particle_system: ParticleSystem::new(1000),
spawn_timer: 0.0,
}
}
fn update(&mut self, dt: f32, input: &InputHandler, world: &mut World) {
if input.is_key_just_pressed(KeyCode::Space) {
let config = ParticleConfig::explosion();
self.particle_system.emit_burst(400.0, 300.0, 50, config);
println!("💥 Explosão!");
}
if input.is_key_just_pressed(KeyCode::Digit1) {
let config = ParticleConfig::smoke();
self.particle_system.emit_burst(400.0, 300.0, 30, config);
println!("💨 Fumaça!");
}
if input.is_key_just_pressed(KeyCode::Digit2) {
let config = ParticleConfig::sparkle();
self.particle_system.emit_burst(400.0, 300.0, 40, config);
println!("✨ Brilho!");
}
if input.is_key_just_pressed(KeyCode::Digit3) {
let config = ParticleConfig::new([255, 100, 50, 255])
.with_speed(100.0, 200.0)
.with_life(0.5, 1.5)
.with_size(8.0, 12.0);
self.particle_system.emit_burst(400.0, 300.0, 60, config);
println!("🔥 Fogo!");
}
if input.is_key_just_pressed(KeyCode::Digit4) {
let config = ParticleConfig::new([200, 50, 255, 255])
.with_speed(50.0, 150.0)
.with_life(1.0, 2.5);
self.particle_system.emit_burst(400.0, 300.0, 40, config);
println!("🌟 Magia!");
}
if input.is_left_mouse_pressed() {
let (mx, my) = input.get_mouse_position();
let config = ParticleConfig::sparkle();
self.particle_system.emit_burst(mx as f32, my as f32, 5, config);
}
self.spawn_timer += dt;
if self.spawn_timer > 0.1 {
self.spawn_timer = 0.0;
let config = ParticleConfig::new([100, 200, 255, 255])
.with_speed(50.0, 100.0)
.with_life(1.0, 2.0);
self.particle_system.emit_stream(400.0, 550.0, 10.0, dt, config);
}
self.particle_system.update(dt, world.gravity);
}
fn draw(&mut self, _world: &World, pixels: &mut [u8]) {
self.particle_system.render(pixels, 0.0, 0.0, 800, 600);
}
}
fn main() {
println!("🎮 SevenX Engine v0.2.7 - Particles Demo");
println!("💫 Sistema de Partículas 2D Avançado");
println!();
println!("🎆 Controles:");
println!(" SPACE - Explosão");
println!(" 1 - Fumaça");
println!(" 2 - Brilho");
println!(" 3 - Fogo");
println!(" 4 - Magia");
println!(" Mouse (Clique) - Partículas no cursor");
println!();
let config = EngineConfig::new()
.with_title("SevenX Engine v0.2.7 - Particles Demo")
.with_size(800, 600)
.with_gravity(200.0)
.with_clear_color(20, 20, 40, 255);
Engine::with_config(config).run::<ParticlesDemo>();
}