Skip to main content

demo/
demo.rs

1//! Ejemplo de rydit-gfx
2//! Rust = Arquitecto, Raylib = Pincel
3
4use ry_gfx::{ColorRydit, Key, RyditGfx};
5
6fn main() {
7    println!("=== RYDIT-GFX v0.1.0 ===");
8    println!("Rust = Arquitecto, Raylib = Pincel\n");
9
10    // Crear ventana (Rust controla)
11    let mut gfx = RyditGfx::new("RyDit v0.0.7 - rydit-gfx", 800, 600);
12    gfx.set_target_fps(60);
13
14    println!("[RUST] Ventana creada, iniciando game loop...\n");
15
16    // Game loop controlado por Rust
17    let mut frame = 0;
18    while !gfx.should_close() {
19        frame += 1;
20
21        // Rust decide input PRIMERO (antes de dibujar)
22        let escape_pressed = gfx.is_key_pressed(Key::Escape);
23
24        // Iniciar dibujo (toma &mut self, no podemos usar gfx después)
25        {
26            let mut d = gfx.begin_draw();
27
28            // Limpiar pantalla
29            d.clear(ColorRydit::Negro);
30
31            // Dibujar círculo rojo en el centro (animado)
32            let radius = 50 + (frame % 20);
33            d.draw_circle(400, 300, radius, ColorRydit::Rojo);
34
35            // Dibujar rectángulo verde
36            d.draw_rectangle(100, 100, 100, 100, ColorRydit::Verde);
37
38            // Dibujar línea azul
39            d.draw_line(0, 0, 800, 600, ColorRydit::Azul);
40
41            // Dibujar texto
42            d.draw_text(
43                "RyDit v0.0.7 - rydit-gfx",
44                250,
45                50,
46                20,
47                ColorRydit::Amarillo,
48            );
49            d.draw_text(
50                "Rust = Arquitecto, Raylib = Pincel",
51                220,
52                80,
53                16,
54                ColorRydit::Blanco,
55            );
56            d.draw_text("Presiona ESC para salir", 280, 550, 16, ColorRydit::Blanco);
57
58            // d se va de scope aquí, finaliza dibujo
59        }
60
61        // Rust decide después de dibujar
62        if escape_pressed {
63            println!("\n[RUST] Decidiendo cerrar en frame {}...", frame);
64            break;
65        }
66    }
67
68    println!("\n[RUST] Juego terminado. ¡Éxito!");
69}