82 lines
1.6 KiB
C++
82 lines
1.6 KiB
C++
#include "raylib.h"
|
|
#include <cmath>
|
|
|
|
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);
|
|
|
|
// Bucle principal del juego
|
|
while (!WindowShouldClose())
|
|
{
|
|
// Movimiento hacia arriba
|
|
if (IsKeyDown(KEY_W))
|
|
{
|
|
y -= velocidad;
|
|
}
|
|
|
|
// Movimiento hacia abajo
|
|
if (IsKeyDown(KEY_S))
|
|
{
|
|
y += velocidad;
|
|
}
|
|
|
|
// Movimiento hacia la izquierda
|
|
if (IsKeyDown(KEY_A))
|
|
{
|
|
x -= velocidad;
|
|
}
|
|
|
|
// Movimiento hacia la derecha
|
|
if (IsKeyDown(KEY_D))
|
|
{
|
|
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);
|
|
|
|
// 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;
|
|
} |