forked from jaildesigner-jailgames/jaildoctors_dilemma
Tiles animados completados
This commit is contained in:
@@ -75,9 +75,9 @@ Room::~Room()
|
||||
delete item;
|
||||
}
|
||||
|
||||
for (auto a: animatedTiles)
|
||||
for (auto a : aTile)
|
||||
{
|
||||
delete a;
|
||||
delete a.sprite;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,8 +525,12 @@ void Room::fillMapTexture()
|
||||
{
|
||||
// Tiled pone los tiles vacios del mapa como cero y empieza a contar de 1 a n.
|
||||
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
|
||||
// Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices)
|
||||
const int index = (y * mapWidth) + x;
|
||||
if (index > -1)
|
||||
const bool a = (tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 19 * tilesetWidth);
|
||||
const bool b = tilemap[index] > -1;
|
||||
|
||||
if (b && !a)
|
||||
{
|
||||
clip.x = (tilemap[index] % tilesetWidth) * tileSize;
|
||||
clip.y = (tilemap[index] / tilesetWidth) * tileSize;
|
||||
@@ -624,10 +628,7 @@ void Room::renderMap()
|
||||
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
|
||||
|
||||
// Dibuja los tiles animados
|
||||
for (auto a:animatedTiles)
|
||||
{
|
||||
a->render();
|
||||
}
|
||||
renderAnimatedTiles();
|
||||
}
|
||||
|
||||
// Dibuja los enemigos en pantalla
|
||||
@@ -739,7 +740,7 @@ tile_e Room::getTile(int index)
|
||||
}
|
||||
|
||||
// La fila 18 es de tiles t_animated
|
||||
if ((tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 29 * tilesetWidth))
|
||||
if ((tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 19 * tilesetWidth))
|
||||
{
|
||||
return t_animated;
|
||||
}
|
||||
@@ -1095,16 +1096,18 @@ void Room::setAnimatedTiles()
|
||||
if (getTile(i) == t_animated)
|
||||
{
|
||||
// la i me da la ubicación
|
||||
int x = (i % mapWidth) * tileSize;
|
||||
int y = (i / mapWidth) * tileSize;
|
||||
const int x = (i % mapWidth) * tileSize;
|
||||
const int y = (i / mapWidth) * tileSize;
|
||||
|
||||
// tilemap[i] me da el tile a poner
|
||||
int xc = (tilemap[i] % tilesetWidth) * tileSize;
|
||||
int yc = (tilemap[i] / tilesetWidth) * tileSize;
|
||||
const int xc = (tilemap[i] % tilesetWidth) * tileSize;
|
||||
const int yc = (tilemap[i] / tilesetWidth) * tileSize;
|
||||
|
||||
Sprite *sp = new Sprite(x, y, 8, 8, texture, renderer);
|
||||
sp->setSpriteClip(xc, yc, 8, 8);
|
||||
animatedTiles.push_back(sp);
|
||||
aTile_t at;
|
||||
at.sprite = new Sprite(x, y, 8, 8, texture, renderer);
|
||||
at.sprite->setSpriteClip(xc, yc, 8, 8);
|
||||
at.xcOrig = xc;
|
||||
aTile.push_back(at);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1112,24 +1115,22 @@ void Room::setAnimatedTiles()
|
||||
// Actualiza los tiles animados
|
||||
void Room::updateAnimatedTiles()
|
||||
{
|
||||
const int frame = (counter / 8) % 4;
|
||||
for (auto &a : animatedTiles)
|
||||
{ // Frame vale 0, 1, 2 o 3. La x se aumenta de 8 en 8, salvo cuando frame vale 0 que ha de volver 3*8
|
||||
SDL_Rect rect = a->getSpriteClip();
|
||||
if (frame == 0)
|
||||
rect.x -= 24;
|
||||
else
|
||||
rect.x += 8;
|
||||
a->setSpriteClip(rect);
|
||||
const int numFrames = 4;
|
||||
const int offset = ((counter / 3) % numFrames * tileSize);
|
||||
for (auto &a : aTile)
|
||||
{
|
||||
SDL_Rect rect = a.sprite->getSpriteClip();
|
||||
rect.x = a.xcOrig + offset;
|
||||
a.sprite->setSpriteClip(rect);
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta los tiles animados en pantalla
|
||||
void Room::renderAnimatedTiles()
|
||||
{
|
||||
for (auto a : animatedTiles)
|
||||
for (auto a : aTile)
|
||||
{
|
||||
a->render();
|
||||
a.sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user