forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya funcionan los tiles atravesables
This commit is contained in:
@@ -145,6 +145,9 @@ void Game::draw()
|
||||
text = "status: " + std::to_string(mPlayer->status);
|
||||
mText->write(0, 17 * 8, text);
|
||||
|
||||
text = "foot: " + std::to_string((int)mPlayer->getLeftFoot().y);
|
||||
mText->write(0, 18 * 8, text);
|
||||
|
||||
// Actualiza la pantalla
|
||||
mScreen->blit();
|
||||
}
|
||||
@@ -208,8 +211,17 @@ void Game::checkPlayerOnBorder()
|
||||
// Comprueba si el jugador esta sobre el suelo
|
||||
void Game::checkPlayerOnFloor()
|
||||
{
|
||||
// Comprueba ambos pies
|
||||
if ((mRoom->isFloor(mPlayer->getLeftFoot())) || (mRoom->isFloor(mPlayer->getRightFoot())))
|
||||
// Comprueba si tiene suelo bajo los pies solo cuando no hay velocidad de subida
|
||||
// y solo cuando el pie este encima de un bloque, es decir, en multiplos de 8
|
||||
if ((mPlayer->getVelY() >= 0) && ((int)mPlayer->getLeftFoot().y % 8 == 0))
|
||||
{ // Comprueba ambos pies
|
||||
bool test = false;
|
||||
test |= (mRoom->getTile(mPlayer->getLeftFoot()) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(mPlayer->getRightFoot()) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(mPlayer->getLeftFoot()) == TILE_TRAVESSABLE);
|
||||
test |= (mRoom->getTile(mPlayer->getRightFoot()) == TILE_TRAVESSABLE);
|
||||
|
||||
if (test)
|
||||
{
|
||||
mPlayer->setStatus(STATUS_STANDING);
|
||||
}
|
||||
@@ -218,6 +230,7 @@ void Game::checkPlayerOnFloor()
|
||||
mPlayer->setStatus(STATUS_FALLING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba que el jugador no atraviese ninguna pared
|
||||
void Game::checkPlayerAndWalls()
|
||||
@@ -234,14 +247,14 @@ void Game::checkPlayerAndWalls()
|
||||
SDL_Point p7 = {rect.x + 7, rect.y + 15};
|
||||
SDL_Point p8 = {rect.x, rect.y + 15};
|
||||
|
||||
bool test = mRoom->isFloor(p1);
|
||||
test |= mRoom->isFloor(p2);
|
||||
test |= mRoom->isFloor(p3);
|
||||
test |= mRoom->isFloor(p4);
|
||||
test |= mRoom->isFloor(p5);
|
||||
test |= mRoom->isFloor(p6);
|
||||
test |= mRoom->isFloor(p7);
|
||||
test |= mRoom->isFloor(p8);
|
||||
bool test = (mRoom->getTile(p1) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p2) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p3) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p4) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p5) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p6) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p7) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p8) == TILE_SOLID);
|
||||
|
||||
if (test)
|
||||
{
|
||||
|
||||
@@ -219,6 +219,12 @@ int Player::getStatus()
|
||||
return status;
|
||||
}
|
||||
|
||||
// Obtiene la velocidad en el eje Y del jugador
|
||||
float Player::getVelY()
|
||||
{
|
||||
return sprite->getVelY();
|
||||
}
|
||||
|
||||
// Aplica gravedad al jugador
|
||||
void Player::applyGravity()
|
||||
{
|
||||
|
||||
@@ -93,6 +93,9 @@ public:
|
||||
// Obtiene el estado del jugador
|
||||
int getStatus();
|
||||
|
||||
// Obtiene la velocidad en el eje Y del jugador
|
||||
float getVelY();
|
||||
|
||||
// Obtiene el rectangulo que delimita al jugador
|
||||
SDL_Rect getRect();
|
||||
|
||||
|
||||
@@ -308,18 +308,24 @@ std::string Room::getRoom(int border)
|
||||
return "";
|
||||
}
|
||||
|
||||
// Indica si el tile al que pertenece el pixel es sólido o no
|
||||
bool Room::isFloor(SDL_Point point)
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
int Room::getTile(SDL_Point point)
|
||||
{
|
||||
int tile = ((point.y / 8) * 32) + (point.x / 8);
|
||||
int pos = ((point.y / 8) * 32) + (point.x / 8);
|
||||
int tile = TILE_EMPTY;
|
||||
|
||||
if (tile < 512)
|
||||
if (pos < 512)
|
||||
{
|
||||
if (tilemap[tile] != 0)
|
||||
if (tilemap[pos] == 41)
|
||||
{
|
||||
return true;
|
||||
return TILE_SOLID;
|
||||
}
|
||||
|
||||
if (tilemap[pos] == 81)
|
||||
{
|
||||
return TILE_TRAVESSABLE;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return tile;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#ifndef ROOM_H
|
||||
#define ROOM_H
|
||||
|
||||
#define TILE_EMPTY 0
|
||||
#define TILE_SOLID 1
|
||||
#define TILE_TRAVESSABLE 2
|
||||
|
||||
/*
|
||||
Cada habitación se crea y destruye cada vez que se entra o sale de la misma
|
||||
Cada habitacion si que tendra lo siguiente:
|
||||
@@ -81,8 +85,8 @@ public:
|
||||
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||
std::string getRoom(int border);
|
||||
|
||||
// Indica si el tile al que pertenece el pixel es sólido o no
|
||||
bool isFloor(SDL_Point point);
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
int getTile(SDL_Point point);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user