From d74834f0b614566a4a25397c9ef7b24adcfe2e1e Mon Sep 17 00:00:00 2001 From: TEC-GO Date: Sat, 26 Sep 2026 15:20:37 -0300 Subject: [PATCH] Ahora el jugador SIEMPRE esta mirando en direccion del mouse --- source/Pacman/main.cpp | 59 ++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/source/Pacman/main.cpp b/source/Pacman/main.cpp index ec038b5..c8ef834 100644 --- a/source/Pacman/main.cpp +++ b/source/Pacman/main.cpp @@ -1,50 +1,81 @@ #include "raylib.h" +#include int main() { + // Crear la ventana InitWindow(800, 600, "Attacks for Bombs 1"); + + // Variables del jugador + float x = 400; + float y = 300; + float tamaño = 50; + float velocidad = 5; + + // 60 cuadros por segundo SetTargetFPS(60); - float x = 375.0f; - float y = 275.0f; - float tamano = 50.0f; - float velocidad = 300.0f; - + // Bucle principal del juego while (!WindowShouldClose()) { - float dt = GetFrameTime(); - + // Movimiento hacia arriba if (IsKeyDown(KEY_W)) { - y -= velocidad * dt; + y -= velocidad; } + // Movimiento hacia abajo if (IsKeyDown(KEY_S)) { - y += velocidad * dt; + y += velocidad; } + // Movimiento hacia la izquierda if (IsKeyDown(KEY_A)) { - x -= velocidad * dt; + x -= velocidad; } + // Movimiento hacia la derecha if (IsKeyDown(KEY_D)) { - x += velocidad * dt; + x += velocidad; } + // Obtener la posición del mouse + Vector2 mouse = GetMousePosition(); + + // Calcular el ángulo hacia el mouse + float angulo = + atan2(mouse.y - y, mouse.x - x) * RAD2DEG; + + // Empezar a dibujar BeginDrawing(); + // Fondo blanco ClearBackground(WHITE); - DrawRectangle((int)x, (int)y, (int)tamano, (int)tamano, RED); - - DrawFPS(10, 10); + // Dibujar el cuadrado rojo girado hacia el mouse + DrawRectanglePro( + { + x, + y, + tamaño, + tamaño + }, + { + tamaño / 2, + tamaño / 2 + }, + angulo, + RED + ); + // Terminar de dibujar EndDrawing(); } + // Cerrar la ventana CloseWindow(); return 0;