117 lines
2.4 KiB
C++
117 lines
2.4 KiB
C++
#include "raylib.h"
|
|
#include <cmath>
|
|
|
|
int main()
|
|
{
|
|
// Tamaño de la ventana
|
|
const int pantallaAncho = 800;
|
|
const int pantallaAlto = 600;
|
|
|
|
// Crear ventana
|
|
InitWindow(
|
|
pantallaAncho,
|
|
pantallaAlto,
|
|
"Attacks for Bombs 1"
|
|
);
|
|
|
|
// Limitar a 60 FPS
|
|
SetTargetFPS(60);
|
|
|
|
// Posición del jugador
|
|
float x = 400.0f;
|
|
float y = 300.0f;
|
|
|
|
// Tamaño del jugador
|
|
float tamaño = 50.0f;
|
|
|
|
// Velocidad del jugador
|
|
float velocidad = 300.0f;
|
|
|
|
while (!WindowShouldClose())
|
|
{
|
|
// Tiempo que pasó desde el frame anterior
|
|
float deltaTime = GetFrameTime();
|
|
|
|
// Posición del mouse
|
|
Vector2 mouse = GetMousePosition();
|
|
|
|
// Dirección hacia el mouse
|
|
float angulo =
|
|
atan2(mouse.y - y, mouse.x - x);
|
|
|
|
float direccionX = cos(angulo);
|
|
float direccionY = sin(angulo);
|
|
|
|
// Movimiento hacia adelante
|
|
if (IsKeyDown(KEY_W))
|
|
{
|
|
x += direccionX * velocidad * deltaTime;
|
|
y += direccionY * velocidad * deltaTime;
|
|
}
|
|
|
|
// Movimiento hacia atrás
|
|
if (IsKeyDown(KEY_S))
|
|
{
|
|
x -= direccionX * velocidad * deltaTime;
|
|
y -= direccionY * velocidad * deltaTime;
|
|
}
|
|
|
|
// Movimiento hacia la izquierda
|
|
if (IsKeyDown(KEY_A))
|
|
{
|
|
x += direccionY * velocidad * deltaTime;
|
|
y -= direccionX * velocidad * deltaTime;
|
|
}
|
|
|
|
// Movimiento hacia la derecha
|
|
if (IsKeyDown(KEY_D))
|
|
{
|
|
x -= direccionY * velocidad * deltaTime;
|
|
y += direccionX * velocidad * deltaTime;
|
|
}
|
|
|
|
// Límites de la pantalla
|
|
float mitad = tamaño / 2.0f;
|
|
|
|
if (x < mitad)
|
|
x = mitad;
|
|
|
|
if (x > pantallaAncho - mitad)
|
|
x = pantallaAncho - mitad;
|
|
|
|
if (y < mitad)
|
|
y = mitad;
|
|
|
|
if (y > pantallaAlto - mitad)
|
|
y = pantallaAlto - mitad;
|
|
|
|
// Dibujar
|
|
BeginDrawing();
|
|
|
|
// Fondo blanco
|
|
ClearBackground(WHITE);
|
|
|
|
// Dibujar jugador
|
|
DrawRectanglePro(
|
|
{
|
|
x,
|
|
y,
|
|
tamaño,
|
|
tamaño
|
|
},
|
|
{
|
|
mitad,
|
|
mitad
|
|
},
|
|
angulo * RAD2DEG,
|
|
RED
|
|
);
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
// Cerrar ventana
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
} |