forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya realiza bien las colisiones con todos los tiles
This commit is contained in:
@@ -148,6 +148,11 @@ void Game::draw()
|
||||
text = "foot: " + std::to_string((int)mPlayer->getLeftFoot().y);
|
||||
mText->write(0, 18 * 8, text);
|
||||
|
||||
const int a = (mPlayer->lastPosition.y + 16) / 8;
|
||||
const int b = mPlayer->getLeftFoot().y / 8;
|
||||
text = "tile: " + std::to_string(a) + " - " + std::to_string(b);
|
||||
mText->write(0, 19 * 8, text);
|
||||
|
||||
// Actualiza la pantalla
|
||||
mScreen->blit();
|
||||
}
|
||||
@@ -214,18 +219,37 @@ void Game::checkPlayerOnFloor()
|
||||
// *** HAY UN POSIBLE PROBLEMA y es que caiga muy rapido y viaje a mas de un pixel de velocidad,
|
||||
// con lo que se saltaria la comprobación
|
||||
|
||||
if ((mPlayer->getVelY() >= 0) && ((int)mPlayer->getLeftFoot().y % 8 == 0))
|
||||
{ // Comprueba ambos pies
|
||||
// *** POSIBLE SOLUCION. Comprobar si el tile actual del pie es diferente al tile del pie previo.
|
||||
// Esto indica que se ha saltado la comprobacion cada 8 pixeles.
|
||||
// En este caso habría que recolocar al jugador en el sitio
|
||||
const int a = (mPlayer->lastPosition.y + 16) / 8;
|
||||
const int b = mPlayer->getLeftFoot().y / 8;
|
||||
const bool tile_change = a != b;
|
||||
|
||||
const bool is_not_going_up = mPlayer->getVelY() >= 0;
|
||||
const bool is_tile_aligned = mPlayer->getLeftFoot().y % 8 == 0;
|
||||
|
||||
if (((is_not_going_up) && (is_tile_aligned)) || ((is_not_going_up) && (tile_change)))
|
||||
{
|
||||
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);
|
||||
|
||||
// Tiene uno de los pies sobre una superficie
|
||||
if (test)
|
||||
{
|
||||
mPlayer->setStatus(STATUS_STANDING);
|
||||
|
||||
// Si ha habido un cambio de tile, hay que recolocarlo
|
||||
if (tile_change)
|
||||
{
|
||||
int offset = (int)mPlayer->sprite->getPosY() % 8;
|
||||
mPlayer->sprite->setPosY((int)mPlayer->sprite->getPosY() - offset);
|
||||
}
|
||||
}
|
||||
// Tiene ambos pies sobre el vacío
|
||||
else if (mPlayer->getStatus() != STATUS_JUMPING)
|
||||
{
|
||||
mPlayer->setStatus(STATUS_FALLING);
|
||||
@@ -237,18 +261,18 @@ void Game::checkPlayerOnFloor()
|
||||
void Game::checkPlayerAndWalls()
|
||||
{
|
||||
// Comprueba las cuatro esquinas de los dos tiles del jugador
|
||||
SDL_Rect rect = mPlayer->getRect();
|
||||
SDL_Point p1 = {rect.x, rect.y};
|
||||
SDL_Point p2 = {rect.x + 7, rect.y};
|
||||
SDL_Point p3 = {rect.x + 7, rect.y + 7};
|
||||
SDL_Point p4 = {rect.x, rect.y + 7};
|
||||
const SDL_Rect rect = mPlayer->getRect();
|
||||
const SDL_Point p1 = {rect.x, rect.y};
|
||||
const SDL_Point p2 = {rect.x + 7, rect.y};
|
||||
const SDL_Point p3 = {rect.x + 7, rect.y + 7};
|
||||
const SDL_Point p4 = {rect.x, rect.y + 7};
|
||||
const SDL_Point p5 = {rect.x, rect.y + 8};
|
||||
const SDL_Point p6 = {rect.x + 7, rect.y + 8};
|
||||
const SDL_Point p7 = {rect.x + 7, rect.y + 15};
|
||||
const SDL_Point p8 = {rect.x, rect.y + 15};
|
||||
|
||||
SDL_Point p5 = {rect.x, rect.y + 8};
|
||||
SDL_Point p6 = {rect.x + 7, rect.y + 8};
|
||||
SDL_Point p7 = {rect.x + 7, rect.y + 15};
|
||||
SDL_Point p8 = {rect.x, rect.y + 15};
|
||||
|
||||
bool test = (mRoom->getTile(p1) == TILE_SOLID);
|
||||
bool test = false;
|
||||
test |= (mRoom->getTile(p1) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p2) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p3) == TILE_SOLID);
|
||||
test |= (mRoom->getTile(p4) == TILE_SOLID);
|
||||
|
||||
@@ -24,13 +24,11 @@ class Player
|
||||
{
|
||||
private:
|
||||
LTexture *texture; // Textura con los graficos del enemigo
|
||||
AnimatedSprite *sprite; // Sprite del enemigo
|
||||
Input *input; // Objeto para gestionar la entrada
|
||||
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
color_t color; // Color del jugador
|
||||
SDL_Rect lastPosition; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento
|
||||
|
||||
bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||
int border; // Indica en cual de los cuatro bordes se encuentra
|
||||
@@ -57,6 +55,8 @@ private:
|
||||
void checkJump();
|
||||
|
||||
public:
|
||||
AnimatedSprite *sprite; // Sprite del enemigo
|
||||
SDL_Rect lastPosition; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento
|
||||
int jump_ini; // Valor del eje Y en el que se inicia el salto
|
||||
int status; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -1,4 +1,4 @@
|
||||
[x] Hacer que deje de poder moverse tras el salto al alcanzar la misma posicion en altura que tenia cuando saltó
|
||||
[ ] Arreglar que no atraviese tiles atravaseables al caer muy rapido
|
||||
[x] Arreglar que no atraviese tiles atravaseables al caer muy rapido
|
||||
[x] Leer los mapas directamente del archivo tmx
|
||||
[ ] Crear la clase item
|
||||
Reference in New Issue
Block a user