añadido map.h y map.cpp

This commit is contained in:
2022-07-01 20:21:28 +02:00
parent 37325a2ec3
commit 661b920dfa
7 changed files with 70 additions and 32 deletions

View File

@@ -7,8 +7,8 @@
#define CONST_H #define CONST_H
// Textos // Textos
#define WINDOW_CAPTION "Pepe el Cazavampiros" #define WINDOW_CAPTION "New JailGame"
#define TEXT_COPYRIGHT "@2021 JailDesigner (v0.1)" #define TEXT_COPYRIGHT "@2022 JailDesigner (v0.1)"
// Tamaño de bloque // Tamaño de bloque
#define BLOCK 8 #define BLOCK 8
@@ -49,21 +49,20 @@ const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
// Secciones del programa // Secciones del programa
#define PROG_SECTION_LOGO 0 #define SECTION_PROG_LOGO 0
#define PROG_SECTION_INTRO 1 #define SECTION_PROG_INTRO 1
#define PROG_SECTION_TITLE 2 #define SECTION_PROG_TITLE 2
#define PROG_SECTION_GAME 3 #define SECTION_PROG_GAME 3
#define PROG_SECTION_QUIT 4 #define SECTION_PROG_QUIT 4
// Subsecciones // Subsecciones
#define GAME_SECTION_PLAY_1P 0 #define SECTION_GAME_PLAY 0
#define GAME_SECTION_PLAY_2P 1 #define SECTION_GAME_PAUSE 1
#define GAME_SECTION_PAUSE 2 #define SECTION_GAME_GAMEOVER 2
#define GAME_SECTION_GAMEOVER 3 #define SECTION_TITLE_1 3
#define TITLE_SECTION_1 3 #define SECTION_TITLE_2 4
#define TITLE_SECTION_2 4 #define SECTION_TITLE_3 5
#define TITLE_SECTION_3 5 #define SECTION_TITLE_INSTRUCTIONS 6
#define TITLE_SECTION_INSTRUCTIONS 6
// Estados de cada elemento que pertenece a un evento // Estados de cada elemento que pertenece a un evento
#define EVENT_WAITING 1 #define EVENT_WAITING 1
@@ -71,7 +70,7 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
#define EVENT_COMPLETED 3 #define EVENT_COMPLETED 3
// Estados de entrada // Estados de entrada
#define NO_INPUT 0 #define INPUT_NULL 0
#define INPUT_FIRE_LEFT 7 #define INPUT_FIRE_LEFT 7
#define INPUT_FIRE_UP 8 #define INPUT_FIRE_UP 8
#define INPUT_FIRE_RIGHT 9 #define INPUT_FIRE_RIGHT 9

View File

@@ -17,9 +17,9 @@ Director::Director(std::string path)
setFileList(); setFileList();
// Si falta algún fichero no inicia el programa // Si falta algún fichero no inicia el programa
Uint8 section = PROG_SECTION_GAME; Uint8 section = SECTION_PROG_GAME;
if (!mAsset->check()) if (!mAsset->check())
section = PROG_SECTION_QUIT; section = SECTION_PROG_QUIT;
// Inicializa el objeto de idioma // Inicializa el objeto de idioma
mLang = new Lang(mAsset); mLang = new Lang(mAsset);
@@ -360,20 +360,20 @@ void Director::runGame()
void Director::run() void Director::run()
{ {
// Bucle principal // Bucle principal
while (!(getSection() == PROG_SECTION_QUIT)) while (!(getSection() == SECTION_PROG_QUIT))
{ {
switch (getSection()) switch (getSection())
{ {
case PROG_SECTION_LOGO: case SECTION_PROG_LOGO:
runLogo(); runLogo();
break; break;
case PROG_SECTION_INTRO: case SECTION_PROG_INTRO:
runIntro(); runIntro();
break; break;
case PROG_SECTION_TITLE: case SECTION_PROG_TITLE:
runTitle(); runTitle();
break; break;
case PROG_SECTION_GAME: case SECTION_PROG_GAME:
runGame(); runGame();
break; break;
} }

View File

@@ -10,6 +10,7 @@ Game::Game(SDL_Window *window,SDL_Renderer *renderer, Asset *asset, Lang *lang,
mInput = input; mInput = input;
mScreen = new Screen(window, renderer); mScreen = new Screen(window, renderer);
mMap = new Map();
mEventHandler = new SDL_Event(); mEventHandler = new SDL_Event();
mTextureText = new LTexture(); mTextureText = new LTexture();
mText = new Text(mAsset->get("nokia2.txt"), mTextureText, renderer); mText = new Text(mAsset->get("nokia2.txt"), mTextureText, renderer);
@@ -33,6 +34,9 @@ Game::~Game()
delete mScreen; delete mScreen;
mScreen = nullptr; mScreen = nullptr;
delete mMap;
mMap = nullptr;
delete mText; delete mText;
mText = nullptr; mText = nullptr;
@@ -49,8 +53,8 @@ void Game::init()
mTicks = 0; mTicks = 0;
mTicksSpeed = 15; mTicksSpeed = 15;
mSection.name = PROG_SECTION_GAME; mSection.name = SECTION_PROG_GAME;
mSection.subsection = GAME_SECTION_PLAY_1P; mSection.subsection = SECTION_GAME_PLAY;
} }
// Carga los recursos necesarios para la sección 'Game' // Carga los recursos necesarios para la sección 'Game'
@@ -69,10 +73,10 @@ section_t Game::run()
{ {
init(); init();
while (mSection.name == PROG_SECTION_GAME) while (mSection.name == SECTION_PROG_GAME)
{ {
// Sección juego jugando // Sección juego jugando
if ((mSection.subsection == GAME_SECTION_PLAY_1P) || (mSection.subsection == GAME_SECTION_PLAY_2P)) if (mSection.subsection == SECTION_GAME_PLAY)
{ {
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - mTicks > mTicksSpeed) if (SDL_GetTicks() - mTicks > mTicksSpeed)
@@ -86,7 +90,7 @@ section_t Game::run()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT) if (mEventHandler->type == SDL_QUIT)
{ {
mSection.name = PROG_SECTION_QUIT; mSection.name = SECTION_PROG_QUIT;
break; break;
} }
} }
@@ -102,7 +106,7 @@ section_t Game::run()
mText->write(0, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), std::to_string(GAMECANVAS_HEIGHT), -1); mText->write(0, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), std::to_string(GAMECANVAS_HEIGHT), -1);
// Texto en el centro de la pantalla // Texto en el centro de la pantalla
mText->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), "Pepe el Cazavampiros", -1); mText->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), "New JailGame", -1);
// Actualiza la pantalla // Actualiza la pantalla
mScreen->blit(); mScreen->blit();

View File

@@ -15,6 +15,7 @@
#include "lang.h" #include "lang.h"
#include "screen.h" #include "screen.h"
#include "asset.h" #include "asset.h"
#include "map.h"
#include "jail_audio.h" #include "jail_audio.h"
#ifndef GAME_H #ifndef GAME_H
@@ -26,7 +27,8 @@ class Game
private: private:
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Event *mEventHandler; // Manejador de eventos SDL_Event *mEventHandler; // Manejador de eventos
Screen *mScreen; // El objeto encargado de manejar el renderizador Screen *mScreen; // Objeto encargado de manejar el renderizador
Map *mMap; // Objeto encargado de gestionar el mapa del juego
Asset *mAsset; // Objeto con la ruta a todos los ficheros de recursos Asset *mAsset; // Objeto con la ruta a todos los ficheros de recursos
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
Input *mInput; // Manejador de entrada Input *mInput; // Manejador de entrada
@@ -45,7 +47,7 @@ private:
public: public:
// Constructor // Constructor
Game(SDL_Window *window,SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input); Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input);
// Destructor // Destructor
~Game(); ~Game();

11
source/map.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include "Map.h"
// Constructor
Map::Map()
{
}
// Destructor
Map::~Map()
{
}

22
source/map.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include "ifdefs.h"
#include <string>
#include <vector>
#ifndef MAP_H
#define MAP_H
// Clase Map
class Map
{
private:
public:
// Constructor
Map();
// Destructor
~Map();
};
#endif