├── vigasoco ├── Abad.h ├── Jorge.h ├── Monje.h ├── Bernardo.h ├── Comando.h ├── Comandos.h ├── Jorge.cpp ├── Monje.cpp ├── Objeto.cpp ├── Objeto.h ├── Puerta.h ├── Severino.h ├── Berengario.h ├── Bernardo.cpp ├── Severino.cpp ├── SpriteLuz.h ├── Berengario.cpp ├── GestorFrases.h ├── Personaje.cpp ├── Serializar.cpp ├── SpriteMonje.h ├── EntidadJuego.cpp ├── GestorFrases.cpp ├── FijarOrientacion.cpp ├── FijarOrientacion.h ├── MezcladorSprites.h ├── PergaminoTextos.cpp ├── TransformacionesCamara.h ├── TransformacionesCamara.cpp ├── NormalLoadHandler.h ├── Paleta.h ├── UncompressedLoader.h ├── Guillermo.h ├── DskReader.h ├── sonidos.h ├── ILoader.h ├── LoadHandler.h ├── NormalLoadHandler.cpp ├── Malaquias.h ├── Singleton.h ├── EntidadJuego.h ├── FileLoader.h ├── Vigasoco.h ├── Adso.h ├── UncompressedLoader.cpp ├── GfxData.h ├── Marcador.h ├── Vigasoco.cpp ├── SDLPalette.h ├── SDLPalette.cpp ├── readme.txt ├── RejillaPantalla.h ├── Paleta.cpp ├── AccionesDia.h ├── DskReader.cpp ├── FontManager.h ├── Sprite.h ├── GfxData.cpp ├── PersonajeConIA.h ├── IDrawPlugin.h ├── GameDataEntity.cpp ├── GameDataEntity.h ├── Types.h ├── MotorGrafico.h ├── Personaje.h ├── FileLoader.cpp ├── AbadiaDriver.h ├── Serializar.h ├── Guillermo.cpp ├── InfoJuego.h ├── Pergamino.h ├── GameDriver.cpp ├── GeneradorPantallas.h ├── GameDriver.h ├── BuscadorRutas.h ├── cpc6128.h ├── SpriteLuz.cpp ├── SpriteMonje.cpp ├── Logica.h ├── Juego.h ├── Puerta.cpp ├── Sprite.cpp ├── cpc6128.cpp └── AbadiaDriver.cpp ├── src ├── game.h ├── game.cpp ├── main.cpp ├── configreader.h ├── configreader.cpp └── system.h ├── README.md ├── cmake ├── FindSDL2_ttf.cmake ├── FindSDL2_Image.cmake ├── FindSDL2_Mixer.cmake └── FindSDL2.cmake └── CMakeLists.txt /vigasoco/Abad.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Abad.h -------------------------------------------------------------------------------- /vigasoco/Jorge.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Jorge.h -------------------------------------------------------------------------------- /vigasoco/Monje.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Monje.h -------------------------------------------------------------------------------- /vigasoco/Bernardo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Bernardo.h -------------------------------------------------------------------------------- /vigasoco/Comando.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Comando.h -------------------------------------------------------------------------------- /vigasoco/Comandos.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Comandos.h -------------------------------------------------------------------------------- /vigasoco/Jorge.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Jorge.cpp -------------------------------------------------------------------------------- /vigasoco/Monje.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Monje.cpp -------------------------------------------------------------------------------- /vigasoco/Objeto.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Objeto.cpp -------------------------------------------------------------------------------- /vigasoco/Objeto.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Objeto.h -------------------------------------------------------------------------------- /vigasoco/Puerta.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Puerta.h -------------------------------------------------------------------------------- /vigasoco/Severino.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Severino.h -------------------------------------------------------------------------------- /vigasoco/Berengario.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Berengario.h -------------------------------------------------------------------------------- /vigasoco/Bernardo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Bernardo.cpp -------------------------------------------------------------------------------- /vigasoco/Severino.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Severino.cpp -------------------------------------------------------------------------------- /vigasoco/SpriteLuz.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/SpriteLuz.h -------------------------------------------------------------------------------- /vigasoco/Berengario.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Berengario.cpp -------------------------------------------------------------------------------- /vigasoco/GestorFrases.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/GestorFrases.h -------------------------------------------------------------------------------- /vigasoco/Personaje.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Personaje.cpp -------------------------------------------------------------------------------- /vigasoco/Serializar.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/Serializar.cpp -------------------------------------------------------------------------------- /vigasoco/SpriteMonje.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/SpriteMonje.h -------------------------------------------------------------------------------- /vigasoco/EntidadJuego.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/EntidadJuego.cpp -------------------------------------------------------------------------------- /vigasoco/GestorFrases.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/GestorFrases.cpp -------------------------------------------------------------------------------- /vigasoco/FijarOrientacion.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/FijarOrientacion.cpp -------------------------------------------------------------------------------- /vigasoco/FijarOrientacion.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/FijarOrientacion.h -------------------------------------------------------------------------------- /vigasoco/MezcladorSprites.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/MezcladorSprites.h -------------------------------------------------------------------------------- /vigasoco/PergaminoTextos.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/PergaminoTextos.cpp -------------------------------------------------------------------------------- /vigasoco/TransformacionesCamara.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/TransformacionesCamara.h -------------------------------------------------------------------------------- /vigasoco/TransformacionesCamara.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samuel85/Abbey/HEAD/vigasoco/TransformacionesCamara.cpp -------------------------------------------------------------------------------- /src/game.h: -------------------------------------------------------------------------------- 1 | #ifndef GAME_H 2 | #define GAME_H 3 | 4 | #include "Vigasoco.h" 5 | 6 | class Game{ 7 | public: 8 | Game(); 9 | ~Game(); 10 | void mainLoop(); 11 | void handleEvents(); 12 | void logic(); 13 | void render(); 14 | 15 | Vigasoco *vigasocosdl; 16 | }; 17 | 18 | #endif -------------------------------------------------------------------------------- /vigasoco/NormalLoadHandler.h: -------------------------------------------------------------------------------- 1 | // NormalLoadHandler.h 2 | // 3 | // Class that handles normal file loading 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _NORMAL_LOAD_HANDLER_H_ 8 | #define _NORMAL_LOAD_HANDLER_H_ 9 | 10 | 11 | #include "LoadHandler.h" 12 | 13 | class GameDataEntity; // defined in GameDataEntity.h 14 | 15 | class NormalLoadHandler : public LoadHandler 16 | { 17 | // methods 18 | public: 19 | NormalLoadHandler(GameDataEntity *gameData); 20 | ~NormalLoadHandler(); 21 | 22 | virtual void loadData(int i, UINT8 *data); 23 | virtual void preProcess(); 24 | virtual void postProcess(); 25 | }; 26 | 27 | #endif // _NORMAL_LOAD_HANDLER_H_ 28 | -------------------------------------------------------------------------------- /vigasoco/Paleta.h: -------------------------------------------------------------------------------- 1 | // Paleta.h 2 | // 3 | // Clase con todos los m�todos relacionados con la paleta 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _PALETA_H_ 8 | #define _PALETA_H_ 9 | 10 | #include "SDLPalette.h" 11 | 12 | class Paleta { 13 | public: 14 | Paleta(UINT8 *gfxVGA); 15 | ~Paleta(); 16 | 17 | SDLPalette *paleta2; // paleta real del juego 18 | void setIntroPalette(); 19 | void setGamePalette(int pal); 20 | 21 | static int introPalette[16]; 22 | static int palettes[4][4]; 23 | UINT8 *PaletasVGA; // Paleta + graficos VGA del remake de PC con 256 colores 24 | static int despPaletasVGA[6]; // a cuantos bytes desde el comienzo de PaletasVGA esta la paleta 25 | }; 26 | 27 | #endif // _PALETA_H_ 28 | -------------------------------------------------------------------------------- /vigasoco/UncompressedLoader.h: -------------------------------------------------------------------------------- 1 | // UncompressedLoader.h 2 | // 3 | // Class to load uncompressed files 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _UNCOMPRESSED_LOADER_H_ 8 | #define _UNCOMPRESSED_LOADER_H_ 9 | 10 | 11 | #include "ILoader.h" 12 | 13 | class UncompressedLoader : public ILoader 14 | { 15 | // fields 16 | protected: 17 | std::string _path; 18 | 19 | // methods 20 | public: 21 | UncompressedLoader(); 22 | virtual ~UncompressedLoader(); 23 | 24 | // loader interface 25 | virtual void open(std::string path, std::string name); 26 | virtual UINT8 *load(std::string fileName, UINT32 fileSize, UINT32 CRC32); 27 | virtual void dispose(UINT8 *ptr); 28 | virtual void close(); 29 | }; 30 | 31 | #endif // _UNCOMPRESSED_LOADER_H_ 32 | -------------------------------------------------------------------------------- /vigasoco/Guillermo.h: -------------------------------------------------------------------------------- 1 | // Guillermo.h 2 | // 3 | // Clase que representa a Guillermo 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _GUILLERMO_H_ 8 | #define _GUILLERMO_H_ 9 | 10 | 11 | #include "Personaje.h" 12 | #include "Types.h" 13 | 14 | 15 | namespace Abadia { 16 | 17 | 18 | class Guillermo : public Personaje 19 | { 20 | // campos 21 | public: 22 | int incrPosY; // incremento de la posici�n y si el estado no es 0 23 | 24 | protected: 25 | static DatosFotograma tablaAnimacion[8]; // tabla con los distintos fotogramas de la animaci�n del personaje 26 | 27 | // m�todos 28 | public: 29 | virtual void run(); 30 | virtual void ejecutaMovimiento(); 31 | 32 | // inicializaci�n y limpieza 33 | Guillermo(Sprite *spr); 34 | virtual ~Guillermo(); 35 | }; 36 | 37 | 38 | } 39 | 40 | #endif // _GUILLERMO_H_ 41 | -------------------------------------------------------------------------------- /vigasoco/DskReader.h: -------------------------------------------------------------------------------- 1 | // DskReader.h 2 | // 3 | // Class to extract data from extended disk images 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _DSK_READER_H_ 8 | #define _DSK_READER_H_ 9 | 10 | 11 | #include "Types.h" 12 | 13 | class DskReader 14 | { 15 | // fields 16 | protected: 17 | UINT8 *_data; // pointer to the disk data 18 | int _numTracks; // number of tracks of the disk 19 | int _numSides; // number of sides of the disk 20 | 21 | bool _isOK; // true if the disk image is valid 22 | 23 | // methods 24 | public: 25 | void getTrackData(int numTrack, UINT8 *buffer, int bufferSize, int &bytesWritten); 26 | 27 | // initialization and cleanup 28 | DskReader(UINT8 *dsk); 29 | ~DskReader(); 30 | 31 | // helper methods 32 | protected: 33 | void checkHeader(); 34 | int getTrackOffset(int numTrack); 35 | }; 36 | 37 | #endif // _DSK_READER_H_ 38 | -------------------------------------------------------------------------------- /vigasoco/sonidos.h: -------------------------------------------------------------------------------- 1 | // SONIDOS.h 2 | // 3 | // This class has helper methods for working with the sounds of the game 4 | // Sorry, using wav, the CPC464 sound is not emulated 5 | // 6 | ///////////////////////////////////////////////////////////////////////////// 7 | 8 | #ifndef _Vigasoco_SONIDOS_H_ 9 | #define _Vigasoco_SONIDOS_H_ 10 | 11 | 12 | 13 | namespace Abadia { 14 | 15 | class SONIDOS { 16 | public: 17 | static const UINT8 Abrir = 0; 18 | static const UINT8 Aporrear = 1; 19 | static const UINT8 Campanas = 2; 20 | static const UINT8 Cerrar = 3; 21 | static const UINT8 Coger = 4; 22 | static const UINT8 Dejar = 5; 23 | static const UINT8 Espejo = 6; 24 | static const UINT8 Final = 7; 25 | static const UINT8 Fondo = 8; 26 | static const UINT8 Inicio = 9; 27 | static const UINT8 Pasos = 10; 28 | static const UINT8 Tintineo = 11; 29 | }; 30 | 31 | } // namespace Abadia 32 | 33 | #endif // _Vigasoco_SONIDOS_H_ 34 | -------------------------------------------------------------------------------- /src/game.cpp: -------------------------------------------------------------------------------- 1 | #include "game.h" 2 | #include "system.h" 3 | 4 | Game::Game() 5 | { 6 | vigasocosdl = new Vigasoco(); 7 | 8 | if (!vigasocosdl->init()){ 9 | vigasocosdl->end(); 10 | return; 11 | } 12 | } 13 | 14 | Game::~Game() 15 | { 16 | } 17 | 18 | void Game::mainLoop() 19 | { 20 | while(!sys->exit) 21 | { 22 | auto frameTime = SDL_GetTicks(); 23 | 24 | handleEvents(); 25 | logic(); 26 | render(); 27 | 28 | //cap the frame rate 29 | if (SDL_GetTicks() - frameTime < sys->minimumFrameTime){ 30 | SDL_Delay(sys->minimumFrameTime - (SDL_GetTicks() - frameTime)); 31 | } 32 | } 33 | } 34 | 35 | void Game::handleEvents() 36 | { 37 | sys->handleEvents(); 38 | 39 | if (sys->pad.start){ 40 | vigasocosdl->changeState(MENU); 41 | sys->pad.start = false; 42 | } 43 | } 44 | 45 | void Game::logic() 46 | { 47 | if (sys->informationMode){ 48 | vigasocosdl->toggleInformationMode(); 49 | sys->informationMode = false; 50 | } 51 | vigasocosdl->mainLoop(); 52 | } 53 | 54 | void Game::render() 55 | { 56 | sys->updateScreen(); 57 | } -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #if VITA 3 | #define VITASDK 4 | #endif 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "system.h" 12 | #include "game.h" 13 | 14 | #if VITA 15 | #include 16 | #endif 17 | 18 | 19 | #define SAVE_DIR "/usr/local/home/Abbey/" 20 | #define VITA_SAVE_DIR "ux0:data/Abbey" 21 | 22 | void checkSaveDirectory() 23 | { 24 | #if RG350 25 | DIR* dir = opendir(SAVE_DIR); 26 | if (dir) { 27 | closedir(dir); 28 | } 29 | else if (ENOENT == errno){ 30 | 31 | mkdir(SAVE_DIR, 0700); 32 | } 33 | #endif 34 | 35 | #if VITA 36 | struct SceIoStat * dirStat = (SceIoStat*)malloc(sizeof(SceIoStat)); 37 | if(sceIoGetstat(VITA_SAVE_DIR , dirStat) < 0){ 38 | sceIoMkdir(VITA_SAVE_DIR, 0777); 39 | } 40 | free(dirStat); 41 | #endif 42 | } 43 | 44 | int main(int argc, char* argv[]) 45 | { 46 | #if defined(VITA) || defined(RG350) 47 | checkSaveDirectory(); 48 | #endif 49 | 50 | Game *game = new Game(); 51 | sys->init(); 52 | game->mainLoop(); 53 | sys->quit(); 54 | return 0; 55 | } -------------------------------------------------------------------------------- /src/configreader.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIGREADER_H_ 2 | #define _CONFIGREADER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | class ConfigReader { 14 | public: 15 | explicit ConfigReader(string fileName) : filename(std::move(fileName)) {} 16 | 17 | // clear content 18 | ~ConfigReader() { data.clear(); } 19 | 20 | // This method returns true if the file contains data. 21 | bool parse(); 22 | 23 | std::map &getData() { return data; } 24 | 25 | // Read/Write values for an existing token 26 | std::string &operator[](const std::string &token) { return data[token]; } 27 | 28 | std::string &getValue(const std::string &token) { return data[token]; } 29 | 30 | void setValue(const std::string &token, const std::string &value) { 31 | data[token] = value; 32 | } 33 | 34 | bool isEmpty(); 35 | 36 | // Save 37 | // void Save(); 38 | 39 | private: 40 | std::map data; 41 | std::string filename; 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /vigasoco/ILoader.h: -------------------------------------------------------------------------------- 1 | // ILoader.h 2 | // 3 | // Abstract class that defines the interface for all loaders 4 | // 5 | // A loader is used like this: 6 | // * open is called in order to do any necessary intialization when opening 7 | // a file or folder (for example, reading a zip header). 8 | // * load is called once for each file to load. Load should return 0 if 9 | // it can't load the file, or a pointer to the allocated memory (the 10 | // memory should be deallocated by the caller). 11 | // * if the file was loaded, dispose will be called. 12 | // * close is called in order to do any necessary cleanup. 13 | // 14 | ///////////////////////////////////////////////////////////////////////////// 15 | 16 | #ifndef _ILOADER_H_ 17 | #define _ILOADER_H_ 18 | 19 | 20 | #include 21 | #include "Types.h" 22 | 23 | class ILoader 24 | { 25 | // methods 26 | public: 27 | ILoader(){} 28 | virtual ~ILoader(){} 29 | 30 | virtual void open(std::string path, std::string name) = 0; 31 | virtual UINT8 *load(std::string fileName, UINT32 fileSize, UINT32 CRC32) = 0; 32 | virtual void dispose(UINT8 *ptr) = 0; 33 | virtual void close() = 0; 34 | }; 35 | 36 | #endif // _ILOADER_H_ 37 | -------------------------------------------------------------------------------- /vigasoco/LoadHandler.h: -------------------------------------------------------------------------------- 1 | // LoadHandler.h 2 | // 3 | // Abstract class that defines the interface of a handler to load files 4 | // 5 | // A loader handler is used like this: 6 | // * preProcess is called before any file has been loaded in order to do 7 | // any specific pre processing. 8 | // * load is called once for each file. The handler has to update the internal 9 | // game data entity memory copying the file data. 10 | // * postProcess is called after all files have been loaded in order to do 11 | // any specific post processing. 12 | // 13 | ///////////////////////////////////////////////////////////////////////////// 14 | 15 | #ifndef _LOAD_HANDLER_H_ 16 | #define _LOAD_HANDLER_H_ 17 | 18 | #include "Types.h" 19 | 20 | class GameDataEntity; // defined in GameDataEntity.h 21 | 22 | class LoadHandler 23 | { 24 | // fields 25 | protected: 26 | GameDataEntity *_gameData; 27 | 28 | // methods 29 | public: 30 | LoadHandler(GameDataEntity *gameData){ _gameData = gameData; } 31 | virtual ~LoadHandler(){} 32 | 33 | virtual void loadData(int i, UINT8 *data) = 0; 34 | virtual void preProcess() = 0; 35 | virtual void postProcess() = 0; 36 | }; 37 | 38 | #endif // _LOAD_HANDLER_H_ 39 | -------------------------------------------------------------------------------- /vigasoco/NormalLoadHandler.cpp: -------------------------------------------------------------------------------- 1 | // NormalLoadHandler.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "GameDataEntity.h" 6 | #include "NormalLoadHandler.h" 7 | 8 | //para memset 9 | #include 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // initialization and cleanup 13 | ///////////////////////////////////////////////////////////////////////////// 14 | 15 | NormalLoadHandler::NormalLoadHandler(GameDataEntity *gameData) : LoadHandler(gameData) 16 | { 17 | } 18 | 19 | NormalLoadHandler::~NormalLoadHandler() 20 | { 21 | } 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // data manipulation 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | void NormalLoadHandler::loadData(int i, UINT8 *data) 28 | { 29 | const GameFile *gf = _gameData->getFile(i); 30 | 31 | // copy loaded data to the GameDataEntity buffer 32 | UINT8 *dest = _gameData->getData(); 33 | memcpy(&dest[gf->baseAddress], data, gf->fileSize); 34 | } 35 | 36 | void NormalLoadHandler::preProcess() 37 | { 38 | } 39 | 40 | void NormalLoadHandler::postProcess() 41 | { 42 | } 43 | -------------------------------------------------------------------------------- /vigasoco/Malaquias.h: -------------------------------------------------------------------------------- 1 | // Malaquias.h 2 | // 3 | // Clase que representa a Malaqu�as 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _MALAQUIAS_H_ 8 | #define _MALAQUIAS_H_ 9 | 10 | #include 11 | #include "Monje.h" 12 | 13 | namespace Abadia { 14 | 15 | 16 | class Malaquias : public Monje 17 | { 18 | // campos 19 | public: 20 | int estaMuerto; // indica si el personaje est� muerto o muri�ndose 21 | int estado2; // guarda informaci�n extra sobre el estado del personaje 22 | 23 | protected: 24 | int contadorEnScriptorium; // indica el tiempo que guillermo est� sin salir del scriptorium 25 | static PosicionJuego posicionesPredef[9]; // posiciones a las que puede ir el personaje seg�n el estado 26 | 27 | // m�todos 28 | public: 29 | void piensa() override; 30 | 31 | // inicializaci�n y limpieza 32 | explicit Malaquias(SpriteMonje *spr); 33 | ~Malaquias() override = default; 34 | 35 | // cargar/salvar 36 | friend std::ofstream& operator<<(std::ofstream&,const Malaquias* const); 37 | friend std::ifstream& operator>>(std::ifstream&,Malaquias* const); 38 | 39 | protected: 40 | void avanzaAnimacionOMueve() override; 41 | }; 42 | 43 | 44 | } 45 | 46 | #endif // _MALAQUIAS_H_ 47 | -------------------------------------------------------------------------------- /vigasoco/Singleton.h: -------------------------------------------------------------------------------- 1 | // Singleton.h 2 | // 3 | // Automatic singleton utility class (Singleton pattern) 4 | // (Presented by Scott Bilas in Game Programming Gems) 5 | // 6 | // How to use it: class MySingleton: public Singleton 7 | // 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef _SINGLETON_H_ 11 | #define _SINGLETON_H_ 12 | 13 | #ifdef _MSC_VER 14 | #pragma warning (disable : 4311) 15 | #pragma warning (disable : 4312) 16 | #endif 17 | 18 | #include 19 | 20 | 21 | template 22 | class Singleton 23 | { 24 | static T *g_singleton; // the singleton object 25 | 26 | // methods 27 | public: 28 | // constructor 29 | Singleton() 30 | { 31 | assert(!g_singleton); 32 | 33 | // get the correct pointer in case of multiple inheritance 34 | g_singleton = static_cast(this); 35 | } 36 | 37 | // destructor 38 | ~Singleton() 39 | { 40 | assert(g_singleton != 0); 41 | 42 | g_singleton = 0; 43 | } 44 | 45 | // getters 46 | static T& getSingleton() { assert(g_singleton); return *g_singleton; } 47 | static T *getSingletonPtr() { return g_singleton; } 48 | }; 49 | 50 | 51 | template T* Singleton::g_singleton = 0; 52 | 53 | 54 | #endif // _SINGLETON_H_ 55 | -------------------------------------------------------------------------------- /src/configreader.cpp: -------------------------------------------------------------------------------- 1 | #include "configreader.h" 2 | 3 | bool ConfigReader::parse() 4 | { 5 | bool r = false; 6 | ifstream f(filename); 7 | std::string line; 8 | 9 | if (f.is_open()) 10 | { 11 | r = true; 12 | while(!f.eof()) 13 | { 14 | // Get new line and ignore empty lines 15 | getline(f >> std::ws ,line); 16 | 17 | if ((line.at(0) != '#') && (line.at(0) != ' ')) 18 | { 19 | // Remove spaces 20 | line.erase(remove(line.begin(), line.end(), ' '), line.end()); 21 | 22 | // find the delimiter 23 | auto delimiterPosition = line.find('='); 24 | 25 | // get token and value 26 | auto token = line.substr(0, delimiterPosition); 27 | auto value = line.substr(delimiterPosition+1,line.length()); 28 | 29 | // store it 30 | data.insert(make_pair(token, value)); 31 | 32 | } 33 | } 34 | } 35 | else { 36 | std::cout << "Can't open:" << filename << std::endl; 37 | } 38 | f.close(); 39 | 40 | return r; 41 | } 42 | 43 | bool ConfigReader::isEmpty(){ 44 | return data.empty(); 45 | } 46 | -------------------------------------------------------------------------------- /vigasoco/EntidadJuego.h: -------------------------------------------------------------------------------- 1 | // EntidadJuego.h 2 | // 3 | // Clase abstracta que representa una entidad del juego 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _ENTIDAD_JUEGO_H_ 8 | #define _ENTIDAD_JUEGO_H_ 9 | 10 | namespace Abadia { 11 | 12 | 13 | enum Orientacion { 14 | DERECHA = 0, // hacia +x 15 | ABAJO = 1, // hacia -y 16 | IZQUIERDA = 2, // hacia -x 17 | ARRIBA = 3 // hacia +y 18 | }; 19 | 20 | class PosicionJuego 21 | { 22 | public: 23 | int orientacion; // orientaci�n de la posici�n en el mundo 24 | int posX; // posici�n x en coordenadas de mundo 25 | int posY; // posici�n y en coordenadas de mundo 26 | int altura; // altura en coordenadas de mundo 27 | 28 | PosicionJuego(); 29 | PosicionJuego(int ori, int pX, int pY, int alt); 30 | virtual ~PosicionJuego(); 31 | }; 32 | 33 | class Sprite; // definido en Sprite.h 34 | 35 | class EntidadJuego : public PosicionJuego 36 | { 37 | // campos 38 | public: 39 | Sprite *sprite; // sprite asociado a la entidad 40 | 41 | // m�todos: 42 | public: 43 | virtual void cambioPantalla(){} 44 | virtual void notificaVisibleEnPantalla(int posXPant, int posYPant, int profundidad) = 0; 45 | 46 | // inicializaci�n y limpieza 47 | EntidadJuego(Sprite *spr); 48 | virtual ~EntidadJuego(); 49 | }; 50 | 51 | 52 | } 53 | 54 | #endif // _ENTIDAD_JUEGO_H_ 55 | -------------------------------------------------------------------------------- /vigasoco/FileLoader.h: -------------------------------------------------------------------------------- 1 | // FileLoader.h 2 | // 3 | // Singleton class that loads game data entities. The class has a collection of 4 | // loaders that can try to load the collection of files in a specific format 5 | // (uncompressed, .zip, .rar, etc). The FileLoader also has multiple path support. 6 | // 7 | // By default, the only loader is the UncompressedLoader and the path is "roms". 8 | // 9 | ///////////////////////////////////////////////////////////////////////////// 10 | 11 | #ifndef _FILE_LOADER_H_ 12 | #define _FILE_LOADER_H_ 13 | 14 | #include 15 | #include 16 | #include "Singleton.h" 17 | #include "Types.h" 18 | 19 | class GameDataEntity; // defined in GameDataEntity.h 20 | class ILoader; // defined in ILoader.h 21 | 22 | //#define theFileLoader FileLoader::getSingletonPtr() 23 | 24 | //class FileLoader : public Singleton 25 | class FileLoader 26 | { 27 | // types 28 | protected: 29 | typedef std::list Loaders; 30 | typedef std::list Paths; 31 | 32 | // fields 33 | protected: 34 | Loaders _loaders; // collection of loaders 35 | Paths _paths; // collection of paths to search the files 36 | 37 | // methods 38 | public: 39 | FileLoader(); 40 | ~FileLoader(); 41 | 42 | void addLoader(ILoader *l); 43 | void removeLoader(ILoader *l); 44 | void addPath(std::string path); 45 | 46 | bool loadGameData(std::string game, GameDataEntity *gde); 47 | }; 48 | 49 | #endif // _FILE_LOADER_H_ 50 | -------------------------------------------------------------------------------- /vigasoco/Vigasoco.h: -------------------------------------------------------------------------------- 1 | // VIGASOCO Project (c) 2003-2005 by VIGASOCO Project Team 2 | // 3 | // See readme.txt for license and usage information. 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | // Vigasoco.h 8 | // 9 | // Abstract class that defines the structure of a VIGASOCO port. 10 | // 11 | // All ports should inherit from this class. This class defines some template 12 | // methods in order to provide a common main loop for a VIGASOCO port. 13 | // 14 | ///////////////////////////////////////////////////////////////////////////// 15 | 16 | #ifndef _VIGASOCO_H_ 17 | #define _VIGASOCO_H_ 18 | 19 | #include 20 | 21 | #include "Singleton.h" 22 | #include "SDLPalette.h" 23 | #include "GameDriver.h" 24 | 25 | #define VigasocoMain Vigasoco::getSingletonPtr() 26 | 27 | class Vigasoco : public Singleton 28 | { 29 | // fields 30 | protected: 31 | GameDriver *_driver; 32 | SDLPalette *_palette; 33 | 34 | // methods 35 | public: 36 | // initialization and cleanup 37 | Vigasoco(); 38 | virtual ~Vigasoco(); 39 | virtual bool init(); 40 | virtual void end(); 41 | virtual void mainLoop(); 42 | 43 | GameDriver *getDriver() const { return _driver; } 44 | SDLPalette *getPalette() const { return _palette; } 45 | 46 | void toggleInformationMode(); 47 | void showMenu(); 48 | void changeState(int newState); 49 | 50 | GameDriver *createGameDriver(std::string game); 51 | }; 52 | 53 | #endif // _VIGASOCO_H_ 54 | 55 | -------------------------------------------------------------------------------- /vigasoco/Adso.h: -------------------------------------------------------------------------------- 1 | // Adso.h 2 | // 3 | // Clase que representa a Adso 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _ADSO_H_ 8 | #define _ADSO_H_ 9 | 10 | 11 | #include "Types.h" 12 | #include "PersonajeConIA.h" 13 | 14 | namespace Abadia { 15 | 16 | 17 | class Adso : public PersonajeConIA 18 | { 19 | // campos 20 | public: 21 | int oldEstado; // indica el estado anterior de adso 22 | int movimientosFrustados; // indica el n�mero de movimientos frustados del personaje 23 | int cntParaDormir; // contador para controlar el tiempo transcurrido desde que se le pregunta a guillermo si duermen 24 | 25 | protected: 26 | static DatosFotograma tablaAnimacion[8]; // tabla con los distintos fotogramas de la animaci�n del personaje 27 | static PosicionJuego posicionesPredef[3]; // posiciones a las que puede ir el personaje seg�n el estado 28 | 29 | static int oriMovimiento[8][4]; // tabla con las orientaciones para probar movimientos 30 | static int despBufferSegunOri[4][2]; // tabla de desplzamientos dentro del buffer de alturas seg�n la orientaci�n 31 | 32 | // m�todos 33 | public: 34 | virtual void run(); 35 | virtual void piensa(); 36 | 37 | // inicializaci�n y limpieza 38 | Adso(Sprite *spr); 39 | virtual ~Adso(); 40 | 41 | // m�todos de ayuda 42 | protected: 43 | void escribeSN(bool muestra); 44 | void grabaComandosAvance(int nuevaOri); 45 | void avanzaSegunGuillermo(); 46 | void liberaPasoAGuillermo(); 47 | void pruebaMover(int numEntrada); 48 | }; 49 | 50 | 51 | } 52 | 53 | #endif // _ADSO_H_ 54 | -------------------------------------------------------------------------------- /vigasoco/UncompressedLoader.cpp: -------------------------------------------------------------------------------- 1 | // UncompressedLoader.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | #include "UncompressedLoader.h" 7 | #include "system.h" 8 | 9 | #ifdef ANDROID 10 | #include 11 | #include 12 | #endif 13 | ///////////////////////////////////////////////////////////////////////////// 14 | // initialization and cleanup 15 | ///////////////////////////////////////////////////////////////////////////// 16 | 17 | UncompressedLoader::UncompressedLoader() 18 | { 19 | } 20 | 21 | UncompressedLoader::~UncompressedLoader() 22 | { 23 | } 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // data loading 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | void UncompressedLoader::open(std::string path, std::string name) 30 | { 31 | _path = path + "/" + name + "/"; 32 | } 33 | 34 | UINT8 *UncompressedLoader::load(std::string fileName, UINT32 fileSize, UINT32 CRC32) 35 | { 36 | UINT8 *ptr = new UINT8[fileSize]; 37 | std::string fname = _path + fileName; 38 | SDL_RWops *rw = SDL_RWFromFile(fname.c_str(),"r"); 39 | if (rw == NULL) { 40 | sys->print("Unable to load file\n"); 41 | } 42 | else 43 | { 44 | SDL_RWread(rw, ptr, fileSize, 1); 45 | SDL_RWclose(rw); 46 | } 47 | 48 | return ptr; 49 | } 50 | 51 | void UncompressedLoader::dispose(UINT8 *ptr) 52 | { 53 | delete[] ptr; 54 | } 55 | 56 | void UncompressedLoader::close() 57 | { 58 | _path = ""; 59 | } 60 | -------------------------------------------------------------------------------- /vigasoco/GfxData.h: -------------------------------------------------------------------------------- 1 | // GfxData.h 2 | // 3 | // Structures and classes to manipulate data and decode graphics 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _GFX_DATA_H_ 8 | #define _GFX_DATA_H_ 9 | 10 | #include 11 | #include "Types.h" 12 | 13 | // struct used to decode graphics 14 | struct GfxEncoding { 15 | int sizeX, sizeY; 16 | int numEntries; 17 | int bpp; 18 | UINT32 planeOffsets[8]; 19 | int xOffs[32]; 20 | int yOffs[32]; 21 | int entryBitSize; 22 | 23 | static GfxEncoding *clone(GfxEncoding *g); 24 | }; 25 | 26 | // sprite attributes 27 | enum SpriteAttr { 28 | NO_FLIP = 0, 29 | FLIP_X, 30 | FLIP_Y, 31 | FLIP_XY, // = FLIP_X | FLIP_Y 32 | TRANSPARENCY_PEN = 0x80, 33 | TRANSPARENCY_COLOR = 0x100 34 | }; 35 | 36 | // struct used to draw decoded graphics 37 | struct GfxElement { 38 | int sizeX, sizeY; 39 | int numEntries; 40 | UINT32 entrySize; 41 | int bpp; 42 | UINT8 **data; 43 | 44 | GfxElement(){ data = 0; } 45 | ~GfxElement(){ 46 | if (data){ 47 | for (int i = 0; i < 4; i++){ 48 | delete[] data[i]; 49 | } 50 | delete[] data; 51 | } 52 | } 53 | }; 54 | 55 | // class to decode graphics 56 | class GfxDecoder 57 | { 58 | public: 59 | // decodes graphics 60 | static GfxElement *decode(const struct GfxEncoding *enc, const UINT8 *pRawGfx); 61 | 62 | protected: 63 | // check if a bit is set. Bit order is 01234567 instead of the usual 76543210 64 | static inline bool isBitSet(const UINT8 *ptr, int bit) 65 | { 66 | return (ptr[bit >> 3] & (0x80 >> (bit & 0x07))) != 0; 67 | } 68 | 69 | private: 70 | GfxDecoder(); 71 | ~GfxDecoder(); 72 | }; 73 | 74 | #endif // _GFX_DATA_H_ 75 | -------------------------------------------------------------------------------- /vigasoco/Marcador.h: -------------------------------------------------------------------------------- 1 | // Marcador.h 2 | // 3 | // Clase que encapsula las acciones relacionadas con el marcador 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _MARCADOR_H_ 8 | #define _MARCADOR_H_ 9 | 10 | 11 | #include 12 | #include "Singleton.h" 13 | 14 | class CPC6128; // definido en CPC6128.h 15 | 16 | namespace Abadia { 17 | 18 | #define elMarcador Marcador::getSingletonPtr() 19 | 20 | class Marcador : public Singleton 21 | { 22 | // campos 23 | public: 24 | CPC6128 *cpc6128; // objeto que presta ayuda para realizar operaciones gr?ficas del cpc6128 25 | UINT8 *roms; // puntero a las roms originales 26 | 27 | int numPosScrollDia; // n?mero de posiciones para completar el scroll del nombre del d?a 28 | UINT8 *nombreMomentoDia; // apunta al nombre del momento actual del d?a 29 | 30 | protected: 31 | static int duracionEtapasDia[7][7]; 32 | 33 | // m?todos 34 | public: 35 | void dibujaMarcador(); 36 | void limpiaAreaMarcador(); 37 | void limpiaAreaFrases(); 38 | void dibujaObjetos(int objetos, int mascara); 39 | 40 | void muestraDiaYMomentoDia(); 41 | void avanzaMomentoDia(); 42 | void realizaScrollMomentoDia(); 43 | 44 | void decrementaObsequium(int unidades); 45 | 46 | void imprimeFrase(std::string frase, int x, int y, int colorTexto, int colorFondo); 47 | void imprimirCaracter(int caracter, int x, int y, int colorTexto, int colorFondo); 48 | 49 | // inicializaci?n y limpieza 50 | Marcador(); 51 | ~Marcador(); 52 | 53 | protected: 54 | void dibujaDia(int numDia); 55 | void dibujaDigitoDia(int digito, int x, int y); 56 | void dibujaBarra(int lgtud, int color, int x, int y); 57 | }; 58 | 59 | 60 | } 61 | 62 | #endif // _MARCADOR_H_ 63 | -------------------------------------------------------------------------------- /vigasoco/Vigasoco.cpp: -------------------------------------------------------------------------------- 1 | // Vigasoco.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | 7 | #include "Vigasoco.h" 8 | #include "AbadiaDriver.h" 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // initialization and cleanup 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | Vigasoco::Vigasoco() 15 | { 16 | _driver = 0; 17 | _palette = 0; 18 | } 19 | 20 | Vigasoco::~Vigasoco() 21 | { 22 | } 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // init 26 | ///////////////////////////////////////////////////////////////////////////// 27 | bool Vigasoco::init() 28 | { 29 | _palette = new SDLPalette(); 30 | 31 | // creates the game driver 32 | _driver = createGameDriver("abadia"); 33 | 34 | if (!_driver) return false; 35 | 36 | // inits the game driver (load files, decode gfx, preprocessing, etc) 37 | if (!_driver->init(_palette)) return false; 38 | 39 | // calls template method to perform specific actions after initialization has been completed 40 | _driver->preRun(); 41 | 42 | return true; 43 | } 44 | 45 | void Vigasoco::end() 46 | { 47 | delete _palette; 48 | _palette = 0; 49 | } 50 | 51 | void Vigasoco::mainLoop() 52 | { 53 | _driver->runAsync(); 54 | _driver->runSync(); 55 | _driver->render(); 56 | } 57 | 58 | GameDriver * Vigasoco::createGameDriver(std::string game) 59 | { 60 | // TODO: move this to a factory 61 | return new AbadiaDriver(); 62 | } 63 | 64 | void Vigasoco::toggleInformationMode() 65 | { 66 | _driver->showGameLogic(); 67 | } 68 | 69 | void Vigasoco::showMenu() 70 | { 71 | _driver->showMenu(); 72 | } 73 | 74 | void Vigasoco::changeState(int newState) 75 | { 76 | _driver->changeState(newState); 77 | } -------------------------------------------------------------------------------- /vigasoco/SDLPalette.h: -------------------------------------------------------------------------------- 1 | // SDLPalette.h 2 | // 3 | // The one and the only palette (R, G, B, A. 8 bits per gun) 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _SDL_PALETTE_H_ 8 | #define _SDL_PALETTE_H_ 9 | 10 | 11 | //#include "IPalette.h" 12 | #include "Types.h" 13 | 14 | // Esto solo vale para la version de Vigasoco para Windows 15 | #ifndef __GNUC__ 16 | #pragma pack(push, paletteAlignment) 17 | #pragma pack(1) 18 | #endif 19 | 20 | struct PaletteEntry { 21 | UINT8 B; 22 | UINT8 G; 23 | UINT8 R; 24 | UINT8 alpha; 25 | 26 | PaletteEntry(){} 27 | PaletteEntry(int r, int g, int b) { R = r; G = g; B = b; alpha = 0xff; } 28 | PaletteEntry(int r, int g, int b, int a) { R = r; G = g; B = b; alpha = a; } 29 | } 30 | #ifdef __GNUC__ 31 | __attribute__((packed)) 32 | #endif 33 | ; 34 | 35 | // Esto solo vale para la version de Vigasoco para Windows 36 | #ifndef __GNUC__ 37 | #pragma pack(pop, paletteAlignment) 38 | #endif 39 | 40 | 41 | // the palette is a Singleton and a Notification Provider 42 | class SDLPalette //: public IPalette 43 | { 44 | // fields 45 | public: 46 | int _colors; // total number of colors 47 | PaletteEntry *_palette; // pointer to color entries 48 | 49 | // methods: 50 | 51 | // initialization and cleanup 52 | SDLPalette(); 53 | virtual ~SDLPalette(); 54 | virtual void init(int colors); 55 | virtual void end(); 56 | 57 | // IPalette interface getters & setters 58 | virtual int getTotalColors() const { return _colors; } 59 | virtual void setColor(int index, UINT8 r, UINT8 g, UINT8 b); 60 | virtual void getColor(int index, UINT8 &r, UINT8 &g, UINT8 &b); 61 | 62 | // custom getters & setters 63 | void setColor(int index, PaletteEntry pe); 64 | PaletteEntry getColor(int index) const; 65 | PaletteEntry *getPalette() const { return _palette; } 66 | virtual UINT8* getRawPalette() { return (UINT8 *)_palette; } 67 | }; 68 | 69 | 70 | #endif // _SDL_PALETTE_H_ 71 | -------------------------------------------------------------------------------- /vigasoco/SDLPalette.cpp: -------------------------------------------------------------------------------- 1 | // SDLPalette.cpp 2 | // 3 | // Es una copia de Win32Palette de VigasocoWin32 4 | // , quizas deberia usar las definiciones de paletas y colores de SDL 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #include 8 | #include "SDLPalette.h" 9 | 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // initialization and cleanup 13 | ///////////////////////////////////////////////////////////////////////////// 14 | 15 | SDLPalette::SDLPalette() 16 | { 17 | _palette = 0; 18 | _colors = 0; 19 | } 20 | 21 | SDLPalette::~SDLPalette() 22 | { 23 | } 24 | 25 | void SDLPalette::init(int colors) 26 | { 27 | assert(_palette == 0); 28 | _palette = new PaletteEntry[colors]; 29 | _colors = colors; 30 | } 31 | 32 | void SDLPalette::end() 33 | { 34 | delete[] _palette; 35 | } 36 | 37 | ///////////////////////////////////////////////////////////////////////////// 38 | // getters & setters 39 | ///////////////////////////////////////////////////////////////////////////// 40 | 41 | void SDLPalette::setColor(int index, UINT8 r, UINT8 g, UINT8 b) 42 | { 43 | assert((index >= 0) && (index < _colors)); 44 | 45 | _palette[index].R = r; 46 | _palette[index].G = g; 47 | _palette[index].B = b; 48 | _palette[index].alpha = 0xff; 49 | 50 | //notify(index); 51 | } 52 | 53 | void SDLPalette::getColor(int index, UINT8 &r, UINT8 &g, UINT8 &b) 54 | { 55 | assert((index >= 0) && (index < _colors)); 56 | 57 | r = _palette[index].R; 58 | g = _palette[index].G; 59 | b = _palette[index].B; 60 | } 61 | 62 | void SDLPalette::setColor(int index, PaletteEntry pe) 63 | { 64 | assert((index >= 0) && (index < _colors)); 65 | 66 | _palette[index].R = pe.R; 67 | _palette[index].G = pe.G; 68 | _palette[index].B = pe.B; 69 | _palette[index].alpha = pe.alpha; 70 | 71 | //notify(index); 72 | } 73 | 74 | PaletteEntry SDLPalette::getColor(int index) const 75 | { 76 | //assert((index >= 0) && (index < _colors)); 77 | 78 | return _palette[index]; 79 | } 80 | -------------------------------------------------------------------------------- /vigasoco/readme.txt: -------------------------------------------------------------------------------- 1 | VIGASOCO (VIdeo GAmes SOurce COde) (v0.02) 2 | 3 | Copyright (c) 2003-2005 "VIGASOCO Project Team" 4 | 5 | About: 6 | ====== 7 | 8 | VIGASOCO is a framework designed to understand how classic games worked. Its main purpose 9 | is to be a learning tool of the internal working of classic games. The games that VIGASOCO 10 | runs are "functionally equivalent" conversions from classic games, reverse engineered from 11 | the original code and converted to C/C++. 12 | 13 | As a nice side effect, VIGASOCO source code can be used as starting point to make remakes 14 | of classic games, as a framework to develop your own 2D games, to find cheats in the 15 | original game, to play converted games, etc. 16 | 17 | 18 | License and distribution: 19 | ========================= 20 | 21 | VIGASOCO's intention is not to infringe on any copyright on the original games. No portions 22 | of the original ROM code are included in the executable or the sources. The game logic has 23 | been reverse engineered from scratch to obtain a functionally equivalent conversion in a 24 | high level language. 25 | 26 | VIGASOCO is a free project. Source code is publically available. 27 | You're not allowed to sell VIGASOCO and you can't distribute VIGASOCO with ROM images. 28 | Official VIGASOCO sources and binaries should be distributed only in the original 29 | archives (you can't add or remove files to the archive). 30 | 31 | VIGASOCO's core has been written in C++ and it's platform independent. No portion of the 32 | source can be used in a commercial product without written authorization of the author. 33 | Use of the source code in noncommercial products is allowed, as long as you credit VIGASOCO 34 | somewhere in the documentation of your project. Any derivate work based on a game driver 35 | has to credit the driver author and VIGASOCO. 36 | 37 | Usage: 38 | ====== 39 | See specific port information: 40 | windows port: windows.txt 41 | 42 | 43 | Contact: 44 | ======== 45 | Contact information is available in the source code. 46 | 47 | 48 | Acknowledgments: 49 | ================ 50 | MAME Project (http://www.mame.net) 51 | MESS Project (http://www.mess.org) 52 | PTS (http://www.emulatronia.com) 53 | -------------------------------------------------------------------------------- /vigasoco/RejillaPantalla.h: -------------------------------------------------------------------------------- 1 | // RejillaPantalla.h 2 | // 3 | // Clase que contiene los m�todos para modificar la rejilla de una pantalla 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _REJILLA_PANTALLA_H_ 8 | #define _REJILLA_PANTALLA_H_ 9 | 10 | #include "Types.h" 11 | 12 | namespace Abadia { 13 | 14 | class MotorGrafico; // definido en MotorGrafico.h 15 | class Personaje; // definido en Personaje.h 16 | class PosicionJuego; // definido en EntidadJuego.h 17 | 18 | 19 | class RejillaPantalla 20 | { 21 | // campos 22 | public: 23 | UINT8 *roms; 24 | MotorGrafico *motor; 25 | UINT8 bufAlturas[24][24]; // buffer de alturas de la rejilla (24x24, 1 byte por entrada) 26 | 27 | int minPosX; // m�nimo valor visible en x para recortar (en coordenadas de mundo) 28 | int minPosY; // m�nimo valor visible en y para recortar (en coordenadas de mundo) 29 | int minAltura; // m�nimo altura visible (en coordenadas de mundo) 30 | 31 | int bufCalculoAvance[4][4]; // buffer auxiliar para el c�lculo del avance del personaje 32 | 33 | protected: 34 | // tabla para el c�lculo del avance seg�n las posiciones que ocupa el personaje 35 | static int calculoAvancePosicion[4][8]; 36 | 37 | // m�todos 38 | public: 39 | void rellenaAlturasPantalla(Personaje *pers); 40 | void calculaMinimosValoresVisibles(Personaje *pers); 41 | 42 | bool estaEnRejillaCentral(PosicionJuego *pos, int &posXRejilla, int &posYRejilla); 43 | bool ajustaAPosRejilla(int posX, int posY, int &posXRejilla, int &posYRejilla); 44 | 45 | bool obtenerAlturaPosicionesAvance(Personaje *pers, int &difAltura1, int &difAltura2, int &avanceX, int &avanceY); 46 | bool obtenerAlturaPosicionesAvance2(Personaje *pers, int &difAltura1, int &difAltura2, int &avanceX, int &avanceY); 47 | 48 | RejillaPantalla(MotorGrafico *motorGrafico); 49 | ~RejillaPantalla(); 50 | 51 | // m�todos de ayuda 52 | protected: 53 | bool obtenerAlturaPosicionesAvanceComun(Personaje *pers, int alturaLocal, int &difAltura1, int &difAltura2, int &avanceX, int &avanceY); 54 | void fijaAlturaRecortando(int posX, int posY, int altura); 55 | }; 56 | 57 | 58 | } 59 | 60 | #endif // _REJILLA_PANTALLA_H_ 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Abbey 2 | 3 | This repository contains a new implementation of the classic video game "La abadía del crimen" or "The Abbey of Crime" for pc and the RG350 handheld. 4 | 5 | Based on the great work of Manuel Abadía for the VIGASOCO project, this new version reduces the computational power necessary for the emulation of the inner behavior of the Amstrad CPC on which the original video game was designed, and replace it with modern programming patterns and data structures. While the original VIGASOCO project needed four threads to emulate video, inputs, sound, and the main game, this new version reduces the need to use threads, making it easy to port to low specs machines like the RG350, the Nintendo 3ds, or Android. 6 | 7 | # Updates 8 | * New PS Vita port (March.7.2021). 9 | * New Android port (Dec.28.2020). 10 | 11 | # Status 12 | * At this point, the game is stable, can run smoothly, includes new features in the menu system, and supports Forcefeedback, but more work needs to be done testing the game and fixing new bugs. 13 | 14 | * There is a need to redesign some of the classes inherited from the VIGASOCO project. While the latter was designed to create a framework for the design of games, most of these features are beyond this project's scope, making the maintenance of the code more difficult. 15 | 16 | # Screenshots 17 | # Abbey-vita 18 | # Abbey-Android 19 | # 20201212-140648 20 | 21 | # Note for Android users 22 | * It's necessary to use a controller. 23 | * The apk file (app-debug.apk) of the game will be located inside of app/build/outputs/apk/debug 24 | * If the program doesn't save the progress, it is necessary to assign storage permisions manually. Hold on the game icon->App info->Permissions. 25 | * To compile the game for android, see the Readme.md file located inside of the build_directory folder. 26 | 27 | # Keys for PC users 28 | | Function | Keyboard | 29 | | ------------- |:-------------:| 30 | | Move | Arrow keys | 31 | | Map | 1 | 32 | | Menu | 2 | 33 | | Accept/Yes | Enter | 34 | | No | N | 35 | | Drop Item | Space | 36 | -------------------------------------------------------------------------------- /vigasoco/Paleta.cpp: -------------------------------------------------------------------------------- 1 | // Paleta.cpp 2 | ///////////////////////////////////////////////////////////////////////////// 3 | 4 | #include "Juego.h" 5 | #include "Paleta.h" 6 | 7 | using namespace Abadia; 8 | 9 | ///////////////////////////////////////////////////////////////////////////// 10 | // paletas del juego 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | int Paleta::introPalette[16] = { 07, 20, 11, 03, 06, 12, 04, 21, 13, 05, 14, 29, 00, 28, 31, 27 }; 14 | 15 | int Paleta::palettes[4][4] = { 16 | { 20, 20, 20, 20 }, // paleta negra 17 | { 07, 28, 20, 12 }, // paleta del pergamino 18 | { 06, 14, 03, 20 }, // paleta de d?a durante el juego 19 | { 04, 29, 00, 20 } // paleta de noche durante el juego 20 | }; 21 | 22 | int Paleta::despPaletasVGA[6] = { 23 | -1, // paleta negra , en realidad no la tenemos en fichero y la generamos en codigo 24 | 0xC00, // paleta del pergamino TODO: FALTA POR COMPROBAR QUE ESTA PALETA ES PARA EL PERGAMINO 25 | 0, // paleta de d?a durante el juego 26 | 0x400, // paleta de noche durante el juego 27 | 0x800, // paleta lampara TODO: FALTA HACER CAMBIOS EN EL CODIGO PARA QUE LA USE 28 | 0x1000 // paleta introduccion 29 | }; 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | // inicializaci?n y limpieza 34 | ///////////////////////////////////////////////////////////////////////////// 35 | 36 | Paleta::Paleta(UINT8 *gfxVGA) 37 | { 38 | paleta2 = new SDLPalette(); 39 | paleta2->init(256); 40 | paleta2->setColor(253, 0x00, 0x00, 0x00); 41 | paleta2->setColor(254, 0xff, 0xff, 0xff); 42 | PaletasVGA = gfxVGA; 43 | } 44 | 45 | Paleta::~Paleta() 46 | { 47 | } 48 | 49 | ///////////////////////////////////////////////////////////////////////////// 50 | // m?todos 51 | ///////////////////////////////////////////////////////////////////////////// 52 | 53 | // coloca la paleta de la introducci?n 54 | void Paleta::setIntroPalette() 55 | { 56 | // VGA 57 | 58 | //init(256); 59 | setGamePalette(5); 60 | } 61 | 62 | 63 | // coloca una paleta 64 | void Paleta::setGamePalette(int pal) 65 | { 66 | // VGA 67 | if ( pal==0 ){ 68 | for (int i = 0; i < 256; i++){ 69 | paleta2->setColor(i,0,0,0); 70 | } 71 | } 72 | else{ 73 | UINT8 *p=PaletasVGA; 74 | p+=despPaletasVGA[pal]; 75 | for (int i = 0; i < 256; i++){ 76 | UINT8 r=*p++; 77 | UINT8 g=*p++; 78 | UINT8 b=*p++; 79 | [[maybe_unused]]UINT8 a=*p++; 80 | paleta2->setColor(i,r,g,b); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vigasoco/AccionesDia.h: -------------------------------------------------------------------------------- 1 | // AccionesDia.h 2 | // 3 | // Clase para ejecutar las acciones programadas depnediendo del momento del d�a 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _ACCIONES_DIA_H_ 8 | #define _ACCIONES_DIA_H_ 9 | 10 | 11 | namespace Abadia { 12 | 13 | class AccionesDia; 14 | 15 | class AccionProgramada 16 | { 17 | // m�todos 18 | public: 19 | virtual void ejecuta([[maybe_unused]] AccionesDia *ad) = 0; 20 | 21 | // inicializaci�n y limpieza 22 | AccionProgramada()= default; 23 | virtual ~AccionProgramada()= default; 24 | }; 25 | 26 | class Objeto; // definido en Objeto.h 27 | class Personaje; // definido en Personaje.h 28 | 29 | class AccionesDia 30 | { 31 | // campos 32 | protected: 33 | static AccionProgramada *acciones[7]; // acciones programadas 34 | 35 | // m�todos 36 | public: 37 | void ejecutaAccionesProgramadas(); 38 | void dibujaEfectoEspiral(); 39 | void colocaObjeto(Objeto *obj, int posX, int posY, int altura); 40 | void colocaPersonaje(Personaje *pers, int posX, int posY, int altura, int orientacion); 41 | 42 | // inicializaci�n y limpieza 43 | AccionesDia(); 44 | virtual ~AccionesDia(); 45 | 46 | // m�todos de ayuda 47 | protected: 48 | void dibujaEspiral(int color); 49 | void dibujaBloque(int posX, int posY, int color); 50 | }; 51 | 52 | 53 | class AccionesNoche : public AccionProgramada 54 | { 55 | // m�todos 56 | public: 57 | void ejecuta(AccionesDia *ad) override; 58 | }; 59 | 60 | class AccionesPrima : public AccionProgramada 61 | { 62 | // m�todos 63 | public: 64 | void ejecuta(AccionesDia *ad) override; 65 | }; 66 | 67 | class AccionesTercia : public AccionProgramada 68 | { 69 | // m�todos 70 | public: 71 | void ejecuta(AccionesDia *ad) override; 72 | }; 73 | 74 | class AccionesSexta : public AccionProgramada 75 | { 76 | // m�todos 77 | public: 78 | void ejecuta(AccionesDia *ad) override; 79 | }; 80 | 81 | class AccionesNona : public AccionProgramada 82 | { 83 | // m�todos 84 | public: 85 | void ejecuta(AccionesDia *ad) override; 86 | }; 87 | 88 | class AccionesVisperas : public AccionProgramada 89 | { 90 | // m�todos 91 | public: 92 | void ejecuta(AccionesDia *ad) override; 93 | }; 94 | 95 | class AccionesCompletas : public AccionProgramada 96 | { 97 | // m�todos 98 | public: 99 | void ejecuta(AccionesDia *ad) override; 100 | }; 101 | 102 | 103 | } 104 | 105 | #endif // _ACCIONES_DIA_H_ 106 | -------------------------------------------------------------------------------- /vigasoco/DskReader.cpp: -------------------------------------------------------------------------------- 1 | // DskReader.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | #include 7 | 8 | #include "DskReader.h" 9 | 10 | using namespace std; 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | // initialization and cleanup 14 | ///////////////////////////////////////////////////////////////////////////// 15 | 16 | DskReader::DskReader(UINT8 *dsk) 17 | { 18 | _data = dsk; 19 | 20 | // checks if the data is valid 21 | checkHeader(); 22 | } 23 | 24 | DskReader::~DskReader() 25 | { 26 | } 27 | 28 | ///////////////////////////////////////////////////////////////////////////// 29 | // get track data 30 | ///////////////////////////////////////////////////////////////////////////// 31 | 32 | void DskReader::getTrackData(int numTrack, UINT8 *buffer, int bufferSize, int &bytesWritten) 33 | { 34 | assert(_isOK); 35 | assert((numTrack >= 0) && (numTrack < _numTracks)); 36 | 37 | // gets a pointer to the track's starting address 38 | UINT8 *start = &_data[getTrackOffset(numTrack)]; 39 | 40 | // get track information 41 | int sectorSize = start[0x14]*256; 42 | int numSectors = start[0x15]; 43 | 44 | // check the length of the data to be copied 45 | bytesWritten = numSectors*sectorSize; 46 | 47 | if (numSectors*sectorSize > bufferSize){ 48 | bytesWritten = bufferSize; 49 | } 50 | 51 | // copy all sectors for this track 52 | memcpy(buffer, &start[0x100], bytesWritten); 53 | } 54 | 55 | ///////////////////////////////////////////////////////////////////////////// 56 | // helper methods 57 | ///////////////////////////////////////////////////////////////////////////// 58 | 59 | // check if the header is for an extended cpc dsk file and extract image information 60 | void DskReader::checkHeader() 61 | { 62 | assert(_data != 0); 63 | 64 | UINT8 aux = _data[0x15]; 65 | _data[0x15] = 0; 66 | 67 | // check if it's a valid extended dsk file 68 | if (strcmp((const char *)&_data[0], "EXTENDED CPC DSK File") != 0){ 69 | _isOK = false; 70 | 71 | return; 72 | } 73 | 74 | _data[0x15] = aux; 75 | 76 | // get disk information 77 | _numTracks = _data[0x30]; 78 | _numSides = _data[0x31]; 79 | 80 | _isOK = true; 81 | } 82 | 83 | // gets the starting offset for a track 84 | int DskReader::getTrackOffset(int numTrack) 85 | { 86 | assert(_isOK); 87 | assert((numTrack >= 0) && (numTrack < _numTracks)); 88 | 89 | int offset = 0x00000100; 90 | 91 | for (int i = 0; i < numTrack; i++){ 92 | offset += _data[0x34 + i]*256; 93 | } 94 | 95 | return offset; 96 | } 97 | -------------------------------------------------------------------------------- /vigasoco/FontManager.h: -------------------------------------------------------------------------------- 1 | // FontManager.h 2 | // 3 | // Class with functionality for writing text to bitmaps 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _FONT_MANAGER_H_ 8 | #define _FONT_MANAGER_H_ 9 | 10 | 11 | #include 12 | #include "Singleton.h" 13 | #include "SDLPalette.h" 14 | #include "IDrawPlugin.h" 15 | #include "Types.h" 16 | 17 | // font types (each font type encodes the font number in the font array and the size) 18 | enum FontSize { 19 | FONT_6x10 = ((0 << 16) | (10 << 8) | 6), 20 | FONT_9x18 = ((1 << 16) | (18 << 8) | 9), 21 | }; 22 | 23 | class IDrawPlugin; // defined in IDrawPlugin.h 24 | class IPalette; // defined in IPalette.h 25 | struct GfxElement; // defined in GfxData.h 26 | 27 | 28 | #define theFontManager FontManager::getSingletonPtr() 29 | 30 | class FontManager : public Singleton 31 | { 32 | // types 33 | protected: 34 | struct FontManagerState { 35 | int currentFont; 36 | int fontWidth, fontHeight; 37 | int xPadding, yPadding; 38 | UINT8 inkColorR, inkColorG, inkColorB; 39 | UINT8 bgColorR, bgColorG, bgColorB; 40 | }; 41 | 42 | // fields 43 | protected: 44 | int _fontColorEntry; 45 | SDLPalette *_palette; 46 | 47 | int _fontWidth; 48 | int _fontHeight; 49 | int _currentFont; 50 | 51 | int _xPadding; 52 | int _yPadding; 53 | 54 | FontManagerState _stack[8]; // stack for storing/retreiving state 55 | int _stackPos; // actual stack position 56 | 57 | // font data 58 | static UINT8 font_6x10[]; 59 | static UINT8 font_9x18[]; 60 | 61 | // available fonts 62 | static UINT8 *fonts[2]; 63 | static int fontDesc[2]; 64 | GfxElement *_fontGfx[2]; 65 | 66 | // methods 67 | public: 68 | // setters 69 | void setFont(int size); 70 | void setXPadding(int xPad) { _xPadding = xPad; } 71 | void setYPadding(int yPad) { _yPadding = yPad; } 72 | void setInkColor(UINT8 r, UINT8 g, UINT8 b); 73 | void setBackGroundColor(UINT8 r, UINT8 g, UINT8 b); 74 | 75 | // getters 76 | int getXPadding() { return _xPadding; } 77 | int getYPadding() { return _yPadding; } 78 | 79 | // load/save state 80 | void pushSettings(); 81 | void popSettings(); 82 | 83 | // string printing 84 | void print(IDrawPlugin *dp, std::string str, int x, int y); 85 | void printTrans(IDrawPlugin *dp, std::string str, int x, int y); 86 | 87 | // initialization and cleanup 88 | FontManager(SDLPalette *palette, int entry); 89 | virtual ~FontManager(); 90 | 91 | void init(); 92 | 93 | // helper methods 94 | void measureString(std::string str, int &width, int &height); 95 | }; 96 | 97 | #endif // _FONT_MANAGER_H_ 98 | -------------------------------------------------------------------------------- /vigasoco/Sprite.h: -------------------------------------------------------------------------------- 1 | // Sprite.h 2 | // 3 | // Clase que representa un sprite gen�rico 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _SPRITE_H_ 8 | #define _SPRITE_H_ 9 | 10 | 11 | #include "Types.h" 12 | 13 | namespace Abadia { 14 | 15 | 16 | class Sprite 17 | { 18 | // campos 19 | public: 20 | bool esVisible; // indica si el sprite es visible 21 | bool haCambiado; // indica si el sprite ha cambiado desde que se dibuj� por �ltima vez 22 | bool seHaProcesado; // indica si el sprite ha sido procesado por el mezclador 23 | int profundidad; // profundidad del sprite (coordenada y de pantalla) 24 | 25 | int posXPant; // coordenada x del sprite en la pantalla (en m�ltiplos de 4 pixels) 26 | int posYPant; // coordenada y del sprite en la pantalla (en pixels) 27 | int oldPosXPant; // anterior coordenada x del sprite en la pantalla (en m�ltiplos de 4 pixels) 28 | int oldPosYPant; // anterior coordenada y del sprite en la pantalla (en pixels) 29 | 30 | bool desaparece; // indica si el sprite va a desaparecer de la pantalla 31 | int ancho; // ancho del sprite (en m�ltiplos de 4 pixels) 32 | int alto; // alto del sprite (en pixels) 33 | int despGfx; // desplazamiento a los gr�ficos que forman el sprite 34 | int oldAncho; // anterior ancho del sprite (en bytes) 35 | int oldAlto; // anterior alto del sprite (en pixels) 36 | 37 | int posXTile; // coordenada x del tile en el que se empieza a dibujar el sprite (en m�ltiplos de 4 pixels) 38 | int posYTile; // coordenada y del tile en el que se empieza a dibujar el sprite (en pixels) 39 | int anchoFinal; // ancho final del �rea a dibujar del sprite (en bytes) 40 | int altoFinal; // alto final del �rea a dibujar del sprite (en pixels) 41 | int despBuffer; // desplazamiento en el buffer para mezclar los sprites 42 | int posXLocal; // coordenada x en la coordenadas locales de la c�mara 43 | int posYLocal; // coordenada y en la coordenadas locales de la c�mara 44 | 45 | // m�todos 46 | public: 47 | // ajuste de las dimensiones para el dibujado 48 | void ajustaATiles(); 49 | void ampliaDimViejo(); 50 | 51 | void preparaParaCambio(); 52 | 53 | // dibujo del sprite 54 | virtual void dibuja(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y); 55 | 56 | // inicializaci�n y limpieza 57 | Sprite(); 58 | virtual ~Sprite(); 59 | private: 60 | void dibujaVGA(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y); 61 | 62 | 63 | }; 64 | 65 | 66 | } 67 | 68 | #endif // _SPRITE_H_ 69 | -------------------------------------------------------------------------------- /vigasoco/GfxData.cpp: -------------------------------------------------------------------------------- 1 | // GfxData.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | #include "GfxData.h" 7 | 8 | // para memset y memcpy 9 | #include 10 | 11 | GfxElement * GfxDecoder::decode(const struct GfxEncoding *enc, const UINT8 *pRawGfx) 12 | { 13 | assert(enc->bpp <= 8); 14 | 15 | int entrySize = enc->sizeX*enc->sizeY; 16 | 17 | // allocate memory for the decoded graphics (1 pixel -> 1 byte) 18 | UINT8 **decodedGfx = new UINT8*[4]; 19 | for (int i = 0; i < 4; i++){ 20 | decodedGfx[i] = new UINT8[enc->numEntries*entrySize]; 21 | memset(decodedGfx[i], 0, enc->numEntries*entrySize); 22 | } 23 | 24 | // for each tile 25 | for (int num = 0; num < enc->numEntries; num++){ 26 | // for each bitplane 27 | for (int plane = 0; plane < enc->bpp; plane++){ 28 | 29 | // get bit to test (order 01234567 instead of the usual 76543210) 30 | int currBit = 1 << (enc->bpp - 1 - plane); 31 | 32 | // get offset to the starting of the current bitplane (in bits) 33 | int offs = enc->planeOffsets[plane] + num*enc->entryBitSize; 34 | 35 | for (int y = 0; y < enc->sizeY; y++){ 36 | // get start of this line (in bits) 37 | int lineOffset = offs + enc->yOffs[y]; 38 | 39 | for (int x = 0; x < enc->sizeX; x++){ 40 | // check bit in the final position 41 | if (isBitSet(pRawGfx, lineOffset + enc->xOffs[x])){ 42 | decodedGfx[NO_FLIP][entrySize*num + (y*enc->sizeX + x)] |= currBit; 43 | decodedGfx[FLIP_X] [entrySize*num + (y*enc->sizeX + (enc->sizeX - x - 1))] |= currBit; 44 | decodedGfx[FLIP_Y] [entrySize*num + ((enc->sizeY - y - 1)*enc->sizeX + x)] |= currBit; 45 | decodedGfx[FLIP_XY][entrySize*num + ((enc->sizeY - y - 1)*enc->sizeX + (enc->sizeX - x - 1))] |= currBit; 46 | } 47 | } 48 | } 49 | } 50 | } 51 | 52 | // return GfxElement struc 53 | GfxElement *g = new GfxElement(); 54 | g->sizeX = enc->sizeX; 55 | g->sizeY = enc->sizeY; 56 | g->numEntries = enc->numEntries; 57 | g->entrySize = entrySize; 58 | g->bpp = enc->bpp; 59 | g->data = decodedGfx; 60 | 61 | return g; 62 | } 63 | 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // cloning 66 | ///////////////////////////////////////////////////////////////////////////// 67 | 68 | GfxEncoding *GfxEncoding::clone(GfxEncoding *g) 69 | { 70 | GfxEncoding *gfx = new GfxEncoding(); 71 | gfx->sizeX = g->sizeX; 72 | gfx->sizeY = g->sizeY; 73 | gfx->numEntries = g->numEntries; 74 | gfx->bpp = g->bpp; 75 | memcpy(gfx->planeOffsets, g->planeOffsets, sizeof(UINT32)*8); 76 | memcpy(gfx->xOffs, g->xOffs, sizeof(int)*32); 77 | memcpy(gfx->yOffs, g->yOffs, sizeof(int)*32); 78 | gfx->entryBitSize = g->entryBitSize; 79 | 80 | return gfx; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /vigasoco/PersonajeConIA.h: -------------------------------------------------------------------------------- 1 | // PersonajeConIA.h 2 | // 3 | // Clase que representa un personaje del juego que tiene inteligencia artificial 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _PERSONAJE_CON_IA_H_ 8 | #define _PERSONAJE_CON_IA_H_ 9 | 10 | 11 | #include "Types.h" 12 | 13 | #include "Personaje.h" 14 | 15 | namespace Abadia { 16 | 17 | 18 | enum PosicionesPredefinidas { 19 | POS_GUILLERMO = -1, 20 | POS_ABAD = -2, 21 | POS_LIBRO = -3, 22 | POS_PERGAMINO = -4 23 | }; 24 | 25 | class PersonajeConIA : public Personaje 26 | { 27 | // campos 28 | public: 29 | int numBitAcciones; // indica el n?mero de bits procesados del byte de acciones actual 30 | bool pensarNuevoMovimiento; // indica si hay que pensar un nuevo movimiento 31 | UINT8 accionActual; // indica las acciones que el personaje est? procesando actualmente 32 | int posAcciones; // posici?n de la acci?n actual en el buffer de acciones del personaje 33 | UINT8 bufAcciones[0x30]; // buffer de acciones del personaje actual 34 | 35 | UINT8 *lugares; // datos de posici?n de los lugares a los que puede ir 36 | int mascarasPuertasBusqueda; // m?scara de las puertas que se comprobar?n en la b?squeda 37 | int aDondeVa; // indica al lugar que trata de ir actualmente 38 | int aDondeHaLlegado; // indica a donde ha llegado el personaje 39 | 40 | PosicionJuego *posiciones; // posiciones a las que puede ir el personaje 41 | 42 | protected: 43 | static UINT16 comandosGirar[4][2]; // tabla con los comandos para cambiar de orientaci?n 44 | static UINT16 comandosAvanzar[5][2];// tabla con los comandos para avanzar 45 | static int bufferDatosPersonaje[10];// buffer para guardar los datos del personaje por si hay que deshacer 46 | static int distanciasOri[4][4]; // tabla con las distancias permisibles seg?n la orientaci?n 47 | 48 | // m?todos 49 | public: 50 | virtual void run(); 51 | 52 | // m?todos relacionados con la generaci?n de comandos de movimiento 53 | void modificaOrientacion(int oriDeseada); 54 | void avanzaPosicion(int difAltura1, int difAltura2, int avanceX, int avanceY); 55 | void reiniciaPosicionBuffer(); 56 | void descartarMovimientosPensados(); 57 | void escribeComandos(UINT16 comandos, int bits); 58 | 59 | // inicializaci?n y limpieza 60 | PersonajeConIA(Sprite *spr); 61 | virtual ~PersonajeConIA(); 62 | 63 | protected: 64 | // comportamiento del personaje 65 | virtual void piensa() = 0; 66 | 67 | // m?todos relacionados con la ejecuci?n de comandos de movimiento 68 | virtual void ejecutaMovimiento(); 69 | 70 | int leeBit(); 71 | int leeComando(); 72 | 73 | void grabaEstado(); 74 | void cargaEstado(); 75 | 76 | // m?todos auxiliares para la l?gica 77 | bool estaCerca(Personaje *pers); 78 | bool siHaLlegadoAvanzaEstado(); 79 | }; 80 | 81 | 82 | } 83 | 84 | #endif // _PERSONAJE_CON_IA_H_ 85 | -------------------------------------------------------------------------------- /vigasoco/IDrawPlugin.h: -------------------------------------------------------------------------------- 1 | // IDrawPlugin.h 2 | // 3 | // Abstract class that defines the interface to handle all drawing 4 | // 5 | // This is preliminary and more methods will be added when more complex 6 | // games are added. For now it's enough. 7 | // 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef _IDRAW_PLUGIN_H_ 11 | #define _IDRAW_PLUGIN_H_ 12 | 13 | 14 | #include 15 | #include "Types.h" 16 | 17 | class IPalette; // defined in IPalette.h 18 | struct GfxElement; // defined in GfxData.h 19 | 20 | class IDrawPlugin 21 | { 22 | // abstract methods 23 | public: 24 | IDrawPlugin() = default; 25 | virtual ~IDrawPlugin() = default; 26 | virtual bool init(const VideoInfo *vi, IPalette *pal) = 0; 27 | virtual void end() = 0; 28 | 29 | // getters 30 | virtual bool isInitialized() const = 0; 31 | virtual bool isFullScreen() const = 0; 32 | 33 | // bitmap creation/destruction 34 | virtual int createBitmap(int width, int height) = 0; 35 | virtual void destroyBitmap(int bitmap) = 0; 36 | 37 | // bitmap methods 38 | virtual void setActiveBitmap(int bitmap) = 0; 39 | virtual void compose(int bitmap, int mode, int attr) = 0; 40 | virtual void getDimensions(int &width, int &height) const = 0; 41 | 42 | // clipping methods 43 | virtual const Rect *getClipArea() const = 0; 44 | virtual void setClipArea(int x, int y, int width, int height) = 0; 45 | virtual void setNoClip() = 0; 46 | 47 | // drawing methods 48 | virtual void render(bool throttle) = 0; 49 | 50 | virtual void setPixel(int x, int y, int color) = 0; 51 | 52 | virtual void drawLine(int x0, int y0, int x1, int y1, int color) = 0; 53 | virtual void drawRect(Rect *rect, int color) = 0; 54 | virtual void drawRect(int x0, int y0, int width, int height, int color) = 0; 55 | virtual void drawCircle(int x, int y, int radius, int color) = 0; 56 | virtual void drawEllipse(int x, int y, int a, int b, int color) = 0; 57 | 58 | virtual void fillRect(Rect *rect, int color) = 0; 59 | virtual void fillRect(int x0, int y0, int width, int height, int color) = 0; 60 | virtual void fillCircle(int x, int y, int radius, int color) = 0; 61 | virtual void fillEllipse(int x, int y, int a, int b, int color) = 0; 62 | 63 | virtual void drawGfx(GfxElement *gfx, int code, int color, int x, int y, int attr) = 0; 64 | virtual void drawGfxClip(GfxElement *gfx, int code, int color, int x, int y, int attr) = 0; 65 | virtual void drawGfxTrans(GfxElement *gfx, int code, int color, int x, int y, int attr, int transData) = 0; 66 | virtual void drawGfxClipTrans(GfxElement *gfx, int code, int color, int x, int y, int attr, int transData) = 0; 67 | 68 | // access to custom plugin properties 69 | virtual const std::string *getProperties(int *num) const = 0; 70 | virtual const int *getPropertiesType() const = 0; 71 | virtual void setProperty(std::string prop, int data) = 0; 72 | virtual void setProperty(std::string prop, int index, int data) = 0; 73 | virtual int getProperty(std::string prop) const = 0; 74 | virtual int getProperty(std::string prop, int index) const = 0; 75 | }; 76 | 77 | #endif // _IDRAW_PLUGIN_H_ 78 | -------------------------------------------------------------------------------- /vigasoco/GameDataEntity.cpp: -------------------------------------------------------------------------------- 1 | // GameDataEntity.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | #include "GameDataEntity.h" 7 | #include "NormalLoadHandler.h" 8 | 9 | ///////////////////////////////////////////////////////////////////////////// 10 | // initialization and cleanup 11 | ///////////////////////////////////////////////////////////////////////////// 12 | 13 | GameDataEntity::GameDataEntity(DataType type, std::string name, LoadingMode mode) 14 | { 15 | _type = type; 16 | _name = name; 17 | _mode = mode; 18 | _data = 0; 19 | _loadHandler = setLoadHandler(mode); 20 | } 21 | 22 | GameDataEntity::~GameDataEntity() 23 | { 24 | assert(!_data); 25 | 26 | free(); 27 | 28 | // delete game's files 29 | for (GameFiles::size_type i = 0; i < _files.size(); i++){ 30 | delete _files[i]; 31 | } 32 | 33 | delete _loadHandler; 34 | } 35 | 36 | ///////////////////////////////////////////////////////////////////////////// 37 | // non inline getters & setters 38 | ///////////////////////////////////////////////////////////////////////////// 39 | 40 | void GameDataEntity::addFile(GameFile *gf) 41 | { 42 | _files.push_back(gf); 43 | } 44 | 45 | // returns total files size (there can be gaps) 46 | UINT32 GameDataEntity::getTotalSize() const 47 | { 48 | GameFiles::size_type i; 49 | 50 | UINT32 totalSize = 0; 51 | for (i = 0; i < _files.size(); i++){ 52 | if ((_files[i]->baseAddress + _files[i]->fileSize) > totalSize){ 53 | totalSize = _files[i]->baseAddress + _files[i]->fileSize; 54 | } 55 | } 56 | 57 | return totalSize; 58 | } 59 | 60 | ///////////////////////////////////////////////////////////////////////////// 61 | // internal data manipulation 62 | ///////////////////////////////////////////////////////////////////////////// 63 | 64 | void GameDataEntity::preProcess() 65 | { 66 | free(); 67 | 68 | // allocates memory for all the files 69 | _data = new UINT8[getTotalSize()]; 70 | 71 | // does some preprocessing if necessary 72 | _loadHandler->preProcess(); 73 | } 74 | 75 | void GameDataEntity::loadData(int i, UINT8 *data) 76 | { 77 | assert(data); 78 | assert(i < (int)_files.size()); 79 | 80 | // handles a loaded game file 81 | _loadHandler->loadData(i, data); 82 | } 83 | 84 | void GameDataEntity::postProcess() 85 | { 86 | // does some postprocessing if necessary 87 | _loadHandler->postProcess(); 88 | } 89 | 90 | void GameDataEntity::free() 91 | { 92 | if (_data){ 93 | delete[] _data; 94 | _data = 0; 95 | } 96 | } 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | // helper methods 100 | ///////////////////////////////////////////////////////////////////////////// 101 | 102 | // sets file processing mode 103 | LoadHandler *GameDataEntity::setLoadHandler(LoadingMode mode) 104 | { 105 | switch (mode){ 106 | case NORMAL: 107 | return new NormalLoadHandler(this); 108 | 109 | default: 110 | assert(false); 111 | return new NormalLoadHandler(this); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /vigasoco/GameDataEntity.h: -------------------------------------------------------------------------------- 1 | // GameDataEntity.h 2 | // 3 | // Class with all data needed to load a game data entity. 4 | // 5 | // A game data entity is a collection of files (GameFiles) with related data. 6 | // Each game data entity has an associated load handler, that reorganizes the 7 | // internal memory as needed. 8 | // 9 | // To populate the game data entity: 10 | // * call preProcess in order to allocate internal memory for all the 11 | // files and to do any specific load handler pre processing. 12 | // * for all the files in the game data entity, call loadData with the 13 | // file data. The load handler will copy and process the data as needed. 14 | // * call postProcess in order to do any specific load handler post 15 | // processing. 16 | // 17 | // To deallocate the internal memory used by the game files, call free. 18 | // 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | #ifndef _GAME_DATA_ENTITY_H_ 22 | #define _GAME_DATA_ENTITY_H_ 23 | 24 | 25 | #include 26 | #include "Types.h" 27 | #include 28 | 29 | class LoadHandler; // defined in LoadHandler.h 30 | 31 | // struct that models a game file 32 | struct GameFile { 33 | std::string fileName; 34 | UINT32 baseAddress; 35 | UINT32 fileSize; 36 | UINT32 CRC32; 37 | UINT32 extraData; 38 | 39 | GameFile(std::string file, UINT32 address, UINT32 size, UINT32 crc, UINT32 data) 40 | { 41 | fileName = file; 42 | baseAddress = address; 43 | fileSize = size; 44 | CRC32 = crc; 45 | extraData = data; 46 | } 47 | }; 48 | 49 | // enumerations 50 | enum LoadingMode { 51 | NORMAL, 52 | FILES_EVEN_ODD // not implemented yet 53 | }; 54 | 55 | enum DataType { 56 | GRAPHICS, 57 | SOUND, 58 | PALETTE, 59 | MIXED 60 | }; 61 | 62 | class GameDataEntity 63 | { 64 | // types 65 | protected: 66 | typedef std::vector GameFiles; 67 | 68 | // fields 69 | protected: 70 | DataType _type; // type of the game data entity 71 | std::string _name; // name of the game data entity 72 | GameFiles _files; // collection of files 73 | LoadingMode _mode; // file loading mode 74 | UINT8 *_data; // internal memory 75 | LoadHandler *_loadHandler; // associated load handler 76 | 77 | // methods 78 | public: 79 | // initialization and cleanup 80 | GameDataEntity(DataType type, std::string name, LoadingMode mode = NORMAL); 81 | ~GameDataEntity(); 82 | 83 | // getters & setters 84 | DataType getType() const { return _type; } 85 | const std::string getName() const { return _name; } 86 | UINT8 *getData() const { return _data; } 87 | int getNumFiles() const { return (int)_files.size(); } 88 | const GameFile *getFile(int i) const { return _files[i]; }; 89 | 90 | void addFile(GameFile *gf); 91 | UINT32 getTotalSize() const; 92 | 93 | // data manipulation 94 | void preProcess(); 95 | void loadData(int i, UINT8 *data); 96 | void postProcess(); 97 | void free(); 98 | 99 | // helper methods 100 | protected: 101 | LoadHandler *setLoadHandler(LoadingMode mode); 102 | }; 103 | 104 | 105 | #endif // _GAME_DATA_ENTITY_H_ 106 | -------------------------------------------------------------------------------- /vigasoco/Types.h: -------------------------------------------------------------------------------- 1 | // Types.h 2 | // 3 | // Common used types for VIGASOCO 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _VIGASOCO_TYPES_H_ 8 | #define _VIGASOCO_TYPES_H_ 9 | 10 | 11 | static const int MIN_INT = - 2147483647 - 1; 12 | static const int MAX_INT = 2147483647; 13 | 14 | typedef unsigned char UINT8; 15 | typedef signed char INT8; 16 | typedef unsigned short UINT16; 17 | typedef signed short INT16; 18 | typedef unsigned int UINT32; 19 | typedef signed int INT32; 20 | 21 | //TODO: otra opcion seria usar los tipos de SDL... 22 | #ifdef __GNUC__ 23 | typedef signed long long INT64; 24 | typedef unsigned long long UINT64; 25 | #else 26 | typedef signed __int64 INT64; 27 | typedef unsigned __int64 UINT64; 28 | #endif 29 | 30 | 31 | struct Rect { 32 | int left; 33 | int top; 34 | int right; 35 | int bottom; 36 | 37 | Rect() { left = top = right = bottom = 0; } 38 | Rect(int l, int t, int r, int b) { left = l; top = t; right = r; bottom = b; } 39 | Rect(int width, int height) { left = top = 0; right = width - 1; bottom = height - 1; } 40 | }; 41 | 42 | struct VideoInfo { 43 | int width, height; 44 | Rect visibleArea; 45 | int colors; 46 | int refreshRate; 47 | 48 | VideoInfo() { width = height = colors = refreshRate = 0; } 49 | }; 50 | 51 | 52 | enum Inputs { 53 | UNMAPPED = -1, 54 | // game driver inputs 55 | GAME_DRIVER_INPUTS = 0, 56 | P1_UP = 0, 57 | P1_LEFT, 58 | P1_DOWN, 59 | P1_RIGHT, 60 | P1_BUTTON1, 61 | P1_BUTTON2, 62 | P2_UP, 63 | P2_LEFT, 64 | P2_DOWN, 65 | P2_RIGHT, 66 | P2_BUTTON1, 67 | P2_BUTTON2, 68 | START_1, 69 | START_2, 70 | COIN_1, 71 | COIN_2, 72 | SERVICE_1, 73 | SERVICE_2, 74 | 75 | // keyboard inputs 76 | KEYBOARD_INPUTS, 77 | KEYBOARD_A = KEYBOARD_INPUTS, 78 | KEYBOARD_B, 79 | KEYBOARD_C, 80 | KEYBOARD_D, 81 | KEYBOARD_E, 82 | KEYBOARD_F, 83 | KEYBOARD_G, 84 | KEYBOARD_H, 85 | KEYBOARD_I, 86 | KEYBOARD_J, 87 | KEYBOARD_K, 88 | KEYBOARD_L, 89 | KEYBOARD_M, 90 | KEYBOARD_N, 91 | KEYBOARD_O, 92 | KEYBOARD_P, 93 | KEYBOARD_Q, 94 | KEYBOARD_R, 95 | KEYBOARD_S, 96 | KEYBOARD_T, 97 | KEYBOARD_U, 98 | KEYBOARD_V, 99 | KEYBOARD_W, 100 | KEYBOARD_X, 101 | KEYBOARD_Y, 102 | KEYBOARD_Z, 103 | KEYBOARD_0, 104 | KEYBOARD_1, 105 | KEYBOARD_2, 106 | KEYBOARD_3, 107 | KEYBOARD_4, 108 | KEYBOARD_5, 109 | KEYBOARD_6, 110 | KEYBOARD_7, 111 | KEYBOARD_8, 112 | KEYBOARD_9, 113 | KEYBOARD_SPACE, 114 | KEYBOARD_INTRO, 115 | KEYBOARD_SUPR, 116 | 117 | // core inputs 118 | CORE_INPUTS, 119 | FUNCTION_1 = CORE_INPUTS, 120 | FUNCTION_2, 121 | FUNCTION_3, 122 | FUNCTION_4, 123 | FUNCTION_5, 124 | FUNCTION_6, 125 | FUNCTION_7, 126 | FUNCTION_8, 127 | FUNCTION_9, 128 | FUNCTION_10, 129 | FUNCTION_11, 130 | FUNCTION_12, 131 | 132 | END_OF_INPUTS 133 | }; 134 | 135 | enum ParameterType { 136 | PARAM_BOOLEAN = 0x00001000, 137 | PARAM_INTEGER = 0x00002000, 138 | PARAM_INPUT = 0x00003000, 139 | PARAM_ARRAY = 0x80000000 140 | }; 141 | 142 | enum PluginType { 143 | VIDEO_PLUGIN = 0x1000, 144 | INPUT_PLUGIN = 0x2000, 145 | AUDIO_PLUGIN = 0x3000, 146 | LOADER_PLUGIN = 0x4000 147 | }; 148 | 149 | #endif // _VIGASOCO_TYPES_H_ 150 | -------------------------------------------------------------------------------- /vigasoco/MotorGrafico.h: -------------------------------------------------------------------------------- 1 | // MotorGrafico.h 2 | // 3 | // Clase que contiene los m�todos de generaci�n de pantallas 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _MOTOR_GRAFICO_H_ 8 | #define _MOTOR_GRAFICO_H_ 9 | 10 | 11 | #include "Singleton.h" 12 | #include "Types.h" 13 | 14 | namespace Abadia { 15 | 16 | class EntidadJuego; // definido en EntidadJuego.h 17 | class GeneradorPantallas; // definido en GeneradorPantallas.h 18 | class MezcladorSprites; // definido en MezcladorSprites.h 19 | class Personaje; // definido en Personaje.h 20 | class RejillaPantalla; // definido en RejillaPantalla.h 21 | class TransformacionCamara; // definido en TransformacionesCamara.h 22 | 23 | #define elMotorGrafico MotorGrafico::getSingletonPtr() 24 | 25 | class MotorGrafico : public Singleton 26 | { 27 | // campos 28 | public: 29 | RejillaPantalla *rejilla; // objeto para realizar operaciones relacionadas con la rejilla de pantalla 30 | GeneradorPantallas *genPant; // generador de pantallas interpretando los bloques de construcci�n 31 | MezcladorSprites *mezclador; // mezclador de los sprites con el resto de la pantalla 32 | 33 | int posXPantalla; // posici�n x de la pantalla actual en coordenadas de mundo 34 | int posYPantalla; // posici�n y de la pantalla actual en coordenadas de mundo 35 | int alturaBasePantalla; // altura base de la planta que se muestra en la pantalla actual 36 | bool pantallaIluminada; // indica si la pantalla est� iluminada o no 37 | bool hayQueRedibujar; // indica que hay que redibujar la pantalla 38 | int numPantalla; // n�mero de la pantalla que muestra la c�mara 39 | int oriCamara; // orientaci�n de la c�mara para ver la pantalla actual 40 | 41 | Personaje *personaje; // personaje al que sigue la c�mara 42 | 43 | static int tablaDespOri[4][2]; // tabla con los desplazamientos seg�n la orientaci�n 44 | static UINT8 plantas[3][256]; // mapa de las plantas de la abad�a 45 | 46 | protected: 47 | UINT8 *roms; // puntero a los datos del juego 48 | 49 | // objetos para la transformaci�n de coordenadas seg�n el tipo de c�mara de la pantalla 50 | TransformacionCamara *transCamara[4]; 51 | 52 | // m�todos 53 | public: 54 | // comprobaci�n del cambio de pantalla 55 | void compruebaCambioPantalla(bool forzarCambio=false); 56 | 57 | // m�todos relacionados con la altura 58 | int obtenerPlanta(int alturaBase); 59 | int obtenerAlturaBasePlanta(int altura); 60 | 61 | // transformaciones relacionadas con la c�mara 62 | int ajustaOrientacionSegunCamara(int orientacion); 63 | void transCoordLocalesACoordCamara(int &x, int &y); 64 | int actualizaCoordCamara(EntidadJuego *entidad, int &posXPant, int &posYPant, int &sprPosY); 65 | 66 | // dibujo de la escena 67 | void dibujaPantalla(); 68 | void dibujaSprites(); 69 | 70 | // inicializaci�n y limpieza 71 | MotorGrafico(UINT8 *buffer, int lgtudBuffer); 72 | ~MotorGrafico(); 73 | 74 | // m�todos de ayuda 75 | protected: 76 | int obtenerDirPantalla(int numPant); 77 | 78 | // actualizaci�n de las entidades del juego seg�n la c�mara 79 | void actualizaPuertas(); 80 | void actualizaObjetos(); 81 | void actualizaPersonajes(); 82 | }; 83 | 84 | 85 | } 86 | 87 | #endif // _MOTOR_GRAFICO_H_ 88 | -------------------------------------------------------------------------------- /vigasoco/Personaje.h: -------------------------------------------------------------------------------- 1 | // Personaje.h 2 | // 3 | // Clase que representa un personaje del juego 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _PERSONAJE_H_ 8 | #define _PERSONAJE_H_ 9 | 10 | 11 | #include "Types.h" 12 | 13 | #include "EntidadJuego.h" 14 | 15 | 16 | namespace Abadia { 17 | 18 | class RejillaPantalla; // definido en RejillaPantalla.h 19 | 20 | class Personaje : public EntidadJuego 21 | { 22 | // tipos 23 | protected: 24 | struct DatosFotograma { 25 | int dirGfx; // direcci�n de los gr�ficos de este fotograma de la animaci�n 26 | int ancho; // ancho de este fotograma de la animaci�n (en m�ltiplos de 4 pixels) 27 | int alto; // alto de este fotograma de la animaci�n (en pixels) 28 | }; 29 | 30 | // campos 31 | public: 32 | int estado; // estado del personaje 33 | int contadorAnimacion; // contador para animar el personaje 34 | bool bajando; // indica si el personaje est� bajando en altura 35 | bool enDesnivel; // indica que el personaje est� en un desnivel 36 | bool giradoEnDesnivel; // indica que el personaje no est� avanzando en el sentido del desnivel 37 | bool flipX; // indica si los gr�ficos est�n girados en x 38 | int despFlipX; // desplazamiento de los gr�ficos girados en x 39 | int despX; // desplazamiento en x para dibujar el personaje (en m�ltiplos de 4 pixels) 40 | int despY; // desplazamiento en y para dibujar el personaje (en pixels) 41 | int valorPosicion; // valor a grabar en las posiciones de la rejilla en las que est� el personaje 42 | 43 | bool puedeQuitarObjetos; // indica si el personaje puede quitar objetos o a otro personaje 44 | int objetos; // objetos que tiene el personaje 45 | int mascaraObjetos; // m�scara de los objetos que puede coger el personaje 46 | int contadorObjetos; // contador para no coger/dejar los objetos varias veces 47 | 48 | int permisosPuertas; // puertas que puede abrir el personaje 49 | 50 | DatosFotograma *animacion; // tabla con los datos para las animaciones 51 | int numFotogramas; // n�mero de fotogramas de la tabla de animaciones 52 | 53 | 54 | 55 | protected: 56 | // tabla para el c�lculo del desplazamiento, seg�n la animaci�n y la c�mara de un personaje 57 | static int difPosAnimCam[4][4][14]; 58 | 59 | // m�todos 60 | public: 61 | virtual void run() = 0; 62 | 63 | void notificaVisibleEnPantalla(int posXPant, int posYPant, int profundidad) override; 64 | 65 | int puedeDejarObjeto(int &posXObj, int &posYObj, int &alturaObj); 66 | 67 | void marcaPosicion(RejillaPantalla *rejilla, int valor); 68 | void actualizaSprite(); 69 | 70 | // inicializaci�n y limpieza 71 | Personaje(Sprite *spr); 72 | virtual ~Personaje(); 73 | 74 | protected: 75 | virtual void ejecutaMovimiento() = 0; 76 | virtual void avanzaAnimacionOMueve(); 77 | 78 | void mueve(); 79 | 80 | void trataDeAvanzar(int difAltura1, int difAltura2, int avanceX, int avanceY); 81 | void incrementaPos(int avanceX, int avanceY); 82 | void gira(int difOrientacion); 83 | bool cambioCentro(); 84 | 85 | void actualizaPosPantSprite(int posXPant, int posYPant, int profundidad); 86 | void avanzaAnimacion(); 87 | virtual DatosFotograma *calculaFotograma(); 88 | void actualizaAnimacion(DatosFotograma *da, int profundidad); 89 | }; 90 | 91 | 92 | } 93 | 94 | #endif // _PERSONAJE_H_ 95 | -------------------------------------------------------------------------------- /vigasoco/FileLoader.cpp: -------------------------------------------------------------------------------- 1 | // FileLoader.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | #include "GameDataEntity.h" 7 | #include "FileLoader.h" 8 | #include "ILoader.h" 9 | #include "UncompressedLoader.h" 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // initialization and cleanup 13 | ///////////////////////////////////////////////////////////////////////////// 14 | 15 | FileLoader::FileLoader() 16 | { 17 | // adds the default loader and path 18 | addLoader(new UncompressedLoader()); 19 | addPath("roms"); 20 | } 21 | 22 | FileLoader::~FileLoader() 23 | { 24 | // deallocate loaders 25 | for (Loaders::iterator i = _loaders.begin(); i != _loaders.end(); i++){ 26 | delete *i; 27 | } 28 | } 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | // loaders management 32 | ///////////////////////////////////////////////////////////////////////////// 33 | 34 | void FileLoader::addLoader(ILoader *l) 35 | { 36 | _loaders.push_back(l); 37 | } 38 | 39 | void FileLoader::removeLoader(ILoader *l) 40 | { 41 | _loaders.remove(l); 42 | } 43 | 44 | void FileLoader::addPath(std::string path) 45 | { 46 | _paths.push_back(path); 47 | } 48 | 49 | 50 | bool FileLoader::loadGameData(std::string game, GameDataEntity *gde) 51 | { 52 | // allocate memory to keep track of allocated files 53 | bool *fileLoaded = new bool[gde->getNumFiles()]; 54 | 55 | for (int num = 0; num < gde->getNumFiles(); num++){ 56 | fileLoaded[num] = false; 57 | } 58 | 59 | Loaders::iterator i; 60 | 61 | gde->preProcess(); 62 | 63 | // try to load all available files from each loader before trying the next one 64 | for (i = _loaders.begin(); i != _loaders.end(); i++){ 65 | ILoader *loader = *i; 66 | Paths::iterator pathIter; 67 | 68 | for (pathIter = _paths.begin(); pathIter != _paths.end(); pathIter++){ 69 | 70 | // if all the files have been loaded, exit 71 | bool loadComplete = true; 72 | for (int num = 0; num < gde->getNumFiles(); num++){ 73 | if (!fileLoaded[num]){ 74 | loadComplete = false; 75 | break; 76 | } 77 | } 78 | 79 | if (loadComplete){ 80 | break; 81 | } 82 | 83 | // otherwise, try to load the remaining files with this loader 84 | loader->open(*pathIter, game); 85 | 86 | for (int num = 0; num < gde->getNumFiles(); num++){ 87 | const GameFile *gf = gde->getFile(num); 88 | 89 | if (!fileLoaded[num]){ 90 | UINT8 *data; 91 | 92 | data = loader->load(gf->fileName, gf->fileSize, gf->CRC32); 93 | 94 | if (data){ 95 | fileLoaded[num] = true; 96 | 97 | // send the data back to the GameDataEntity to be processed 98 | gde->loadData(num, data); 99 | 100 | // makes the loader to dispose the memory it reserved 101 | loader->dispose(data); 102 | } 103 | } 104 | } 105 | 106 | loader->close(); 107 | } 108 | } 109 | 110 | gde->postProcess(); 111 | 112 | // check if all the files have been loaded 113 | bool loadComplete = true; 114 | for (int num = 0; num < gde->getNumFiles(); num++){ 115 | if (!fileLoaded[num]){ 116 | loadComplete = false; 117 | break; 118 | } 119 | } 120 | 121 | return loadComplete; 122 | } 123 | -------------------------------------------------------------------------------- /vigasoco/AbadiaDriver.h: -------------------------------------------------------------------------------- 1 | // AbadiaDriver.h 2 | // 3 | // Driver para "La abad�a del crimen" 4 | // 5 | // Dedicado a la memoria de Paco Menendez 6 | // 7 | // Reingenier�a inversa por Manuel Abad�a 8 | // 9 | // Notas de la conversi�n: 10 | // ======================= 11 | // * la conversi�n se ha hecho trabajando sobre la versi�n de Amstrad CPC 6128, que fue 12 | // el ordenador en el que se cre� originalmente el juego, entendiendo el c�digo del Z80 13 | // y creando una serie de objetos que interactuan entre si para que el resultado sea 14 | // equivalente al juego original. 15 | // 16 | // * el juego original tiene 2 capas de tiles para generar las pantallas y crear un efecto 17 | // de profundidad. Para una gran parte de las pantallas, estas 2 capas son suficiente, 18 | // aunque para algunas pantallas con gran cantidad de bloques que coinciden en los mismos 19 | // tiles, como la pantalla 0x34, esto provoca ligeras imperfecciones gr�ficas. Probablemente 20 | // en el juego original no se usaron m�s capas porque cada capa adicional supone 960 bytes, 21 | // una pasada m�s a la hora de dibujar la pantalla y una pasada m�s en el bucle interior del 22 | // dibujado de sprites, y este incremento en memoria y c�lculos consigue una mejora gr�fica 23 | // muy peque�a. Aprovechando que ahora los ordenadores son m�s potentes, he generalizado los 24 | // algoritmos que tratan con las capas de forma que el n�mero de capas que se usan viene 25 | // determinado por la constante nivelesProfTiles de la clase GeneradorPantallas (que por 26 | // defecto vale 3, para que las pantallas se vean sin errores gr�ficos). 27 | // 28 | // * el juego posee un int�rprete para la construcci�n de los bloques que forman las 29 | // pantallas. Actualmente se interpretan los bloques ya compilados (que est�n en los 30 | // datos originales), aunque estar�a bien crear ficheros con los scripts de cada bloque 31 | // y un compilador de bloques, de forma que se interprete el c�digo que genere el 32 | // compilador de bloques en vez del que viene en los datos originales. 33 | // 34 | // * el comportamiento de los personajes se basa en el int�rprete de scripts que trae el 35 | // juego original. En la conversi�n, el comportamiento se ha pasado directamente a C++. 36 | // 37 | // Por hacer: 38 | // ========== 39 | // * a�adir sonido -> A�adido en la version SDL 40 | // 41 | // * cargar/grabar partidas -> A�adido en la version SDL 42 | // 43 | ///////////////////////////////////////////////////////////////////////////// 44 | 45 | #ifndef _ABADIA_DRIVER_H_ 46 | #define _ABADIA_DRIVER_H_ 47 | 48 | #include "GameDriver.h" 49 | #include "Juego.h" 50 | 51 | class CPC6128; // definido en CPC6128.h 52 | 53 | class AbadiaDriver : public GameDriver 54 | { 55 | // campos 56 | protected: 57 | Abadia::Juego *_abadiaGame; // objeto principal del juego 58 | CPC6128 *cpc6128; // clase de ayuda para realizar operaciones gr�ficas 59 | UINT8 *romsPtr; // puntero a los datos del juego una vez extraidos del disco 60 | // y de GraficosCPC y GraficosVGA 61 | // los wav del sonido no van aqui 62 | 63 | // m�todos 64 | public: 65 | // iniciaci�n y limpieza 66 | AbadiaDriver(); 67 | ~AbadiaDriver() override = default; 68 | void preRun() override; 69 | void runSync() override; 70 | void runAsync() override; 71 | void showMenu() override; 72 | void changeState(int newState) override; 73 | void render() override; 74 | void showGameLogic() override; 75 | 76 | int state; 77 | 78 | protected: 79 | // template methods overrides 80 | void filesLoaded() override; 81 | void finishInit() override; 82 | void end() override; 83 | 84 | // m�todos de ayuda 85 | void createGameDataEntities(); 86 | 87 | static void reOrderAndCopy(const UINT8 *src, UINT8 *dst, int size); 88 | }; 89 | 90 | #endif // _ABADIA_DRIVER_H_ 91 | -------------------------------------------------------------------------------- /vigasoco/Serializar.h: -------------------------------------------------------------------------------- 1 | // Serializar.h 2 | // 3 | // Metodos sobrecargados de los 4 | // operadores << y >> 5 | // para cargar/salvar la partida 6 | // 7 | ///////////////////////////////////////////////////////////////////////////// 8 | 9 | #ifndef _SERIALIZAR_H 10 | #define _SERIALIZAR_H 11 | 12 | #include "fstream" 13 | #include "EntidadJuego.h" 14 | #include "Objeto.h" 15 | #include "Puerta.h" 16 | #include "Sprite.h" 17 | #include "Personaje.h" 18 | #include "Guillermo.h" 19 | #include "Adso.h" 20 | #include "Malaquias.h" 21 | #include "Abad.h" 22 | #include "Berengario.h" 23 | #include "Severino.h" 24 | #include "Jorge.h" 25 | #include "Bernardo.h" 26 | #include "Logica.h" 27 | 28 | namespace Abadia { 29 | 30 | std::ofstream& operator<< ( 31 | std::ofstream& out, 32 | const PosicionJuego* const pos ); 33 | 34 | std::ifstream& operator>> ( 35 | std::ifstream& in, 36 | PosicionJuego* const pos ); 37 | 38 | std::ofstream& operator<< ( 39 | std::ofstream& out, 40 | const Objeto* const obj ); 41 | 42 | std::ifstream& operator>> ( 43 | std::ifstream& in, 44 | Objeto* const obj ); 45 | 46 | std::ofstream& operator<< ( 47 | std::ofstream& out, 48 | const Puerta* const puerta ); 49 | 50 | std::ifstream& operator>> ( 51 | std::ifstream& in, 52 | Puerta* const puerta ); 53 | 54 | std::ofstream& operator<< ( 55 | std::ofstream& out, 56 | const Sprite* const sprite ); 57 | 58 | std::ifstream& operator>> ( 59 | std::ifstream& in, 60 | Sprite* const sprite ); 61 | 62 | std::ofstream& operator<< ( 63 | std::ofstream& out, 64 | const Personaje* const pers ); 65 | 66 | std::ifstream& operator>> ( 67 | std::ifstream& in, 68 | Personaje* const pers ); 69 | 70 | std::ofstream& operator<< ( 71 | std::ofstream& out, 72 | const Guillermo* const guillermo ); 73 | 74 | std::ifstream& operator>> ( 75 | std::ifstream& in, 76 | Guillermo* const guillermo ); 77 | 78 | std::ofstream& operator<< ( 79 | std::ofstream& out, 80 | const PersonajeConIA* const persIA ); 81 | 82 | std::ifstream& operator>> ( 83 | std::ifstream& in, 84 | PersonajeConIA* const persIA ); 85 | 86 | std::ifstream& operator>> ( 87 | std::ifstream& in, 88 | Adso* const adso ); 89 | 90 | std::ofstream& operator<< ( 91 | std::ofstream& out, 92 | const Adso* const adso ); 93 | 94 | std::ofstream& operator<< ( 95 | std::ofstream& out, 96 | const Malaquias* const malaquias ); 97 | 98 | std::ifstream& operator>> ( 99 | std::ifstream& in, 100 | Malaquias* const malaquias ); 101 | 102 | std::ofstream& operator<< ( 103 | std::ofstream& out, 104 | const Abad* const abad ); 105 | 106 | std::ifstream& operator>> ( 107 | std::ifstream& in, 108 | Abad* const abad ); 109 | 110 | std::ofstream& operator<< ( 111 | std::ofstream& out, 112 | const Berengario* const berengario ); 113 | 114 | std::ifstream& operator>> ( 115 | std::ifstream& in, 116 | Berengario* const berengario ); 117 | 118 | std::ofstream& operator<< ( 119 | std::ofstream& out, 120 | const Severino* const severino ); 121 | 122 | std::ifstream& operator>> ( 123 | std::ifstream& in, 124 | Severino* const severino ); 125 | 126 | std::ofstream& operator<< ( 127 | std::ofstream& out, 128 | const Jorge* const jorge ); 129 | 130 | std::ifstream& operator>> ( 131 | std::ifstream& in, 132 | Jorge* const jorge ); 133 | 134 | std::ofstream& operator<< ( 135 | std::ofstream& out, 136 | const Bernardo* const bernardo ); 137 | 138 | std::ifstream& operator>> ( 139 | std::ifstream& in, 140 | Bernardo* const bernardo ); 141 | 142 | std::ofstream& operator<< ( 143 | std::ofstream& out, 144 | const Logica* const logica); 145 | 146 | std::ifstream& operator>> ( 147 | std::ifstream& in, 148 | Logica* const logica); 149 | 150 | }; // namespace Abadia 151 | 152 | #endif // _SERIALIZAR_H 153 | -------------------------------------------------------------------------------- /vigasoco/Guillermo.cpp: -------------------------------------------------------------------------------- 1 | // Guillermo.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | 6 | #include "Guillermo.h" 7 | #include "Juego.h" 8 | #include "Logica.h" 9 | #include "MotorGrafico.h" 10 | #include "RejillaPantalla.h" 11 | #include "Sprite.h" 12 | 13 | #include "system.h" 14 | 15 | using namespace Abadia; 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // tabla de la animaci�n del personaje 19 | ///////////////////////////////////////////////////////////////////////////// 20 | /* CPC 21 | Personaje::DatosFotograma Guillermo::tablaAnimacion[8] = { 22 | { 0xa3b4, 0x05, 0x22 }, 23 | { 0xa300, 0x05, 0x24 }, 24 | { 0xa3b4, 0x05, 0x22 }, 25 | { 0xa45e, 0x05, 0x22 }, 26 | { 0xa666, 0x04, 0x21 }, 27 | { 0xa508, 0x05, 0x23 }, 28 | { 0xa666, 0x04, 0x21 }, 29 | { 0xa5b7, 0x05, 0x21 } 30 | }; 31 | */ 32 | // VGA 33 | Personaje::DatosFotograma Guillermo::tablaAnimacion[8] = { 34 | { 54480, 0x05, 0x22 }, 35 | { 53760, 0x05, 0x24 }, 36 | { 54480, 0x05, 0x22 }, 37 | { 55180, 0x05, 0x22 }, 38 | { 57240, 0x04, 0x21 }, 39 | { 55880, 0x05, 0x23 }, 40 | { 57240, 0x04, 0x21 }, 41 | { 56580, 0x05, 0x21 } 42 | }; 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // inicializaci�n y limpieza 46 | ///////////////////////////////////////////////////////////////////////////// 47 | 48 | Guillermo::Guillermo(Sprite *spr) : Personaje(spr) 49 | { 50 | // asigna la tabla de animaci�n del personaje 51 | animacion = tablaAnimacion; 52 | numFotogramas = 8; 53 | 54 | incrPosY = 2; 55 | } 56 | 57 | Guillermo::~Guillermo() 58 | { 59 | } 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // movimiento 63 | ///////////////////////////////////////////////////////////////////////////// 64 | 65 | // m�todo llamado desde el bucle principal para que el personaje interactue con el mundo virtual 66 | void Guillermo::run() 67 | { 68 | mueve(); 69 | } 70 | 71 | // mueve el personaje seg�n el estado en el que se encuentra 72 | void Guillermo::ejecutaMovimiento() 73 | { 74 | // si est� vivo, responde a la pulsaci�n de los cursores 75 | if (estado == 0){ 76 | // si la c�mara no sigue a guillermo, sale 77 | if (laLogica->numPersonajeCamara != 0) return; 78 | 79 | // dependiendo de la tecla que se pulse, act�a en consecuencia 80 | //if (losControles->estaSiendoPulsado(P1_LEFT)){ 81 | if (sys->pad.left){ 82 | gira(1); 83 | sys->pad.left = false; 84 | //} else if (losControles->estaSiendoPulsado(P1_RIGHT)){ 85 | } else if (sys->pad.right){ 86 | gira(-1); 87 | sys->pad.right = false; 88 | //} else if (losControles->estaSiendoPulsado(P1_UP)){ 89 | } else if (sys->pad.up){ 90 | int difAltura1, difAltura2, avanceX, avanceY; 91 | 92 | // obtiene la altura de las posiciones hacia las que se va a mover 93 | elMotorGrafico->rejilla->obtenerAlturaPosicionesAvance(this, difAltura1, difAltura2, avanceX, avanceY); 94 | trataDeAvanzar(difAltura1, difAltura2, avanceX, avanceY); 95 | } 96 | } else { 97 | // si ha llegado al �ltimo estado cuando est� muerto, sale 98 | if (estado == 1) return; 99 | 100 | estado = estado - 1; 101 | 102 | // si ha caido en la trampa del espejo, lo mete en el agujero 103 | if (estado == 0x13){ 104 | if (incrPosY == 2){ 105 | posX = posX - 1; 106 | actualizaSprite(); 107 | return; 108 | } 109 | } 110 | 111 | if (estado != 1){ 112 | // modifica la posici�n y del sprite en pantalla 113 | sprite->posYPant += incrPosY; 114 | sprite->haCambiado = true; 115 | 116 | laLogica->hayMovimiento = true; 117 | } else { 118 | // en el estado 1 desaparece el sprite de guillermo 119 | sprite->esVisible = false; 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /cmake/FindSDL2_ttf.cmake: -------------------------------------------------------------------------------- 1 | # Locate SDL_image library 2 | # 3 | # This module defines: 4 | # 5 | # :: 6 | # 7 | # SDL_TTF_LIBRARIES, the name of the library to link against 8 | # SDL_TTF_INCLUDE_DIRS, where to find the headers 9 | # SDL_TTF_FOUND, if false, do not try to link against 10 | # SDL_F_VERSION_STRING - human-readable string containing the version of SDL_ttf 11 | # 12 | # 13 | # 14 | # For backward compatiblity the following variables are also set: 15 | # 16 | # :: 17 | # 18 | # SDLTTF_LIBRARY (same value as SDL_TTF_LIBRARIES) 19 | # SDLTTF_INCLUDE_DIR (same value as SDL_TTF_INCLUDE_DIRS) 20 | # SDLTTF_FOUND (same value as SDL_TTF_FOUND) 21 | # 22 | # 23 | # 24 | # $SDLDIR is an environment variable that would correspond to the 25 | # ./configure --prefix=$SDLDIR used in building SDL. 26 | # 27 | # Created by Eric Wing. This was influenced by the FindSDL.cmake 28 | # module, but with modifications to recognize OS X frameworks and 29 | # additional Unix paths (FreeBSD, etc). 30 | 31 | #============================================================================= 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # Copyright 2012 Benjamin Eikel 34 | # 35 | # Distributed under the OSI-approved BSD License (the "License"); 36 | # see accompanying file Copyright.txt for details. 37 | # 38 | # This software is distributed WITHOUT ANY WARRANTY; without even the 39 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | # See the License for more information. 41 | #============================================================================= 42 | # (To distribute this file outside of CMake, substitute the full 43 | # License text for the above reference.) 44 | 45 | find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h 46 | HINTS 47 | ENV SDL2TTFDIR 48 | ENV SDL2DIR 49 | PATH_SUFFIXES SDL2 50 | # path suffixes to search inside ENV{SDLDIR} 51 | include/SDL2 include 52 | ) 53 | 54 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 55 | set(VC_LIB_PATH_SUFFIX lib/x64) 56 | else() 57 | set(VC_LIB_PATH_SUFFIX lib/x86) 58 | endif() 59 | 60 | find_library(SDL2_TTF_LIBRARY 61 | NAMES SDL2_ttf 62 | HINTS 63 | ENV SDL2TTFDIR 64 | ENV SDL2DIR 65 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 66 | ) 67 | 68 | if(SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") 69 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") 70 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_TTF_MINOR_VERSION[ \t]+[0-9]+$") 71 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_TTF_PATCHLEVEL[ \t]+[0-9]+$") 72 | string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") 73 | string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") 74 | string(REGEX REPLACE "^#define[ \t]+SDL2_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") 75 | set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) 76 | unset(SDL2_TTF_VERSION_MAJOR_LINE) 77 | unset(SDL2_TTF_VERSION_MINOR_LINE) 78 | unset(SDL2_TTF_VERSION_PATCH_LINE) 79 | unset(SDL2_TTF_VERSION_MAJOR) 80 | unset(SDL2_TTF_VERSION_MINOR) 81 | unset(SDL2_TTF_VERSION_PATCH) 82 | endif() 83 | 84 | set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) 85 | set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) 86 | 87 | include(FindPackageHandleStandardArgs) 88 | 89 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf 90 | REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS 91 | VERSION_VAR SDL2_TTF_VERSION_STRING) 92 | 93 | # for backward compatiblity 94 | #set(SDLTTF_LIBRARY ${SDL_TTF_LIBRARIES}) 95 | #set(SDLTTF_INCLUDE_DIR ${SDL_TTF_INCLUDE_DIRS}) 96 | #set(SDLTTF_FOUND ${SDL_TTF_FOUND}) 97 | 98 | mark_as_advanced(SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR) 99 | -------------------------------------------------------------------------------- /src/system.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEM_H 2 | #define SYSTEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define SDL_MAIN_HANDLED 10 | #include 11 | #include 12 | 13 | #ifdef ANDROID 14 | #include 15 | #endif 16 | 17 | #define WINDOW_WIDTH 1280 18 | #define WINDOW_HEIGHT 800 19 | #define TEXTURE_WIDTH 640 20 | #define TEXTURE_HEIGHT 400 21 | #define WINDOW_TITLE "Abbey" 22 | #define GAME_FRAME_TIME 130 23 | #define SCROLL_FRAME_TIME 60 24 | 25 | enum MUSICFILES{ 26 | START, 27 | END, 28 | BACKGROUND, 29 | 30 | TOTAL_MUSIC_FILES 31 | }; 32 | #ifdef ANDROID 33 | static const char* const 34 | musicPathList[] = { 35 | "roms/abadia/inicio.wav", 36 | "roms/abadia/final.wav", 37 | "roms/abadia/fondo.wav", 38 | }; 39 | #else 40 | static const char* const 41 | musicPathList[] = { 42 | "./roms/abadia/inicio.wav", 43 | "./roms/abadia/final.wav", 44 | "./roms/abadia/fondo.wav", 45 | }; 46 | #endif 47 | 48 | enum SOUNDFILES{ 49 | OPEN, 50 | HIT, 51 | BELLS, 52 | CLOSE, 53 | GET, 54 | LET, 55 | MIRROR, 56 | STEPS, 57 | JINGLE, 58 | 59 | TOTAL_SOUND_FILES 60 | }; 61 | 62 | enum STATES{ 63 | INTRO, 64 | SCROLL, 65 | MENU, 66 | LANGUAGE, 67 | LOAD, 68 | SAVE, 69 | PLAY, 70 | ASK_NEW_GAME, 71 | ASK_CONTINUE, 72 | ASK_EXIT, 73 | ENDING 74 | }; 75 | 76 | enum TILEMAP{ 77 | DAY, 78 | NIGHT, 79 | LAMP, 80 | 81 | TOTAL_TILEMAP_FILES 82 | }; 83 | 84 | #ifdef ANDROID 85 | static const char* 86 | soundsPathList[] = { 87 | "roms/abadia/abrir.wav", 88 | "roms/abadia/aporrear.wav", 89 | "roms/abadia/campanas.wav", 90 | "roms/abadia/cerrar.wav", 91 | "roms/abadia/coger.wav", 92 | "roms/abadia/dejar.wav", 93 | "roms/abadia/espejo.wav", 94 | "roms/abadia/pasos.wav", 95 | "roms/abadia/tintineo.wav", 96 | }; 97 | #else 98 | [[maybe_unused]] static const char* 99 | soundsPathList[] = { 100 | "./roms/abadia/abrir.wav", 101 | "./roms/abadia/aporrear.wav", 102 | "./roms/abadia/campanas.wav", 103 | "./roms/abadia/cerrar.wav", 104 | "./roms/abadia/coger.wav", 105 | "./roms/abadia/dejar.wav", 106 | "./roms/abadia/espejo.wav", 107 | "./roms/abadia/pasos.wav", 108 | "./roms/abadia/tintineo.wav", 109 | }; 110 | #endif 111 | 112 | struct PlayerInput 113 | { 114 | bool up, down, left, right, button1, button2, button3, button4; 115 | bool start; 116 | }; 117 | 118 | #define BUTTON_YES sys->pad.button3 119 | #define BUTTON_NO sys->pad.button2 120 | 121 | struct System 122 | { 123 | PlayerInput pad; 124 | bool exit = false; 125 | bool informationMode = false; 126 | bool enableJoystick = true; 127 | bool fullscreen = false; 128 | bool haveHapticDevice = false; 129 | int w = WINDOW_WIDTH; 130 | int h = WINDOW_HEIGHT; 131 | Uint32 minimumFrameTime = GAME_FRAME_TIME; 132 | 133 | #if SDL_BYTEORDER == SDL_BIG_ENDIAN 134 | const Uint32 rmask = 0xff000000; 135 | const Uint32 gmask = 0x00ff0000; 136 | const Uint32 bmask = 0x0000ff00; 137 | const Uint32 amask = 0x000000ff; 138 | #else 139 | const Uint32 rmask = 0; 140 | const Uint32 gmask = 0; 141 | const Uint32 bmask = 0; 142 | const Uint32 amask = 0; 143 | #endif 144 | 145 | SDL_Surface *surface; 146 | SDL_Renderer *renderer; 147 | SDL_Texture *texture; 148 | SDL_Window *window; 149 | SDL_GameController *gamepad; 150 | SDL_Haptic *hapticDevice; 151 | 152 | SDL_Surface *tilemap[TOTAL_TILEMAP_FILES]; 153 | 154 | std::vectorsounds; 155 | std::vectormusic; 156 | 157 | void init(); 158 | void quit(); 159 | void playMusic(int i); 160 | void stopMusic(); 161 | void playSound(int i); 162 | void updateScreen(); 163 | void handleEvents(); 164 | void hapticFeedback(); 165 | 166 | SDL_Surface* flipSurfaceHorizontally(SDL_Surface *src); 167 | 168 | void setFastSpeed(); 169 | void setNormalSpeed(); 170 | Uint32 RGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a); 171 | void updateTexture(); 172 | void exitGame(); 173 | void print(const std::string message); 174 | }; 175 | extern System *const sys; 176 | 177 | #endif 178 | -------------------------------------------------------------------------------- /cmake/FindSDL2_Image.cmake: -------------------------------------------------------------------------------- 1 | # Locate SDL_image library 2 | # 3 | # This module defines: 4 | # 5 | # :: 6 | # 7 | # SDL_IMAGE_LIBRARIES, the name of the library to link against 8 | # SDL_IMAGE_INCLUDE_DIRS, where to find the headers 9 | # SDL_IMAGE_FOUND, if false, do not try to link against 10 | # SDL_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image 11 | # 12 | # 13 | # 14 | # For backward compatiblity the following variables are also set: 15 | # 16 | # :: 17 | # 18 | # SDLIMAGE_LIBRARY (same value as SDL_IMAGE_LIBRARIES) 19 | # SDLIMAGE_INCLUDE_DIR (same value as SDL_IMAGE_INCLUDE_DIRS) 20 | # SDLIMAGE_FOUND (same value as SDL_IMAGE_FOUND) 21 | # 22 | # 23 | # 24 | # $SDLDIR is an environment variable that would correspond to the 25 | # ./configure --prefix=$SDLDIR used in building SDL. 26 | # 27 | # Created by Eric Wing. This was influenced by the FindSDL.cmake 28 | # module, but with modifications to recognize OS X frameworks and 29 | # additional Unix paths (FreeBSD, etc). 30 | 31 | #============================================================================= 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # Copyright 2012 Benjamin Eikel 34 | # 35 | # Distributed under the OSI-approved BSD License (the "License"); 36 | # see accompanying file Copyright.txt for details. 37 | # 38 | # This software is distributed WITHOUT ANY WARRANTY; without even the 39 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | # See the License for more information. 41 | #============================================================================= 42 | # (To distribute this file outside of CMake, substitute the full 43 | # License text for the above reference.) 44 | 45 | find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h 46 | HINTS 47 | ENV SDL2IMAGEDIR 48 | ENV SDL2DIR 49 | PATH_SUFFIXES SDL2 50 | # path suffixes to search inside ENV{SDLDIR} 51 | include/SDL2 include 52 | ) 53 | 54 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 55 | set(VC_LIB_PATH_SUFFIX lib/x64) 56 | else() 57 | set(VC_LIB_PATH_SUFFIX lib/x86) 58 | endif() 59 | 60 | find_library(SDL2_IMAGE_LIBRARY 61 | NAMES SDL2_image 62 | HINTS 63 | ENV SDL2IMAGEDIR 64 | ENV SDL2DIR 65 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 66 | ) 67 | 68 | if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") 69 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") 70 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") 71 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") 72 | string(REGEX REPLACE "^#define[ \t]+SDL2_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") 73 | string(REGEX REPLACE "^#define[ \t]+SDL2_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") 74 | string(REGEX REPLACE "^#define[ \t]+SDL2_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") 75 | set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) 76 | unset(SDL2_IMAGE_VERSION_MAJOR_LINE) 77 | unset(SDL2_IMAGE_VERSION_MINOR_LINE) 78 | unset(SDL2_IMAGE_VERSION_PATCH_LINE) 79 | unset(SDL2_IMAGE_VERSION_MAJOR) 80 | unset(SDL2_IMAGE_VERSION_MINOR) 81 | unset(SDL2_IMAGE_VERSION_PATCH) 82 | endif() 83 | 84 | set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) 85 | set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) 86 | 87 | include(FindPackageHandleStandardArgs) 88 | 89 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image 90 | REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS 91 | VERSION_VAR SDL2_IMAGE_VERSION_STRING) 92 | 93 | # for backward compatiblity 94 | #set(SDLIMAGE_LIBRARY ${SDL_IMAGE_LIBRARIES}) 95 | #set(SDLIMAGE_INCLUDE_DIR ${SDL_IMAGE_INCLUDE_DIRS}) 96 | #set(SDLIMAGE_FOUND ${SDL_IMAGE_FOUND}) 97 | 98 | mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) 99 | -------------------------------------------------------------------------------- /cmake/FindSDL2_Mixer.cmake: -------------------------------------------------------------------------------- 1 | # Locate SDL_mixer library 2 | # 3 | # This module defines: 4 | # 5 | # :: 6 | # 7 | # SDL_MIXER_LIBRARIES, the name of the library to link against 8 | # SDL_MIXER_INCLUDE_DIRS, where to find the headers 9 | # SDL_MIXER_FOUND, if false, do not try to link against 10 | # SDL_MIXER_VERSION_STRING - human-readable string containing the version of SDL_mixer 11 | # 12 | # 13 | # 14 | # For backward compatiblity the following variables are also set: 15 | # 16 | # :: 17 | # 18 | # SDLMIXER_LIBRARY (same value as SDL_MIXER_LIBRARIES) 19 | # SDLMIXER_INCLUDE_DIR (same value as SDL_MIXER_INCLUDE_DIRS) 20 | # SDLMIXER_FOUND (same value as SDL_MIXER_FOUND) 21 | # 22 | # 23 | # 24 | # $SDLDIR is an environment variable that would correspond to the 25 | # ./configure --prefix=$SDLDIR used in building SDL. 26 | # 27 | # Created by Eric Wing. This was influenced by the FindSDL.cmake 28 | # module, but with modifications to recognize OS X frameworks and 29 | # additional Unix paths (FreeBSD, etc). 30 | 31 | #============================================================================= 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # Copyright 2012 Benjamin Eikel 34 | # 35 | # Distributed under the OSI-approved BSD License (the "License"); 36 | # see accompanying file Copyright.txt for details. 37 | # 38 | # This software is distributed WITHOUT ANY WARRANTY; without even the 39 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | # See the License for more information. 41 | #============================================================================= 42 | # (To distribute this file outside of CMake, substitute the full 43 | # License text for the above reference.) 44 | 45 | find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h 46 | HINTS 47 | ENV SDL2MIXERDIR 48 | ENV SDL2DIR 49 | PATH_SUFFIXES SDL2 50 | # path suffixes to search inside ENV{SDLDIR} 51 | include/SDL2 include 52 | ) 53 | 54 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 55 | set(VC_LIB_PATH_SUFFIX lib/x64) 56 | else() 57 | set(VC_LIB_PATH_SUFFIX lib/x86) 58 | endif() 59 | 60 | find_library(SDL2_MIXER_LIBRARY 61 | NAMES SDL2_mixer 62 | HINTS 63 | ENV SDL2MIXERDIR 64 | ENV SDL2DIR 65 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 66 | ) 67 | 68 | if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") 69 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") 70 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_MIXER_MINOR_VERSION[ \t]+[0-9]+$") 71 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_MIXER_PATCHLEVEL[ \t]+[0-9]+$") 72 | string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") 73 | string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") 74 | string(REGEX REPLACE "^#define[ \t]+SDL2_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") 75 | set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) 76 | unset(SDL2_MIXER_VERSION_MAJOR_LINE) 77 | unset(SDL2_MIXER_VERSION_MINOR_LINE) 78 | unset(SDL2_MIXER_VERSION_PATCH_LINE) 79 | unset(SDL2_MIXER_VERSION_MAJOR) 80 | unset(SDL2_MIXER_VERSION_MINOR) 81 | unset(SDL2_MIXER_VERSION_PATCH) 82 | endif() 83 | 84 | set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) 85 | set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) 86 | 87 | include(FindPackageHandleStandardArgs) 88 | 89 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer 90 | REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS 91 | VERSION_VAR SDL2_MIXER_VERSION_STRING) 92 | 93 | # for backward compatiblity 94 | #set(SDLMIXER_LIBRARY ${SDL_MIXER_LIBRARIES}) 95 | #set(SDLMIXER_INCLUDE_DIR ${SDL_MIXER_INCLUDE_DIRS}) 96 | #set(SDLMIXER_FOUND ${SDL_MIXER_FOUND}) 97 | 98 | mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) 99 | -------------------------------------------------------------------------------- /vigasoco/InfoJuego.h: -------------------------------------------------------------------------------- 1 | // InfoJuego.h 2 | // 3 | // Clase que muestra informaci�n interna del juego 4 | // 5 | // Cuando se llama al m�todo muestraInfo() se sobreescribe parte de la pantalla con mapas 6 | // del juego. En la esquina superior derecha se muestra el mapa de alturas para la 7 | // pantalla que sigue la c�mara. A la derecha del mapa de alturas se muestra el mapa de 8 | // alturas completo de la planta en la que est� el personaje al que sigue la c�mara. 9 | // Debajo del mapa de alturas de la pantalla actual se muestran los mapas de las plantas 10 | // en las que no se encuentra el personaje. 11 | // 12 | // Como actualmente VIGASOCO no soporte m�ltiples bitmpaps desde distintos threads, no 13 | // hay m�s remedio que dibujar encima del bitmap principal, por lo que aunque se desactive 14 | // parte de la informaci�n que se muestra, la zona de juego estar� sucia hasta que no se 15 | // redibuje, y la parte que no cae en la zona de juego no se limpiar�. Cuando VIGASOCO 16 | // soporte m�ltiples bitmaps en distintos threads esto se corregir�. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #ifndef _INFO_JUEGO_H_ 21 | #define _INFO_JUEGO_H_ 22 | 23 | #include 24 | #include 25 | #include "Types.h" 26 | 27 | class CPC6128; // definido en CPC6128.h 28 | 29 | namespace Abadia { 30 | 31 | class EntidadJuego; // definido en EntidadJuego.h 32 | class Objeto; // definido en Objeto.h 33 | class Personaje; // definido en Personaje.h 34 | class Puerta; // definido en Puerta.h 35 | class Sprite; // definido en Sprite.h 36 | 37 | class InfoJuego 38 | { 39 | // campos 40 | protected: 41 | int numPersonaje; // indica que personaje se est� mostrando actualmente 42 | int numObjeto; // indica que objeto se est� mostrando actualmente 43 | int numPuerta; // indica que puerta se est� mostrando actualmente 44 | bool mostrarLogica; // indica si se muestran los datos relacionados con la l�gica 45 | bool mostrarRejilla; // indica si se muestra la rejilla de pantalla 46 | bool mostrarMapaPlantaActual; // indica si se muestra el mapa de la planta actual 47 | bool mostrarMapaRestoPlantas; // indica si se muestra el mapa de las plantas en las que no estamos 48 | 49 | CPC6128 *cpc6128; // objeto de ayuda para realizar operaciones gr�ficas del cpc6128 50 | UINT8 *alturasPlanta[3]; // array de punteros a los buffers donde se almacenan las alturas de cada planta 51 | 52 | // tablas 53 | static int alturaBasePlanta[3]; // altura base de cada planta 54 | static int zonaVisiblePlanta[3][4]; // zonas visibles para cada planta 55 | 56 | // m�todos 57 | public: 58 | void inicia(); 59 | void muestraInfo(); 60 | 61 | // inicializaci�n y limpieza 62 | InfoJuego(); 63 | virtual ~InfoJuego(); 64 | 65 | // m�todos de ayuda 66 | protected: 67 | // dibujo de la rejilla 68 | void dibujaRejilla(); 69 | void dibujaPosicionRejilla(int x, int y, int valor); 70 | 71 | // dibujo de los mapas 72 | void generaAlturasPlanta(); 73 | void dibujaAlturaPlanta(int numPlanta); 74 | void dibujaAlturaPosicionPlanta(int posX, int posY, int x, int y, int zoom, UINT8 *alturas); 75 | void dibujaMapa(int posX, int numPlanta); 76 | 77 | // dibujo de la posici�n de los personajes 78 | void muestraPosicionMapaAlturas(int numPlanta); 79 | void muestraPosicionMapa(int posX, int numPlanta); 80 | 81 | // mostrar informaci�n sobre la l�gica y las entidades del juego 82 | void muestraInfoLogica(int x, int y); 83 | void muestraInfoPersonaje(int i, int x, int y); 84 | void muestraInfoPuerta(int i, int x, int y); 85 | void muestraInfoObjeto(int i, int x, int y); 86 | 87 | // dibujo de pixels 88 | void dibujaPixelCuadrado(int x, int y, int color); 89 | void dibujaPixelCuadradoZoom(int posX, int posY, int i, int j, int zoom, int color); 90 | 91 | // conversi�n de tipos a cadenas 92 | std::string muestraEntidad(EntidadJuego *entidad); 93 | std::string muestraPersonaje(int i, Personaje *pers); 94 | std::string muestraPuerta(Puerta *puerta); 95 | std::string muestraObjeto(Objeto *obj); 96 | std::string muestraSprite(Sprite *spr); 97 | 98 | // conversi�n de valores a cadenas 99 | std::string muestra(int valor); 100 | std::string muestra(bool valor); 101 | }; 102 | 103 | 104 | } 105 | 106 | #endif // _INFO_JUEGO_H_ 107 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if (VITA) 4 | add_compile_definitions(VITA) 5 | 6 | if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) 7 | if(DEFINED ENV{VITASDK}) 8 | set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file") 9 | else() 10 | message(FATAL_ERROR "Please define VITASDK to point to your SDK path!") 11 | endif() 12 | endif() 13 | endif() 14 | 15 | project (abbey) 16 | 17 | 18 | if(RG350) 19 | add_compile_definitions(RG350) 20 | SET(CMAKE_C_COMPILER "/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-gcc") 21 | SET(CMAKE_CXX_COMPILER "/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-g++") 22 | SET(CMAKE_RANLIB "/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-ranlib") 23 | SET(CMAKE_LINKER "/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-ld") 24 | SET(CMAKE_FIND_ROOT_PATH "/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot") 25 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 26 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 27 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 28 | add_compile_definitions(RG350) 29 | endif(RG350) 30 | 31 | if (VITA) 32 | include("${VITASDK}/share/vita.cmake" REQUIRED) 33 | set(VITA_APP_NAME "Abbey") 34 | set(VITA_TITLEID "ABBEY0001") 35 | set(VITA_VERSION "01.00") 36 | endif(VITA) 37 | 38 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -fno-lto -std=c++11") 39 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-q -Wall -fno-lto -std=c++11") 40 | 41 | file(GLOB_RECURSE vigasoco_core_SOURCES "vigasoco/*.cpp") 42 | file(GLOB_RECURSE vigasoco_SOURCES "src/*.cpp") 43 | 44 | include_directories( 45 | src 46 | vigasoco 47 | SDL2 48 | ) 49 | 50 | add_executable(${PROJECT_NAME} 51 | ${vigasoco_SOURCES} 52 | ${vigasoco_core_SOURCES} 53 | ) 54 | 55 | if (VITA) 56 | target_link_libraries(${PROJECT_NAME} 57 | SDL2_mixer 58 | SDL2 59 | vita2d 60 | SceDisplay_stub 61 | SceCtrl_stub 62 | SceAudio_stub 63 | SceSysmodule_stub 64 | SceGxm_stub 65 | SceCommonDialog_stub 66 | SceAppMgr_stub 67 | SceTouch_stub 68 | SceHid_stub 69 | SceMotion_stub 70 | m 71 | FLAC 72 | mikmod 73 | mpg123 74 | freetype 75 | png 76 | vorbisfile 77 | vorbis 78 | ogg 79 | z 80 | ) 81 | else(VITA) 82 | target_link_libraries(${PROJECT_NAME} 83 | SDL2_mixer 84 | SDL2 85 | ) 86 | endif(VITA) 87 | 88 | ######################################## 89 | ## Create packages for VITA and the RG350 90 | ######################################## 91 | if (VITA) 92 | vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME}) 93 | vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} ${PROJECT_NAME}.self 94 | VERSION ${VITA_VERSION} 95 | NAME ${VITA_APP_NAME} 96 | FILE build_vita/sce_sys/icon0.png sce_sys/icon0.png 97 | FILE build_vita/sce_sys/livearea/contents/bg.png sce_sys/livearea/contents/bg.png 98 | FILE build_vita/sce_sys/livearea/contents/startup.png sce_sys/livearea/contents/startup.png 99 | FILE build_vita/sce_sys/livearea/contents/template.xml sce_sys/livearea/contents/template.xml 100 | FILE build_vita/gamecontrollerdb.txt gamecontrollerdb.txt 101 | FILE build/fonts/arial.ttf fonts/arial.ttf 102 | FILE build/roms/abadia/abadia.dsk roms/abadia/abadia.dsk 103 | FILE build/roms/abadia/GraficosCPC roms/abadia/GraficosCPC 104 | FILE build/roms/abadia/GraficosVGA roms/abadia/GraficosVGA 105 | FILE build/roms/abadia/abrir.wav roms/abadia/abrir.wav 106 | FILE build/roms/abadia/aporrear.wav roms/abadia/aporrear.wav 107 | FILE build/roms/abadia/campanas.wav roms/abadia/campanas.wav 108 | FILE build/roms/abadia/cerrar.wav roms/abadia/cerrar.wav 109 | FILE build/roms/abadia/coger.wav roms/abadia/coger.wav 110 | FILE build/roms/abadia/dejar.wav roms/abadia/dejar.wav 111 | FILE build/roms/abadia/espejo.wav roms/abadia/espejo.wav 112 | FILE build/roms/abadia/final.wav roms/abadia/final.wav 113 | FILE build/roms/abadia/fondo.wav roms/abadia/fondo.wav 114 | FILE build/roms/abadia/inicio.wav roms/abadia/inicio.wav 115 | FILE build/roms/abadia/pasos.wav roms/abadia/pasos.wav 116 | FILE build/roms/abadia/tintineo.wav roms/abadia/tintineo.wav 117 | ) 118 | endif(VITA) 119 | 120 | if (RG350) 121 | add_custom_command(TARGET abbey 122 | POST_BUILD 123 | COMMAND sh make_opk.sh 124 | COMMENT "Creating OPK file..." 125 | ) 126 | endif(RG350) 127 | -------------------------------------------------------------------------------- /vigasoco/Pergamino.h: -------------------------------------------------------------------------------- 1 | // Pergamino.h 2 | // 3 | // Clase que representa el pergamino 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _PERGAMINO_H_ 8 | #define _PERGAMINO_H_ 9 | 10 | #include "Types.h" 11 | 12 | class CPC6128; // definido en CPC6128.h 13 | 14 | namespace Abadia { 15 | 16 | 17 | class Pergamino 18 | { 19 | // campos 20 | public: 21 | // array por cada idioma 22 | //static const char *pergaminoInicio[8]; // texto del pergamino de la presentaci�n del juego 23 | static const unsigned char *pergaminoInicio[8]; // texto del pergamino de la presentaci�n del juego 24 | //static const char *pergaminoFinal[8]; // texto del pergamino del final del juego 25 | static const unsigned char *pergaminoFinal[8]; // texto del pergamino del final del juego 26 | static const unsigned char *pergaminoReferencias[8]; // texto del pergamino del final del juego 27 | // no esta definido el caracter 5 en el pergamino y no podemos , por ejemplo, 28 | // poner el texto para F5 29 | // static const unsigned char *pergaminoAyudasyMejoras[8]; // texto del pergamino del final del juego 30 | static const unsigned char *pergaminoManejo[8]; // texto del pergamino del manejo del teclado 31 | static const unsigned char *pergaminoIntroduccion[8]; // texto del pergamino del manejo del teclado 32 | 33 | 34 | int posX, posY; // posici�n inicial del texto en el pergamino 35 | UINT16 *charTable; // puntero a la tabla de punteros a los gr�ficos de los caracteres 36 | UINT8 const *pTrazosCaracter; 37 | 38 | int x; 39 | int y; 40 | int dim; 41 | int num; 42 | int pasaPaginaStep; 43 | 44 | 45 | bool writing; 46 | bool finished; 47 | 48 | protected: 49 | CPC6128 *cpc6128; // objeto que presta ayuda para realizar operaciones gr�ficas del cpc6128 50 | UINT8 *roms; 51 | 52 | // m�todos 53 | public: 54 | //void muestraTexto(const char *texto); 55 | const unsigned char *texto; 56 | void muestraTexto(const unsigned char *mensaje); 57 | 58 | // inicializaci�n y limpieza 59 | Pergamino(); 60 | ~Pergamino(); 61 | 62 | // m�todos de ayuda 63 | protected: 64 | void dibuja(); 65 | void dibujaTexto(); 66 | 67 | void dibujaTiraHorizontal(int y, UINT8 *data); 68 | void dibujaTiraVertical(int x, UINT8 *data); 69 | 70 | void dibujaTriangulo(int x, int y, int lado, int color1, int color2); 71 | void restauraParteSuperiorYDerecha(int x, int y, int lado); 72 | void restauraParteInferior(int x, int y, int lado); 73 | bool pasaPagina(); 74 | private: 75 | int AdaptaColorAPaletaVGA(int a,int b); // VGA 76 | // los primeros 0x20 caracteres del ASCII no son imprimibles 77 | //UINT8 const *TablapTrazosCaracter[0x127-0x20]; 78 | // Para cubrir los caracteres usados en las traducciones 79 | // la tabla cubre los 255 posibles caracteres del ASCII extendido 80 | UINT8 const *TablapTrazosCaracter[0xFF-0x20]; 81 | static const UINT8 charD6[]; // � 82 | static const UINT8 charE0[]; // � 83 | static const UINT8 charE1[]; // � 84 | static const UINT8 charE3[]; // � 85 | static const UINT8 charE4[]; // � 86 | static const UINT8 charE7[]; // � 87 | static const UINT8 charE8[]; // � 88 | static const UINT8 charE9[]; // � 89 | static const UINT8 charEA[]; // � 90 | static const UINT8 charEC[]; // � 91 | static const UINT8 charED[]; // � 92 | static const UINT8 charEF[]; // � 93 | static const UINT8 charF1[]; // � 94 | static const UINT8 charF2[]; // � 95 | static const UINT8 charF3[]; // � 96 | static const UINT8 charF6[]; // � 97 | static const UINT8 charF9[]; // � 98 | static const UINT8 charFA[]; // � 99 | static const UINT8 charFC[]; // � 100 | 101 | // W y w, que en el original no se usaban 102 | // y la w estaba intercambiada por la enye � 103 | static const UINT8 char27[]; // ' 104 | static const UINT8 char42[]; // B 105 | static const UINT8 char46[]; // F 106 | static const UINT8 char49[]; // I 107 | static const UINT8 char4B[]; // K 108 | static const UINT8 char4E[]; // N 109 | static const UINT8 char51[]; // Q 110 | static const UINT8 char52[]; // R 111 | static const UINT8 char55[]; // U 112 | static const UINT8 char56[]; // V 113 | static const UINT8 char57[]; // W 114 | static const UINT8 char58[]; // X 115 | static const UINT8 char5A[]; // Z 116 | static const UINT8 char77[]; // w 117 | }; 118 | 119 | } 120 | 121 | #endif // _PERGAMINO_H_ 122 | -------------------------------------------------------------------------------- /vigasoco/GameDriver.cpp: -------------------------------------------------------------------------------- 1 | // GameDriver.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "FileLoader.h" 6 | #include "GameDataEntity.h" 7 | #include "GameDriver.h" 8 | #include "GfxData.h" 9 | #include 10 | #include 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | // initialization and cleanup 14 | ///////////////////////////////////////////////////////////////////////////// 15 | 16 | GameDriver::GameDriver(std::string driverName, std::string fullName, int intsPerSecond) 17 | { 18 | _driverName = driverName; 19 | _fullName = fullName; 20 | 21 | _numInterruptsPerSecond = intsPerSecond; 22 | _numInterruptsPerVideoUpdate = 1; 23 | _numInterruptsPerLogicUpdate = 1; 24 | 25 | _palette = 0; 26 | 27 | _errorMsg = ""; 28 | theFileLoader = new FileLoader(); 29 | } 30 | 31 | GameDriver::~GameDriver() 32 | { 33 | // delete graphics elements 34 | GfxElements::size_type i; 35 | 36 | for (i = 0; i < _gfx.size(); i++){ 37 | delete _gfx[i]; 38 | } 39 | 40 | // delete graphics encodings 41 | GfxEncodings::size_type j; 42 | 43 | for (j = 0; j < _gfxEncoding.size(); j++){ 44 | delete _gfxEncoding[j]; 45 | } 46 | 47 | // delete game's data files 48 | GameDataEntities::size_type k; 49 | 50 | for (k = 0; k < _gameFiles.size(); k++){ 51 | _gameFiles[k]->free(); 52 | delete _gameFiles[k]; 53 | } 54 | } 55 | 56 | ///////////////////////////////////////////////////////////////////////////// 57 | // game driver initialization and cleanup 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | bool GameDriver::init(SDLPalette *pal) 61 | { 62 | _palette = pal; 63 | 64 | // recalculate the refresh rate 65 | _videoInfo.refreshRate = _numInterruptsPerSecond/_numInterruptsPerVideoUpdate; 66 | 67 | // try to load all the files 68 | if (!loadFiles()){ 69 | return false; 70 | } 71 | 72 | // call template method to do any necessary processing 73 | filesLoaded(); 74 | 75 | // try to decode the graphics 76 | if (!decodeGraphics()){ 77 | _errorMsg = "unable to decode GFX"; 78 | deallocateFilesMemory(); 79 | 80 | return false; 81 | } 82 | 83 | // call template method to do any necessary processing 84 | graphicsDecoded(); 85 | 86 | // deallocate memory used by the files 87 | deallocateFilesMemory(); 88 | 89 | // call template method to inform that the initialization process has finished 90 | finishInit(); 91 | 92 | return true; 93 | } 94 | 95 | ///////////////////////////////////////////////////////////////////////////// 96 | // helper methods 97 | ///////////////////////////////////////////////////////////////////////////// 98 | 99 | bool GameDriver::loadFiles() 100 | { 101 | GameDataEntities::size_type i, j; 102 | 103 | // load the files 104 | for (i = 0; i < _gameFiles.size(); i++){ 105 | // if a file is missing, deallocates used memory and init fails 106 | if (!theFileLoader->loadGameData(_driverName, _gameFiles[i])){ 107 | // compose error message 108 | std::ostringstream buffer; 109 | buffer << "Unable to load " << _gameFiles[i]->getName() << "\nNeeded files:" << std::hex << std::setfill('0'); 110 | 111 | for (int f = 0; f < _gameFiles[i]->getNumFiles(); f++){ 112 | const GameFile *file = _gameFiles[i]->getFile(f); 113 | buffer << std::endl << file->fileName << " (size = 0x" << file->fileSize 114 | << ") (CRC32 = 0x" << std::setw(8) << file->CRC32 << ")"; 115 | } 116 | 117 | _errorMsg = buffer.str(); 118 | 119 | // free loaded files 120 | for (j = 0; j <= i; j++){ 121 | _gameFiles[j]->free(); 122 | } 123 | 124 | return false; 125 | } 126 | } 127 | 128 | // if all files were loaded, return ok status 129 | return true; 130 | } 131 | 132 | bool GameDriver::decodeGraphics() 133 | { 134 | GfxEncodings::size_type i = 0; 135 | GameDataEntities::size_type j = 0; 136 | 137 | while (i < _gfxEncoding.size()){ 138 | // if it's a graphic entity, decode it 139 | if (_gameFiles[j]->getType() == GRAPHICS){ 140 | 141 | // decode this data with the current encoding 142 | _gfx.push_back(GfxDecoder::decode(_gfxEncoding[i], _gameFiles[j]->getData())); 143 | 144 | i++, j++; 145 | } else { 146 | // otherwise skip it 147 | j++; 148 | 149 | // if we've processed all files and not all encodings, error! 150 | if (j == _gameFiles.size()){ 151 | return false; 152 | } 153 | } 154 | } 155 | 156 | return true; 157 | } 158 | 159 | void GameDriver::deallocateFilesMemory() 160 | { 161 | for (GameDataEntities::size_type i = 0; i < _gameFiles.size(); i++){ 162 | _gameFiles[i]->free(); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /vigasoco/GeneradorPantallas.h: -------------------------------------------------------------------------------- 1 | // GeneradorPantallas.h 2 | // 3 | // Clase que se encarga de generar los bloques que forman las pantallas, calcular la zona que 4 | // tapa el bloque y grabar toda esa informaci�n en la capas que forman el buffer de tiles. 5 | // Adem�s, esta clase se encarga de dibujar las pantallas una vez que se ha rellenado el buffer 6 | // de tiles. 7 | // 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifndef _GENERADOR_PANTALLAS_H_ 11 | #define _GENERADOR_PANTALLAS_H_ 12 | 13 | #include 14 | 15 | class CPC6128; // definido en CPC6128.h 16 | 17 | namespace Abadia { 18 | 19 | class Comando; // definido en Comando.h 20 | 21 | 22 | class GeneradorPantallas 23 | { 24 | // constantes 25 | public: 26 | //static const int nivelesProfTiles = 3; 27 | //Con 3 en CPC se ve bastante bien 28 | //pero con VGA hay imperfecciones visuales bastante notables (ver la pantalla en la iglesia justo antes de llegar 29 | //a la pantalla del altar. Hay un pulpito al que se llega por unas escaleras, en el que queda un hueco sin dibujar que 30 | //queda con el color de fondo de la pantalla !!! 31 | // En el remake 32 bits 256 colores el pulpito se ve bien, pero en el suelo al empezar las escaleras, se mezclan 2 tipos 32 | // de suelos � cual es el bueno ? por que en la pantalla anterior, en la otra vista, el suelo es gris completo antes de 33 | // empezar las escaleras ..., pero en esta pantalla salen losas cuadradas ... 34 | // 35 | static const int nivelesProfTiles = 4; // Con esto ya se ve bien casi todo, incluso a veces mejor al remake 32 bits 256 colores 36 | // static const int nivelesProfTiles = 5; // No se nota diferencia con el anterior ... 37 | //hay que usar al menos 2, ya que los parches al mapeo de pantallas 38 | //copiados del remake de PC modifican los 2 primeros niveles 39 | //y si no existen da core al sobreescribir memoria 40 | 41 | 42 | // tipos 43 | public: 44 | struct TileInfo { 45 | UINT8 profX[nivelesProfTiles]; // profundidad del tile en x (en coordenadas locales) 46 | UINT8 profY[nivelesProfTiles]; // profundidad del tile en y (en coordenadas locales) 47 | UINT8 tile[nivelesProfTiles]; // n�mero de tile 48 | }; 49 | 50 | // campos 51 | public: 52 | UINT8 *roms; // puntero a los datos del juego 53 | CPC6128 *cpc6128; // objeto de ayuda para realizar operaciones gr�ficas del cpc6128 54 | 55 | TileInfo bufferTiles[20][16]; // buffer de tiles (16x20 tiles) 56 | int mascaras[4][4]; // tablas de m�scaras and y or para cada uno de los colores 57 | 58 | UINT8 *datosPantalla; // puntero a los datos que forman la pantalla 59 | int comandosBloque; // desplazamiento a los datos de los comandos que forman un bloque 60 | int datosBloque[17]; // buffer donde guarda los datos para construir el bloque actual 61 | int tilePosX, tilePosY; // posici�n actual en el buffer de tiles 62 | bool cambioSistemaCoord; // indica si se ha cambiado el sistema de coordenadas 63 | int estadoOpsX[4]; // usado para cambiar el sentido de las x en algunas operaciones 64 | 65 | protected: 66 | int pila[64]; // pila para evaluar los comandos de generaci�n de bloques 67 | int posPila; // posici�n actual de la pila 68 | 69 | Comando* manejadores[0x1c]; // tabla con los manejadores para cada comando 70 | 71 | // m�todos 72 | public: 73 | // m�todos para la generaci�n de bloques 74 | void genera(UINT8 *datosPantalla); 75 | void Parchea(UINT8 numPantalla); 76 | void iniciaInterpretacionBloque(UINT8 *tilesBloque, bool modificaTiles, int altura); 77 | 78 | // m�todos de dibujado de tiles 79 | void grabaTile(int tile); 80 | void actualizaTile(int tile, TileInfo *tileDesc); 81 | void limpiaPantalla(int color); 82 | void dibujaBufferTiles(); 83 | 84 | bool dibujaBufferTiles2(); 85 | 86 | // operaciones sobre registros y expresiones del generador de bloques 87 | int leeDatoORegistro(int *posReg); 88 | int obtenerRegistro(int reg, int *posReg); 89 | int actualizaRegistro(int reg, int delta); 90 | int evaluaExpresion(int rdo); 91 | 92 | // operaciones sobre la pila 93 | void push(int data); 94 | int pop(); 95 | 96 | // inicializaci�n y limpieza 97 | GeneradorPantallas(); 98 | ~GeneradorPantallas(); 99 | 100 | // m�todos de ayuda 101 | int obtenerDir(int direccion); 102 | 103 | int tilesAnimationCounter; 104 | int x, y; 105 | int abajo, derecha, arriba, izquierda; 106 | protected: 107 | void transformaCoordBloqueRejilla(int altura); 108 | void interpretaComandos(); 109 | 110 | void generaMascaras(); 111 | 112 | void dibujaTile(int x, int y, int num); 113 | void dibujaTira(int &x, int &y, int deltaX, int deltaY, int veces); 114 | }; 115 | 116 | 117 | } 118 | 119 | #endif // _GENERADOR_PANTALLAS_H_ 120 | -------------------------------------------------------------------------------- /vigasoco/GameDriver.h: -------------------------------------------------------------------------------- 1 | // GameDriver.h 2 | // 3 | // Abstract class that models a game 4 | // 5 | // All game drivers should inherit from this class. This class defines some 6 | // template methods in order to simplify common tasks. 7 | // 8 | // The lifecycle of a game driver is: 9 | // * fill all game fields in the constructor (video info, game files, gfx 10 | // format, input ports, DIPS, etc). 11 | // * the core calls to GameDriver::init that does the following: 12 | // - load all the files in the game data entities. 13 | // - call template method filesLoaded, where the driver does specific 14 | // initialization (set color palette, unscramble gfx, etc). 15 | // - decode all game data entity of type GRAPHICS, using the items in 16 | // _gfxEncoding (the first graphic entity uses the first item, and so on). 17 | // - call template method graphicsDecoded, where the driver can do any 18 | // specific processing. 19 | // - deallocate the memory used by the game data entities. 20 | // - call template method finishInit, where the driver can do last 21 | // specific processing before the driver starts running. 22 | // * the core calls to the template method videoInitialized after creating the 23 | // graphic plugin. 24 | // * while the application is running, the core calls to: 25 | // - GameDriver::runAsync, only once at the beginning, that starts a new 26 | // thread to execute game logic that isn't synchronized with a frame. 27 | // - GameDriver::runSync, that executes the logic for a frame. 28 | // - GameDriver::render, that draws the game bitmap. 29 | // - GameDriver::showGameLogic, that it's used to show some internal 30 | // data in order to better understand how the game works. 31 | // * when the application is closing, the core calls to the template method 32 | // videoFinalizing to notify that the graphic plugin is going to be disposed. 33 | // After that, it calls to the template method end where the driver can 34 | // perform any specific cleanup. 35 | // 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | #ifndef _GAME_DRIVER_H_ 39 | #define _GAME_DRIVER_H_ 40 | 41 | #include "FileLoader.h" 42 | #include "GameDataEntity.h" 43 | #include "SDLPalette.h" 44 | #include 45 | #include "Types.h" 46 | #include 47 | 48 | class IDrawPlugin; // defined in video/IDrawPlugin.h 49 | struct GfxElement; // defined in GfxData.h 50 | struct GfxEncoding; // defined in GfxData.h 51 | 52 | class GameDriver 53 | { 54 | // types 55 | public: 56 | typedef std::vector GameDataEntities; 57 | typedef std::vector GfxEncodings; 58 | typedef std::vector GfxElements; 59 | // typedef std::vector InputPorts; 60 | 61 | // fields 62 | protected: 63 | std::string _driverName; 64 | std::string _fullName; 65 | VideoInfo _videoInfo; 66 | 67 | int _numInterruptsPerSecond; 68 | int _numInterruptsPerVideoUpdate; 69 | int _numInterruptsPerLogicUpdate; 70 | 71 | GameDataEntities _gameFiles; 72 | GfxEncodings _gfxEncoding; 73 | GfxElements _gfx; 74 | 75 | SDLPalette *_palette; 76 | 77 | std::string _errorMsg; 78 | 79 | // methods 80 | public: 81 | FileLoader *theFileLoader; 82 | // getters 83 | const VideoInfo *getVideoInfo() const { return &_videoInfo; } 84 | const std::string getDriverName() const { return _driverName; } 85 | const std::string getFullName() const { return _fullName; } 86 | const GameDataEntities* getGameFiles() const { return &_gameFiles; } 87 | const GfxEncodings* getGameGfxEncoding() const { return &_gfxEncoding; } 88 | const GfxElements* getGameGfx() const { return &_gfx; } 89 | int getNumInterruptsPerSecond() const { return _numInterruptsPerSecond; } 90 | int getNumInterruptsPerVideoUpdate() const { return _numInterruptsPerVideoUpdate; } 91 | int getnumInterruptsPerLogicUpdate() const { return _numInterruptsPerLogicUpdate; } 92 | const std::string getError() const { return _errorMsg; } 93 | 94 | // game driver initialization and cleanup 95 | bool init(SDLPalette *pal); 96 | virtual void end() = 0; 97 | 98 | virtual void preRun() = 0; 99 | virtual void runSync() = 0; 100 | virtual void runAsync() = 0; 101 | virtual void render() = 0; 102 | 103 | virtual void showMenu() = 0; 104 | virtual void changeState(int newState) = 0; 105 | virtual void showGameLogic() = 0; 106 | 107 | 108 | // initialization and cleanup 109 | GameDriver(std::string driverName, std::string fullName, int intsPerSecond); 110 | virtual ~GameDriver(); 111 | 112 | 113 | 114 | 115 | 116 | 117 | protected: 118 | // template methods 119 | virtual void filesLoaded(){} 120 | virtual void graphicsDecoded(){} 121 | virtual void finishInit(){} 122 | 123 | // helper methods 124 | bool loadFiles(); 125 | bool decodeGraphics(); 126 | void deallocateFilesMemory(); 127 | }; 128 | 129 | #endif // _GAME_DRIVER_H_ 130 | -------------------------------------------------------------------------------- /vigasoco/BuscadorRutas.h: -------------------------------------------------------------------------------- 1 | // BuscadorRutas.h 2 | // 3 | // Clase que contiene los m�todos para buscar rutas y caminos entre posiciones 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _BUSCADOR_RUTAS_H_ 8 | #define _BUSCADOR_RUTAS_H_ 9 | 10 | 11 | #include "Singleton.h" 12 | #include "Types.h" 13 | 14 | #include "EntidadJuego.h" 15 | 16 | namespace Abadia { 17 | 18 | class FijarOrientacion; // definido en FijarOrientacion.h 19 | class PersonajeConIA; // definido en PersonajeConIA.h 20 | class RejillaPantalla; // definido en RejillaPantalla.h 21 | 22 | #define elBuscadorDeRutas BuscadorRutas::getSingletonPtr() 23 | 24 | class BuscadorRutas : public Singleton 25 | { 26 | // campos 27 | public: 28 | bool generadoCamino; // indica si se ha generado alg�n camino en esta iteraci�n del bucle principal 29 | bool seBuscaRuta; // indica si se ejecuta el buscador de rutas o no 30 | int contadorAnimGuillermo; // contador de la animaci�n de guillermo al inicio de esta iteraci�n del bucle principal 31 | 32 | int numAlternativas; // n�mero de alternativas generadas 33 | int alternativaActual; // alternativa que se est� probando actualmente 34 | int nivelRecursion; // nivel de recursi�n de la �ltima ejecuci�n del algoritmo de b�squeda de caminos 35 | int posXIni, posYIni; // datos sobre la posici�n final de las b�squedas 36 | int posXFinal, posYFinal, oriFinal; // datos sobre la posici�n final de las b�squedas 37 | 38 | RejillaPantalla *rejilla; // objeto para realizar operaciones relacionadas con la rejilla de pantalla 39 | 40 | protected: 41 | INT32 *buffer; // buffer para la b�squeda de caminos 42 | int lgtudBuffer; // longitud del buffer de b�squeda 43 | 44 | static UINT8 habitaciones[3][256]; // tabla con las habitaciones alcanzables desde una habitaci�n concreta 45 | static UINT8 habitacionesPuerta[6][4]; // tabla con las puertas y las habitaciones que comunican 46 | static PosicionJuego alternativas[5]; // posiciones alternativas para la b�squeda del camino 47 | static int despOrientacion[4][2]; // tabla de desplazamientos seg�n la orientaci�n 48 | static int posDestinoOrientacion[4][2]; // tabla con las posiciones de destino seg�n la orientaci�n 49 | 50 | int posPila; // posici�n actual de la pila 51 | int posProcesadoPila; // posici�n de la pila mientras se examinan las alternativas 52 | 53 | FijarOrientacion *fijaPosOri[4]; // objetos para indicar las posiciones a las que hay que ir seg�n la orientaci�n a coger 54 | 55 | // m�todos 56 | public: 57 | // inicializaci�n y limpieza 58 | BuscadorRutas(UINT8 *buf, int lgtud); 59 | ~BuscadorRutas(); 60 | 61 | void modificaPuertasRuta(int mascara); 62 | void generaAccionesMovimiento(PersonajeConIA *pers); 63 | 64 | int buscaCamino(PersonajeConIA *origen, PosicionJuego *destino); 65 | bool buscaEnPantalla(int posXDest, int posYDest); 66 | bool esPosicionDestino(int posX, int posY, int altura, int alturaBase, bool buscandoSolucion); 67 | void limpiaBitsBusquedaEnPantalla(); 68 | 69 | // m�todos de ayuda 70 | protected: 71 | // m�todos de m�s alto nivel relacionados con la b�squeda y generaci�n de rutas 72 | void generaAlternativas(PosicionJuego *pos, int oriInicial, int oldOri); 73 | void generaAlternativa(PosicionJuego *pos, int orientacion, int oldOri); 74 | void procesaAlternativas(PersonajeConIA *pers, PosicionJuego *destino); 75 | 76 | int generaCaminoAPantalla(PersonajeConIA *pers, int numPlanta); 77 | 78 | void generaAlturasPantalla(PersonajeConIA *pers); 79 | bool estaCerca(int coord1, int coord2, int &distancia); 80 | 81 | int generaCaminoAPosicion(PersonajeConIA *pers, int posXDest, int posYDest); 82 | int generaCaminoAPosicionSiAlcanzable(PersonajeConIA *pers, int posXDest, int posYDest); 83 | int compruebaFinCamino(PersonajeConIA *pers, bool encontrado); 84 | 85 | void grabaComandosCamino(PersonajeConIA *pers); 86 | void reconstruyeCamino(PersonajeConIA *pers); 87 | 88 | // m�todos relacionados con la b�squeda de caminos en una pantalla 89 | bool buscaEnPantalla(); 90 | bool buscaEnPantallaSiAlcanzable(int posXDest, int posYDest); 91 | bool buscaEnPantallaComun(); 92 | bool esPosicionAlcanzable(int posX, int posY, int altura); 93 | bool esPosicionDestino(int posX, int posY, int alturaBase); 94 | 95 | // m�todos relacionados con la b�squeda de caminos entre pantallas 96 | bool buscaPantalla(int numPlanta, int mascara); 97 | bool buscaPantalla(int posXDest, int posYDest, int numPlanta); 98 | bool esPantallaDestino(int posX, int posY, int numPlanta, int mascara, int mascaraDestino); 99 | void limpiaBitsBusquedaPantalla(int numPlanta); 100 | 101 | // operaciones sobre la pila 102 | void push(INT32 val1, INT32 val2); 103 | void pop(INT32 &val1, INT32 &val2); 104 | void elem(int posicion, INT32 &val1, INT32 &val2); 105 | void pushInv(int &posicion, INT32 val1, INT32 val2); 106 | void pushInv(int &posicion, INT32 val1); 107 | void popInv(int &posicion, INT32 &val1); 108 | void popInv(int &posicion, INT32 &val1, INT32 &val2); 109 | }; 110 | 111 | 112 | } 113 | 114 | #endif // _BUSCADOR_RUTAS_H_ 115 | -------------------------------------------------------------------------------- /vigasoco/cpc6128.h: -------------------------------------------------------------------------------- 1 | // cpc6128.h 2 | // 3 | // This class has helper methods for working with CPC6128 games 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _CPC_6128_H_ 8 | #define _CPC_6128_H_ 9 | 10 | #include 11 | #include "Types.h" 12 | #include "system.h" 13 | #include "SDLPalette.h" 14 | 15 | // friendly color names 16 | enum Inks { 17 | BLACK, 18 | BLUE, 19 | BRIGHT_BLUE, 20 | RED, 21 | MAGENTA, 22 | MAUVE, 23 | BRIGHT_RED, 24 | PURPLE, 25 | BRIGHT_MAGENTA, 26 | GREEN, 27 | CYAN, 28 | SKY_BLUE, 29 | YELLOW, 30 | WHITE, 31 | PASTEL_BLUE, 32 | ORANGE, 33 | PINK, 34 | PASTEL_MAGENTA, 35 | BRIGHT_GREEN, 36 | SEA_GREEN, 37 | BRIGHT_CYAN, 38 | LIME, 39 | PASTEL_GREEN, 40 | PASTEL_CYAN, 41 | BRIGHT_YELLOW, 42 | PASTEL_YELLOW, 43 | BRIGHT_WHITE 44 | }; 45 | 46 | class CPC6128 47 | { 48 | // tables 49 | protected: 50 | // hardware palette 51 | static UINT8 hardwarePalette[32][3]; 52 | 53 | // ink to hardware color conversion 54 | static int inkColors[27]; 55 | 56 | public: 57 | UINT8 screenBuffer[640*200]; // CPC6128 video RAM 58 | //TODO VGA hay que usar esto ya que no se puede usar un bit como marcador 59 | //al igual que en CPC 60 | UINT8 DirtyPixels[(640*200)/8]; // pixeles modificados en la CPC6128 video RAM 61 | 62 | // initialization and cleanup 63 | CPC6128(); 64 | ~CPC6128(); 65 | 66 | // palette related 67 | void setHardwareColor(SDLPalette *pal, int color, int value); 68 | void setInkColor(SDLPalette *pal, int color, int value); 69 | 70 | // pixel drawing/retrieving 71 | void setMode0Pixel(int x, int y, int color); 72 | void setMode1Pixel(int x, int y, int color); 73 | void setVGAPixel(int x, int y, int color); // TODO: VGA 74 | void setMode2Pixel(int x, int y, int color); 75 | int getMode0Pixel(int x, int y); 76 | int getMode1Pixel(int x, int y); 77 | int getMode2Pixel(int x, int y); 78 | 79 | void markAllPixelsDirty(); 80 | 81 | void showMode0Screen(const UINT8 *data); 82 | void showVGAScreen(const UINT8 *data); 83 | 84 | // rectangle filling 85 | void fillMode0Rect(int x, int y, int width, int height, int color); 86 | void fillMode1Rect(int x, int y, int width, int height, int color); 87 | void fillMode2Rect(int x, int y, int width, int height, int color); 88 | 89 | // pixel unpacking 90 | inline int unpackPixelMode0(int data, int pixel) 91 | { 92 | return (((data >> (1 - pixel)) & 0x01) << 3) | (((data >> (5 - pixel)) & 0x01) << 2) | (((data >> (3 - pixel)) & 0x01) << 1) | (((data >> (7 - pixel)) & 0x01) << 0); 93 | } 94 | 95 | inline int unpackPixelMode1(int data, int pixel) 96 | { 97 | return (((data >> (3 - pixel)) & 0x01) << 1) | ((data >> (7 - pixel)) & 0x01); 98 | } 99 | 100 | inline int unpackPixelMode2(int data, int pixel) 101 | { 102 | return (data >> (7 - pixel)) & 0x01; 103 | } 104 | 105 | // pixel packing 106 | inline int packPixelMode0(int oldByte, int pixel, int color) 107 | { 108 | assert ((pixel >= 0) && (pixel < 2)); 109 | assert ((color >= 0) && (color < 16)); 110 | 111 | // find out the 4 bits of the new pixel 112 | int mask = 0xaa; 113 | mask = mask >> pixel; 114 | 115 | // save the other pixels 116 | oldByte = (oldByte & (~mask)) & 0xff; 117 | 118 | // array with the sixteen colors 119 | static int byteColors[16] = { 120 | 0x00, 0xc0, 0x44, 0xcc, 0x30, 0xf0, 0x74, 0xfc, 121 | 0x03, 0xc3, 0x47, 0xcf, 0x33, 0xf3, 0x77, 0xff 122 | }; 123 | 124 | // combines the other pixels with the new pixel 125 | return oldByte | (byteColors[color] & mask); 126 | } 127 | 128 | // pixel packing 129 | inline int packPixelMode1(int oldByte, int pixel, int color) 130 | { 131 | assert ((pixel >= 0) && (pixel < 4)); 132 | assert ((color >= 0) && (color < 4)); 133 | 134 | // find out the 2 bits of the new pixel 135 | int mask = 0x88; 136 | mask = mask >> pixel; 137 | 138 | // save the other pixels 139 | oldByte = (oldByte & (~mask)) & 0xff; 140 | 141 | // array with the four colors 142 | static int byteColors[4] = { 0x00, 0xf0, 0x0f, 0xff }; 143 | 144 | // combines the other pixels with the new pixel 145 | return oldByte | (byteColors[color] & mask); 146 | } 147 | 148 | // pixel packing 149 | inline int packPixelMode2(int oldByte, int pixel, int color) 150 | { 151 | assert ((pixel >= 0) && (pixel < 8)); 152 | assert ((color >= 0) && (color < 2)); 153 | 154 | // find out the bit of the new pixel 155 | int mask = 0x80; 156 | mask = mask >> pixel; 157 | 158 | // save the other pixels 159 | oldByte = (oldByte & (~mask)) & 0xff; 160 | 161 | // array with the two colors 162 | static int byteColors[2] = { 0x00, 0xff }; 163 | 164 | // combines the other pixels with the new pixel 165 | return oldByte | (byteColors[color] & mask); 166 | } 167 | 168 | // pixel get/set 169 | inline void setPixel(int x, int y, int color) 170 | { 171 | // VGA 172 | // set pixel 173 | screenBuffer[y*640 + x] = color; 174 | 175 | // mark the pixel as dirty 176 | UINT8 *p=&(DirtyPixels[(y*640 + x)/8]); 177 | UINT8 bit = 1<<((y*640 + x)%8); 178 | *p = *p|bit; 179 | 180 | } 181 | 182 | inline int getPixel(int x, int y) 183 | { 184 | // VGA 185 | return screenBuffer[y*640 + x]; 186 | } 187 | 188 | // helper methods 189 | protected: 190 | void fillRect(int x, int y, int width, int height, int color); 191 | }; 192 | 193 | #endif // _CPC_6128_H_ 194 | -------------------------------------------------------------------------------- /vigasoco/SpriteLuz.cpp: -------------------------------------------------------------------------------- 1 | // SpriteLuz.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "Juego.h" 6 | #include "Personaje.h" 7 | #include "SpriteLuz.h" 8 | #include "cpc6128.h" 9 | 10 | using namespace Abadia; 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | // tabla con el patr�n de relleno de la luz 14 | ///////////////////////////////////////////////////////////////////////////// 15 | 16 | int SpriteLuz::rellenoLuz[16] = { 17 | 0x00e0, 18 | 0x03f8, 19 | 0x07fc, 20 | 0x07fc, 21 | 0x0ffe, 22 | 0x0ffe, 23 | 0x1fff, 24 | 0x1fff, 25 | 0x1fff, 26 | 0x1fff, 27 | 0x0ffe, 28 | 0x0ffe, 29 | 0x07fc, 30 | 0x07fc, 31 | 0x03f8, 32 | 0x00e0 33 | }; 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | // inicializaci�n y limpieza 37 | ///////////////////////////////////////////////////////////////////////////// 38 | 39 | SpriteLuz::SpriteLuz() 40 | { 41 | ancho = oldAncho = 80/4; 42 | alto = oldAlto = 80; 43 | 44 | posXLocal = posYLocal = 0xfe; 45 | 46 | flipX = false; 47 | rellenoAbajo = 0; 48 | rellenoArriba = 0; 49 | rellenoDerecha = 0; 50 | rellenoIzquierda = 0; 51 | } 52 | 53 | SpriteLuz::~SpriteLuz() 54 | { 55 | } 56 | 57 | ///////////////////////////////////////////////////////////////////////////// 58 | // colocaci�n de la luz 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | // ajusta el sprite de la luz a la posici�n del personaje que se le pasa 62 | void SpriteLuz::ajustaAPersonaje(Personaje *pers) 63 | { 64 | // asigna una profundidad en pantalla muy alta al sprite de la luz 65 | posXLocal = 0xfe; 66 | posYLocal = 0xfe; 67 | 68 | // calcula los rellenos del sprite de la luz seg�n la posici�n del personaje 69 | rellenoIzquierda = (pers->sprite->posXPant & 0x03)*4; 70 | rellenoDerecha = (4 - (pers->sprite->posXPant & 0x03))*4; 71 | rellenoArriba = ((pers->sprite->posYPant & 0x07) >= 4) ? 0xf0*4 : 0xa0*4; 72 | rellenoAbajo = ((pers->sprite->posYPant & 0x07) >= 4) ? 0xa0*4 : 0xf0*4; 73 | 74 | // coloca la posici�n de la luz basada en la posici�n del personaje (ajustando la posici�n al inicio de un tile) 75 | posXPant = (pers->sprite->posXPant & 0xfc) - 8; 76 | if (posXPant < 0) posXPant = 0; 77 | posYPant = (pers->sprite->posYPant & 0xf8) - 24; 78 | if (posYPant < 0) posYPant = 0; 79 | 80 | oldPosXPant = posXPant; 81 | oldPosYPant = posYPant; 82 | 83 | // obtiene si el personaje est� girado 84 | flipX = pers->flipX; 85 | } 86 | 87 | ///////////////////////////////////////////////////////////////////////////// 88 | // dibujado de sprites 89 | ///////////////////////////////////////////////////////////////////////////// 90 | 91 | // dibuja la parte visible del sprite actual en el �rea ocupada por el sprite que se le pasa como par�metro 92 | void SpriteLuz::dibuja(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y) 93 | { 94 | // rellena de negro la parte superior del sprite 95 | for (int i = 0; i < rellenoArriba; i++){ 96 | // CPC *bufferMezclas = 3; 97 | *bufferMezclas = 0; // VGA 98 | bufferMezclas++; 99 | } 100 | 101 | // para 15 bloques 102 | for (int j = 0; j < 15; j++){ 103 | // guarda la posici�n inicial de este bloque 104 | UINT8 *posBuffer = bufferMezclas; 105 | 106 | // obtiene el patr�n para rellenar este bloque 107 | int patron = rellenoLuz[j]; 108 | 109 | // rellena 4 l�neas de alto en la parte de la izquierda 110 | for (int i = 0; i < rellenoIzquierda; i++){ 111 | /* CPC 112 | bufferMezclas[0] = 3; 113 | bufferMezclas[20*4] = 3; 114 | bufferMezclas[40*4] = 3; 115 | bufferMezclas[60*4] = 3; 116 | */ 117 | // VGA 118 | bufferMezclas[0] = bufferMezclas[20*4] = bufferMezclas[40*4] = bufferMezclas[60*4] = 0; 119 | 120 | bufferMezclas++; 121 | } 122 | 123 | // modifica levemente el patr�n dependiendo de a donde mira el personaje 124 | if (flipX){ 125 | patron = patron << 1; 126 | } 127 | 128 | // completa el sprite de la luz seg�n el patr�n de relleno 129 | for (int i = 0; i < 16; i++){ 130 | // si el bit actual es 0, rellena de negro un bloque de 4x4 131 | if ((patron & 0x8000) == 0){ 132 | for (int k = 0; k < 4; k++){ 133 | /* CPC 134 | bufferMezclas[0] = 3; 135 | bufferMezclas[20*4] = 3; 136 | bufferMezclas[40*4] = 3; 137 | bufferMezclas[60*4] = 3; 138 | */ 139 | // VGA 140 | bufferMezclas[0] = bufferMezclas[20*4] = bufferMezclas[40*4] = bufferMezclas[60*4] = 0; 141 | 142 | bufferMezclas++; 143 | } 144 | } else { 145 | bufferMezclas += 4; 146 | } 147 | 148 | patron = patron << 1; 149 | } 150 | 151 | // rellena 4 l�neas de alto en la parte de la derecha 152 | for (int i = 0; i < rellenoDerecha; i++){ 153 | /* CPC 154 | bufferMezclas[0] = 3; 155 | bufferMezclas[20*4] = 3; 156 | bufferMezclas[40*4] = 3; 157 | bufferMezclas[60*4] = 3; */ 158 | // VGA 159 | bufferMezclas[0] = bufferMezclas[20*4] = bufferMezclas[40*4] = bufferMezclas[60*4] = 0; 160 | 161 | bufferMezclas++; 162 | } 163 | 164 | // avanza la posici�n hasta la del siguiente bloque 165 | bufferMezclas = posBuffer + 80*4; 166 | } 167 | 168 | // rellena de negro la parte inferior del sprite 169 | for (int i = 0; i < rellenoAbajo; i++){ 170 | // CPC *bufferMezclas = 3; 171 | *bufferMezclas = 0; // VGA 172 | bufferMezclas++; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /vigasoco/SpriteMonje.cpp: -------------------------------------------------------------------------------- 1 | // SpriteMonje.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "Juego.h" 6 | #include "SpriteMonje.h" 7 | #include "cpc6128.h" 8 | 9 | using namespace Abadia; 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // tabla de desplazamientos a los datos gr�ficos de los trajes de los monjes 13 | ///////////////////////////////////////////////////////////////////////////// 14 | 15 | // CPC 16 | /* 17 | int SpriteMonje::despAnimTraje[16] = { 18 | 0x0ab59 + 0x0082, 19 | 0x0ab59 + 0x0000, 20 | 0x0ab59 + 0x0082, 21 | 0x0ab59 + 0x00fa, 22 | 0x0ab59 + 0x0262, 23 | 0x0ab59 + 0x0172, 24 | 0x0ab59 + 0x0262, 25 | 0x0ab59 + 0x01ef, 26 | 0x16b59 + 0x0262, 27 | 0x16b59 + 0x0172, 28 | 0x16b59 + 0x0262, 29 | 0x16b59 + 0x01ef, 30 | 0x16b59 + 0x0082, 31 | 0x16b59 + 0x0000, 32 | 0x16b59 + 0x0082, 33 | 0x16b59 + 0x00fa 34 | }; 35 | */ 36 | // VGA 37 | int SpriteMonje::despAnimTraje[16] = { 38 | 61628, // 0x0ab59 + 0x0082, 39 | 61108, // 0x0ab59 + 0x0000, 40 | 61628, // 0x0ab59 + 0x0082, 41 | 62108, // 0x0ab59 + 0x00fa, 42 | 63548, // 0x0ab59 + 0x0262, 43 | 62588, // 0x0ab59 + 0x0172, 44 | 63548, // 0x0ab59 + 0x0262, 45 | 63088, // 0x0ab59 + 0x01ef, 46 | 63548+120305, // 0x16b59 + 0x0262, 47 | 62588+120305, // 0x16b59 + 0x0172, 48 | 63548+120305, // 0x16b59 + 0x0262, 49 | 63088+120305, // 0x16b59 + 0x01ef, 50 | 61628+120305, // 0x16b59 + 0x0082, 51 | 61108+120305, // 0x16b59 + 0x0000, 52 | 61628+120305, // 0x16b59 + 0x0082, 53 | 62108+120305, // 0x16b59 + 0x00fa 54 | }; 55 | 56 | ///////////////////////////////////////////////////////////////////////////// 57 | // inicializaci�n y limpieza 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | SpriteMonje::SpriteMonje() 61 | { 62 | animacionTraje = 0; 63 | } 64 | 65 | SpriteMonje::~SpriteMonje() 66 | { 67 | } 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | // dibujado de sprites 72 | ///////////////////////////////////////////////////////////////////////////// 73 | 74 | /* CPC 75 | // dibuja la parte visible del sprite actual en el �rea ocupada por el sprite que se le pasa como par�metro 76 | void SpriteMonje::dibuja(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y) 77 | { 78 | // obtiene los objetos que se usan luego 79 | UINT8 *roms = elJuego->roms; 80 | CPC6128 *cpc6128 = elJuego->cpc6128; 81 | 82 | int despSrc; 83 | 84 | // si ya ha pasado la zona de la cabeza, obtiene los gr�ficos de la parte del traje 85 | if (dist2Y >= 10){ 86 | despSrc = despAnimTraje[animacionTraje] + (dist2Y - 10)*ancho + dist2X; 87 | } else { 88 | despSrc = despGfx + dist2Y*ancho + dist2X; 89 | } 90 | 91 | // calcula la direcci�n de destino de los gr�ficos en el buffer de sprites 92 | int despDest = spr->despBuffer + (dist1Y*spr->anchoFinal + dist1X)*4; 93 | 94 | // recorre los pixels visibles en Y 95 | for (int lgtudY = 0; lgtudY < lgtudClipY; lgtudY++){ 96 | UINT8 *src = &roms[despSrc]; 97 | UINT8 *dest = &bufferMezclas[despDest]; 98 | 99 | // recorre los pixels visibles en X 100 | for (int lgtudX = 0; lgtudX < lgtudClipX; lgtudX++){ 101 | // lee un byte del gr�fico (4 pixels) 102 | int data = *src; 103 | 104 | // para cada pixel del byte leido 105 | for (int k = 0; k < 4; k++){ 106 | // obtiene el color del pixel 107 | int color = cpc6128->unpackPixelMode1(data, k); 108 | 109 | // si no es un pixel transparente lo copia al destino 110 | if (color != 0){ 111 | *dest = color; 112 | } 113 | dest++; 114 | } 115 | src++; 116 | } 117 | 118 | despSrc += ancho; 119 | despDest += spr->anchoFinal*4; 120 | 121 | dist2Y++; 122 | 123 | // si ya se ha dibujado la cabeza, obtiene los gr�ficos de la parte del traje 124 | if (dist2Y == 10){ 125 | despSrc = despAnimTraje[animacionTraje] + dist2X; 126 | } 127 | } 128 | } 129 | */ 130 | // VGA 131 | // dibuja la parte visible del sprite actual en el �rea ocupada por el sprite que se le pasa como par�metro 132 | void SpriteMonje::dibuja(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y) 133 | { 134 | // obtiene los objetos que se usan luego 135 | UINT8 *roms = elJuego->roms + 0x20000-1; 136 | 137 | int despSrc; 138 | 139 | // si ya ha pasado la zona de la cabeza, obtiene los gr�ficos de la parte del traje 140 | if (dist2Y >= 10){ 141 | despSrc = despAnimTraje[animacionTraje] + (dist2Y - 10)*ancho*4 + dist2X*4; 142 | } else { 143 | despSrc = despGfx + dist2Y*ancho*4 + dist2X*4; 144 | } 145 | 146 | // calcula la direcci�n de destino de los gr�ficos en el buffer de sprites 147 | int despDest = spr->despBuffer + (dist1Y*spr->anchoFinal + dist1X)*4; 148 | 149 | // recorre los pixels visibles en Y 150 | for (int lgtudY = 0; lgtudY < lgtudClipY; lgtudY++){ 151 | UINT8 *src = &roms[despSrc]; 152 | UINT8 *dest = &bufferMezclas[despDest]; 153 | 154 | // recorre los pixels visibles en X 155 | for (int lgtudX = 0; lgtudX < lgtudClipX*4; lgtudX++){ 156 | // lee un byte del gr�fico (1 pixel) 157 | int data = *src++; 158 | 159 | if(data!=255) *dest=data; 160 | dest++; 161 | } 162 | 163 | despSrc += ancho*4; 164 | despDest += spr->anchoFinal*4; 165 | 166 | dist2Y++; 167 | 168 | // si ya se ha dibujado la cabeza, obtiene los gr�ficos de la parte del traje 169 | if (dist2Y == 10){ 170 | despSrc = despAnimTraje[animacionTraje] + dist2X*4; 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /vigasoco/Logica.h: -------------------------------------------------------------------------------- 1 | // Logica.h 2 | // 3 | // Clase que encapsula la l�gica del juego 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _LOGICA_H_ 8 | #define _LOGICA_H_ 9 | 10 | 11 | #include "Singleton.h" 12 | #include "Types.h" 13 | 14 | #include 15 | 16 | namespace Abadia { 17 | 18 | 19 | // momentos del d�a 20 | enum MomentosDia { 21 | NOCHE = 0, 22 | PRIMA = 1, 23 | TERCIA = 2, 24 | SEXTA = 3, 25 | NONA = 4, 26 | VISPERAS = 5, 27 | COMPLETAS = 6 28 | }; 29 | 30 | 31 | // objetos del juego 32 | enum ObjetosJuego { 33 | LIBRO = 0x80, 34 | GUANTES = 0x40, 35 | GAFAS = 0x20, 36 | PERGAMINO = 0x10, 37 | LLAVE1 = 0x08, 38 | LLAVE2 = 0x04, 39 | LLAVE3 = 0x02, 40 | LAMPARA = 0x01 41 | }; 42 | 43 | class Abad; // definido en Abad.h 44 | class AccionesDia; // definido en AccionesDia.h 45 | class Adso; // definido en Adso.h 46 | class Berengario; // definido en Berengario.h 47 | class Bernardo; // definido en Bernardo.h 48 | class BuscadorRutas; // definido en BuscadorRutas.h 49 | class GestorFrases; // definido en GestorFrases.h 50 | class Guillermo; // definido en Guillermo.h 51 | class Jorge; // definido en Jorge.h 52 | class Malaquias; // definido en Malaquias.h 53 | class Personaje; // definido en Personaje.h 54 | class Severino; // definido en Severino.h 55 | class Sprite; // definido en Sprite.h 56 | 57 | #define laLogica Logica::getSingletonPtr() 58 | 59 | class Logica : public Singleton 60 | { 61 | // campos 62 | public: 63 | UINT8 *roms; // puntero a las roms originales 64 | 65 | AccionesDia *accionesDia; // ejecutor de las acciones dependiendo del momento del d�a 66 | BuscadorRutas *buscRutas; // buscador y generador de rutas 67 | GestorFrases *gestorFrases; // gestor de las frases del juego 68 | 69 | Guillermo *guillermo; // guillermo 70 | Adso *adso; // adso 71 | Malaquias *malaquias; // malaquias 72 | Abad *abad; // el abad 73 | Berengario *berengario; // berengario 74 | Severino *severino; // severino 75 | Jorge *jorge; // jorge 76 | Bernardo *bernardo; // bernardo gui 77 | 78 | int dia; // dia actual 79 | int momentoDia; // momento del d�a 80 | int duracionMomentoDia; // indica lo que falta para pasar al siguiente momento del d�a 81 | int oldMomentoDia; // indica el momento del d�a de las �ltimas acciones programadas ejecutadas 82 | bool avanzarMomentoDia; // indica si debe avanzar el momento del d�a 83 | int obsequium; // nivel de obsequium (de 0 a 31) 84 | bool haFracasado; // indica si guillermo ha fracasado en la investigaci�n 85 | bool investigacionCompleta; // indica si se ha completado la investigaci�n 86 | int bonus; // bonus que se han conseguido 87 | 88 | int mascaraPuertas; // m�scara de las puertas que pueden abrirse 89 | 90 | bool espejoCerrado; // indica si el espejo est� cerrado o se ha abierto 91 | int numeroRomano; // indica el n�mero romano de la habitaci�n del espejo (en el caso de que se haya generado) 92 | int despDatosAlturaEspejo; // desplazamiento hasta el final de los datos de altura de la habitaci�n del espejo 93 | int despBloqueEspejo; // desplazamiento hasta los datos del bloque que forma el espejo 94 | 95 | bool seAcabaLaNoche; // indica si falta poco para que se termine la noche 96 | bool haAmanecido; // indica si ya ha amanecido 97 | bool usandoLampara; // indica si se est� usando la l�mpara 98 | bool lamparaDesaparecida; // indica si ha desaparecido la l�mpara 99 | int tiempoUsoLampara; // contador del tiempo de uso de la l�mpara 100 | int cambioEstadoLampara; // indica un cambio en el estado de la l�mpara 101 | int cntTiempoAOscuras; // contador del tiempo que pueden ir a oscuras por la biblioteca 102 | 103 | int cntLeeLibroSinGuantes; // contador para llevar un control del tiempo que lee guillermo el libro sin los guantes 104 | bool pergaminoGuardado; // indica que el pergamino lo tiene el abad en su habitaci�n o est� detr�s de la habitaci�n del espejo 105 | 106 | int numeroAleatorio; // n�mero aleatorio 107 | 108 | bool hayMovimiento; // cuando hay alg�n movimiento de un personaje, esto se pone a true 109 | int cntMovimiento; // contador que se pone a 0 con cada movimiento de guillermo (usado para cambios de c�mara) 110 | 111 | int numPersonajeCamara; // indica el personaje al que sigue la c�mara actualmente 112 | int opcionPersonajeCamara; // indica el personaje al que podr�a seguir la c�mara si no hay movimiento 113 | 114 | // m�todos 115 | public: 116 | void inicia(); 117 | 118 | void compruebaLecturaLibro(); 119 | void compruebaBonusYCambiosDeCamara(); 120 | void compruebaCogerDejarObjetos(); 121 | void compruebaCogerObjetos(); 122 | void dejaObjeto(Personaje *pers); 123 | void compruebaAbrirCerrarPuertas(); 124 | 125 | void actualizaVariablesDeTiempo(); 126 | void compruebaFinMomentoDia(); 127 | void compruebaFinLampara(); 128 | void compruebaFinNoche(); 129 | void reiniciaContadoresLampara(); 130 | void ejecutaAccionesMomentoDia(); 131 | 132 | int calculaPorcentajeMision(); 133 | 134 | void compruebaAbreEspejo(); 135 | int pulsadoQR(); 136 | void realizaReflejoEspejo(); 137 | void despHabitacionEspejo(); 138 | 139 | // inicializaci�n y limpieza 140 | Logica(UINT8 *romData, UINT8 *buf, int lgtud); 141 | ~Logica(); 142 | 143 | 144 | friend std::ifstream& operator>>(std::ifstream& in, 145 | Logica* const logica); 146 | 147 | 148 | // m�todos de ayuda 149 | protected: 150 | // inicializaci�n 151 | void iniciaSprites(); 152 | void iniciaPersonajes(); 153 | void iniciaPuertas(); 154 | void iniciaObjetos(); 155 | void iniciaHabitacionEspejo(); 156 | 157 | void generaNumeroRomano(); 158 | bool reflejaPersonaje(Personaje *pers, Sprite *spr); 159 | 160 | void actualizaBonusYCamara(); 161 | }; 162 | 163 | 164 | } 165 | 166 | #endif // _LOGICA_H_ 167 | -------------------------------------------------------------------------------- /vigasoco/Juego.h: -------------------------------------------------------------------------------- 1 | // Juego.h 2 | // 3 | // Clase principal del juego. Almacena el estado y las entidades del juego. 4 | // 5 | ///////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef __ABADIA_JUEGO_H__ 8 | #define __ABADIA_JUEGO_H__ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "Singleton.h" 18 | #include "Types.h" 19 | #include "Paleta.h" 20 | #include "configreader.h" 21 | 22 | class CPC6128; // definido en CPC6128.h 23 | 24 | namespace Abadia { 25 | 26 | class InfoJuego; // definido en InfoJuego.h 27 | class Logica; // definido en Logica.h 28 | class Marcador; // definido en Marcador.h 29 | class MotorGrafico; // definido en MotorGrafico.h 30 | class Objeto; // definido en Objeto.h 31 | class Pergamino; // definido en Pergamino.h 32 | class Personaje; // definido en Personaje.h 33 | class Puerta; // definido en Puerta.h 34 | class Sprite; // definido en Sprite.h 35 | 36 | #define elJuego Juego::getSingletonPtr() 37 | 38 | class Juego : public Singleton 39 | { 40 | // constantes 41 | public: 42 | static const int numPersonajes = 8; 43 | static const int numPuertas = 7; 44 | static const int numObjetos = 8; 45 | 46 | static const int primerSpritePersonajes = 0; 47 | static const int primerSpritePuertas = primerSpritePersonajes + numPersonajes; 48 | static const int primerSpriteObjetos = primerSpritePuertas + numPuertas; 49 | static const int spritesReflejos = primerSpriteObjetos + numObjetos; 50 | static const int spriteLuz = spritesReflejos + 2; 51 | static const int numSprites = spriteLuz + 1; 52 | static const char *savefile[7]; 53 | 54 | // campos 55 | private: 56 | bool mute; 57 | unsigned short slot; 58 | public: 59 | int idioma; // idioma de los textos TODO ponerlo como un enumerado 60 | // GraficosCPC estaba como privado 61 | // se pone como publico para que pueda acceder 62 | // el MotorGrafico.cpp y decidir si tiene que parchear las pantallas 63 | // o no 64 | // TODO: Poner metodos get para no dar acceso directo y que lo 65 | // pueda cambiar por error desde otro lado 66 | bool GraficosCPC; // Indica si se usan los datos del archivo GraficosCPC 67 | // o del GraficosVGA 68 | // En ambos casos, son de 8 bits 69 | CPC6128 *cpc6128; // objeto de ayuda para realizar operaciones gr??ficas del cpc6128 70 | 71 | Paleta *paleta; // paleta del juego 72 | UINT8 buffer[8192]; // buffer para mezclar los sprites y para buscar las rutas 73 | UINT8 *roms; // puntero a las roms originales 74 | Logica *logica; // objeto que se encarga de gestionar la l??gica del juego 75 | 76 | Pergamino *pergamino; // pergamino para la presentaci??n y el final 77 | Marcador *marcador; // marcador del juego 78 | MotorGrafico *motor; // motor gr??fico 79 | 80 | Sprite *sprites[numSprites]; // sprites del juego 81 | Puerta *puertas[numPuertas]; // puertas del juego 82 | Objeto *objetos[numObjetos]; // objetos del juego 83 | Personaje *personajes[numPersonajes]; // personajes del juego 84 | 85 | 86 | 87 | bool pausa; // indica si el juego est?? pausado 88 | bool modoInformacion; // modo de informaci??n del juego 89 | bool cambioModoInformacion; // se ha cambiado el estado 90 | InfoJuego *infoJuego; // objeto para mostrar informaci??n interna del juego 91 | int currentState; 92 | int firstTime; 93 | int seleccionado; 94 | ConfigReader *configReader; 95 | int selectedSlot; 96 | 97 | 98 | private: 99 | bool cargar(int slot); 100 | void save(int slot); 101 | 102 | ///////////////////////////////////////////////////////// 103 | void pintaMenuCargar(int seleccionado,bool efecto=false); 104 | 105 | bool menuCargar2(); 106 | void pintaMenuGrabar(int seleccionado,bool efecto=false); 107 | bool menuGrabar2(); 108 | bool menuIntroduccion(void); 109 | void pintaMenuTeclado(int seleccionado); 110 | bool menuTeclado(void); 111 | void pintaMenuCamaras(int seleccionado); 112 | bool menuCamaras(void); 113 | void pintaMenuMejoras(int seleccionado); 114 | bool menuMejoras(void); 115 | void pintaMenuTutorial(int seleccionado,bool efecto=false); 116 | bool menuTutorial(void); 117 | void pintaMenuAyuda(int seleccionado,bool efecto=false); 118 | bool menuAyuda(void); 119 | void pintaMenuIdioma(int seleccionado,bool efecto=false); 120 | bool menuIdioma(void); 121 | void pintaMenuPrincipal(int seleccionado,bool efecto=false); 122 | bool menu(void); 123 | //////////////////////////////////////////////////////////// 124 | 125 | void cambioCPC_VGA(void); 126 | void compruebaCambioCPC_VGA(void); 127 | bool compruebaMenu(void); 128 | void ReiniciaPantalla(void); 129 | public: 130 | void muestraFinal(); 131 | void limpiaAreaJuego(int color); 132 | 133 | // bucle principal del juego 134 | void preRun(); 135 | void run(); 136 | void run2(); 137 | void stateMachine(); 138 | void changeState(int newState); 139 | 140 | // inicializaci??n y limpieza 141 | Juego(UINT8 *romData, CPC6128 *cpc); 142 | ~Juego(); 143 | bool showingMenu; 144 | bool activeGame; 145 | 146 | protected: 147 | void muestraPresentacion(); 148 | void muestraIntroduccion(); 149 | bool muestraPantallaFinInvestigacion(); 150 | 151 | void creaEntidadesJuego(); 152 | 153 | void actualizaLuz(); 154 | void generaGraficosFlipeados(); 155 | void flipeaGraficos(UINT8 *tablaFlip, UINT8 *src, UINT8 *dest, int ancho, int bytes); 156 | void generaGraficosFlipeadosVGA(); 157 | void flipeaGraficosVGA(UINT8 *src, UINT8 *dest, int ancho, int bytes); 158 | 159 | void checkForSaveFiles(); 160 | bool saveFileExist[7]; 161 | string saveFile[7]; 162 | void checkConfigFile(); 163 | bool readConfigFile(); 164 | bool saveConfigFile(); 165 | string getDateAndTime(); 166 | 167 | void menuAsk(); 168 | void askForNewGame(); 169 | void askForNewGameLogic(); 170 | 171 | void askToContinue(); 172 | void askToContinueLogic(); 173 | 174 | void askExit(); 175 | void askExitLogic(); 176 | 177 | }; 178 | 179 | 180 | } 181 | 182 | #endif // _ABADIA_JUEGO_H_ 183 | -------------------------------------------------------------------------------- /cmake/FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This module defines 3 | # SDL2_LIBRARY, the name of the library to link against 4 | # SDL2_FOUND, if false, do not try to link to SDL2 5 | # SDL2_INCLUDE_DIR, where to find SDL.h 6 | # 7 | # This module responds to the the flag: 8 | # SDL2_BUILDING_LIBRARY 9 | # If this is defined, then no SDL2main will be linked in because 10 | # only applications need main(). 11 | # Otherwise, it is assumed you are building an application and this 12 | # module will attempt to locate and set the the proper link flags 13 | # as part of the returned SDL2_LIBRARY variable. 14 | # 15 | # Don't forget to include SDLmain.h and SDLmain.m your project for the 16 | # OS X framework based version. (Other versions link to -lSDL2main which 17 | # this module will try to find on your behalf.) Also for OS X, this 18 | # module will automatically add the -framework Cocoa on your behalf. 19 | # 20 | # 21 | # Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration 22 | # and no SDL2_LIBRARY, it means CMake did not find your SDL2 library 23 | # (SDL2.dll, libsdl2.so, SDL2.framework, etc). 24 | # Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. 25 | # Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value 26 | # as appropriate. These values are used to generate the final SDL2_LIBRARY 27 | # variable, but when these values are unset, SDL2_LIBRARY does not get created. 28 | # 29 | # 30 | # $SDL2DIR is an environment variable that would 31 | # correspond to the ./configure --prefix=$SDL2DIR 32 | # used in building SDL2. 33 | # l.e.galup 9-20-02 34 | # 35 | # Modified by Eric Wing. 36 | # Added code to assist with automated building by using environmental variables 37 | # and providing a more controlled/consistent search behavior. 38 | # Added new modifications to recognize OS X frameworks and 39 | # additional Unix paths (FreeBSD, etc). 40 | # Also corrected the header search path to follow "proper" SDL guidelines. 41 | # Added a search for SDL2main which is needed by some platforms. 42 | # Added a search for threads which is needed by some platforms. 43 | # Added needed compile switches for MinGW. 44 | # 45 | # On OSX, this will prefer the Framework version (if found) over others. 46 | # People will have to manually change the cache values of 47 | # SDL2_LIBRARY to override this selection or set the CMake environment 48 | # CMAKE_INCLUDE_PATH to modify the search paths. 49 | # 50 | # Note that the header path has changed from SDL2/SDL.h to just SDL.h 51 | # This needed to change because "proper" SDL convention 52 | # is #include "SDL.h", not . This is done for portability 53 | # reasons because not all systems place things in SDL2/ (see FreeBSD). 54 | 55 | #============================================================================= 56 | # Copyright 2003-2009 Kitware, Inc. 57 | # 58 | # Distributed under the OSI-approved BSD License (the "License"); 59 | # see accompanying file Copyright.txt for details. 60 | # 61 | # This software is distributed WITHOUT ANY WARRANTY; without even the 62 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 63 | # See the License for more information. 64 | #============================================================================= 65 | # (To distribute this file outside of CMake, substitute the full 66 | # License text for the above reference.) 67 | 68 | message("") 69 | 70 | SET(SDL2_SEARCH_PATHS 71 | ~/Library/Frameworks 72 | /Library/Frameworks 73 | /usr/local 74 | /usr 75 | /sw # Fink 76 | /opt/local # DarwinPorts 77 | /opt/csw # Blastwave 78 | /opt 79 | ${SDL2_PATH} 80 | ) 81 | 82 | FIND_PATH(SDL2_INCLUDE_DIR SDL.h 83 | HINTS 84 | $ENV{SDL2DIR} 85 | PATH_SUFFIXES include/SDL2 include 86 | PATHS ${SDL2_SEARCH_PATHS} 87 | ) 88 | 89 | FIND_LIBRARY(SDL2_LIBRARY_TEMP 90 | NAMES SDL2 91 | HINTS 92 | $ENV{SDL2DIR} 93 | PATH_SUFFIXES lib64 lib 94 | PATHS ${SDL2_SEARCH_PATHS} 95 | ) 96 | 97 | IF(NOT SDL2_BUILDING_LIBRARY) 98 | IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") 99 | # Non-OS X framework versions expect you to also dynamically link to 100 | # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms 101 | # seem to provide SDL2main for compatibility even though they don't 102 | # necessarily need it. 103 | FIND_LIBRARY(SDL2MAIN_LIBRARY 104 | NAMES SDL2main 105 | HINTS 106 | $ENV{SDL2DIR} 107 | PATH_SUFFIXES lib64 lib 108 | PATHS ${SDL2_SEARCH_PATHS} 109 | ) 110 | ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") 111 | ENDIF(NOT SDL2_BUILDING_LIBRARY) 112 | 113 | # SDL2 may require threads on your system. 114 | # The Apple build may not need an explicit flag because one of the 115 | # frameworks may already provide it. 116 | # But for non-OSX systems, I will use the CMake Threads package. 117 | IF(NOT APPLE) 118 | FIND_PACKAGE(Threads) 119 | ENDIF(NOT APPLE) 120 | 121 | # MinGW needs an additional library, mwindows 122 | # It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows 123 | # (Actually on second look, I think it only needs one of the m* libraries.) 124 | IF(MINGW) 125 | SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") 126 | ENDIF(MINGW) 127 | 128 | IF(SDL2_LIBRARY_TEMP) 129 | # For SDL2main 130 | IF(NOT SDL2_BUILDING_LIBRARY) 131 | IF(SDL2MAIN_LIBRARY) 132 | SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) 133 | ENDIF(SDL2MAIN_LIBRARY) 134 | ENDIF(NOT SDL2_BUILDING_LIBRARY) 135 | 136 | # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. 137 | # CMake doesn't display the -framework Cocoa string in the UI even 138 | # though it actually is there if I modify a pre-used variable. 139 | # I think it has something to do with the CACHE STRING. 140 | # So I use a temporary variable until the end so I can set the 141 | # "real" variable in one-shot. 142 | IF(APPLE) 143 | SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") 144 | ENDIF(APPLE) 145 | 146 | # For threads, as mentioned Apple doesn't need this. 147 | # In fact, there seems to be a problem if I used the Threads package 148 | # and try using this line, so I'm just skipping it entirely for OS X. 149 | IF(NOT APPLE) 150 | SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) 151 | ENDIF(NOT APPLE) 152 | 153 | # For MinGW library 154 | IF(MINGW) 155 | SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) 156 | ENDIF(MINGW) 157 | 158 | # Set the final string here so the GUI reflects the final state. 159 | SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") 160 | # Set the temp variable to INTERNAL so it is not seen in the CMake GUI 161 | SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") 162 | ENDIF(SDL2_LIBRARY_TEMP) 163 | 164 | message("") 165 | 166 | INCLUDE(FindPackageHandleStandardArgs) 167 | 168 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) 169 | 170 | -------------------------------------------------------------------------------- /vigasoco/Puerta.cpp: -------------------------------------------------------------------------------- 1 | // Puerta.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "Logica.h" 6 | #include "MotorGrafico.h" 7 | #include "Personaje.h" 8 | #include "Puerta.h" 9 | #include "Sprite.h" 10 | #include "RejillaPantalla.h" 11 | 12 | #include "sonidos.h" 13 | #include "system.h" 14 | using namespace Abadia; 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // tabla para el c�lculo de los desplazamientos de las puertas seg�n la orientaci�n 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | int Puerta::despOrientacion[4][12] = { 21 | { +2, 0, 0, -1, -1, -34, +1, +1, 0, 0, +1, 0 }, 22 | { 0, -4, -1, -1, -1, -42, 0, 0, 0, 0, 0, -1 }, 23 | { -2, 0, -1, 0, -5, -42, 0, +1, 0, 0, -1, 0 }, 24 | { 0, +4, 0, 0, -5, -34, +1, 0, +1, +1, 0, +1 } 25 | }; 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | // inicializaci�n y limpieza 29 | ///////////////////////////////////////////////////////////////////////////// 30 | 31 | Puerta::Puerta(Sprite *spr) : EntidadJuego(spr) 32 | { 33 | identificador = 0; 34 | estaAbierta = false; 35 | estaFija = false; 36 | haciaDentro = false; 37 | hayQueRedibujar = false; 38 | } 39 | 40 | Puerta::~Puerta() 41 | { 42 | } 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // actualizaci�n del entorno cuando una puerta es visible en la pantalla actual 46 | ///////////////////////////////////////////////////////////////////////////// 47 | 48 | // actualiza la posici�n del sprite dependiendo de su posici�n con respecto a la c�mara 49 | void Puerta::notificaVisibleEnPantalla(int posXPant, int posYPant, int profundidad) 50 | { 51 | // pone la posici�n y dimensiones actuales como posici�n y dimensiones antiguas 52 | sprite->preparaParaCambio(); 53 | 54 | int oriEntrada = elMotorGrafico->ajustaOrientacionSegunCamara(ARRIBA); 55 | 56 | sprite->posXLocal += despOrientacion[oriEntrada][2]; 57 | sprite->posYLocal += despOrientacion[oriEntrada][3]; 58 | 59 | int oriPuerta = elMotorGrafico->ajustaOrientacionSegunCamara(orientacion); 60 | sprite->posXPant = posXPant + despOrientacion[oriEntrada][0] + despOrientacion[oriPuerta][4]; 61 | sprite->posYPant = posYPant + despOrientacion[oriEntrada][1] + despOrientacion[oriPuerta][5]; 62 | sprite->profundidad = profundidad + despOrientacion[oriPuerta][6]; 63 | sprite->haCambiado = elMotorGrafico->hayQueRedibujar | hayQueRedibujar; 64 | sprite->esVisible = true; 65 | // CPC sprite->despGfx = 0x0aa49 + 0xc000*despOrientacion[oriPuerta][7]; 66 | sprite->despGfx = 69708 + 120305*despOrientacion[oriPuerta][7]; // VGA 67 | // 69708 es la posicion de la puerta dentro de GraficosVGA 68 | // 120305 es el desplazamiento entre el grafico de la puerta y su 69 | // grafico "flipeado" 70 | sprite->posXLocal += despOrientacion[oriPuerta][8]; 71 | sprite->posYLocal += despOrientacion[oriPuerta][9]; 72 | 73 | // marca las posiciones ocupadas por la puerta en el buffer de alturas 74 | marcaPosiciones(elMotorGrafico->rejilla, 0x0f); 75 | } 76 | 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // m�todos para abrir y cerrar las puertas 79 | ///////////////////////////////////////////////////////////////////////////// 80 | 81 | // comprueba si hay que abrir o cerrar una puerta 82 | void Puerta::compruebaAbrirCerrar(Personaje **personajes, int numPersonajes) 83 | { 84 | // si la puerta est� fija, sale 85 | if (estaFija) return; 86 | 87 | int mascara = (laLogica->mascaraPuertas | 0x10) & identificador; 88 | 89 | // TODO: si guillermo o adso est�n cerca de la puerta y no tienen permisos para abrirla, se cierra 90 | 91 | for (int i = 0; i < numPersonajes; i++){ 92 | // si tiene permisos para entrar en esa puerta 93 | if ((personajes[i]->permisosPuertas & mascara) != 0){ 94 | if (puedeAbrir(personajes[i])){ 95 | return; 96 | } 97 | } 98 | } 99 | 100 | // aqu� llega si la puerta no se ha abierto 101 | 102 | // ejecuta las acciones correspondientes para cerrar la puerta 103 | accionesAbrirCerrar(false); 104 | } 105 | 106 | // comprueba si el personaje est� cerca de la puerta y si es as�, si se puede abrir 107 | bool Puerta::puedeAbrir(Personaje *pers) 108 | { 109 | int difX = pers->posX - (posX - 1); 110 | // si no est� cerca de la puerta en x, sale 111 | if ((difX < 0) || (difX >= 4)) return false; 112 | 113 | int difY = pers->posY - (posY - 1); 114 | // si no est� cerca de la puerta en y, sale 115 | if ((difY < 0) || (difY >= 4)) return false; 116 | 117 | // ejecuta las acciones correspondientes para abrir la puerta 118 | return accionesAbrirCerrar(true); 119 | } 120 | 121 | // ejecuta las acciones correspondientes para abrir o cerrar la puerta 122 | bool Puerta::accionesAbrirCerrar(bool abrir) 123 | { 124 | if (abrir){ 125 | // si la puerta est� abierta, sale 126 | if (estaAbierta) return true; 127 | // si lo ponemos aqui, suena aunque la puerta no este en la pantalla actual 128 | //VigasocoMain->getAudioPlugin()->Play(1,false); 129 | } else { 130 | // si la puerta est� cerrada, sale 131 | if (!estaAbierta) return true; 132 | //VigasocoMain->getAudioPlugin()->Play(2,false); 133 | } 134 | 135 | // marca la puerta como abierta o cerrada e indica que hay que redibujarla 136 | estaAbierta = abrir; 137 | hayQueRedibujar = true; 138 | 139 | // pone a 0 la altura de las posiciones ocupadas por la puerta cuando estaba abierta o cerrada 140 | marcaPosiciones(elMotorGrafico->rejilla, altura); 141 | 142 | int difOri = (abrir) ? 1 : -1; 143 | 144 | // cambia la orientaci�n de la puerta dependiendo de hacia donde se abra o se cierre 145 | orientacion = (haciaDentro) ? (orientacion - difOri) & 0x03 : (orientacion + difOri) & 0x03; 146 | 147 | int posXRejilla, posYRejilla; 148 | RejillaPantalla *rejilla = elMotorGrafico->rejilla; 149 | 150 | // si la puerta est� en las 20x20 posiciones centrales de la rejilla 151 | if (rejilla->estaEnRejillaCentral(this, posXRejilla, posYRejilla)){ 152 | posXRejilla += 2*despOrientacion[orientacion][10]; 153 | posYRejilla += 2*despOrientacion[orientacion][11]; 154 | 155 | // si no hay un personaje en la posici�n en la que se abre o cierra la puerta, sale 156 | //if ((rejilla->bufAlturas[posYRejilla][posXRejilla] & 0xf0) == 0) return true; 157 | if ((rejilla->bufAlturas[posYRejilla][posXRejilla] & 0xf0) == 0) 158 | { 159 | if (abrir) 160 | { 161 | //VigasocoMain->getAudioPlugin()->Play(SONIDOS::Abrir); 162 | sys->playSound(OPEN); 163 | } 164 | else 165 | { 166 | //VigasocoMain->getAudioPlugin()->Play(SONIDOS::Cerrar); 167 | sys->playSound(CLOSE); 168 | } 169 | return true; 170 | } 171 | 172 | // en otro caso, deshace el cambio 173 | estaAbierta = !abrir; 174 | hayQueRedibujar = false; 175 | orientacion = (haciaDentro) ? (orientacion + difOri) & 0x03 : (orientacion - difOri) & 0x03; 176 | 177 | marcaPosiciones(elMotorGrafico->rejilla, altura); 178 | } 179 | 180 | return true; 181 | } 182 | 183 | ///////////////////////////////////////////////////////////////////////////// 184 | // m�todos de ayuda 185 | ///////////////////////////////////////////////////////////////////////////// 186 | 187 | // marca la altura de las posiciones ocupadas por la puerta 188 | void Puerta::marcaPosiciones(RejillaPantalla *rejilla, int valor) 189 | { 190 | int posXRejilla, posYRejilla; 191 | 192 | // si la puerta est� en las 20x20 posiciones centrales de la rejilla, marca las posiciones que ocupa 193 | if (rejilla->estaEnRejillaCentral(this, posXRejilla, posYRejilla)){ 194 | for (int i = 0; i < 3; i++){ 195 | rejilla->bufAlturas[posYRejilla][posXRejilla] = valor; 196 | posXRejilla += despOrientacion[orientacion][10]; 197 | posYRejilla += despOrientacion[orientacion][11]; 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /vigasoco/Sprite.cpp: -------------------------------------------------------------------------------- 1 | // Sprite.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "Juego.h" 6 | #include "Sprite.h" 7 | #include "cpc6128.h" 8 | 9 | using namespace Abadia; 10 | 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // inicializaci�n y limpieza 13 | ///////////////////////////////////////////////////////////////////////////// 14 | 15 | Sprite::Sprite() 16 | { 17 | esVisible = false; 18 | haCambiado = false; 19 | seHaProcesado = false; 20 | profundidad = 0; 21 | 22 | posXPant = 0; 23 | posYPant = 0; 24 | oldPosXPant = 0; 25 | oldPosYPant = 0; 26 | 27 | desaparece = false; 28 | ancho = 0; 29 | alto = 0; 30 | despGfx = 0; 31 | oldAncho = 0; 32 | oldAlto = 0; 33 | 34 | posXTile = 0; 35 | posYTile = 0; 36 | anchoFinal = 0; 37 | altoFinal = 0; 38 | despBuffer = 0; 39 | posXLocal = 0; 40 | posYLocal = 0; 41 | } 42 | 43 | Sprite::~Sprite() 44 | { 45 | } 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // ajuste de las dimensiones para el dibujado 49 | ///////////////////////////////////////////////////////////////////////////// 50 | 51 | // dadas la posici�n y dimensiones del sprite, calcula la posici�n y dimensiones ampliados a los tiles que ocupa (x en bytes, y en tiles) 52 | void Sprite::ajustaATiles() 53 | { 54 | // calcula la posici�n inicial del tile que contiene al sprite 55 | posXTile = posXPant & 0xfc; 56 | posYTile = posYPant & 0xf8; 57 | 58 | // calcula la posici�n del sprite dentro del tile 59 | int despXTile = posXPant & 0x03; 60 | int despYTile = posYPant & 0x07; 61 | 62 | // calcula la dimensi�n ampliada del sprite para que abarque todos los tiles en los que se va a dibujar 63 | anchoFinal = (ancho + despXTile + 3) & 0xfc; 64 | altoFinal = (alto + despYTile + 7) & 0xf8; 65 | } 66 | 67 | // amplia las dimensiones a dibujar para que se redibuje el �rea ocupada anteriormente por el sprite 68 | void Sprite::ampliaDimViejo() 69 | { 70 | // ajusta en x 71 | 72 | // halla la distancia en x entre el origen del tile en el que empieza el sprite y el origen del sprite anterior 73 | int difX = posXTile - oldPosXPant; 74 | 75 | // si empieza primero el sprite antiguo 76 | if (difX >= 0){ 77 | // obtiene la m�xima anchura del sprite antiguo que se cubre con el ancho ampliado actual 78 | int anchoCubierto = difX + anchoFinal; 79 | 80 | // obtiene el m�nimo ancho que debe cubrirse para limpiar el sprite antiguo 81 | int oldAnchoAmpliado = oldAncho; 82 | 83 | // si el sprite antiguo termina antes que el �rea cubierta, amplia el ancho del sprite antiguo 84 | if (anchoCubierto >= oldAnchoAmpliado){ 85 | oldAnchoAmpliado = anchoCubierto; 86 | } 87 | 88 | // como empieza primero el sprite antiguo, cambia la posici�n inicial del tile y amplia su ancho 89 | posXTile = oldPosXPant & 0xfc; 90 | int oldDespXTile = oldPosXPant & 0x03; 91 | anchoFinal = (oldAnchoAmpliado + oldDespXTile + 3) & 0xfc; 92 | } else { 93 | // si empieza primero el sprite actual 94 | 95 | // obtiene la m�xima anchura que ocupa el sprite antiguo dentro del sprite ampliado 96 | int anchoCubierto = -difX + oldAncho; 97 | 98 | // si el ancho ampliado no cubre el ancho del sprite viejo, ampl�a el ancho 99 | if (anchoFinal < anchoCubierto){ 100 | anchoFinal = (anchoCubierto + 3) & 0xfc; 101 | } 102 | } 103 | 104 | // ajusta en y 105 | 106 | // halla la distancia en y entre el origen del tile en el que empieza el sprite y el origen del sprite anterior 107 | int difY = posYTile - oldPosYPant; 108 | 109 | // si empieza primero el sprite antiguo 110 | if (difY >= 0){ 111 | // obtiene la m�xima altura del sprite antiguo que se cubre con el alto ampliado actual 112 | int altoCubierto = difY + altoFinal; 113 | 114 | // obtiene el m�nimo alto que debe cubrirse para limpiar el sprite antiguo 115 | int oldAltoAmpliado = oldAlto; 116 | 117 | // si el sprite antiguo termina antes que el �rea cubierta, amplia el alto del sprite antiguo 118 | if (altoCubierto >= oldAltoAmpliado){ 119 | oldAltoAmpliado = altoCubierto; 120 | } 121 | 122 | // como empieza primero el sprite antiguo, cambia la posici�n inicial del tile y amplia su alto 123 | posYTile = oldPosYPant & 0xf8; 124 | int oldDespYTile = oldPosYPant & 0x07; 125 | altoFinal = (oldAltoAmpliado + oldDespYTile + 7) & 0xf8; 126 | } else { 127 | // si empieza primero el sprite actual 128 | 129 | // obtiene la m�xima altura que ocupa el sprite antiguo dentro del sprite ampliado 130 | int altoCubierto = -difY + oldAlto; 131 | 132 | // si el alto ampliado no cubre el alto del sprite viejo, ampl�a el alto 133 | if (altoFinal < altoCubierto){ 134 | altoFinal = (altoCubierto + 7) & 0xf8; 135 | } 136 | } 137 | } 138 | 139 | ///////////////////////////////////////////////////////////////////////////// 140 | // dibujado del sprite 141 | ///////////////////////////////////////////////////////////////////////////// 142 | 143 | // dibuja la parte visible del sprite actual en el �rea ocupada por el sprite que se le pasa como par�metro 144 | void Sprite::dibuja(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y) 145 | { 146 | dibujaVGA(spr,bufferMezclas,lgtudClipX,lgtudClipY,dist1X,dist2X,dist1Y,dist2Y); 147 | 148 | /* CPC 149 | // obtiene los objetos que se usan luego 150 | UINT8 *roms = elJuego->roms; 151 | CPC6128 *cpc6128 = elJuego->cpc6128; 152 | 153 | // calcula la direcci�n de inicio de los gr�ficos visibles del sprite a mezclar en el �rea ocupada por el sprite que se est� procesando 154 | int despSrc = despGfx + dist2Y*ancho + dist2X; 155 | 156 | // calcula la direcci�n de destino de los gr�ficos en el buffer de sprites 157 | int despDest = spr->despBuffer + (dist1Y*spr->anchoFinal + dist1X)*4; 158 | 159 | // recorre los pixels visibles en Y 160 | for (int lgtudY = 0; lgtudY < lgtudClipY; lgtudY++){ 161 | UINT8 *src = &roms[despSrc]; 162 | UINT8 *dest = &bufferMezclas[despDest]; 163 | // recorre los pixels visibles en X 164 | for (int lgtudX = 0; lgtudX < lgtudClipX; lgtudX++){ 165 | // lee un byte del gr�fico (4 pixels) 166 | int data = *src; 167 | 168 | // para cada pixel del byte leido 169 | for (int k = 0; k < 4; k++){ 170 | // obtiene el color del pixel 171 | int color = cpc6128->unpackPixelMode1(data, k); 172 | 173 | // si no es un pixel transparente lo copia al destino 174 | if (color != 0){ 175 | *dest = color; 176 | } 177 | dest++; 178 | } 179 | src++; 180 | } 181 | 182 | despSrc += ancho; 183 | despDest += spr->anchoFinal*4; 184 | } 185 | */ 186 | } 187 | 188 | // dibuja la parte visible del sprite actual en el �rea ocupada por el sprite que se le pasa como par�metro 189 | void Sprite::dibujaVGA(Sprite *spr, UINT8 *bufferMezclas, int lgtudClipX, int lgtudClipY, int dist1X, int dist2X, int dist1Y, int dist2Y) 190 | { 191 | //assert(VGA); // todos los graficos ya son VGA 192 | 193 | // obtiene los objetos que se usan luego 194 | UINT8 *roms = elJuego->roms+0x20000-1; // pasamos de la rom del CPC a GraficosVGA 195 | 196 | // calcula la direcci�n de inicio de los gr�ficos visibles del sprite a mezclar en el �rea ocupada por el sprite que se est� procesando 197 | int despSrc = despGfx + dist2Y*ancho*4 + dist2X*4; 198 | 199 | // calcula la direcci�n de destino de los gr�ficos en el buffer de sprites 200 | int despDest = spr->despBuffer + (dist1Y*spr->anchoFinal + dist1X)*4; 201 | 202 | // recorre los pixels visibles en Y 203 | for (int lgtudY = 0; lgtudY < lgtudClipY; lgtudY++){ 204 | UINT8 *src = &roms[despSrc]; 205 | UINT8 *dest = &bufferMezclas[despDest]; 206 | // recorre los pixels visibles en X 207 | for (int lgtudX = 0; lgtudX < lgtudClipX*4; lgtudX++){ 208 | // lee un byte del gr�fico (1 pixel) 209 | int data = *src++; 210 | 211 | if(data!=255) *dest=data; 212 | dest++; 213 | } 214 | 215 | despSrc += ancho*4; 216 | despDest += spr->anchoFinal*4; 217 | } 218 | } 219 | ///////////////////////////////////////////////////////////////////////////// 220 | // m�todos de ayuda 221 | ///////////////////////////////////////////////////////////////////////////// 222 | 223 | // pone la posici�n y dimensiones actuales como posici�n y dimensiones antiguas 224 | void Sprite::preparaParaCambio() 225 | { 226 | oldPosXPant = posXPant; 227 | oldPosYPant = posYPant; 228 | oldAncho = ancho; 229 | oldAlto = alto; 230 | } 231 | -------------------------------------------------------------------------------- /vigasoco/cpc6128.cpp: -------------------------------------------------------------------------------- 1 | // cpc6128.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | 7 | #include "cpc6128.h" 8 | 9 | ///////////////////////////////////////////////////////////////////////////// 10 | // initialization and cleanup 11 | ///////////////////////////////////////////////////////////////////////////// 12 | CPC6128::CPC6128() 13 | { 14 | // cleans the screen buffer 15 | // CPC memset(screenBuffer, 0x80, 640*200); 16 | // TODO: VGA 17 | memset(screenBuffer,0,sizeof(screenBuffer)); 18 | memset(DirtyPixels,0,sizeof(DirtyPixels)); 19 | } 20 | 21 | CPC6128::~CPC6128() 22 | { 23 | } 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // CPC 6128 palette 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | // hardware colors 30 | UINT8 CPC6128::hardwarePalette[32][3] = { 31 | { 0x080, 0x080, 0x080 }, // 00 white 32 | { 0x080, 0x080, 0x080 }, // 01 white 33 | { 0x000, 0x0ff, 0x080 }, // 02 sea green 34 | { 0x0ff, 0x0ff, 0x080 }, // 03 pastel yellow 35 | { 0x000, 0x000, 0x080 }, // 04 blue 36 | { 0x0ff, 0x000, 0x080 }, // 05 purple 37 | { 0x000, 0x080, 0x080 }, // 06 cyan 38 | { 0x0ff, 0x080, 0x080 }, // 07 pink 39 | { 0x0ff, 0x000, 0x080 }, // 08 purple 40 | { 0x0ff, 0x0ff, 0x080 }, // 09 pastel yellow 41 | { 0x0ff, 0x0ff, 0x000 }, // 10 bright yellow 42 | { 0x0ff, 0x0ff, 0x0ff }, // 11 bright white 43 | { 0x0ff, 0x000, 0x000 }, // 12 bright red 44 | { 0x0ff, 0x000, 0x0ff }, // 13 bright magenta 45 | { 0x0ff, 0x080, 0x000 }, // 14 orange 46 | { 0x0ff, 0x080, 0x0ff }, // 15 pastel magenta 47 | { 0x000, 0x000, 0x080 }, // 16 blue 48 | { 0x000, 0x0ff, 0x080 }, // 17 sea green 49 | { 0x000, 0x0ff, 0x000 }, // 18 bright green 50 | { 0x000, 0x0ff, 0x0ff }, // 19 bright cyan 51 | { 0x000, 0x000, 0x000 }, // 20 black 52 | { 0x000, 0x000, 0x0ff }, // 21 bright blue 53 | { 0x000, 0x080, 0x000 }, // 22 green 54 | { 0x000, 0x080, 0x0ff }, // 23 sky blue 55 | { 0x080, 0x000, 0x080 }, // 24 magenta 56 | { 0x080, 0x0ff, 0x080 }, // 25 pastel green 57 | { 0x080, 0x0ff, 0x080 }, // 26 lime 58 | { 0x080, 0x0ff, 0x0ff }, // 27 pastel cyan 59 | { 0x080, 0x000, 0x000 }, // 28 red 60 | { 0x080, 0x000, 0x0ff }, // 29 mauve 61 | { 0x080, 0x080, 0x000 }, // 30 yellow 62 | { 0x080, 0x080, 0x0ff } // 31 pastel blue 63 | }; 64 | 65 | // mapping from inks to hardware colors 66 | int CPC6128::inkColors[27] = { 67 | 20, // 00 black 68 | 4, // 01 blue 69 | 21, // 02 brigth blue 70 | 28, // 03 red 71 | 24, // 04 magenta 72 | 29, // 05 mauve 73 | 12, // 06 bright red 74 | 5, // 07 purple 75 | 13, // 08 bright magenta 76 | 22, // 09 green 77 | 6, // 10 cyan 78 | 23, // 11 sky blue 79 | 30, // 12 yellow 80 | 0, // 13 white 81 | 31, // 14 pastel blue 82 | 14, // 15 orange 83 | 7, // 16 pink 84 | 15, // 17 pastel magenta 85 | 18, // 18 bright green 86 | 2, // 19 sea green 87 | 19, // 20 bright cyan 88 | 26, // 21 lime 89 | 25, // 22 pastel green 90 | 27, // 23 pastel cyan 91 | 10, // 24 bright yellow 92 | 3, // 25 pastel yellow 93 | 11 // 26 bright white 94 | }; 95 | 96 | void CPC6128::setHardwareColor(SDLPalette *pal, int numInk, int color) 97 | { 98 | assert((numInk >= 0) && (numInk < 16)); 99 | assert((color >= 0) && (color < 32)); 100 | pal->setColor(numInk, CPC6128::hardwarePalette[color][0], CPC6128::hardwarePalette[color][1], CPC6128::hardwarePalette[color][2]); 101 | } 102 | 103 | void CPC6128::setInkColor(SDLPalette *pal, int numInk, int color) 104 | { 105 | assert((numInk >= 0) && (numInk < 16)); 106 | assert((color >= 0) && (color < 27)); 107 | 108 | pal->setColor(numInk, CPC6128::hardwarePalette[inkColors[color]][0], CPC6128::hardwarePalette[inkColors[color]][1], CPC6128::hardwarePalette[inkColors[color]][2]); 109 | } 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | // CPC 6128 screen modes helpers 113 | ///////////////////////////////////////////////////////////////////////////// 114 | 115 | // sets a pixel in mode 0 (160x200, x pixels = 4 width, y pixels = 2 height, 16 colors) 116 | void CPC6128::setMode0Pixel(int x, int y, int color) 117 | { 118 | assert((x >= 0) && (x < 160)); 119 | assert((y >= 0) && (y < 200)); 120 | assert((color >= 0) && (color < 16)); 121 | 122 | setPixel(4*x, y, color); 123 | setPixel(4*x + 1, y, color); 124 | setPixel(4*x + 2, y, color); 125 | setPixel(4*x + 3, y, color); 126 | } 127 | 128 | // sets a pixel in mode 1 (320x200, x pixels = 2 width, y pixels = 2 height, 4 colors) 129 | void CPC6128::setMode1Pixel(int x, int y, int color) 130 | { 131 | assert((x >= 0) && (x < 320)); 132 | assert((y >= 0) && (y < 200)); 133 | assert((color >= 0) && (color < 256)); //TODO VGA 134 | 135 | setPixel(2*x, y, color); 136 | setPixel(2*x + 1, y, color); 137 | } 138 | 139 | // TODO: SEPARAR ESTO EN OTRO FUENTE QUE NO SEA CPC 140 | // sets a pixel in mode 1 (320x200, x pixels = 2 width, y pixels = 2 height, 256 colors) 141 | void CPC6128::setVGAPixel(int x, int y, int color) 142 | { 143 | assert((x >= 0) && (x < 320)); 144 | assert((y >= 0) && (y < 200)); 145 | assert((color >= 0) && (color < 256)); 146 | 147 | setPixel(2*x, y, color); 148 | setPixel(2*x + 1, y, color); 149 | } 150 | 151 | // sets a pixel in mode 2 (640x200, x pixels = 1 width, y pixels = 2 height, 2 colors) 152 | void CPC6128::setMode2Pixel(int x, int y, int color) 153 | { 154 | assert((x >= 0) && (x < 640)); 155 | assert((y >= 0) && (y < 200)); 156 | assert((color >= 0) && (color < 2)); 157 | 158 | setPixel(x, y, color); 159 | } 160 | 161 | // gets a pixel in mode 0 (160x200, x pixels = 4 width, y pixels = 2 height, 16 colors) 162 | int CPC6128::getMode0Pixel(int x, int y) 163 | { 164 | assert((x >= 0) && (x < 160)); 165 | assert((y >= 0) && (y < 200)); 166 | 167 | return getPixel(4*x, y); 168 | } 169 | 170 | // gets a pixel in mode 1 (320x200, x pixels = 2 width, y pixels = 2 height, 4 colors) 171 | int CPC6128::getMode1Pixel(int x, int y) 172 | { 173 | assert((x >= 0) && (x < 320)); 174 | assert((y >= 0) && (y < 200)); 175 | 176 | return getPixel(2*x, y); 177 | } 178 | 179 | // gets a pixel in mode 2 (640x200, x pixels = 1 width, y pixels = 2 height, 2 colors) 180 | int CPC6128::getMode2Pixel(int x, int y) 181 | { 182 | assert((x >= 0) && (x < 640)); 183 | assert((y >= 0) && (y < 200)); 184 | 185 | return getPixel(x, y); 186 | } 187 | 188 | // fills a rectange in mode 0 (160x200, x pixels = 4 width, y pixels = 2 height, 16 colors) 189 | void CPC6128::fillMode0Rect(int x, int y, int width, int height, int color) 190 | { 191 | assert((x >= 0) && (x < 160)); 192 | assert((y >= 0) && (y < 200)); 193 | assert((color >= 0) && (color < 16)); 194 | assert(((x + width) <= 160) && ((y + height) <= 200)); 195 | 196 | fillRect(x*4, y, width*4, height, color); 197 | } 198 | 199 | // sets a pixel in mode 1 (320x200, x pixels = 2 width, y pixels = 2 height, 4 colors) 200 | void CPC6128::fillMode1Rect(int x, int y, int width, int height, int color) 201 | { 202 | assert((x >= 0) && (x < 320)); 203 | assert((y >= 0) && (y < 200)); 204 | // CPC assert((color >= 0) && (color < 4)); 205 | assert((color >= 0) && (color < 256)); // VGA ya que se llama en Marcador::dibujaBarra y ya se usan colores VGA 206 | assert(((x + width) <= 320) && ((y + height) <= 200)); 207 | 208 | fillRect(x*2, y, width*2, height, color); 209 | } 210 | 211 | // sets a pixel in mode 2 (640x200, x pixels = 1 width, y pixels = 2 height, 2 colors) 212 | void CPC6128::fillMode2Rect(int x, int y, int width, int height, int color) 213 | { 214 | assert((x >= 0) && (x < 640)); 215 | assert((y >= 0) && (y < 200)); 216 | assert((color >= 0) && (color < 2)); 217 | assert(((x + width) <= 640) && ((y + height) <= 200)); 218 | 219 | fillRect(x, y, width, height, color); 220 | } 221 | 222 | 223 | // shows a screen stored in standard mode 0 format 224 | void CPC6128::showMode0Screen(const UINT8 *data) 225 | { 226 | // scan the rows 227 | for (int j = 0; j < 200; j++){ 228 | // convert from CPC VRAM to standard coordinates 229 | const UINT8 *lineData = &data[(j & 0x07)*0x800 + (j >> 3)*80]; 230 | 231 | // scan the cols 232 | for (int i = 0; i < 160/2; i++){ 233 | int data = *lineData; 234 | 235 | // draw pixels 236 | setMode0Pixel(2*i, j, unpackPixelMode0(data, 0)); 237 | setMode0Pixel(2*i + 1, j, unpackPixelMode0(data, 1)); 238 | 239 | lineData++; 240 | } 241 | } 242 | } 243 | 244 | // shows a screen stored in 320x200 1 pixel por byte 245 | void CPC6128::showVGAScreen(const UINT8 *data) 246 | { 247 | // scan the rows 248 | for (int j = 0; j < 200; j++){ 249 | // scan the cols 250 | for (int i = 0; i < 320; i++){ 251 | // draw pixels 252 | setVGAPixel(i,j,*data++); 253 | } 254 | } 255 | } 256 | 257 | 258 | 259 | // marks all pixels as dirty 260 | void CPC6128::markAllPixelsDirty() 261 | { 262 | //TODO VGA 263 | memset(DirtyPixels,0xFF,sizeof(DirtyPixels)); 264 | 265 | } 266 | 267 | ///////////////////////////////////////////////////////////////////////////// 268 | // helper methods 269 | ///////////////////////////////////////////////////////////////////////////// 270 | 271 | // fill a rectangle 272 | void CPC6128::fillRect(int x, int y, int width, int height, int color) 273 | { 274 | int xLimit = width + x - 1; 275 | 276 | for (; height > 0; height--, y++){ 277 | if (xLimit < x) { 278 | std::swap(x, xLimit); 279 | } 280 | 281 | for (int xx = x; xx <= xLimit; xx++){ 282 | setPixel(xx, y, color); 283 | } 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /vigasoco/AbadiaDriver.cpp: -------------------------------------------------------------------------------- 1 | // AbadiaDriver.cpp 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "AbadiaDriver.h" 6 | #include "cpc6128.h" 7 | #include "DskReader.h" 8 | 9 | #include "GameDataEntity.h" 10 | #include "GameDriver.h" 11 | #include "GfxData.h" 12 | 13 | #include "system.h" 14 | 15 | #include "GestorFrases.h" 16 | #include "Juego.h" 17 | 18 | #include 19 | 20 | using namespace Abadia; 21 | 22 | ///////////////////////////////////////////////////////////////////////////// 23 | // initialization and cleanup 24 | ///////////////////////////////////////////////////////////////////////////// 25 | 26 | AbadiaDriver::AbadiaDriver() : GameDriver("abadia", "La abadia del crimen", 300), 27 | _abadiaGame{0}, cpc6128{0}, romsPtr{0} 28 | { 29 | createGameDataEntities(); 30 | } 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | // creates the necessary file info, graphics specifications and inputs 34 | ///////////////////////////////////////////////////////////////////////////// 35 | 36 | void AbadiaDriver::createGameDataEntities() 37 | { 38 | // el c?digo y los gr?ficos est?n mezclados en la imagen 39 | auto *roms = new GameDataEntity(MIXED, "Code + Graphics + Sound"); 40 | roms->addFile(new GameFile("abadia.dsk", 0x00000, 0x27400, 0xd37cf8e7, 0)); 41 | _gameFiles.push_back(roms); 42 | 43 | // Graficos VGA 44 | auto *GfxVGA = new GameDataEntity(GRAPHICS,"Graphics VGA + Palette"); 45 | GfxVGA->addFile(new GameFile("GraficosVGA",0,174065,0,0)); 46 | _gameFiles.push_back(GfxVGA); 47 | 48 | // Graficos CPC adaptados a modo 256 colores 49 | auto *GfxCPC = new GameDataEntity(GRAPHICS,"Graphics CPC + Palette"); 50 | GfxCPC->addFile(new GameFile("GraficosCPC",0,174065,0,0)); 51 | _gameFiles.push_back(GfxCPC); 52 | 53 | // Los sonidos se cargan directamente en el AudioPlugin 54 | // para reducir el uso de memoria y no tenerlos 55 | // cargados en 2 sitios a la vez 56 | 57 | // El delete de roms, GfxVGA y GfxCPC 58 | // lo hace GameDriver::deallocateFilesMemory() 59 | // asi , que cuidado al usar los _gameFiles despues de iniciar, porque 60 | // no estan disponibles 61 | } 62 | 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // template method overrides to customize initialization 65 | ///////////////////////////////////////////////////////////////////////////// 66 | void AbadiaDriver::filesLoaded() 67 | { 68 | int bytesWritten; 69 | UINT8 auxBuffer[0xff00]; 70 | 71 | // reserva espacio para los datos del juego 72 | // TODO: VGA 73 | // para no pasar mas punteros y cambiar las interfaces 74 | // pegamos al final de romsPtr los datos de GraficosVGA del "remake" a 256 colores 75 | 76 | romsPtr = NULL; 77 | romsPtr = new UINT8[ 0x24000 + 78 | ((_gameFiles[1]->getTotalSize()+21600)*3) ]; 79 | 80 | // TODO: La funcion filesLoaded no debe ser void y se debe revisar si se pudo conseguir la memoria 81 | // y devolver este resultado 82 | if (romsPtr==NULL ) printf("No se pudo reservar memoria para la rom \n"); 83 | 84 | // 0x24000 de la rom original de CPC 85 | // 174065 de Graficos VGA 86 | // 21600 para copiar los graficos VGA flipeados necesarios ... (falta ajustar este valor) 87 | // Y por 3, porque tenemos primero los graficos a utilizar, y 88 | // luego una copia de los graficos VGA de 8 bits 89 | // y otra copia de los graficos CPC de 8 bits para poder 90 | // cambiar en caliente entre ellos 91 | // ver Juego::compruebaCambioCPC_VGA 92 | // los sonidos en formato WAV no se copian aqui, porque 93 | // el AudioPlugin vuelve a reservar memoria para ellos 94 | // y seria desperdiciar mucha memoria 95 | 96 | // extrae los datos del juego de la imagen del disco 97 | DskReader dsk(_gameFiles[0]->getData()); 98 | 99 | // obtiene los datos de las pistas 0x01-0x11 100 | for (int i = 0x01; i <= 0x11; i++){ 101 | dsk.getTrackData(i, &auxBuffer[(i - 0x01)*0x0f00], 0x0f00, bytesWritten); 102 | } 103 | 104 | // reordena los datos y los copia al destino 105 | reOrderAndCopy(&auxBuffer[0x0000], &romsPtr[0x00000], 0x4000); // abadia0.bin 106 | reOrderAndCopy(&auxBuffer[0x4000], &romsPtr[0x0c000], 0x4000); // abadia3.bin 107 | reOrderAndCopy(&auxBuffer[0x8000], &romsPtr[0x20000], 0x4000); // abadia8.bin 108 | reOrderAndCopy(&auxBuffer[0xc000], &romsPtr[0x04100], 0x3f00); // abadia1.bin 109 | 110 | // obtiene los datos de las pistas 0x12-0x16 111 | for (int i = 0x12; i <= 0x16; i++){ 112 | dsk.getTrackData(i, &auxBuffer[(i - 0x12)*0x0f00], 0x0f00, bytesWritten); 113 | } 114 | 115 | // reordena los datos y los copia al destino 116 | reOrderAndCopy(&auxBuffer[0x0000], &romsPtr[0x1c000], 0x4000); // abadia7.bin 117 | 118 | // obtiene los datos de las pistas 0x17-0x1b 119 | for (int i = 0x17; i <= 0x1b; i++){ 120 | dsk.getTrackData(i, &auxBuffer[(i - 0x17)*0x0f00], 0x0f00, bytesWritten); 121 | } 122 | 123 | // reordena los datos y los copia al destino 124 | reOrderAndCopy(&auxBuffer[0x0000], &romsPtr[0x18000], 0x4000); // abadia6.bin 125 | 126 | // obtiene los datos de las pistas 0x1c-0x21 127 | for (int i = 0x1c; i <= 0x21; i++){ 128 | dsk.getTrackData(i, &auxBuffer[(i - 0x1c)*0x0f00], 0x0f00, bytesWritten); 129 | } 130 | 131 | // reordena los datos y los copia al destino 132 | reOrderAndCopy(&auxBuffer[0x0000], &romsPtr[0x14000], 0x4000); // abadia5.bin 133 | 134 | // obtiene los datos de las pistas 0x21-0x25 135 | for (int i = 0x21; i <= 0x25; i++){ 136 | dsk.getTrackData(i, &auxBuffer[(i - 0x21)*0x0f00], 0x0f00, bytesWritten); 137 | } 138 | 139 | // reordena los datos y los copia al destino 140 | reOrderAndCopy(&auxBuffer[0x0000], &romsPtr[0x08000], 0x4000); // abadia2.bin 141 | 142 | // TODO: VGA 143 | // Copiamos de primeras los graficos VGA despues de la rom 144 | // y detras copiamos otra vez los VGA y luego los CPC 145 | // para poder cambiar en caliente entre ellos 146 | // ver Abadia::Juego::compruebaCambioCPC_VGA 147 | memcpy(&romsPtr[0x24000-1],_gameFiles[1]->getData(),_gameFiles[1]->getTotalSize()); 148 | memcpy(&romsPtr[0x24000-1+_gameFiles[1]->getTotalSize()+21600],_gameFiles[1]->getData(),_gameFiles[1]->getTotalSize()); 149 | memcpy(&romsPtr[0x24000-1+(_gameFiles[1]->getTotalSize()+21600)*2],_gameFiles[2]->getData(),_gameFiles[1]->getTotalSize()); 150 | // Los sonidos no se copian, y se cargan directamente en Audioplugin 151 | } 152 | 153 | // reordena los datos gr?ficos y los copia en el destino 154 | void AbadiaDriver::reOrderAndCopy(const UINT8 *src, UINT8 *dst, int size) 155 | { 156 | for (int i = 0; i < size; i++){ 157 | dst[size - i - 1] = src[i]; 158 | } 159 | } 160 | 161 | void AbadiaDriver::finishInit() 162 | { 163 | // crea e inicia la secci?n cr?tica para la sincronizaci?n del dibujado de gr?ficos 164 | //cs = VigasocoMain->createCriticalSection(); 165 | //cs->init(); 166 | 167 | //crea el objeto para tratar con gr?ficos del amstrad 168 | //cpc6128 = new CPC6128(cs); 169 | cpc6128 = new CPC6128(); 170 | 171 | // crea el objeto del juego 172 | _abadiaGame = new Abadia::Juego(romsPtr, cpc6128); 173 | } 174 | 175 | 176 | 177 | ///////////////////////////////////////////////////////////////////////////// 178 | // template method overrides to customize cleanup 179 | ///////////////////////////////////////////////////////////////////////////// 180 | 181 | 182 | 183 | void AbadiaDriver::end() 184 | { 185 | // borra el objeto de ayuda para los gr?ficos 186 | delete cpc6128; 187 | 188 | // borra el objeto del juego 189 | delete _abadiaGame; 190 | 191 | // libera la memoria utilizada por las roms del juego 192 | delete[] romsPtr; 193 | } 194 | 195 | ///////////////////////////////////////////////////////////////////////////// 196 | // run and refresh methods 197 | ///////////////////////////////////////////////////////////////////////////// 198 | 199 | void AbadiaDriver::runSync() 200 | { 201 | if (!_abadiaGame->pausa){ 202 | // incrementa el contador de la interrupci?n 203 | //_abadiaGame->contadorInterrupcion++; 204 | 205 | // si se est? mostrando alguna frase en el marcador, contin?a mostr?ndola 206 | elGestorFrases->procesaFraseActual(); 207 | } 208 | } 209 | void AbadiaDriver::preRun() 210 | { 211 | _abadiaGame->preRun(); 212 | } 213 | void AbadiaDriver::runAsync() 214 | { 215 | _abadiaGame->stateMachine(); 216 | } 217 | void AbadiaDriver::showMenu() 218 | { 219 | _abadiaGame->changeState(MENU); 220 | } 221 | void AbadiaDriver::changeState(int newState) 222 | { 223 | _abadiaGame->changeState(newState); 224 | } 225 | void AbadiaDriver::render() 226 | { 227 | //TODO: VGA 228 | //El codigo si usasemos los graficos originales 229 | //de abadia.dsk seria diferente 230 | 231 | auto *posPant = cpc6128->screenBuffer; 232 | UINT8 *posPantTmp = NULL; 233 | auto *pixels = (uint8_t*)sys->surface->pixels; 234 | auto p = (Uint32 *)pixels; 235 | 236 | for (int y = 0; y < TEXTURE_HEIGHT/2; y++) 237 | { 238 | posPantTmp = posPant; 239 | for (int x = 0; x < TEXTURE_WIDTH; x++) 240 | { 241 | auto data = *posPant; 242 | auto r = (Uint8) _abadiaGame->paleta->paleta2->_palette[data].R; 243 | auto g = (Uint8) _abadiaGame->paleta->paleta2->_palette[data].G; 244 | auto b = (Uint8) _abadiaGame->paleta->paleta2->_palette[data].B; 245 | *p = sys->RGBA(r,g,b,0xFF); 246 | 247 | p++; 248 | posPant++; 249 | } 250 | 251 | posPant = posPantTmp; 252 | for (int x = 0; x < TEXTURE_WIDTH; x++) 253 | { 254 | auto data = *posPant; 255 | auto r = (Uint8) _abadiaGame->paleta->paleta2->_palette[data].R; 256 | auto g = (Uint8) _abadiaGame->paleta->paleta2->_palette[data].G; 257 | auto b = (Uint8) _abadiaGame->paleta->paleta2->_palette[data].B; 258 | *p = sys->RGBA(r,g,b,0xFF); 259 | 260 | p++; 261 | posPant++; 262 | } 263 | 264 | } 265 | 266 | sys->updateTexture(); 267 | } 268 | 269 | ///////////////////////////////////////////////////////////////////////////// 270 | // display internal game information 271 | ///////////////////////////////////////////////////////////////////////////// 272 | 273 | void AbadiaDriver::showGameLogic() 274 | { 275 | _abadiaGame->modoInformacion = !_abadiaGame->modoInformacion; 276 | _abadiaGame->cambioModoInformacion = true; 277 | 278 | } 279 | --------------------------------------------------------------------------------