Ya se pueden pillar los items. Falta llevar el control de los iterms conseguidos

This commit is contained in:
2022-07-12 19:33:09 +02:00
parent f8db0e3a90
commit 6152dc4255
12 changed files with 140 additions and 51 deletions

View File

@@ -6,6 +6,7 @@ Game::Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang,
// Inicia variables
mCurrentRoom = "01.room";
mSpawnPoint = {2 * 8, 12 * 8, 0, 0, 0, STATUS_STANDING, SDL_FLIP_NONE};
mDebug = false;
// Copia los punteros
mRenderer = renderer;
@@ -122,6 +123,7 @@ void Game::update()
checkPlayerAndWalls(); // Debe ir detras del player update, por si se ha metido en algun muro
checkPlayerOnBorder();
checkPlayerOnFloor();
checkPlayerAndItems();
if (checkPlayerAndEnemies())
{
// Destruye la habitacion y el jugador
@@ -132,6 +134,8 @@ void Game::update()
mRoom = new Room(mAsset->get(mCurrentRoom), mRenderer, mAsset);
mPlayer = new Player(mSpawnPoint, mAsset->get("player01.png"), mRenderer, mAsset, mInput, mRoom);
}
checkInput();
}
}
@@ -156,43 +160,50 @@ void Game::draw()
mText->writeCentered(GAMECANVAS_CENTER_X, 16 * 8, mRoom->getName());
// Debug info
std::string text;
text = "status: " + std::to_string(mPlayer->status);
mText->write(0, 17 * 8, text);
if (mDebug)
{
std::string text;
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);
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);
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);
const bool collision = checkPlayerAndEnemies();
text = "collision: " + std::to_string(collision);
mText->write(0, 20 * 8, text);
const bool collision = checkPlayerAndEnemies();
text = "collision: " + std::to_string(collision);
mText->write(0, 20 * 8, text);
}
// Actualiza la pantalla
mScreen->blit();
}
// Comprueba la entrada
/*
void Game::checkInput()
{
if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
changeRoom(mRoom->getRoomUp());
/*
if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
changeRoom(mRoom->getRoomUp());
if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE))
changeRoom(mRoom->getRoomDown());
if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE))
changeRoom(mRoom->getRoomDown());
if (mInput->checkInput(INPUT_LEFT, REPEAT_FALSE))
changeRoom(mRoom->getRoomLeft());
if (mInput->checkInput(INPUT_LEFT, REPEAT_FALSE))
changeRoom(mRoom->getRoomLeft());
if (mInput->checkInput(INPUT_RIGHT, REPEAT_FALSE))
changeRoom(mRoom->getRoomRight());
if (mInput->checkInput(INPUT_RIGHT, REPEAT_FALSE))
changeRoom(mRoom->getRoomRight());
*/
if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_FALSE))
mDebug = !mDebug;
}
*/
// Cambia de habitación
bool Game::changeRoom(std::string file)
@@ -246,7 +257,7 @@ void Game::checkPlayerOnFloor()
// En este caso habría que recolocar al jugador en el sitio
// *** PARECE RESUELTO
const int a = (mPlayer->lastPosition.y + 16) / 8;
const int b = mPlayer->getLeftFoot().y / 8;
const bool tile_change = a != b;
@@ -318,4 +329,10 @@ void Game::checkPlayerAndWalls()
bool Game::checkPlayerAndEnemies()
{
return mRoom->enemyCollision(mPlayer->getCollider());
}
// Comprueba las colisiones del jugador con los objetos
void Game::checkPlayerAndItems()
{
mRoom->itemCollision(mPlayer->getCollider());
}