sevenx_engine 0.2.11

Engine de jogos 2D/3D completa com suporte Android, física, áudio, partículas, tilemap, UI, eventos e sistema 3D avançado com PBR.
Documentation
// Showcase do sistema de input avançado v0.2.7
use sevenx_engine::*;
use sevenx_engine::world::World;
use sevenx_engine::input::InputHandler;

struct InputShowcase {
    player_x: f32,
    player_y: f32,
    zoom: f32,
    info_lines: Vec<String>,
}

impl InputShowcase {
    fn new() -> Self {
        Self {
            player_x: 400.0,
            player_y: 300.0,
            zoom: 1.0,
            info_lines: Vec::new(),
        }
    }
}

impl GameState for InputShowcase {
    fn new() -> Self {
        Self::new()
    }

    fn update(&mut self, dt: f32, input: &InputHandler, _world: &mut World) {
        self.info_lines.clear();

        // Movimento com WASD/Setas
        let (axis_x, axis_y) = input.get_movement_vector();
        let speed = 200.0;
        
        // Velocidade aumentada com Shift
        let speed_multiplier = if input.is_shift_pressed() { 2.0 } else { 1.0 };
        
        self.player_x += axis_x * speed * speed_multiplier * dt;
        self.player_y += axis_y * speed * speed_multiplier * dt;

        // Zoom com scroll do mouse
        let scroll = input.get_mouse_wheel_delta();
        if scroll != 0.0 {
            self.zoom += scroll * 0.1;
            self.zoom = self.zoom.clamp(0.5, 3.0);
            self.info_lines.push(format!("Zoom: {:.1}x", self.zoom));
        }

        // Mouse
        let (mx, my) = input.get_mouse_position();
        self.info_lines.push(format!("Mouse: ({:.0}, {:.0})", mx, my));

        let (dx, dy) = input.get_mouse_delta();
        if dx != 0.0 || dy != 0.0 {
            self.info_lines.push(format!("Mouse Delta: ({:.1}, {:.1})", dx, dy));
        }

        // Botões do mouse
        if input.is_mouse_button_just_pressed(MouseBtn::Left) {
            self.info_lines.push("Left Click!".to_string());
        }
        if input.is_mouse_button_just_pressed(MouseBtn::Right) {
            self.info_lines.push("Right Click!".to_string());
        }
        if input.is_mouse_button_just_pressed(MouseBtn::Middle) {
            self.info_lines.push("Middle Click!".to_string());
        }

        // Atalhos
        if input.is_ctrl_pressed() && input.is_key_just_pressed(KeyCode::KeyS) {
            self.info_lines.push("Ctrl+S - Save!".to_string());
        }
        if input.is_ctrl_pressed() && input.is_key_just_pressed(KeyCode::KeyZ) {
            self.info_lines.push("Ctrl+Z - Undo!".to_string());
        }

        // Teclas pressionadas
        if input.any_key_pressed() {
            let keys = input.get_pressed_keys();
            if !keys.is_empty() {
                self.info_lines.push(format!("Keys: {} pressed", keys.len()));
            }
        }

        // Reset com R
        if input.is_key_just_pressed(KeyCode::KeyR) {
            self.player_x = 400.0;
            self.player_y = 300.0;
            self.zoom = 1.0;
            self.info_lines.push("Reset!".to_string());
        }

        // Informações de movimento
        if axis_x != 0.0 || axis_y != 0.0 {
            self.info_lines.push(format!("Movement: ({:.1}, {:.1})", axis_x, axis_y));
        }

        if input.is_shift_pressed() {
            self.info_lines.push("Shift: Speed Boost!".to_string());
        }
    }

    fn draw(&mut self, _world: &World, pixels: &mut [u8]) {
        // Limpa o buffer
        for pixel in pixels.chunks_exact_mut(4) {
            pixel.copy_from_slice(&[30, 30, 40, 255]);
        }

        let mut prims = Primitives2D::new(pixels, 800, 600);

        // Grade de fundo
        prims.draw_grid(50, [50, 50, 50, 100]);

        // Player (círculo)
        let size = (50.0 * self.zoom) as i32;
        prims.draw_circle_filled(
            self.player_x as i32,
            self.player_y as i32,
            size,
            [100, 200, 255, 255],
        );

        // Direção do movimento
        prims.draw_circle(
            self.player_x as i32,
            self.player_y as i32,
            size + 5,
            [255, 255, 255, 255],
        );

        // UI - Título
        prims.draw_rect_filled(0, 0, 800, 60, [0, 0, 0, 200]);
        
        // UI - Controles
        prims.draw_rect_filled(10, 70, 380, 200, [0, 0, 0, 180]);
        
        // UI - Info em tempo real
        prims.draw_rect_filled(10, 280, 380, 150, [0, 0, 0, 180]);
        
        // Desenha linhas de info
        for (i, line) in self.info_lines.iter().take(5).enumerate() {
            // Texto seria renderizado aqui
            let _ = (i, line);
        }

        // UI - Rodapé
        prims.draw_rect_filled(0, 540, 800, 60, [0, 0, 0, 200]);
    }
}

fn main() {
    println!("🎮 SevenX Engine v0.2.7 - Input Showcase");
    println!();
    println!("Controles:");
    println!("  WASD/Setas - Mover");
    println!("  Shift - Velocidade aumentada");
    println!("  Mouse Wheel - Zoom");
    println!("  Mouse Buttons - Testar cliques");
    println!("  Ctrl+S - Salvar (simulado)");
    println!("  Ctrl+Z - Desfazer (simulado)");
    println!("  R - Reset");
    println!();

    let config = EngineConfig::new()
        .with_title("SevenX - Input Showcase")
        .with_size(800, 600)
        .with_gravity(0.0);

    Engine::with_config(config).run::<InputShowcase>();
}