Ya recuerda los items recogidos
This commit is contained in:
@@ -11,7 +11,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
|||||||
|
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
map = new Map(asset->get("01.map"), renderer, asset);
|
itemTracker = new Item_tracker();
|
||||||
|
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
||||||
player = new Player(renderer, asset, input, map);
|
player = new Player(renderer, asset, input, map);
|
||||||
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
music = JA_LoadMusic(asset->get("music_surface.ogg").c_str());
|
||||||
@@ -32,6 +33,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
|||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
delete eventHandler;
|
delete eventHandler;
|
||||||
|
delete itemTracker;
|
||||||
delete map;
|
delete map;
|
||||||
delete player;
|
delete player;
|
||||||
delete debugText;
|
delete debugText;
|
||||||
@@ -124,7 +126,7 @@ void Game::checkInput()
|
|||||||
if (input->checkInput(INPUT_BUTTON_3, REPEAT_FALSE))
|
if (input->checkInput(INPUT_BUTTON_3, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
delete map;
|
delete map;
|
||||||
map = new Map(asset->get("01.map"), renderer, asset);
|
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
||||||
delete player;
|
delete player;
|
||||||
player = new Player(renderer, asset, input, map);
|
player = new Player(renderer, asset, input, map);
|
||||||
}
|
}
|
||||||
@@ -216,7 +218,7 @@ bool Game::changeMap(std::string file)
|
|||||||
delete map;
|
delete map;
|
||||||
|
|
||||||
// Crea un objeto habitación nuevo a partir del fichero
|
// Crea un objeto habitación nuevo a partir del fichero
|
||||||
map = new Map(asset->get(file), renderer, asset);
|
map = new Map(asset->get(file), renderer, asset, itemTracker);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "item_tracker.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
@@ -15,20 +16,21 @@
|
|||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Asset *asset; // Objeto encargado de gestionar los ficheros de recursos
|
Asset *asset; // Objeto encargado de gestionar los ficheros de recursos
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
Input *input; // Objeto Input para gestionar las entradas
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
JA_Music music; // Contiene la musica que se reproduce durante el juego
|
JA_Music music; // Contiene la musica que se reproduce durante el juego
|
||||||
Text *debugText; // Objeto para escribir texto con información de debug
|
Text *debugText; // Objeto para escribir texto con información de debug
|
||||||
Map *map; // Objeto encargado de gestionar el mapeado del juego
|
Map *map; // Objeto encargado de gestionar el mapeado del juego
|
||||||
Player *player; // Objeto para gestionar el jugador
|
Player *player; // Objeto para gestionar el jugador
|
||||||
section_t section; // Seccion actual dentro del programa
|
Item_tracker *itemTracker; // Objeto para gestionar los items recogidos
|
||||||
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
section_t section; // Seccion actual dentro del programa
|
||||||
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
bool debug; // Indica si esta activo el modo de depuración
|
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
bool musicEnabled; // Indica si la musica puede sonar o no
|
bool debug; // Indica si esta activo el modo de depuración
|
||||||
|
bool musicEnabled; // Indica si la musica puede sonar o no
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset)
|
Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, Item_tracker *itemTracker)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
tile_size = 8;
|
tile_size = 8;
|
||||||
map_width = 40;
|
map_width = 40;
|
||||||
map_height = 26;
|
map_height = 26;
|
||||||
tileset_width = 32;
|
tileset_width = 32;
|
||||||
|
name = file.substr(file.find_last_of("\\/") + 1);
|
||||||
|
|
||||||
// Copia los punteros a objetos
|
// Copia los punteros a objetos
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
|
this->itemTracker = itemTracker;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
texture_tile = new LTexture();
|
texture_tile = new LTexture();
|
||||||
@@ -165,8 +167,12 @@ bool Map::load(std::string file_path)
|
|||||||
|
|
||||||
} while (line != "[/diamond]");
|
} while (line != "[/diamond]");
|
||||||
|
|
||||||
printf("** actor diamond loaded\n\n");
|
// Comprueba si el actor no ha sido recogido previamente
|
||||||
actors.push_back(new ActorDiamond(actor));
|
if (!itemTracker->hasBeenPicked(name, {(int)actor.x, (int)actor.y}))
|
||||||
|
{
|
||||||
|
printf("** actor diamond loaded\n\n");
|
||||||
|
actors.push_back(new ActorDiamond(actor));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (line != "[/actors]");
|
} while (line != "[/actors]");
|
||||||
@@ -578,4 +584,11 @@ bool Map::deleteActor(int index)
|
|||||||
|
|
||||||
actors.erase(actors.begin() + index);
|
actors.erase(actors.begin() + index);
|
||||||
return success;
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coge un item
|
||||||
|
void Map::getItem(int index)
|
||||||
|
{
|
||||||
|
const SDL_Rect r = getActorCollider(index);
|
||||||
|
itemTracker->addItem(name, {r.x, r.y});
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
#include "item_tracker.h"
|
||||||
#include "actor_moving_platform.h"
|
#include "actor_moving_platform.h"
|
||||||
#include "actor_diamond.h"
|
#include "actor_diamond.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -36,6 +37,7 @@ class Map
|
|||||||
private:
|
private:
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
std::string name; // Identificador de la habitación
|
||||||
std::string room_up; // Identificador de la habitación que se encuentra arriba
|
std::string room_up; // Identificador de la habitación que se encuentra arriba
|
||||||
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
||||||
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
||||||
@@ -47,6 +49,7 @@ private:
|
|||||||
std::vector<Actor *> actors; // Listado con los actores de la habitación
|
std::vector<Actor *> actors; // Listado con los actores de la habitación
|
||||||
color_t bgColor1; // Color superior del degradado de fondo
|
color_t bgColor1; // Color superior del degradado de fondo
|
||||||
color_t bgColor2; // Color inferior del degradado de fondo
|
color_t bgColor2; // Color inferior del degradado de fondo
|
||||||
|
Item_tracker *itemTracker; // Objeto que gestiona los items que ya se han recogido
|
||||||
|
|
||||||
int tile_size; // Ancho del tile en pixels
|
int tile_size; // Ancho del tile en pixels
|
||||||
int map_width; // Ancho del mapa en tiles
|
int map_width; // Ancho del mapa en tiles
|
||||||
@@ -67,7 +70,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Map(std::string file, SDL_Renderer *renderer, Asset *asset);
|
Map(std::string file, SDL_Renderer *renderer, Asset *asset, Item_tracker *itemTracker);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Map();
|
~Map();
|
||||||
@@ -110,6 +113,9 @@ public:
|
|||||||
|
|
||||||
// Elimina un actor
|
// Elimina un actor
|
||||||
bool deleteActor(int index);
|
bool deleteActor(int index);
|
||||||
|
|
||||||
|
// Coge un item
|
||||||
|
void getItem(int index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -448,6 +448,7 @@ int Player::checkActors()
|
|||||||
{
|
{
|
||||||
diamonds++;
|
diamonds++;
|
||||||
JA_PlaySound(sound_coin);
|
JA_PlaySound(sound_coin);
|
||||||
|
map->getItem(index);
|
||||||
map->deleteActor(index);
|
map->deleteActor(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user