Ahora el jugador SIEMPRE esta mirando en direccion del mouse
This commit is contained in:
1 parent
739a4c8109
commit
d74834f0b6
1 file changed
+45
-14
+45
-14
@@ -1,50 +1,81 @@
|
||||
#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);
|
||||
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user