Estoy estudiando y practicando otras formas de desarrollar videojuegos; aprovechando la enorme ayuda de la IA y con mi tremenda curiosidad de estos temas.....boi a contar algunos logros que estoy consiguiendo con programacion en c++,
Pongo un video de algun trasteo que estoy haciendo.
// Parche definitivo de compatibilidad para MinGW
extern "C" {
int stat64(const char *path, void *buffer) { return 0; }
int stat6432(const char *path, void *buffer) { return 0; }
int stat64i32(const char *path, void *buffer) { return 0; }
int _stat64(const char *path, void *buffer) { return 0; }
}
#include "raylib.h"
#include <stdio.h>
int main() {
// 1. Inicializamos la ventana
const int ancho = 1500;
const int alto = 700;
InitWindow(ancho, alto, "Control de Velocidades con Sliders y Teclado");
// 2. Configuramos la cámara 3D
Camera3D camera = { 0 };
camera.position = (Vector3){ 0.0f, 6.0f, 12.0f };
camera.target = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE;
// Posiciones iniciales
Vector3 posicionCubo = { -3.0f, 1.0f, 0.0f };
Vector3 posicionAra = { 3.0f, 0.0f, 0.0f };
// --- VARIABLES DE VELOCIDAD (Sliders ajustables) ---
float velocidadTrasladoCubo = 4.0f;
float velocidadTrasladoAra = 4.0f;
float velocidadAnimacionAra = 1.0f;
// Acumulador flotante para la animación de la ara
float frameAnimacionFloat = 0.0f;
// --- 3. CARGAR EL MODELO "ara.glb" Y SUS ANIMACIONES ---
Model modeloAra = LoadModel("ara.glb");
int animsCount = 0;
ModelAnimation *animaciones = LoadModelAnimations("ara.glb", &animsCount);
SetTargetFPS(60);
// 4. Bucle principal del juego
while (!WindowShouldClose()) {
float deltaTime = GetFrameTime();
// --- GESTIÓN DE SLIDER / CAMBIO DE VELOCIDADES CON TECLADO ---
if (IsKeyPressed(KEY_UP)) velocidadTrasladoAra += 0.5f;
if (IsKeyPressed(KEY_DOWN)) velocidadTrasladoAra -= 0.5f;
if (IsKeyPressed(KEY_RIGHT)) velocidadTrasladoCubo += 0.5f;
if (IsKeyPressed(KEY_LEFT)) velocidadTrasladoCubo -= 0.5f;
// Límites lógicos
if (velocidadTrasladoAra < 0.5f) velocidadTrasladoAra = 0.5f;
if (velocidadTrasladoCubo < 0.5f) velocidadTrasladoCubo = 0.5f;
// Control con ratón para los Sliders visuales en pantalla
Vector2 mousePos = GetMousePosition();
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
if (mousePos.x >= 20 && mousePos.x <= 220 && mousePos.y >= 540 && mousePos.y <= 560) {
velocidadTrasladoAra = ((mousePos.x - 20) / 200.0f) * 10.0f;
}
if (mousePos.x >= 340 && mousePos.x <= 540 && mousePos.y >= 540 && mousePos.y <= 560) {
velocidadAnimacionAra = ((mousePos.x - 340) / 200.0f) * 4.0f;
}
if (mousePos.x >= 660 && mousePos.x <= 860 && mousePos.y >= 540 && mousePos.y <= 560) {
velocidadTrasladoCubo = ((mousePos.x - 660) / 200.0f) * 10.0f;
}
}
// --- GESTIÓN DE ENTRADAS: Cubo con WASD ---
if (IsKeyDown(KEY_W)) posicionCubo.z -= velocidadTrasladoCubo * deltaTime;
if (IsKeyDown(KEY_S)) posicionCubo.z += velocidadTrasladoCubo * deltaTime;
if (IsKeyDown(KEY_A)) posicionCubo.x -= velocidadTrasladoCubo * deltaTime;
if (IsKeyDown(KEY_D)) posicionCubo.x += velocidadTrasladoCubo * deltaTime;
// --- GESTIÓN DE ENTRADAS Y ANIMACIÓN: Ara.glb con U-H-J-K ---
bool estaMoviendoAra = false;
if (IsKeyDown(KEY_U)) { posicionAra.z -= velocidadTrasladoAra * deltaTime; estaMoviendoAra = true; }
if (IsKeyDown(KEY_J)) { posicionAra.z += velocidadTrasladoAra * deltaTime; estaMoviendoAra = true; }
if (IsKeyDown(KEY_H)) { posicionAra.x -= velocidadTrasladoAra * deltaTime; estaMoviendoAra = true; }
if (IsKeyDown(KEY_K)) { posicionAra.x += velocidadTrasladoAra * deltaTime; estaMoviendoAra = true; }
// Si se está moviendo, avanzamos la animación de forma fluida
if (animsCount > 0) {
if (estaMoviendoAra) {
frameAnimacionFloat += 150.0f * velocidadAnimacionAra * deltaTime;
// Bucle estándar de seguridad (asumiendo 60 frames por ciclo de animación)
if (frameAnimacionFloat >= 60.0f) {
frameAnimacionFloat = 0.0f;
}
}
// Actualizamos el modelo sin depender de propiedades privadas de la estructura
UpdateModelAnimation(modeloAra, animaciones[0], (int)frameAnimacionFloat);
}
// --- DIBUJO ---
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
// Dibujamos el cubo azul
DrawCube(posicionCubo, 2.0f, 2.0f, 2.0f, BLUE);
DrawCubeWires(posicionCubo, 2.0f, 2.0f, 2.0f, DARKGRAY);
// Dibujamos ara.glb
DrawModelEx(modeloAra, posicionAra, (Vector3){ 0.0f, 1.0f, 0.0f }, 0.0f, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE);
// Rejilla de suelo
DrawGrid(10, 1.0f);
EndMode3D();
// --- INTERFAZ / SLIDERS VISUALES EN 2D ---
DrawRectangle(0, 500, ancho, 150, LIGHTGRAY);
DrawRectangleLines(0, 500, ancho, 150, DARKGRAY);
DrawText("PANEL DE CONTROL DE VELOCIDADES (Haz clic en las barras o usa Flechas/WASD)", 20, 510, 15, DARKGRAY);
// 1. Slider Velocidad Traslado Ara
DrawText(TextFormat("Vel. Traslado Ara: %.1f", velocidadTrasladoAra), 20, 535, 10, DARKGRAY);
DrawRectangle(20, 550, 200, 10, WHITE);
DrawRectangle(20, 550, (int)((velocidadTrasladoAra / 10.0f) * 200), 10, RED);
// 2. Slider Velocidad Animación Ara
DrawText(TextFormat("Vel. Animacion Ara: %.1f", velocidadAnimacionAra), 340, 535, 10, DARKGRAY);
DrawRectangle(340, 550, 200, 10, WHITE);
DrawRectangle(340, 550, (int)((velocidadAnimacionAra / 4.0f) * 200), 10, GREEN);
// 3. Slider Velocidad Traslado Cubo
DrawText(TextFormat("Vel. Traslado Cubo: %.1f", velocidadTrasladoCubo), 660, 535, 10, DARKGRAY);
DrawRectangle(660, 550, 200, 10, WHITE);
DrawRectangle(660, 550, (int)((velocidadTrasladoCubo / 10.0f) * 200), 10, BLUE);
// Instrucciones en texto
DrawText("Cubo: W-A-S-D | Ara: U-H-J-K", 20, 580, 12, DARKGRAY);
EndDrawing();
}
// --- DESCARGAR RECURSOS DE LA MEMORIA AL SALIR ---
if (animsCount > 0) {
UnloadModelAnimations(animaciones, animsCount);
}
UnloadModel(modeloAra);
CloseWindow();
return 0;
}