ERROR: no pinta los enemigos

This commit is contained in:
2022-07-04 18:01:21 +02:00
parent 4be611e0e4
commit b65c425c84
10 changed files with 367 additions and 80 deletions

View File

@@ -29,10 +29,10 @@ bool checkCollision(circle_t &a, circle_t &b)
// Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(circle_t &a, SDL_Rect &b)
{
//Closest point on collision box
// Closest point on collision box
int cX, cY;
//Find closest x offset
// Find closest x offset
if (a.x < b.x)
{
cX = b.x;
@@ -46,7 +46,7 @@ bool checkCollision(circle_t &a, SDL_Rect &b)
cX = a.x;
}
//Find closest y offset
// Find closest y offset
if (a.y < b.y)
{
cY = b.y;
@@ -60,33 +60,33 @@ bool checkCollision(circle_t &a, SDL_Rect &b)
cY = a.y;
}
//If the closest point is inside the circle_t
// If the closest point is inside the circle_t
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
{
//This box and the circle_t have collided
// This box and the circle_t have collided
return true;
}
//If the shapes have not collided
// If the shapes have not collided
return false;
}
// Detector de colisiones entre un dos rectangulos
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
{
//Calculate the sides of rect A
// Calculate the sides of rect A
int leftA = a.x;
int rightA = a.x + a.w;
int topA = a.y;
int bottomA = a.y + a.h;
//Calculate the sides of rect B
// Calculate the sides of rect B
int leftB = b.x;
int rightB = b.x + b.w;
int topB = b.y;
int bottomB = b.y + b.h;
//If any of the sides from A are outside of B
// If any of the sides from A are outside of B
if (bottomA <= topB)
{
return false;
@@ -107,18 +107,89 @@ bool checkCollision(SDL_Rect &a, SDL_Rect &b)
return false;
}
//If none of the sides from A are outside B
// If none of the sides from A are outside B
return true;
}
// Carga un archivo de imagen en una textura
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer)
{
bool success = true;
if (!texture->loadFromFile(path, renderer))
{
printf("Failed to load %s texture!\n", path.c_str());
success = false;
}
return success;
bool success = true;
if (!texture->loadFromFile(path, renderer))
{
printf("Failed to load %s texture!\n", path.c_str());
success = false;
}
return success;
}
// Devuelve un color_t a partir de un string
color_t stringToColor(std::string str)
{
color_t color = {0x00, 0x00, 0x00};
if (str == "black")
{
color = {0x00, 0x00, 0x00};
}
else if (str == "light_black")
{
color = {0x3C, 0x35, 0x1F};
}
else if (str == "blue")
{
color = {0x31, 0x33, 0x90};
}
else if (str == "light_blue")
{
color = {0x15, 0x59, 0xDB};
}
else if (str == "red")
{
color = {0xA7, 0x32, 0x11};
}
else if (str == "light_red")
{
color = {0xD8, 0x55, 0x25};
}
else if (str == "purple")
{
color = {0xA1, 0x55, 0x89};
}
else if (str == "light_purple")
{
color = {0xCD, 0x7A, 0x50};
}
else if (str == "green")
{
color = {0x62, 0x9A, 0x31};
}
else if (str == "light_green")
{
color = {0x9C, 0xD3, 0x3C};
}
else if (str == "cyan")
{
color = {0x28, 0xA4, 0xCB};
}
else if (str == "light_cyan")
{
color = {0x65, 0xDC, 0xD6};
}
else if (str == "yellow")
{
color = {0xE8, 0xBC, 0x50};
}
else if (str == "light_yellow")
{
color = {0xF1, 0xE7, 0x82};
}
else if (str == "white")
{
color = {0xBF, 0xBF, 0xBD};
}
else if (str == "light_white")
{
color = {0xF2, 0xF1, 0xED};
}
return color;
}