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
use sevenx_engine::{
    collision::Collider,
    game_object::{Direction, GameObject, ObjectType, PlayerAction},
    input::InputHandler,
    physics::Physics,
    sprite::SpriteSheet,
    world::World,
    Engine, EngineConfig, GameState, KeyCode,
};

struct PhysicsDemo {
    spawn_timer: f32,
}

impl GameState for PhysicsDemo {
    fn new() -> Self {
        PhysicsDemo { spawn_timer: 0.0 }
    }

    fn update(&mut self, dt: f32, input: &InputHandler, world: &mut World) {
        // Controle do jogador com input avançado v0.2.7
        if let Some(player) = world
            .game_objects
            .iter_mut()
            .find(|obj| obj.object_type == ObjectType::Player && obj.active)
        {
            // Velocidade aumentada com Shift (v0.2.7!)
            let speed = if input.is_shift_pressed() { 450.0 } else { 300.0 };
            let jump_force = -500.0;

            // Movimento horizontal usando eixo (v0.2.7!)
            let axis_x = input.get_axis_horizontal();
            
            if axis_x != 0.0 {
                if let Some(physics) = &mut player.physics {
                    physics.velocity.0 = axis_x * speed;
                }
                player.facing_direction = if axis_x < 0.0 { Direction::Left } else { Direction::Right };
                player.current_action = PlayerAction::Walk;
            } else {
                if let Some(physics) = &mut player.physics {
                    physics.velocity.0 = 0.0;
                }
                player.current_action = PlayerAction::Idle;
            }

            // Pulo usando just_pressed (v0.2.7!)
            if input.is_key_just_pressed(KeyCode::Space) {
                if let Some(physics) = &mut player.physics {
                    // Só pula se estiver próximo do chão
                    if player.transform.position.1 >= 500.0 {
                        physics.velocity.1 = jump_force;
                        println!("🦘 Pulo!");
                    }
                }
            }

            // Limita posição no chão
            if player.transform.position.1 > 500.0 {
                player.transform.position.1 = 500.0;
                if let Some(physics) = &mut player.physics {
                    physics.velocity.1 = 0.0;
                }
            }
        }

        // Spawna moedas periodicamente
        self.spawn_timer += dt;
        if self.spawn_timer > 2.0 {
            self.spawn_timer = 0.0;
            self.spawn_coin(world);
        }

        // Remove moedas que caíram fora da tela
        world.game_objects.retain(|obj| {
            if obj.object_type == ObjectType::Coin {
                obj.transform.position.1 < 700.0
            } else {
                true
            }
        });
    }

    fn draw(&mut self, _world: &World, _pixels: &mut [u8]) {
        // Renderização automática
    }
}

impl PhysicsDemo {
    fn spawn_coin(&self, world: &mut World) {
        use rand::Rng;
        let mut rng = rand::thread_rng();
        let x = rng.gen_range(50.0..750.0);

        let mut coin = GameObject::new(x, -50.0, ObjectType::Coin)
            .with_physics(Physics::new().with_gravity(1.0).with_drag(0.1))
            .with_collider(Collider::new(32.0, 32.0).as_trigger())
            .with_z_index(5);

        let coin_sprite = SpriteSheet::create_placeholder();
        coin.sheets.insert(PlayerAction::Idle, coin_sprite);

        world.add_object(coin);
    }
}

fn main() {
    println!("🎮 SevenX Engine v0.2.7 - Physics Demo");
    println!("🎯 Controles:");
    println!("   A/D ou Setas - Mover");
    println!("   Shift - Correr mais rápido");
    println!("   Espaço - Pular");
    println!();

    let config = EngineConfig::new()
        .with_title("SevenX Engine v0.2.7 - Physics Demo")
        .with_size(800, 600)
        .with_gravity(980.0);

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