use sevenx_engine::*;
use sevenx_engine::world::World;
struct LightingDemo {
lighting: LightingSystem,
player_pos: (f32, f32),
torch_light: usize,
}
impl GameState for LightingDemo {
fn new() -> Self {
let mut lighting = LightingSystem::new();
lighting.set_ambient(30, 30, 50, 0.3);
let torch = Light::point(400.0, 300.0, 200.0)
.with_color(255, 200, 100)
.with_intensity(1.0);
let torch_light = lighting.add_light(torch);
lighting.add_light(
Light::point(100.0, 100.0, 150.0)
.with_color(100, 100, 255)
.with_intensity(0.8),
);
lighting.add_light(
Light::spot(700.0, 500.0, 180.0, 30.0, 250.0)
.with_color(255, 50, 50)
.with_intensity(1.0),
);
Self {
lighting,
player_pos: (400.0, 300.0),
torch_light,
}
}
fn update(&mut self, dt: f32, input: &sevenx_engine::input::InputHandler, _world: &mut World) {
let (move_x, move_y) = input.get_movement_vector();
let speed = if input.is_shift_pressed() { 400.0 } else { 200.0 };
self.player_pos.0 += move_x * speed * dt;
self.player_pos.1 += move_y * speed * dt;
self.lighting.lights[self.torch_light].position = self.player_pos;
let scroll = input.get_mouse_wheel_delta();
if scroll != 0.0 {
let current_intensity = self.lighting.lights[self.torch_light].intensity;
self.lighting.lights[self.torch_light].intensity = (current_intensity + scroll * 0.1).clamp(0.1, 2.0);
println!("💡 Intensidade da tocha: {:.1}", self.lighting.lights[self.torch_light].intensity);
}
}
fn draw(&mut self, _world: &World, frame: &mut [u8]) {
let width = 800;
let height = 600;
for y in 0..height {
for x in 0..width {
let idx = ((y * width + x) * 4) as usize;
let tile_size = 50;
let is_dark = ((x / tile_size) + (y / tile_size)) % 2 == 0;
let base_color = if is_dark {
[80, 80, 80, 255]
} else {
[120, 120, 120, 255]
};
let lit_color = self.lighting.apply_lighting(x as f32, y as f32, base_color);
frame[idx] = lit_color[0];
frame[idx + 1] = lit_color[1];
frame[idx + 2] = lit_color[2];
frame[idx + 3] = lit_color[3];
}
}
let px = self.player_pos.0 as i32;
let py = self.player_pos.1 as i32;
for dy in -5..=5 {
for dx in -5..=5 {
let x = px + dx;
let y = py + dy;
if x >= 0 && x < width as i32 && y >= 0 && y < height as i32 {
let idx = ((y * width as i32 + x) * 4) as usize;
frame[idx] = 255;
frame[idx + 1] = 255;
frame[idx + 2] = 0;
frame[idx + 3] = 255;
}
}
}
}
}
fn main() {
println!("🎮 SevenX Engine v0.2.7 - Lighting Demo");
println!("💡 Sistema de Iluminação 2D Avançado");
println!();
println!("🎯 Controles:");
println!(" WASD/Setas - Mover");
println!(" Shift - Correr (v0.2.7!)");
println!(" Scroll - Ajustar intensidade da tocha (v0.2.7!)");
println!();
let config = EngineConfig::default()
.with_title("SevenX Engine v0.2.7 - Lighting Demo")
.with_size(800, 600);
let engine = Engine::with_config(config);
engine.run::<LightingDemo>();
}