Implementado el cambio de habitación
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
id=1
|
||||
name=Test Room
|
||||
bg_color=cyan
|
||||
bg_color=black
|
||||
tileset=room1.png
|
||||
room_up=0
|
||||
room_down=0
|
||||
room_left=0
|
||||
room_right=2
|
||||
room_right=02.room
|
||||
tilemap=41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,81,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,41,41,41,41,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,41,41,41,41,41,41,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,0,0,0,0,0,0,0,0,0,41,0,0,0,0,0,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41
|
||||
enemy=1,0,0,0,1
|
||||
enemy=2,10,0,0,1
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
id=2
|
||||
name=Test Room 2
|
||||
bg_color=blue
|
||||
tileset=1
|
||||
bg_color=black
|
||||
tileset=room1.png
|
||||
room_up=0
|
||||
room_down=
|
||||
room_left=1
|
||||
room_down=0
|
||||
room_left=01.room
|
||||
room_right=0
|
||||
tilemap=67,67,89,92,93
|
||||
tilemap=43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,43,43,43,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,43,0,0,0,0,0,0,0,83,83,83,83,83,83,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,83,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63
|
||||
enemy=1,0,0,0,1
|
||||
enemy=2,10,0,0,1
|
||||
item=1,10,10
|
||||
122
source/game.cpp
122
source/game.cpp
@@ -78,43 +78,95 @@ section_t Game::run()
|
||||
// Sección juego jugando
|
||||
if (mSection.subsection == SECTION_GAME_PLAY)
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
mTicks = SDL_GetTicks();
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(mEventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (mEventHandler->type == SDL_QUIT)
|
||||
{
|
||||
mSection.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepara para dibujar el frame
|
||||
const color_t color = {0xAA, 0x55, 0x55};
|
||||
mScreen->start();
|
||||
mScreen->clean(color);
|
||||
mScreen->clean(mRoom->getBGColor());
|
||||
|
||||
mRoom->drawMap();
|
||||
|
||||
// Escribe las medidas de ancho y alto de la pantalla
|
||||
// mText->writeCentered(GAMECANVAS_CENTER_X, 0, std::to_string(GAMECANVAS_WIDTH), -1);
|
||||
// mText->write(0, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), std::to_string(GAMECANVAS_HEIGHT), -1);
|
||||
|
||||
// Texto en el centro de la pantalla
|
||||
mText->writeCentered(GAMECANVAS_CENTER_X, 18 * 8, mRoom->getName(), -1);
|
||||
|
||||
// Actualiza la pantalla
|
||||
mScreen->blit();
|
||||
update();
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
return mSection;
|
||||
}
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void Game::update()
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
mTicks = SDL_GetTicks();
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(mEventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (mEventHandler->type == SDL_QUIT)
|
||||
{
|
||||
mSection.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
checkInput();
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta los objetos en pantalla
|
||||
void Game::draw()
|
||||
{
|
||||
// Prepara para dibujar el frame
|
||||
const color_t color = {0xAA, 0x55, 0x55};
|
||||
mScreen->start();
|
||||
mScreen->clean(color);
|
||||
mScreen->clean(mRoom->getBGColor());
|
||||
|
||||
mRoom->drawMap();
|
||||
|
||||
// Escribe las medidas de ancho y alto de la pantalla
|
||||
// mText->writeCentered(GAMECANVAS_CENTER_X, 0, std::to_string(GAMECANVAS_WIDTH), -1);
|
||||
// mText->write(0, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), std::to_string(GAMECANVAS_HEIGHT), -1);
|
||||
|
||||
// Texto en el centro de la pantalla
|
||||
mText->writeCentered(GAMECANVAS_CENTER_X, 18 * 8, mRoom->getName(), -1);
|
||||
|
||||
// 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_DOWN, REPEAT_FALSE))
|
||||
changeRoom(mRoom->getRoomDown());
|
||||
|
||||
if (mInput->checkInput(INPUT_LEFT, REPEAT_FALSE))
|
||||
changeRoom(mRoom->getRoomLeft());
|
||||
|
||||
if (mInput->checkInput(INPUT_RIGHT, REPEAT_FALSE))
|
||||
changeRoom(mRoom->getRoomRight());
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
bool Game::changeRoom(std::string file)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
|
||||
if (file != "0")
|
||||
// Verifica que exista el fichero que se va a cargar
|
||||
if (mAsset->get(file) != "")
|
||||
{
|
||||
// Elimina la habitación actual
|
||||
delete mRoom;
|
||||
mRoom = nullptr;
|
||||
|
||||
// Crea un objeto habitación nuevo a partir del fichero
|
||||
mRoom = new Room(mAsset->get(file), mRenderer, mAsset);
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -45,6 +45,18 @@ private:
|
||||
// Carga los recursos
|
||||
bool loadMedia();
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void update();
|
||||
|
||||
// Pinta los objetos en pantalla
|
||||
void draw();
|
||||
|
||||
// Comprueba la entrada
|
||||
void checkInput();
|
||||
|
||||
// Cambia de habitación
|
||||
bool changeRoom(std::string file);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input);
|
||||
|
||||
@@ -179,14 +179,14 @@ void Room::fillMapTexture()
|
||||
|
||||
// Los tilesets son de 20x20 tiles. El primer tile es el 1. Cuentan hacia la derecha y hacia abajo
|
||||
|
||||
printf("Filling map\n");
|
||||
// printf("Filling map\n");
|
||||
SDL_Rect clip = {0, 0, 8, 8};
|
||||
for (int y = 0; y < 16; y++)
|
||||
for (int x = 0; x < 32; x++)
|
||||
{
|
||||
{
|
||||
clip.x = ((tilemap[(y * 32) + x] - 1) % 20) * 8;
|
||||
clip.y = ((tilemap[(y * 32) + x] - 1) / 20) * 8;
|
||||
printf("tilemap [%i] = %i | x = %i | y = %i\n", ((y * 32) + x), tilemap[(y * 32) + x], clip.x, clip.y);
|
||||
// printf("tilemap [%i] = %i | x = %i | y = %i\n", ((y * 32) + x), tilemap[(y * 32) + x], clip.x, clip.y);
|
||||
texture->render(renderer, x * 8, y * 8, &clip);
|
||||
}
|
||||
|
||||
@@ -200,4 +200,28 @@ void Room::drawMap()
|
||||
|
||||
// Dibuja la textura con el mapa en pantalla
|
||||
SDL_RenderCopy(renderer, map_texture, &rect, NULL);
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string Room::getRoomUp()
|
||||
{
|
||||
return room_up;
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string Room::getRoomDown()
|
||||
{
|
||||
return room_down;
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string Room::getRoomLeft()
|
||||
{
|
||||
return room_left;
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string Room::getRoomRight()
|
||||
{
|
||||
return room_right;
|
||||
}
|
||||
@@ -67,6 +67,18 @@ public:
|
||||
|
||||
// Dibuja el mapa en pantalla
|
||||
void drawMap();
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string getRoomUp();
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string getRoomDown();
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string getRoomLeft();
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
std::string getRoomRight();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user