use sevenx_engine::{
input::InputHandler,
particles::{BlendMode, ParticleConfig, ParticleSystem},
ui::render_text,
world::World,
Engine, EngineConfig, GameState, KeyCode,
};
struct AdvancedParticles {
fire_system: ParticleSystem,
magic_system: ParticleSystem,
snow_system: ParticleSystem,
current_system: usize,
spawn_timer: f32,
}
impl GameState for AdvancedParticles {
fn new() -> Self {
AdvancedParticles {
fire_system: ParticleSystem::new(500)
.with_blend_mode(BlendMode::Additive)
.with_drag(0.1),
magic_system: ParticleSystem::new(500)
.with_blend_mode(BlendMode::Additive)
.with_drag(0.2),
snow_system: ParticleSystem::new(1000).with_drag(0.05),
current_system: 0,
spawn_timer: 0.0,
}
}
fn update(&mut self, dt: f32, input: &InputHandler, world: &mut World) {
if input.is_key_pressed(KeyCode::Space) {
self.current_system = (self.current_system + 1) % 3;
self.clear_all();
}
self.spawn_timer += dt;
if self.spawn_timer > 0.05 {
self.spawn_timer = 0.0;
self.spawn_particles();
}
self.fire_system.update(dt, 50.0);
self.magic_system.update(dt, -100.0); self.snow_system.update(dt, 100.0);
}
fn draw(&mut self, _world: &World, pixels: &mut [u8]) {
match self.current_system {
0 => self.fire_system.render(pixels, 0.0, 0.0, 800, 600),
1 => self.magic_system.render(pixels, 0.0, 0.0, 800, 600),
2 => self.snow_system.render(pixels, 0.0, 0.0, 800, 600),
_ => {}
}
let system_name = match self.current_system {
0 => "FOGO (Additive Blend)",
1 => "MAGIA (Additive + Gravidade Negativa)",
2 => "NEVE (Normal Blend)",
_ => "Desconhecido",
};
render_text(system_name, 10, 10, [255, 255, 255, 255], pixels, 800);
let count_text = format!(
"PARTICULAS: {}",
match self.current_system {
0 => self.fire_system.count(),
1 => self.magic_system.count(),
2 => self.snow_system.count(),
_ => 0,
}
);
render_text(&count_text, 10, 30, [255, 255, 255, 255], pixels, 800);
render_text(
"SPACE: TROCAR SISTEMA",
250,
550,
[255, 255, 255, 255],
pixels,
800,
);
}
}
impl AdvancedParticles {
fn spawn_particles(&mut self) {
match self.current_system {
0 => {
let config = ParticleConfig::fire();
self.fire_system.emit_stream(400.0, 550.0, 50.0, 0.05, config);
}
1 => {
let config = ParticleConfig::magic();
self.magic_system
.emit_stream(400.0, 300.0, 30.0, 0.05, config);
}
2 => {
use rand::Rng;
let mut rng = rand::thread_rng();
let x = rng.gen_range(0.0..800.0);
let config = ParticleConfig::snow();
self.snow_system.emit_stream(x, 0.0, 10.0, 0.05, config);
}
_ => {}
}
}
fn clear_all(&mut self) {
self.fire_system.clear();
self.magic_system.clear();
self.snow_system.clear();
}
}
fn main() {
println!("✨ Partículas Avançadas");
println!("SPACE - Trocar sistema");
println!("Sistemas:");
println!(" 1. Fogo (Additive Blend)");
println!(" 2. Magia (Additive + Gravidade Negativa)");
println!(" 3. Neve (Normal Blend)");
let config = EngineConfig::new()
.with_title("SevenX Engine - Partículas Avançadas")
.with_size(800, 600)
.with_clear_color(10, 10, 20, 255);
Engine::with_config(config).run::<AdvancedParticles>();
}