forked from jaildesigner-jailgames/jaildoctors_dilemma
Tiles animados completados
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 5.0 KiB |
@@ -75,9 +75,9 @@ Room::~Room()
|
|||||||
delete item;
|
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.
|
// 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
|
// 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;
|
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.x = (tilemap[index] % tilesetWidth) * tileSize;
|
||||||
clip.y = (tilemap[index] / tilesetWidth) * tileSize;
|
clip.y = (tilemap[index] / tilesetWidth) * tileSize;
|
||||||
@@ -624,10 +628,7 @@ void Room::renderMap()
|
|||||||
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
|
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
|
||||||
|
|
||||||
// Dibuja los tiles animados
|
// Dibuja los tiles animados
|
||||||
for (auto a:animatedTiles)
|
renderAnimatedTiles();
|
||||||
{
|
|
||||||
a->render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja los enemigos en pantalla
|
// Dibuja los enemigos en pantalla
|
||||||
@@ -739,7 +740,7 @@ tile_e Room::getTile(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// La fila 18 es de tiles t_animated
|
// 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;
|
return t_animated;
|
||||||
}
|
}
|
||||||
@@ -1095,16 +1096,18 @@ void Room::setAnimatedTiles()
|
|||||||
if (getTile(i) == t_animated)
|
if (getTile(i) == t_animated)
|
||||||
{
|
{
|
||||||
// la i me da la ubicación
|
// la i me da la ubicación
|
||||||
int x = (i % mapWidth) * tileSize;
|
const int x = (i % mapWidth) * tileSize;
|
||||||
int y = (i / mapWidth) * tileSize;
|
const int y = (i / mapWidth) * tileSize;
|
||||||
|
|
||||||
// tilemap[i] me da el tile a poner
|
// tilemap[i] me da el tile a poner
|
||||||
int xc = (tilemap[i] % tilesetWidth) * tileSize;
|
const int xc = (tilemap[i] % tilesetWidth) * tileSize;
|
||||||
int yc = (tilemap[i] / tilesetWidth) * tileSize;
|
const int yc = (tilemap[i] / tilesetWidth) * tileSize;
|
||||||
|
|
||||||
Sprite *sp = new Sprite(x, y, 8, 8, texture, renderer);
|
aTile_t at;
|
||||||
sp->setSpriteClip(xc, yc, 8, 8);
|
at.sprite = new Sprite(x, y, 8, 8, texture, renderer);
|
||||||
animatedTiles.push_back(sp);
|
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
|
// Actualiza los tiles animados
|
||||||
void Room::updateAnimatedTiles()
|
void Room::updateAnimatedTiles()
|
||||||
{
|
{
|
||||||
const int frame = (counter / 8) % 4;
|
const int numFrames = 4;
|
||||||
for (auto &a : animatedTiles)
|
const int offset = ((counter / 3) % numFrames * tileSize);
|
||||||
{ // 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
|
for (auto &a : aTile)
|
||||||
SDL_Rect rect = a->getSpriteClip();
|
{
|
||||||
if (frame == 0)
|
SDL_Rect rect = a.sprite->getSpriteClip();
|
||||||
rect.x -= 24;
|
rect.x = a.xcOrig + offset;
|
||||||
else
|
a.sprite->setSpriteClip(rect);
|
||||||
rect.x += 8;
|
|
||||||
a->setSpriteClip(rect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta los tiles animados en pantalla
|
// Pinta los tiles animados en pantalla
|
||||||
void Room::renderAnimatedTiles()
|
void Room::renderAnimatedTiles()
|
||||||
{
|
{
|
||||||
for (auto a : animatedTiles)
|
for (auto a : aTile)
|
||||||
{
|
{
|
||||||
a->render();
|
a.sprite->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ enum tile_e
|
|||||||
t_animated
|
t_animated
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct aTile_t
|
||||||
|
{
|
||||||
|
Sprite *sprite; // Sprite para dibujar el tile
|
||||||
|
int xcOrig; // Poicion X donde se encuentra el primer tile de la animacion en la tilesheet
|
||||||
|
};
|
||||||
|
|
||||||
// Clase Room
|
// Clase Room
|
||||||
class Room
|
class Room
|
||||||
{
|
{
|
||||||
@@ -76,7 +82,7 @@ private:
|
|||||||
std::vector<d_line_t> leftSlopes; // Lista con todas las rampas que suben hacia la izquierda
|
std::vector<d_line_t> leftSlopes; // Lista con todas las rampas que suben hacia la izquierda
|
||||||
std::vector<d_line_t> rightSlopes; // Lista con todas las rampas que suben hacia la derecha
|
std::vector<d_line_t> rightSlopes; // Lista con todas las rampas que suben hacia la derecha
|
||||||
int counter; // Contador para lo que haga falta
|
int counter; // Contador para lo que haga falta
|
||||||
std::vector<Sprite *> animatedTiles; // Vector con los indices de tiles animados
|
std::vector<aTile_t> aTile; // Vector con los indices de tiles animados
|
||||||
|
|
||||||
int tileSize; // Ancho del tile en pixels
|
int tileSize; // Ancho del tile en pixels
|
||||||
int mapWidth; // Ancho del mapa en tiles
|
int mapWidth; // Ancho del mapa en tiles
|
||||||
|
|||||||
Reference in New Issue
Block a user