From 6d226242b44efdb4368d6cf1b53e26dbac58a253 Mon Sep 17 00:00:00 2001 From: TEC-GO Date: Sat, 26 Sep 2026 17:29:09 -0300 Subject: [PATCH] A4B1 Relase 0.0.1 --- source/A4B1/main.cpp | 1227 +++++++++++++++++++++++++++++++++--------- 1 file changed, 975 insertions(+), 252 deletions(-) diff --git a/source/A4B1/main.cpp b/source/A4B1/main.cpp index 9a6da0d..1ff80e3 100644 --- a/source/A4B1/main.cpp +++ b/source/A4B1/main.cpp @@ -8,6 +8,14 @@ struct Bala Vector2 posicion; Vector2 direccion; float velocidad; + int equipo; + int rebotes; + bool activa; +}; + +struct Municion +{ + Vector2 posicion; bool activa; }; @@ -15,7 +23,15 @@ struct Entidad { Vector2 posicion; Vector2 velocidad; + Vector2 direccion; float radio; + float vida; + float vidaMaxima; + int equipo; + bool jugador; + bool viva; + int municion; + float tiempoDisparo; }; struct Pared @@ -25,11 +41,19 @@ struct Pared const float MUNDO_ANCHO = 1000.0f; const float MUNDO_ALTO = 650.0f; - const float BORDE = 35.0f; + const float RADIO_JUGADOR = 18.0f; const float RADIO_ENEMIGO = 20.0f; +const float VELOCIDAD_JUGADOR = 300.0f; +const float VELOCIDAD_IA = 175.0f; + +const float VELOCIDAD_BALA = 720.0f; +const float DAÑO_BALA = 25.0f; + +const float RADIO_VISION = 235.0f; + float Limitar(float valor, float minimo, float maximo) { if (valor < minimo) @@ -62,7 +86,19 @@ float Distancia(Vector2 a, Vector2 b) return sqrtf(x * x + y * y); } -bool CirculoRectangulo(Vector2 centro, float radio, Rectangle rect) +bool CirculoCirculo( + Vector2 a, + float radioA, + Vector2 b, + float radioB) +{ + return Distancia(a, b) < radioA + radioB; +} + +bool CirculoRectangulo( + Vector2 centro, + float radio, + Rectangle rect) { float puntoX = Limitar( centro.x, @@ -82,23 +118,6 @@ bool CirculoRectangulo(Vector2 centro, float radio, Rectangle rect) return dx * dx + dy * dy < radio * radio; } -void DibujarBorde(float escalaX, float escalaY) -{ - Rectangle borde = { - BORDE * escalaX, - BORDE * escalaY, - (MUNDO_ANCHO - BORDE * 2.0f) * escalaX, - (MUNDO_ALTO - BORDE * 2.0f) * escalaY - }; - - DrawRectangleRoundedLines( - borde, - 0.08f, - 16, - WHITE - ); -} - void RebotarBorde(Entidad& entidad) { float izquierda = BORDE + entidad.radio; @@ -109,37 +128,31 @@ void RebotarBorde(Entidad& entidad) if (entidad.posicion.x < izquierda) { entidad.posicion.x = izquierda; - - if (entidad.velocidad.x < 0.0f) - entidad.velocidad.x *= -1.0f; + entidad.velocidad.x = fabsf(entidad.velocidad.x); } if (entidad.posicion.x > derecha) { entidad.posicion.x = derecha; - - if (entidad.velocidad.x > 0.0f) - entidad.velocidad.x *= -1.0f; + entidad.velocidad.x = -fabsf(entidad.velocidad.x); } if (entidad.posicion.y < arriba) { entidad.posicion.y = arriba; - - if (entidad.velocidad.y < 0.0f) - entidad.velocidad.y *= -1.0f; + entidad.velocidad.y = fabsf(entidad.velocidad.y); } if (entidad.posicion.y > abajo) { entidad.posicion.y = abajo; - - if (entidad.velocidad.y > 0.0f) - entidad.velocidad.y *= -1.0f; + entidad.velocidad.y = -fabsf(entidad.velocidad.y); } } -void RebotarPared(Entidad& entidad, const std::vector& paredes) +void RebotarPared( + Entidad& entidad, + const std::vector& paredes) { for (const Pared& pared : paredes) { @@ -152,14 +165,24 @@ void RebotarPared(Entidad& entidad, const std::vector& paredes) } float izquierda = pared.rectangulo.x; - float derecha = pared.rectangulo.x + pared.rectangulo.width; - float arriba = pared.rectangulo.y; - float abajo = pared.rectangulo.y + pared.rectangulo.height; + float derecha = pared.rectangulo.x + + pared.rectangulo.width; - float dIzquierda = fabsf(entidad.posicion.x - izquierda); - float dDerecha = fabsf(entidad.posicion.x - derecha); - float dArriba = fabsf(entidad.posicion.y - arriba); - float dAbajo = fabsf(entidad.posicion.y - abajo); + float arriba = pared.rectangulo.y; + float abajo = pared.rectangulo.y + + pared.rectangulo.height; + + float dIzquierda = + fabsf(entidad.posicion.x - izquierda); + + float dDerecha = + fabsf(entidad.posicion.x - derecha); + + float dArriba = + fabsf(entidad.posicion.y - arriba); + + float dAbajo = + fabsf(entidad.posicion.y - abajo); float menor = std::min( std::min(dIzquierda, dDerecha), @@ -168,27 +191,448 @@ void RebotarPared(Entidad& entidad, const std::vector& paredes) if (menor == dIzquierda) { - entidad.posicion.x = izquierda - entidad.radio; - entidad.velocidad.x = -fabsf(entidad.velocidad.x); + entidad.posicion.x = + izquierda - entidad.radio; + + entidad.velocidad.x = + -fabsf(entidad.velocidad.x); } else if (menor == dDerecha) { - entidad.posicion.x = derecha + entidad.radio; - entidad.velocidad.x = fabsf(entidad.velocidad.x); + entidad.posicion.x = + derecha + entidad.radio; + + entidad.velocidad.x = + fabsf(entidad.velocidad.x); } else if (menor == dArriba) { - entidad.posicion.y = arriba - entidad.radio; - entidad.velocidad.y = -fabsf(entidad.velocidad.y); + entidad.posicion.y = + arriba - entidad.radio; + + entidad.velocidad.y = + -fabsf(entidad.velocidad.y); } else { - entidad.posicion.y = abajo + entidad.radio; - entidad.velocidad.y = fabsf(entidad.velocidad.y); + entidad.posicion.y = + abajo + entidad.radio; + + entidad.velocidad.y = + fabsf(entidad.velocidad.y); } } } +bool TocarPared( + Vector2 posicion, + const std::vector& paredes) +{ + for (const Pared& pared : paredes) + { + if (CheckCollisionPointRec( + posicion, + pared.rectangulo)) + { + return true; + } + } + + return false; +} + +void MoverBala( + Bala& bala, + float dt, + const std::vector& paredes) +{ + if (!bala.activa) + return; + + Vector2 siguiente = { + bala.posicion.x + + bala.direccion.x * + bala.velocidad * + dt, + + bala.posicion.y + + bala.direccion.y * + bala.velocidad * + dt + }; + + bool golpeo = false; + + if (siguiente.x < BORDE) + { + siguiente.x = BORDE; + + if (bala.rebotes == 0) + { + bala.direccion.x *= -1.0f; + bala.rebotes++; + } + else + { + bala.activa = false; + } + + golpeo = true; + } + + if (siguiente.x > MUNDO_ANCHO - BORDE) + { + siguiente.x = MUNDO_ANCHO - BORDE; + + if (bala.rebotes == 0) + { + bala.direccion.x *= -1.0f; + bala.rebotes++; + } + else + { + bala.activa = false; + } + + golpeo = true; + } + + if (siguiente.y < BORDE) + { + siguiente.y = BORDE; + + if (bala.rebotes == 0) + { + bala.direccion.y *= -1.0f; + bala.rebotes++; + } + else + { + bala.activa = false; + } + + golpeo = true; + } + + if (siguiente.y > MUNDO_ALTO - BORDE) + { + siguiente.y = MUNDO_ALTO - BORDE; + + if (bala.rebotes == 0) + { + bala.direccion.y *= -1.0f; + bala.rebotes++; + } + else + { + bala.activa = false; + } + + golpeo = true; + } + + if (!bala.activa) + return; + + if (!golpeo) + { + for (const Pared& pared : paredes) + { + if (!CheckCollisionPointRec( + siguiente, + pared.rectangulo)) + { + continue; + } + + if (bala.rebotes == 0) + { + float izquierda = pared.rectangulo.x; + float derecha = + pared.rectangulo.x + + pared.rectangulo.width; + + float arriba = pared.rectangulo.y; + float abajo = + pared.rectangulo.y + + pared.rectangulo.height; + + float dxIzquierda = + fabsf(siguiente.x - izquierda); + + float dxDerecha = + fabsf(siguiente.x - derecha); + + float dyArriba = + fabsf(siguiente.y - arriba); + + float dyAbajo = + fabsf(siguiente.y - abajo); + + float menorX = + std::min(dxIzquierda, dxDerecha); + + float menorY = + std::min(dyArriba, dyAbajo); + + if (menorX < menorY) + bala.direccion.x *= -1.0f; + else + bala.direccion.y *= -1.0f; + + bala.rebotes++; + + siguiente.x += + bala.direccion.x * 3.0f; + + siguiente.y += + bala.direccion.y * 3.0f; + } + else + { + bala.activa = false; + } + + break; + } + } + + if (bala.activa) + bala.posicion = siguiente; +} + +int BuscarObjetivo( + int indice, + const std::vector& entidades) +{ + int objetivo = -1; + float menorDistancia = 999999.0f; + + for (int i = 0; + i < (int)entidades.size(); + i++) + { + if (i == indice) + continue; + + if (!entidades[i].viva) + continue; + + if (entidades[i].equipo == + entidades[indice].equipo) + { + continue; + } + + float distancia = + Distancia( + entidades[indice].posicion, + entidades[i].posicion + ); + + if (distancia < menorDistancia) + { + menorDistancia = distancia; + objetivo = i; + } + } + + return objetivo; +} + +void Disparar( + Entidad& entidad, + std::vector& balas) +{ + if (!entidad.viva) + return; + + if (entidad.municion <= 0) + return; + + Bala bala; + + bala.posicion = { + entidad.posicion.x + + entidad.direccion.x * 27.0f, + + entidad.posicion.y + + entidad.direccion.y * 27.0f + }; + + bala.direccion = + Normalizar(entidad.direccion); + + bala.velocidad = + VELOCIDAD_BALA; + + bala.equipo = + entidad.equipo; + + bala.rebotes = 0; + bala.activa = true; + + balas.push_back(bala); + + entidad.municion--; +} + +bool HayMunicion( + const std::vector& municiones) +{ + for (const Municion& municion : municiones) + { + if (municion.activa) + return true; + } + + return false; +} + +void CrearMunicion( + std::vector& municiones, + const std::vector& paredes, + const std::vector& entidades) +{ + if ((int)municiones.size() >= 2) + return; + + Vector2 posicion; + + bool valida = false; + + for (int intento = 0; + intento < 100 && !valida; + intento++) + { + posicion = { + (float)GetRandomValue( + (int)BORDE + 25, + (int)MUNDO_ANCHO - + (int)BORDE - 25 + ), + + (float)GetRandomValue( + (int)BORDE + 25, + (int)MUNDO_ALTO - + (int)BORDE - 25 + ) + }; + + valida = + !TocarPared( + posicion, + paredes + ); + + if (!valida) + continue; + + valida = false; + } + + if (!valida) + return; + + for (const Entidad& entidad : entidades) + { + if (!entidad.viva) + continue; + + if (Distancia( + posicion, + entidad.posicion) < 100.0f) + { + return; + } + } + + municiones.push_back({ + posicion, + true + }); +} + +void DibujarEntidad( + const Entidad& entidad, + float escalaX, + float escalaY, + float escala) +{ + if (!entidad.viva) + return; + + Vector2 posicion = { + entidad.posicion.x * escalaX, + entidad.posicion.y * escalaY + }; + + Color color = + entidad.equipo == 0 + ? BLUE + : RED; + + DrawCircleV( + posicion, + entidad.radio * escala, + color + ); + + Vector2 direccion = { + posicion.x + + entidad.direccion.x * + 25.0f * + escala, + + posicion.y + + entidad.direccion.y * + 25.0f * + escala + }; + + DrawLineEx( + posicion, + direccion, + 3.0f * escala, + WHITE + ); + + float vidaAncho = + 42.0f * escala; + + float vidaAlto = + 5.0f * escala; + + float vidaX = + posicion.x - + vidaAncho * 0.5f; + + float vidaY = + posicion.y - + entidad.radio * escala - + 13.0f * escala; + + DrawRectangle( + (int)vidaX, + (int)vidaY, + (int)vidaAncho, + (int)vidaAlto, + DARKGRAY + ); + + DrawRectangle( + (int)vidaX, + (int)vidaY, + (int)( + vidaAncho * + (entidad.vida / + entidad.vidaMaxima) + ), + (int)vidaAlto, + GREEN + ); +} + int main() { SetConfigFlags( @@ -199,24 +643,14 @@ int main() InitWindow( 1100, 750, - "A4B1" + "A4B1 0.1" ); SetTargetFPS(120); - Entidad jugador = { - {220.0f, 325.0f}, - {0.0f, 0.0f}, - RADIO_JUGADOR - }; - - Entidad enemigo = { - {780.0f, 325.0f}, - {210.0f, 145.0f}, - RADIO_ENEMIGO - }; - - std::vector balas; + SetRandomSeed( + (unsigned int)GetTime() + ); std::vector paredes = { {{280.0f, 150.0f, 180.0f, 14.0f}}, @@ -229,8 +663,69 @@ int main() {{450.0f, 391.0f, 100.0f, 14.0f}} }; + std::vector entidades = { + { + {220.0f, 325.0f}, + {0.0f, 0.0f}, + {1.0f, 0.0f}, + RADIO_JUGADOR, + 100.0f, + 100.0f, + 0, + true, + true, + 5, + 0.0f + }, + + { + {180.0f, 500.0f}, + {0.0f, 0.0f}, + {1.0f, 0.0f}, + RADIO_ENEMIGO, + 100.0f, + 100.0f, + 0, + false, + true, + 5, + 0.0f + }, + + { + {780.0f, 180.0f}, + {0.0f, 0.0f}, + {-1.0f, 0.0f}, + RADIO_ENEMIGO, + 100.0f, + 100.0f, + 1, + false, + true, + 5, + 0.0f + }, + + { + {780.0f, 470.0f}, + {0.0f, 0.0f}, + {-1.0f, 0.0f}, + RADIO_ENEMIGO, + 100.0f, + 100.0f, + 1, + false, + true, + 5, + 0.0f + } + }; + + std::vector balas; + std::vector municiones; + + float tiempoAparicionMunicion = 0.0f; int impactos = 0; - float tiempoDisparo = 0.0f; while (!WindowShouldClose()) { @@ -239,23 +734,28 @@ int main() if (IsKeyPressed(KEY_F11)) ToggleFullscreen(); - int anchoPantalla = GetScreenWidth(); - int altoPantalla = GetScreenHeight(); + int anchoPantalla = + GetScreenWidth(); - float escalaX = anchoPantalla / MUNDO_ANCHO; - float escalaY = altoPantalla / MUNDO_ALTO; + int altoPantalla = + GetScreenHeight(); - Vector2 mouse = GetMousePosition(); + float escalaX = + anchoPantalla / + MUNDO_ANCHO; - Vector2 mouseMundo = { - mouse.x / escalaX, - mouse.y / escalaY - }; + float escalaY = + altoPantalla / + MUNDO_ALTO; - Vector2 direccionMira = Normalizar({ - mouseMundo.x - jugador.posicion.x, - mouseMundo.y - jugador.posicion.y - }); + float escala = + std::min( + escalaX, + escalaY + ); + + Entidad& jugador = + entidades[0]; Vector2 movimiento = { 0.0f, @@ -274,144 +774,211 @@ int main() if (IsKeyDown(KEY_D)) movimiento.x += 1.0f; - movimiento = Normalizar(movimiento); + movimiento = + Normalizar(movimiento); - Vector2 derecha = { - -direccionMira.y, - direccionMira.x - }; - - Vector2 movimientoRelativo = { - derecha.x * movimiento.x + - direccionMira.x * (-movimiento.y), - - derecha.y * movimiento.x + - direccionMira.y * (-movimiento.y) - }; + if (movimiento.x != 0.0f || + movimiento.y != 0.0f) + { + jugador.direccion = + movimiento; + } jugador.velocidad = { - movimientoRelativo.x * 300.0f, - movimientoRelativo.y * 300.0f + movimiento.x * + VELOCIDAD_JUGADOR, + + movimiento.y * + VELOCIDAD_JUGADOR }; - jugador.posicion.x += - jugador.velocidad.x * dt; - - jugador.posicion.y += - jugador.velocidad.y * dt; - - RebotarBorde(jugador); - RebotarPared(jugador, paredes); - - tiempoDisparo -= dt; - - if (IsKeyDown(KEY_SPACE) && - tiempoDisparo <= 0.0f) + if (jugador.viva) { - if (direccionMira.x != 0.0f || - direccionMira.y != 0.0f) + jugador.posicion.x += + jugador.velocidad.x * + dt; + + jugador.posicion.y += + jugador.velocidad.y * + dt; + + RebotarBorde(jugador); + RebotarPared( + jugador, + paredes + ); + } + + jugador.tiempoDisparo -= dt; + + if (jugador.viva && + IsKeyPressed(KEY_SPACE) && + jugador.tiempoDisparo <= 0.0f) + { + if (jugador.municion > 0) { - Bala bala; + Disparar( + jugador, + balas + ); - bala.posicion = { - jugador.posicion.x + - direccionMira.x * 27.0f, - - jugador.posicion.y + - direccionMira.y * 27.0f - }; - - bala.direccion = direccionMira; - bala.velocidad = 850.0f; - bala.activa = true; - - balas.push_back(bala); - - tiempoDisparo = 0.11f; + jugador.tiempoDisparo = + 0.18f; } } - enemigo.posicion.x += - enemigo.velocidad.x * dt; + for (int i = 1; + i < (int)entidades.size(); + i++) + { + Entidad& entidad = + entidades[i]; - enemigo.posicion.y += - enemigo.velocidad.y * dt; + if (!entidad.viva) + continue; - RebotarBorde(enemigo); - RebotarPared(enemigo, paredes); + int objetivo = + BuscarObjetivo( + i, + entidades + ); + + if (objetivo >= 0) + { + Vector2 direccion = + Normalizar({ + entidades[objetivo].posicion.x - + entidad.posicion.x, + + entidades[objetivo].posicion.y - + entidad.posicion.y + }); + + entidad.direccion = + direccion; + + float distancia = + Distancia( + entidad.posicion, + entidades[objetivo].posicion + ); + + Vector2 movimientoIA = + direccion; + + if (distancia < 250.0f) + { + movimientoIA = { + -direccion.y, + direccion.x + }; + } + + entidad.velocidad = { + movimientoIA.x * + VELOCIDAD_IA, + + movimientoIA.y * + VELOCIDAD_IA + }; + + entidad.tiempoDisparo -= dt; + + if (entidad.tiempoDisparo <= 0.0f && + entidad.municion > 0) + { + Disparar( + entidad, + balas + ); + + entidad.tiempoDisparo = + 0.75f; + } + } + + entidad.posicion.x += + entidad.velocidad.x * + dt; + + entidad.posicion.y += + entidad.velocidad.y * + dt; + + RebotarBorde( + entidad + ); + + RebotarPared( + entidad, + paredes + ); + } for (Bala& bala : balas) { if (!bala.activa) continue; - bala.posicion.x += - bala.direccion.x * - bala.velocidad * - dt; - - bala.posicion.y += - bala.direccion.y * - bala.velocidad * - dt; - - if (bala.posicion.x < BORDE || - bala.posicion.x > MUNDO_ANCHO - BORDE || - bala.posicion.y < BORDE || - bala.posicion.y > MUNDO_ALTO - BORDE) - { - bala.activa = false; - continue; - } - - for (const Pared& pared : paredes) - { - if (CheckCollisionPointRec( - bala.posicion, - pared.rectangulo)) - { - bala.activa = false; - break; - } - } + MoverBala( + bala, + dt, + paredes + ); if (!bala.activa) continue; - if (Distancia( - bala.posicion, - enemigo.posicion) - < enemigo.radio + 6.0f) + for (int i = 0; + i < (int)entidades.size(); + i++) { + Entidad& entidad = + entidades[i]; + + if (!entidad.viva) + continue; + + if (entidad.equipo == + bala.equipo) + continue; + + if (!CirculoCirculo( + bala.posicion, + 6.0f, + entidad.posicion, + entidad.radio)) + { + continue; + } + + entidad.vida -= + DAÑO_BALA; + impactos++; - enemigo.velocidad.x += - bala.direccion.x * 300.0f; + Vector2 empuje = + bala.direccion; - enemigo.velocidad.y += - bala.direccion.y * 300.0f; + entidad.posicion.x += + empuje.x * 10.0f; - float velocidad = sqrtf( - enemigo.velocidad.x * - enemigo.velocidad.x + - enemigo.velocidad.y * - enemigo.velocidad.y - ); + entidad.posicion.y += + empuje.y * 10.0f; - if (velocidad > 600.0f) + if (entidad.vida <= 0.0f) { - enemigo.velocidad.x = - enemigo.velocidad.x / - velocidad * - 600.0f; - - enemigo.velocidad.y = - enemigo.velocidad.y / - velocidad * - 600.0f; + entidad.vida = 0.0f; + entidad.viva = false; + entidad.velocidad = { + 0.0f, + 0.0f + }; } bala.activa = false; + + break; } } @@ -427,22 +994,102 @@ int main() balas.end() ); + tiempoAparicionMunicion -= + dt; + + if (tiempoAparicionMunicion <= 0.0f) + { + CrearMunicion( + municiones, + paredes, + entidades + ); + + tiempoAparicionMunicion = + 4.0f; + } + + for (Municion& municion : + municiones) + { + if (!municion.activa) + continue; + + if (!jugador.viva) + continue; + + if (Distancia( + jugador.posicion, + municion.posicion + ) < 28.0f) + { + jugador.municion += 5; + municion.activa = false; + } + } + + municiones.erase( + std::remove_if( + municiones.begin(), + municiones.end(), + [](const Municion& municion) + { + return !municion.activa; + } + ), + municiones.end() + ); + BeginDrawing(); ClearBackground({ - 18, - 18, - 22, + 0, + 0, + 0, 255 }); - for (const Pared& pared : paredes) + Vector2 jugadorPantalla = { + jugador.posicion.x * + escalaX, + + jugador.posicion.y * + escalaY + }; + + for (const Pared& pared : + paredes) { + Vector2 centro = { + pared.rectangulo.x + + pared.rectangulo.width * + 0.5f, + + pared.rectangulo.y + + pared.rectangulo.height * + 0.5f + }; + + if (Distancia( + centro, + jugador.posicion + ) > RADIO_VISION + 180.0f) + { + continue; + } + Rectangle r = { - pared.rectangulo.x * escalaX, - pared.rectangulo.y * escalaY, - pared.rectangulo.width * escalaX, - pared.rectangulo.height * escalaY + pared.rectangulo.x * + escalaX, + + pared.rectangulo.y * + escalaY, + + pared.rectangulo.width * + escalaX, + + pared.rectangulo.height * + escalaY }; DrawRectangleRounded( @@ -470,85 +1117,169 @@ int main() ); } - DibujarBorde( - escalaX, - escalaY - ); + Rectangle borde = { + BORDE * escalaX, + BORDE * escalaY, - Vector2 jugadorPantalla = { - jugador.posicion.x * escalaX, - jugador.posicion.y * escalaY - }; - - Vector2 enemigoPantalla = { - enemigo.posicion.x * escalaX, - enemigo.posicion.y * escalaY - }; - - float escalaRadio = - std::min(escalaX, escalaY); - - DrawCircleV( - jugadorPantalla, - jugador.radio * escalaRadio, - RED - ); - - DrawCircleV( - enemigoPantalla, - enemigo.radio * escalaRadio, - BLUE - ); - - Vector2 mira = { - jugadorPantalla.x + - direccionMira.x * - 38.0f * + (MUNDO_ANCHO - + BORDE * 2.0f) * escalaX, - jugadorPantalla.y + - direccionMira.y * - 38.0f * + (MUNDO_ALTO - + BORDE * 2.0f) * escalaY }; - DrawLineEx( - jugadorPantalla, - mira, - 4.0f, - WHITE - ); - - for (const Bala& bala : balas) + if (Distancia( + jugador.posicion, + { + MUNDO_ANCHO * 0.5f, + MUNDO_ALTO * 0.5f + } + ) < RADIO_VISION + 500.0f) { + DrawRectangleRoundedLines( + borde, + 0.08f, + 16, + WHITE + ); + } + + for (const Municion& municion : + municiones) + { + if (!municion.activa) + continue; + + if (Distancia( + jugador.posicion, + municion.posicion + ) > RADIO_VISION) + continue; + Vector2 posicion = { - bala.posicion.x * escalaX, - bala.posicion.y * escalaY + municion.posicion.x * + escalaX, + + municion.posicion.y * + escalaY }; + DrawRectangle( + (int)posicion.x - 9, + (int)posicion.y - 9, + 18, + 18, + YELLOW + ); + + DrawText( + "+5", + (int)posicion.x - 8, + (int)posicion.y - 7, + 14, + BLACK + ); + } + + for (const Bala& bala : + balas) + { + if (!bala.activa) + continue; + + if (Distancia( + jugador.posicion, + bala.posicion + ) > RADIO_VISION) + continue; + + Vector2 posicion = { + bala.posicion.x * + escalaX, + + bala.posicion.y * + escalaY + }; + + Color color = + bala.equipo == 0 + ? BLUE + : RED; + DrawCircleV( posicion, - 5.0f * escalaRadio, - YELLOW + 5.0f * escala, + color ); } + for (const Entidad& entidad : + entidades) + { + if (!entidad.viva) + continue; + + if (Distancia( + jugador.posicion, + entidad.posicion + ) > RADIO_VISION) + continue; + + DibujarEntidad( + entidad, + escalaX, + escalaY, + escala + ); + } + + DrawCircle( + (int)jugadorPantalla.x, + (int)jugadorPantalla.y, + RADIO_VISION * escala, + Fade(BLACK, 0.0f) + ); + DrawRectangle( 15, 15, - 230, - 110, + 270, + 145, Fade(BLACK, 0.75f) ); + DrawText( + TextFormat( + "VIDA: %d", + (int)jugador.vida + ), + 28, + 25, + 22, + WHITE + ); + + DrawText( + TextFormat( + "BALAS: %d", + jugador.municion + ), + 28, + 53, + 22, + YELLOW + ); + DrawText( TextFormat( "IMPACTOS: %d", impactos ), 28, - 27, - 22, + 81, + 19, WHITE ); @@ -558,23 +1289,15 @@ int main() GetFPS() ), 28, - 57, - 20, + 107, + 18, GREEN ); DrawText( - "WASD MOVER", + "AZUL 2 VS ROJO 2", 28, - 87, - 16, - LIGHTGRAY - ); - - DrawText( - "ESPACIO DISPARAR", - 28, - 106, + 132, 16, LIGHTGRAY );