From ad553db1ae9ab6640ef68b2a555d1243bf5bc47b Mon Sep 17 00:00:00 2001 From: jaildoctor Date: Fri, 6 Mar 2009 13:03:27 +0000 Subject: [PATCH] =?UTF-8?q?Versi=C3=B3=201.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AiguaProcesor.cpp | 47 +++ AiguaProcesor.h | 20 + AppController.cpp | 101 +++++ AppController.h | 25 ++ ArounderProcesor.cpp | 818 +++++++++++++++++++++++++++++++++++++++++ ArounderProcesor.h | 106 ++++++ DrawManager.cpp | 309 ++++++++++++++++ DrawManager.h | 42 +++ GameController.cpp | 422 +++++++++++++++++++++ GameController.h | 58 +++ GameInfo.cpp | 11 + GameInfo.h | 14 + InputManager.cpp | 192 ++++++++++ InputManager.h | 41 +++ MarcadorProcesor.cpp | 110 ++++++ MarcadorProcesor.h | 38 ++ MenuController.cpp | 76 ++++ MenuController.h | 25 ++ MortController.cpp | 72 ++++ MortController.h | 25 ++ MusicManager.cpp | 52 +++ MusicManager.h | 18 + PasswordController.cpp | 116 ++++++ PasswordController.h | 30 ++ PostfaseController.cpp | 137 +++++++ PostfaseController.h | 28 ++ PrefaseController.cpp | 105 ++++++ PrefaseController.h | 32 ++ SequenceController.cpp | 214 +++++++++++ SequenceController.h | 36 ++ const.h | 49 +++ fileManager.cpp | 90 +++++ fileManager.h | 5 + main.cpp | 27 ++ 34 files changed, 3491 insertions(+) create mode 100644 AiguaProcesor.cpp create mode 100644 AiguaProcesor.h create mode 100644 AppController.cpp create mode 100644 AppController.h create mode 100644 ArounderProcesor.cpp create mode 100644 ArounderProcesor.h create mode 100644 DrawManager.cpp create mode 100644 DrawManager.h create mode 100644 GameController.cpp create mode 100644 GameController.h create mode 100644 GameInfo.cpp create mode 100644 GameInfo.h create mode 100644 InputManager.cpp create mode 100644 InputManager.h create mode 100644 MarcadorProcesor.cpp create mode 100644 MarcadorProcesor.h create mode 100644 MenuController.cpp create mode 100644 MenuController.h create mode 100644 MortController.cpp create mode 100644 MortController.h create mode 100644 MusicManager.cpp create mode 100644 MusicManager.h create mode 100644 PasswordController.cpp create mode 100644 PasswordController.h create mode 100644 PostfaseController.cpp create mode 100644 PostfaseController.h create mode 100644 PrefaseController.cpp create mode 100644 PrefaseController.h create mode 100644 SequenceController.cpp create mode 100644 SequenceController.h create mode 100644 const.h create mode 100644 fileManager.cpp create mode 100644 fileManager.h create mode 100644 main.cpp diff --git a/AiguaProcesor.cpp b/AiguaProcesor.cpp new file mode 100644 index 0000000..5a1ce19 --- /dev/null +++ b/AiguaProcesor.cpp @@ -0,0 +1,47 @@ +#include "AiguaProcesor.h" + +AiguaProcesor::AiguaProcesor(DrawManager *p_drawManager, int p_fase) +{ + drawManager = p_drawManager; + fase = p_fase; + + grafic = drawManager->LoadFont("aigua.gif"); + frame1 = 0; + frame2 = 5; +} + +AiguaProcesor::~AiguaProcesor(void) +{ + SDL_FreeSurface(grafic); +} + +void AiguaProcesor::Pintar() { + int frames1[10] = {0,1,2,1,0,3,4,5,4,3}; + int frames2[10] = {6,7,8,7,6,9,10,11,10,9}; + int *frames; + if ((fase+1) % 5 == 0) { + frames = frames2; + } else { + frames = frames1; + } + + SDL_Rect clip; + clip.y = 0; + clip.w = 16; + clip.h = 15; + + for (int i=0;i<10;i++) { + clip.x = frames[frame1]*16; + drawManager->Blit(i*32, 150, grafic, &clip); + clip.x = frames[frame2]*16; + drawManager->Blit(16+i*32, 150, grafic, &clip); + } +} + +void AiguaProcesor::Procesar() { + frame1++; + frame2++; + + if (frame1 == 10) frame1 = 0; + if (frame2 == 10) frame2 = 0; +} \ No newline at end of file diff --git a/AiguaProcesor.h b/AiguaProcesor.h new file mode 100644 index 0000000..c2113bf --- /dev/null +++ b/AiguaProcesor.h @@ -0,0 +1,20 @@ +#pragma once +#include "DrawManager.h" + +class AiguaProcesor +{ +public: + AiguaProcesor(DrawManager *p_drawManager, int p_fase); + ~AiguaProcesor(void); + + void Pintar(); + void Procesar(); + +private: + DrawManager *drawManager; + + SDL_Surface *grafic; + int frame1; + int frame2; + int fase; +}; diff --git a/AppController.cpp b/AppController.cpp new file mode 100644 index 0000000..266dc1a --- /dev/null +++ b/AppController.cpp @@ -0,0 +1,101 @@ +#include +#include "AppController.h" +#include "SequenceController.h" +#include "MenuController.h" +#include "PasswordController.h" +#include "PrefaseController.h" +#include "GameController.h" +#include "PostfaseController.h" +#include "MortController.h" +#include "const.h" + +AppController::AppController(int pMode) +{ + gameInfo = new GameInfo(pMode); +} + +AppController::~AppController(void) +{ +} + +bool AppController::Init(void) +{ + if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } + + drawManager = new DrawManager(gameInfo->modeGrafic); + inputManager = new InputManager(gameInfo); + musicManager = new MusicManager(); + + if ( !drawManager->Init() ) { return false; } + musicManager->Init(); + + SDL_WM_SetCaption( APPLICATION_NAME, NULL ); + + SDL_ShowCursor(0); + + return true; +} + +void AppController::Go() +{ + if (!Init()) gameInfo->estado = ESTADO_SALIR; + + while ( gameInfo->estado != ESTADO_SALIR ) { + switch ( gameInfo->estado ) { + case ESTADO_SEQUENCIA: + SequenceController *sequenceController; + sequenceController = new SequenceController(drawManager, inputManager, musicManager); + sequenceController->Go(gameInfo); + delete sequenceController; + break; + case ESTADO_MENU: + MenuController *menuController; + menuController = new MenuController(drawManager, inputManager, musicManager); + menuController->Go(gameInfo); + delete menuController; + break; + case ESTADO_PASSWORD: + PasswordController *passwordController; + passwordController = new PasswordController(drawManager, inputManager, musicManager); + passwordController->Go(gameInfo); + delete passwordController; + break; + case ESTADO_PREFASE: + PrefaseController *prefaseController; + prefaseController = new PrefaseController(drawManager, inputManager, musicManager); + prefaseController->Go(gameInfo); + delete prefaseController; + break; + case ESTADO_JUEGO: + GameController *gameController; + gameController = new GameController(drawManager, inputManager, musicManager); + gameController->Go(gameInfo); + delete gameController; + break; + case ESTADO_POSTFASE: + PostfaseController *postfaseController; + postfaseController = new PostfaseController(drawManager, inputManager, musicManager); + postfaseController->Go(gameInfo); + delete postfaseController; + break; + case ESTADO_MORT: + MortController *mortController; + mortController = new MortController(drawManager, inputManager, musicManager); + mortController->Go(gameInfo); + delete mortController; + break; + } + } + + Finalize(); +} + +void AppController::Finalize(void) +{ + delete drawManager; + delete inputManager; + delete musicManager; + delete gameInfo; + + SDL_Quit(); +} \ No newline at end of file diff --git a/AppController.h b/AppController.h new file mode 100644 index 0000000..d5e9c17 --- /dev/null +++ b/AppController.h @@ -0,0 +1,25 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class AppController +{ +public: + AppController(int pMode); + ~AppController(void); + + void Go(); + +private: + bool Init(void); + void Finalize(void); + + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + GameInfo *gameInfo; + +}; diff --git a/ArounderProcesor.cpp b/ArounderProcesor.cpp new file mode 100644 index 0000000..b68e81d --- /dev/null +++ b/ArounderProcesor.cpp @@ -0,0 +1,818 @@ +#include "ArounderProcesor.h" + +ArounderProcesor::ArounderProcesor(DrawManager *pDrawManager, MarcadorProcesor *pMarcadorProcesor, SDL_Surface *pSprites, SDL_Surface *pMapa, int pxInicial, int pyInicial, int pxFinal, int pyFinal ) +{ + drawManager = pDrawManager; + marcadorProcesor = pMarcadorProcesor; + sprites = pSprites; + mapa = pMapa; + pixels = (Uint32 *)mapa->pixels; + explosio = drawManager->LoadMask("explosio.gif"); + + xInicial = pxInicial; + yInicial = pyInicial; + xFinal = pxFinal; + yFinal = pyFinal; + + X = xInicial; + Y = yInicial; + O = marcadorProcesor->orientacioInicial; + frame = 0; + frameX = 0; + frameY = 0; + altura = 0; + + accio = ACCIO_CAMINAR; + prevista = ACCIO_CAMINAR; + + clip.w = 8; + clip.h = 8; + + siguiente = NULL; + anterior = NULL; + + colorEscalo = SDL_MapRGB( mapa->format, 60, 0, 60 ); + colorCorda = SDL_MapRGB( mapa->format, 255, 251, 194 ); +} + +ArounderProcesor::~ArounderProcesor(void) +{ + if (anterior != NULL) anterior->siguiente = siguiente; + if (siguiente != NULL) siguiente->anterior = anterior; + + SDL_FreeSurface(explosio); +} + +ArounderProcesor *ArounderProcesor::Afegir() { + if (siguiente != NULL) { + return siguiente->Afegir(); + } else { + siguiente = new ArounderProcesor(drawManager, marcadorProcesor, sprites, mapa, xInicial, yInicial, xFinal, yFinal); + siguiente->anterior = this; + return siguiente; + } +} + +void ArounderProcesor::Pintar() { + clip.y = frameY; + clip.x = frameX*8; + drawManager->Blit(X, Y, sprites, &clip); + + if (siguiente != NULL) siguiente->Pintar(); +} + +ArounderProcesor *ArounderProcesor::Seleccionar(int mouseX, int mouseY) { + if (X <= mouseX && (X+8) >= mouseX && Y <= mouseY && (Y+8) >= mouseY) { + return this; + } else { + if (siguiente != NULL) { + return siguiente->Seleccionar(mouseX, mouseY); + } else { + return NULL; + } + } +} + +void ArounderProcesor::Procesar() { + + switch(accio) { + case ACCIO_CAMINAR: + procesarCaminar(); + break; + case ACCIO_CAURE: + procesarCaure(); + break; + case ACCIO_CAVAR: + procesarCavar(); + break; + case ACCIO_ESCALAR: + procesarEscalar(); + break; + case ACCIO_PERFORAR: + procesarPerforar(); + break; + case ACCIO_ESCALERA: + procesarEscalera(); + break; + case ACCIO_PASARELA: + procesarPasarela(); + break; + case ACCIO_CORDA: + procesarCorda(); + break; + case ACCIO_PUJARCORDA: + procesarPujarCorda(); + break; + case ACCIO_BAIXARCORDA: + procesarBaixarCorda(); + break; + case ACCIO_SUICIDI: + procesarSuicidi(); + break; + } + + if (X == xFinal && Y == yFinal) initArrivat(); + + if (siguiente != NULL) siguiente->Procesar(); +} + +void ArounderProcesor::AbortarAccio() { + if (accio == ACCIO_ESCALAR) { + if (O == ORIENT_DRETA) X=X-5; else X=X+5; + } + if (accio != ACCIO_CAMINAR && accio != ACCIO_CAURE && accio != ACCIO_PUJARCORDA && accio != ACCIO_BAIXARCORDA) { + accio = ACCIO_CAMINAR; + } +} + +void ArounderProcesor::initMort() { + accio = ACCIO_MORT; + drawManager->apply_surface(X-9, Y-12, explosio, mapa); + marcadorProcesor->numAroundersMorts++; +} + +void ArounderProcesor::initArrivat() { + accio = ACCIO_MORT; + marcadorProcesor->numAroundersArrivats++; +} + +void ArounderProcesor::initCaminar() { + frame = 0; + accio = ACCIO_CAMINAR; + procesarCaminar(); +} + +void ArounderProcesor::initCaure() { + frame = 0; + accio = ACCIO_CAURE; + altura = 0; + procesarCaure(); +} + +void ArounderProcesor::initParar() { + if (marcadorProcesor->numParar > 0) { + frame = 0; + accio = ACCIO_PARAR; + prevista = ACCIO_CAMINAR; + marcadorProcesor->numParar--; + procesarParar(); + } else { + frame = 0; + accio = ACCIO_CAMINAR; + prevista = ACCIO_CAMINAR; + procesarCaminar(); + } +} + +void ArounderProcesor::initCavar() { + if (marcadorProcesor->numCavar > 0) { + frame = 0; + accio = ACCIO_CAVAR; + prevista = ACCIO_CAMINAR; + marcadorProcesor->numCavar--; + procesarCavar(); + } else { + frame = 0; + accio = ACCIO_CAMINAR; + prevista = ACCIO_CAMINAR; + procesarCaminar(); + } +} + +void ArounderProcesor::initEscalar() { + if (marcadorProcesor->numEscalar > 0) { + frame = 0; + accio = ACCIO_ESCALAR; + prevista = ACCIO_CAMINAR; + marcadorProcesor->numEscalar--; + if (O == ORIENT_DRETA) { + X = X + 5; + } else { + X = X - 5; + } + procesarEscalar(); + } else { + frame = 0; + accio = ACCIO_CAMINAR; + prevista = ACCIO_CAMINAR; + procesarCaminar(); + } +} + +void ArounderProcesor::initPerforar() { + if (marcadorProcesor->numPerforar > 0) { + frame = 0; + accio = ACCIO_PERFORAR; + prevista = ACCIO_CAMINAR; + marcadorProcesor->numPerforar--; + procesarPerforar(); + } else { + frame = 0; + accio = ACCIO_CAMINAR; + prevista = ACCIO_CAMINAR; + procesarCaminar(); + } +} + +void ArounderProcesor::initEscalera() { + frame = 0; + accio = ACCIO_ESCALERA; + prevista = ACCIO_CAMINAR; + procesarEscalera(); +} + +void ArounderProcesor::initPasarela() { + frame = 0; + accio = ACCIO_PASARELA; + prevista = ACCIO_CAMINAR; + procesarPasarela(); +} + +void ArounderProcesor::initCorda() { + if (marcadorProcesor->numCorda > 0) { + frame = 0; + accio = ACCIO_CORDA; + prevista = ACCIO_CAMINAR; + marcadorProcesor->numCorda--; + procesarCorda(); + altura = 0; + } else { + frame = 0; + accio = ACCIO_CAMINAR; + prevista = ACCIO_CAMINAR; + procesarCaminar(); + } +} + +void ArounderProcesor::initPujarCorda() { + frame = 0; + accio = ACCIO_PUJARCORDA; + if (O == ORIENT_DRETA) { + X = X + 3; + } else { + X = X - 3; + } + procesarPujarCorda(); +} + +void ArounderProcesor::initBaixarCorda() { + frame = 0; + accio = ACCIO_BAIXARCORDA; + if (O == ORIENT_DRETA) { + X = X + 2; + } else { + X = X - 2; + } + procesarBaixarCorda(); +} + +void ArounderProcesor::initSuicidi() { + frame = 0; + accio = ACCIO_SUICIDI; + prevista = accio; + procesarSuicidi(); +} + + +void ArounderProcesor::procesarCaminar() { + const int frames[4] = {3,4,3,5}; + frame++; + if (frame >= 4) frame = 0; + frameX = frames[frame]; + frameY = O; + + if (blockCaure()) { + initCaure(); + } else { + switch ( prevista ) { + case ACCIO_PARAR: + initParar(); + break; + case ACCIO_PERFORAR: + initPerforar(); + break; + case ACCIO_ESCALERA: + initEscalera(); + break; + case ACCIO_SUICIDI: + initSuicidi(); + break; + default: + if (blockCordaPujar()) { + initPujarCorda(); + } else if (blockCaminar()) { + if (prevista == ACCIO_CAVAR) { + initCavar(); + } else if (prevista == ACCIO_ESCALAR) { + initEscalar(); + } else { + O = O ^ ORIENT_ESQUERRA; + } + } else { + if (blockArounder()) { + O = O ^ ORIENT_ESQUERRA; + } else { + if (blockPrecipici() && (prevista == ACCIO_PASARELA || prevista == ACCIO_CORDA)) { + if (prevista == ACCIO_PASARELA) { + initPasarela(); + } else { + initCorda(); + } + } else { + if (blockCordaBaixar()) { + initBaixarCorda(); + } else if (blockCordaPujar()) { + initPujarCorda(); + } else { + if (pujarEscalo()) Y--; + X+= ((((O ^ 8) << 1) >> 3) - 1); + if (baixarEscalo()) Y++; + } + } + } + } + } + } +} + +void ArounderProcesor::procesarCaure() { + frame = 0; + frameX = 11; + frameY = O; + + if (!blockCaure()) { + if (altura >= 32) { + initMort(); + } else { + initCaminar(); + } + } else { + if (Y > 151) { + initMort(); + } else { + Y++; + altura++; + } + } +} + +void ArounderProcesor::procesarParar() { + frame = 0; + frameX = 2; + frameY = 8; +} + +void ArounderProcesor::procesarCavar() { + const int frames[3] = {6,7,8}; + frame++; + if (frame == 3) frame = 0; + frameX = frames[frame]; + frameY = O; + + if (blockCaure()) { + initCaure(); + } else { + if (!blockCaminar()) { + initCaminar(); + } else { + if (frame == 2) { + doCavar(); + if (O == ORIENT_DRETA) { + X++; + } else { + X--; + } + } + } + } +} + +void ArounderProcesor::procesarEscalar() { + const int frames[2] = {9,10}; + frame++; + if (frame == 2) frame = 0; + frameX = frames[frame]; + frameY = O; + + if (!blockParet(5)) { + if (O == ORIENT_DRETA) { + X = X - 1; + } else { + X = X + 1; + } + Y=Y-1; + initCaminar(); + } else { + if (blockTecho(5)) { + if (O == ORIENT_DRETA) { + X = X - 5; + } else { + X = X + 5; + } + initCaminar(); + } else { + Y--; + } + } +} + +void ArounderProcesor::procesarPerforar() { + const int frames[2] = {0,1}; + frame++; + if (frame == 2) frame = 0; + frameX = frames[frame]; + frameY = 8; + + if (blockCaure()) { + initCaure(); + } else { + if (frame == 1) { + doPerforar(); + Y++; + } + } +} + +void ArounderProcesor::procesarEscalera() { + const int frames[5] = {12,13,14,15,4}; + frame++; + if (frame == 5) frame = 0; + frameX = frames[frame]; + frameY = O; + + if (blockParet() || blockTecho() || marcadorProcesor->numEscalera == 0) { + initCaminar(); + } else { + if (frame == 3) { + doEscalera(); + marcadorProcesor->numEscalera--; + } + if (frame == 4) { + Y--; + if (O == ORIENT_DRETA) { + X++; + } else { + X--; + } + } + } +} + +void ArounderProcesor::procesarPasarela() { + const int frames[5] = {12,13,14,15,4}; + frame++; + if (frame == 5) frame = 0; + frameX = frames[frame]; + frameY = O; + + if (blockParet() || !blockPrecipiciPasarela() || marcadorProcesor->numPasarela == 0) { + initCaminar(); + } else { + if (frame == 3) { + doEscalera(1); + marcadorProcesor->numPasarela--; + } + if (frame == 4) { + if (O == ORIENT_DRETA) { + X=X+2; + } else { + X=X-2; + } + } + } +} + +void ArounderProcesor::procesarCorda() { + const int frames[4] = {12,13,14,15}; + if (frame < 3) frame++; + frameX = frames[frame]; + frameY = O; + + if (frame == 3 ) { + if (!blockNovaCorda()) { + initCaminar(); + } else { + doCorda(); + altura++; + } + } + +} + +void ArounderProcesor::procesarPujarCorda() { + const int frames[2] = {9,10}; + frame++; + if (frame == 2) frame = 0; + frameX = frames[frame]; + frameY = O; + + if (!blockCordaPujar(3)) { + Y = Y - 2; + initCaminar(); + } else { + if (blockTecho(3)) { + if (O == ORIENT_DRETA) { + X = X - 3; + } else { + X = X + 3; + } + initCaminar(); + } else { + Y--; + } + } +} + +void ArounderProcesor::procesarBaixarCorda() { + const int frames[2] = {9,10}; + frame++; + if (frame == 2) frame = 0; + frameX = frames[frame]; + frameY = ORIENT_ESQUERRA - O; + + if (!blockCordaBaixar(2)) { + initCaminar(); + } else { + if (!blockCaure(3)) { + if (O == ORIENT_DRETA) { + X = X - 2; + } else { + X = X + 2; + } + initCaminar(); + } else { + Y++; + } + } +} + +void ArounderProcesor::procesarSuicidi() { + const int frames[5] = {0,1,2,1,2}; + frameX = frames[frame]; + frameY = 0; + + if (frame == 4) initMort(); + frame++; +} + +bool ArounderProcesor::blockCaure(int desfase) { + if ( O == ORIENT_ESQUERRA) desfase = -desfase; + return ( (get_pixel(X+desfase , Y+8) == 0 || get_pixel(X+desfase , Y+8) == colorCorda) && + (get_pixel(X+desfase+1, Y+8) == 0 || get_pixel(X+desfase+1, Y+8) == colorCorda) && + (get_pixel(X+desfase+2, Y+8) == 0 || get_pixel(X+desfase+2, Y+8) == colorCorda) && + (get_pixel(X+desfase+3, Y+8) == 0 || get_pixel(X+desfase+3, Y+8) == colorCorda) && + (get_pixel(X+desfase+4, Y+8) == 0 || get_pixel(X+desfase+4, Y+8) == colorCorda) && + (get_pixel(X+desfase+5, Y+8) == 0 || get_pixel(X+desfase+5, Y+8) == colorCorda) && + (get_pixel(X+desfase+6, Y+8) == 0 || get_pixel(X+desfase+6, Y+8) == colorCorda) && + (get_pixel(X+desfase+7, Y+8) == 0 || get_pixel(X+desfase+7, Y+8) == colorCorda) && + (get_pixel(X+desfase , Y+9) == 0 || get_pixel(X+desfase , Y+9) == colorCorda) && + (get_pixel(X+desfase+1, Y+9) == 0 || get_pixel(X+desfase+1, Y+9) == colorCorda) && + (get_pixel(X+desfase+2, Y+9) == 0 || get_pixel(X+desfase+2, Y+9) == colorCorda) && + (get_pixel(X+desfase+3, Y+9) == 0 || get_pixel(X+desfase+3, Y+9) == colorCorda) && + (get_pixel(X+desfase+4, Y+9) == 0 || get_pixel(X+desfase+4, Y+9) == colorCorda) && + (get_pixel(X+desfase+5, Y+9) == 0 || get_pixel(X+desfase+5, Y+9) == colorCorda) && + (get_pixel(X+desfase+6, Y+9) == 0 || get_pixel(X+desfase+6, Y+9) == colorCorda) && + (get_pixel(X+desfase+7, Y+9) == 0 || get_pixel(X+desfase+7, Y+9) == colorCorda) + ); +} + +bool ArounderProcesor::baixarEscalo() { + return ( get_pixel(X , Y+8) == 0 && + get_pixel(X+1, Y+8) == 0 && + get_pixel(X+2, Y+8) == 0 && + get_pixel(X+3, Y+8) == 0 && + get_pixel(X+4, Y+8) == 0 && + get_pixel(X+5, Y+8) == 0 && + get_pixel(X+6, Y+8) == 0 && + get_pixel(X+7, Y+8) == 0 && + + ( get_pixel(X , Y+9) != 0 || + get_pixel(X+1, Y+9) != 0 || + get_pixel(X+2, Y+9) != 0 || + get_pixel(X+3, Y+9) != 0 || + get_pixel(X+4, Y+9) != 0 || + get_pixel(X+5, Y+9) != 0 || + get_pixel(X+6, Y+9) != 0 || + get_pixel(X+7, Y+9) != 0 + ) + ); +} + +bool ArounderProcesor::blockCaminar() { + if (O == ORIENT_DRETA) { + return (get_pixel(X+8, Y+6) != 0 && get_pixel(X+8, Y+7) != 0 && get_pixel(X+8, Y+6) != colorEscalo); + } else { + return (get_pixel(X-1, Y+6) != 0 && get_pixel(X-1, Y+7) != 0 && get_pixel(X-1, Y+6) != colorEscalo); + } +} + +bool ArounderProcesor::pujarEscalo() { + if (O == ORIENT_DRETA) { + return ( (get_pixel(X+8, Y+6) == 0 || get_pixel(X+8, Y+6) == colorEscalo) && get_pixel(X+8, Y+7) != 0); + } else { + return ( (get_pixel(X-1, Y+6) == 0 || get_pixel(X-1, Y+6) == colorEscalo) && get_pixel(X-1, Y+7) != 0); + } +} + +bool ArounderProcesor::blockArounder() { + bool resultado = false; + if (anterior != NULL) resultado = anterior->checkArounderAnt(X, Y, O); + if (siguiente != NULL) resultado = resultado || siguiente->checkArounderSig(X, Y, O); + + return resultado; +} + +bool ArounderProcesor::blockParet(int desfase) { + if (O == ORIENT_DRETA) { + return (get_pixel(X+8-desfase, Y ) != 0 || + get_pixel(X+8-desfase, Y+1) != 0 || + get_pixel(X+8-desfase, Y+2) != 0 || + get_pixel(X+8-desfase, Y+3) != 0 || + get_pixel(X+8-desfase, Y+4) != 0 || + get_pixel(X+8-desfase, Y+5) != 0 || + get_pixel(X+8-desfase, Y+6) != 0// || + //get_pixel(X+8-desfase, Y+7) != 0 + ); + } else { + return (get_pixel(X-1+desfase, Y ) != 0 || + get_pixel(X-1+desfase, Y+1) != 0 || + get_pixel(X-1+desfase, Y+2) != 0 || + get_pixel(X-1+desfase, Y+3) != 0 || + get_pixel(X-1+desfase, Y+4) != 0 || + get_pixel(X-1+desfase, Y+5) != 0 || + get_pixel(X-1+desfase, Y+6) != 0// || + //get_pixel(X-1+desfase, Y+7) != 0 + ); + } +} + +bool ArounderProcesor::blockTecho(int desfase) { + if ( O == ORIENT_DRETA) desfase = -desfase; + + return ( (get_pixel(X+desfase , Y-1) != 0 && get_pixel(X+desfase , Y-1) != colorCorda) || + (get_pixel(X+desfase+1, Y-1) != 0 && get_pixel(X+desfase+1, Y-1) != colorCorda) || + (get_pixel(X+desfase+2, Y-1) != 0 && get_pixel(X+desfase+2, Y-1) != colorCorda) || + (get_pixel(X+desfase+3, Y-1) != 0 && get_pixel(X+desfase+3, Y-1) != colorCorda) || + (get_pixel(X+desfase+4, Y-1) != 0 && get_pixel(X+desfase+4, Y-1) != colorCorda) || + (get_pixel(X+desfase+5, Y-1) != 0 && get_pixel(X+desfase+5, Y-1) != colorCorda) || + (get_pixel(X+desfase+6, Y-1) != 0 && get_pixel(X+desfase+6, Y-1) != colorCorda) || + (get_pixel(X+desfase+7, Y-1) != 0 && get_pixel(X+desfase+7, Y-1) != colorCorda) + ); +} + +bool ArounderProcesor::blockPrecipici() { + if (O == ORIENT_DRETA) { + return (get_pixel(X+7, Y+8) == 0 && + get_pixel(X+6, Y+8) == 0 && + get_pixel(X+5, Y+8) == 0 && + get_pixel(X+7, Y+9) == 0 && + get_pixel(X+6, Y+9) == 0 && + get_pixel(X+5, Y+9) == 0 + ); + } else { + return (get_pixel(X , Y+8) == 0 && + get_pixel(X+1, Y+8) == 0 && + get_pixel(X+2, Y+8) == 0 && + get_pixel(X , Y+9) == 0 && + get_pixel(X+1, Y+9) == 0 && + get_pixel(X+2, Y+9) == 0 + ); + } +} + +bool ArounderProcesor::blockPrecipiciPasarela() { + if (O == ORIENT_DRETA) { + return ((get_pixel(X+7, Y+8) == 0 || get_pixel(X+7, Y+8) == colorEscalo) && + (get_pixel(X+6, Y+8) == 0 || get_pixel(X+6, Y+8) == colorEscalo) && + (get_pixel(X+5, Y+8) == 0 || get_pixel(X+5, Y+8) == colorEscalo) && + (get_pixel(X+7, Y+9) == 0 || get_pixel(X+7, Y+9) == colorEscalo) && + (get_pixel(X+6, Y+9) == 0 || get_pixel(X+6, Y+9) == colorEscalo) && + (get_pixel(X+5, Y+9) == 0 || get_pixel(X+5, Y+9) == colorEscalo) + ); + } else { + return ((get_pixel(X , Y+8) == 0 || get_pixel(X , Y+8) == colorEscalo) && + (get_pixel(X+1, Y+8) == 0 || get_pixel(X+1, Y+8) == colorEscalo) && + (get_pixel(X+2, Y+8) == 0 || get_pixel(X+2, Y+8) == colorEscalo) && + (get_pixel(X , Y+9) == 0 || get_pixel(X , Y+9) == colorEscalo) && + (get_pixel(X+1, Y+9) == 0 || get_pixel(X+1, Y+9) == colorEscalo) && + (get_pixel(X+2, Y+9) == 0 || get_pixel(X+2, Y+9) == colorEscalo) + ); + } +} + +bool ArounderProcesor::blockNovaCorda() { + if (O == ORIENT_DRETA) { + return (get_pixel(X+6, Y+8+altura) == 0 && + get_pixel(X+6, Y+9+altura) == 0 && + get_pixel(X+6, Y+10+altura) == 0 + ); + } else { + return (get_pixel(X+1, Y+8+altura) == 0 && + get_pixel(X+1, Y+9+altura) == 0 && + get_pixel(X+1, Y+10+altura) == 0 + ); + } +} + +bool ArounderProcesor::blockCordaBaixar(int desfase) { + if (O == ORIENT_DRETA) { + return (get_pixel(X+6-desfase, Y+8) == colorCorda); + } else { + return (get_pixel(X+1+desfase, Y+8) == colorCorda); + } +} + +bool ArounderProcesor::blockCordaPujar(int desfase) { + if (O == ORIENT_DRETA) { + return (get_pixel(X+6-desfase, Y+5) == colorCorda); + } else { + return (get_pixel(X+1+desfase, Y+5) == colorCorda); + } +} + +bool ArounderProcesor::checkArounderAnt(int x, int y, int o) { + if ( accio == ACCIO_PARAR && (y >= Y-8) && (y <= Y+8) && ( (o == ORIENT_DRETA && X == x+8) || (o == ORIENT_ESQUERRA && X == x-8) ) ) { + return true; + } else { + if (anterior != NULL) { + return anterior->checkArounderAnt(x, y, o); + } else { + return false; + } + } +} + +bool ArounderProcesor::checkArounderSig(int x, int y, int o) { + if ( accio == ACCIO_PARAR && (y >= Y-8) && (y <= Y+8) && ( (o == ORIENT_DRETA && X == x+8) || (o == ORIENT_ESQUERRA && X == x-8) ) ) { + return true; + } else { + if (siguiente != NULL) { + return siguiente->checkArounderSig(x, y, o); + } else { + return false; + } + } +} + +void ArounderProcesor::doCavar() { + if (O == ORIENT_DRETA) { + put_pixel(X+8, Y, 0); + put_pixel(X+8, Y+1, 0); + put_pixel(X+8, Y+2, 0); + put_pixel(X+8, Y+3, 0); + put_pixel(X+8, Y+4, 0); + put_pixel(X+8, Y+5, 0); + put_pixel(X+8, Y+6, 0); + put_pixel(X+8, Y+7, 0); + } else { + put_pixel(X-1, Y, 0); + put_pixel(X-1, Y+1, 0); + put_pixel(X-1, Y+2, 0); + put_pixel(X-1, Y+3, 0); + put_pixel(X-1, Y+4, 0); + put_pixel(X-1, Y+5, 0); + put_pixel(X-1, Y+6, 0); + put_pixel(X-1, Y+7, 0); + } +} + +void ArounderProcesor::doPerforar() { + put_pixel(X , Y+8, 0); + put_pixel(X+1, Y+8, 0); + put_pixel(X+2, Y+8, 0); + put_pixel(X+3, Y+8, 0); + put_pixel(X+4, Y+8, 0); + put_pixel(X+5, Y+8, 0); + put_pixel(X+6, Y+8, 0); + put_pixel(X+7, Y+8, 0); +} + +void ArounderProcesor::doEscalera(int desfase) { + if (O == ORIENT_DRETA) { + put_pixel(X+5, Y+7+desfase, colorEscalo); + put_pixel(X+6, Y+7+desfase, colorEscalo); + put_pixel(X+7, Y+7+desfase, colorEscalo); + } else { + put_pixel(X+2, Y+7+desfase, colorEscalo); + put_pixel(X+1, Y+7+desfase, colorEscalo); + put_pixel(X , Y+7+desfase, colorEscalo); + } +} + +void ArounderProcesor::doCorda() { + if (O == ORIENT_DRETA) { + put_pixel(X+6, Y+8+altura, colorCorda); + } else { + put_pixel(X+1, Y+8+altura, colorCorda); + } +} + +Uint32 ArounderProcesor::get_pixel( int x, int y ) +{ + return pixels[ ( y * mapa->w ) + x ]; +} + +void ArounderProcesor::put_pixel( int x, int y, Uint32 pixel ) +{ + pixels[ ( y * mapa->w ) + x ] = pixel; +} diff --git a/ArounderProcesor.h b/ArounderProcesor.h new file mode 100644 index 0000000..24c817d --- /dev/null +++ b/ArounderProcesor.h @@ -0,0 +1,106 @@ +#pragma once +#include "DrawManager.h" +#include "MarcadorProcesor.h" +#include "const.h" + +const int ORIENT_DRETA = 0; +const int ORIENT_ESQUERRA = 8; + +class ArounderProcesor +{ +public: + ArounderProcesor(DrawManager *pDrawManager, MarcadorProcesor *pMarcadorProcesor, SDL_Surface *pSprites, SDL_Surface *pMapa, int pxInicial, int pyInicial, int pxFinal, int pyFinal ); + ~ArounderProcesor(void); + ArounderProcesor *Afegir(); + + void Pintar(); + void Procesar(); + ArounderProcesor *Seleccionar(int mouseX, int mouseY); + void AbortarAccio(); + + ArounderProcesor *anterior; + ArounderProcesor *siguiente; + + int prevista; + int accio; + int X; + int Y; + int O; + + Uint32 colorEscalo; + Uint32 colorCorda; + +private: + SDL_Rect clip; + SDL_Surface *sprites; + SDL_Surface *mapa; + SDL_Surface *explosio; + Uint32 *pixels; + + int frame; + int frameX; + int frameY; + int altura; + + int xInicial; + int yInicial; + int xFinal; + int yFinal; + + DrawManager *drawManager; + MarcadorProcesor *marcadorProcesor; + + void initMort(); + void initArrivat(); + void initCaminar(); + void initCaure(); + void initParar(); + void initCavar(); + void initEscalar(); + void initPerforar(); + void initEscalera(); + void initPasarela(); + void initCorda(); + void initPujarCorda(); + void initBaixarCorda(); + void initSuicidi(); + + void Matar(); + + void procesarCaminar(); + void procesarCaure(); + void procesarParar(); + void procesarCavar(); + void procesarEscalar(); + void procesarPerforar(); + void procesarEscalera(); + void procesarPasarela(); + void procesarCorda(); + void procesarPujarCorda(); + void procesarBaixarCorda(); + void procesarSuicidi(); + + bool blockCaure(int desfase = 0); + bool blockCaminar(); + bool blockArounder(); + bool blockParet(int desfase = 0); + bool blockTecho(int desfase = 0); + bool blockPrecipici(); + bool blockPrecipiciPasarela(); + bool blockNovaCorda(); + bool blockCordaBaixar(int desfase = 0); + bool blockCordaPujar(int desfase = 0); + bool pujarEscalo(); + bool baixarEscalo(); + + bool checkArounderAnt(int x, int y, int o); + bool checkArounderSig(int x, int y, int o); + + void doCavar(); + void doPerforar(); + void doEscalera(int desfase = 0); + void doCorda(); + + Uint32 get_pixel( int x, int y ); + void put_pixel( int x, int y, Uint32 pixel ); +}; diff --git a/DrawManager.cpp b/DrawManager.cpp new file mode 100644 index 0000000..1746d21 --- /dev/null +++ b/DrawManager.cpp @@ -0,0 +1,309 @@ +#include "DrawManager.h" +#include "const.h" +#include "fileManager.h" +#include "SDL/SDL_image.h" + + + +DrawManager::DrawManager(int pMode) +{ + mode = pMode; + screen = NULL; + screenBig = NULL; +} + +DrawManager::~DrawManager(void) +{ + SDL_FreeSurface(temp); + SDL_FreeSurface(black); + SDL_FreeSurface(faded); +} + +bool DrawManager::Init(void) +{ + switch (mode) { + case 1: + screenBig = SDL_SetVideoMode( SCREEN_WIDTH<<1, SCREEN_HEIGHT<<1, SCREEN_BPP, SDL_SWSURFACE ); + if( screenBig == NULL ) { return false; } + screen = LoadBitmap("black.gif"); + break; + case 2: + screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_FULLSCREEN ); + if( screen == NULL ) { return false; } + break; + default: + screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); + if( screen == NULL ) { return false; } + break; + } + color_blanco = -1; + color_rojo = SDL_MapRGB( screen->format, 255, 0, 0 ); + color_verde = SDL_MapRGB( screen->format, 0, 255, 0 ); + color_azul = SDL_MapRGB( screen->format, 0, 0, 255 ); + + black = LoadBitmap("black.gif"); + temp = LoadBitmap("black.gif"); + faded = LoadBitmap("black.gif"); + + return true; +} + +bool DrawManager::Flip(void) +{ + if (mode == 1) { + for (int x=0; x<320; x++) { + for (int y=0; y<200; y++) { + put_pixel32(screenBig, x<<1 , y<<1 , get_pixel32(screen, x, y)); + put_pixel32(screenBig, (x<<1)+1, y<<1 , get_pixel32(screen, x, y)); + put_pixel32(screenBig, x<<1 , (y<<1)+1, get_pixel32(screen, x, y)); + put_pixel32(screenBig, (x<<1)+1, (y<<1)+1, get_pixel32(screen, x, y)); + } + } + if (SDL_Flip( screenBig ) == -1 ) { + return true; + } else { + return false; + } + } else { + if (SDL_Flip( screen ) == -1 ) { + return true; + } else { + return false; + } + } +} + +SDL_Surface *DrawManager::LoadBitmap(char *bitmapfilename, bool doColorKey) +{ + //Get the bitmap's buffer and size from the resource file + int filesize = 0; + char *buffer = GetBufferFromResource(bitmapfilename, &filesize); + + //Load the buffer into a surface using RWops + SDL_RWops *rw = SDL_RWFromMem(buffer, filesize); + //SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1); + SDL_Surface *temp = IMG_Load_RW(rw, 1); + + //Release the bitmap buffer memory + free(buffer); + + //Were we able to load the bitmap? + if (temp == NULL) + { + printf("Unable to load bitmap: %s\n", SDL_GetError()); + exit(1); + } + + //Convert the image to optimal display format + SDL_Surface *image; + image = SDL_DisplayFormat(temp); + + if (doColorKey) { + Uint32 colorkey = SDL_MapRGB( image->format, 0, 0, 0 ); + SDL_SetColorKey( image, SDL_SRCCOLORKEY, colorkey ); + } + + //Free the temporary surface + SDL_FreeSurface(temp); + + //Return our loaded image + return image; +} + + +SDL_Surface *DrawManager::LoadMask(char *bitmapfilename) +{ + //Get the bitmap's buffer and size from the resource file + int filesize = 0; + char *buffer = GetBufferFromResource(bitmapfilename, &filesize); + + //Load the buffer into a surface using RWops + SDL_RWops *rw = SDL_RWFromMem(buffer, filesize); + //SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1); + SDL_Surface *temp = IMG_Load_RW(rw, 1); + + //Release the bitmap buffer memory + free(buffer); + + //Were we able to load the bitmap? + if (temp == NULL) + { + printf("Unable to load bitmap: %s\n", SDL_GetError()); + exit(1); + } + + //Convert the image to optimal display format + SDL_Surface *image; + image = SDL_DisplayFormat(temp); + + Uint32 colorkey = SDL_MapRGB( image->format, 255, 255, 255 ); + SDL_SetColorKey( image, SDL_SRCCOLORKEY, colorkey ); + + //Free the temporary surface + SDL_FreeSurface(temp); + + //Return our loaded image + return image; +} + + +void DrawManager::apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip ) +{ + SDL_Rect offset; + + offset.x = x; + offset.y = y; + + SDL_BlitSurface( source, clip, destination, &offset ); +} + +void DrawManager::Blit( int x, int y, SDL_Surface* source, SDL_Rect* clip ) +{ + apply_surface(x, y, source, screen, clip); +} + +void DrawManager::Print( int x, int y, SDL_Surface* source, int w, int h, char *text, SDL_Surface *dest ) { + int index = 0; + SDL_Rect clip; + + clip.y = 0; + clip.w = w; + clip.h = h; + + if (dest == NULL) dest = screen; + + while (text[index] > 0) { + clip.x = (text[index] - 32) * 7; + apply_surface(x+(index*w), y, source, dest, &clip); + index++; + } +} + +void DrawManager::FadeOut() +{ + alpha = 0; + apply_surface(0, 0, screen, temp); + + int currentTicks; + int startTicks = SDL_GetTicks(); + + while (alpha < 255) { + SDL_SetAlpha( black, SDL_SRCALPHA | SDL_RLEACCEL, alpha ); + Blit(0,0, temp); + Blit(0,0, black); + Flip(); + + currentTicks = SDL_GetTicks() - startTicks; + if( currentTicks >= 10 ) { + startTicks = SDL_GetTicks(); + alpha+=8; + } + + } +} + +void DrawManager::FadeIn() +{ + alpha = 255; + apply_surface(0, 0, screen, temp); + + int currentTicks; + int startTicks = SDL_GetTicks(); + + while (alpha > 0) { + SDL_SetAlpha( black, SDL_SRCALPHA | SDL_RLEACCEL, alpha ); + Blit(0,0, temp); + Blit(0,0, black); + Flip(); + + currentTicks = SDL_GetTicks() - startTicks; + if( currentTicks >= 10 ) { + startTicks = SDL_GetTicks(); + alpha-=8; + } + } +} + +void DrawManager::FadeOutGray() +{ + alpha = 0; + apply_surface(0, 0, screen, temp); + + int currentTicks; + int startTicks = SDL_GetTicks(); + + while (alpha < 127) { + SDL_SetAlpha( black, SDL_SRCALPHA | SDL_RLEACCEL, alpha ); + Blit(0,0, temp); + Blit(0,0, black); + Flip(); + + currentTicks = SDL_GetTicks() - startTicks; + if( currentTicks >= 10 ) { + startTicks = SDL_GetTicks(); + alpha+=8; + } + } + apply_surface(0, 0, screen, faded); +} + +void DrawManager::FadeInGray() +{ + alpha = 127; + //apply_surface(0, 0, screen, temp); + + int currentTicks; + int startTicks = SDL_GetTicks(); + + while (alpha > 0) { + SDL_SetAlpha( black, SDL_SRCALPHA | SDL_RLEACCEL, alpha ); + Blit(0,0, temp); + Blit(0,0, black); + Flip(); + + currentTicks = SDL_GetTicks() - startTicks; + if( currentTicks >= 10 ) { + startTicks = SDL_GetTicks(); + alpha-=8; + } + } +} + +void DrawManager::DrawFadedBack() { + Blit(0,0, faded); +} + +SDL_Surface *DrawManager::LoadFont(char *bitmapfilename, Uint32 color) +{ + if (color == 0xFFFFFFFF) { + return LoadBitmap(bitmapfilename, true); + } else { + SDL_Surface *temporal = LoadBitmap(bitmapfilename, true); + if( SDL_MUSTLOCK( temporal ) ) { SDL_LockSurface( temporal ); } + + for (int x=0; xw; x++) { + for (int y=0; yh; y++) { + if (get_pixel32(temporal, x, y) == 0xFFFFFF) { + put_pixel32(temporal, x, y, color); + } + } + } + + if( SDL_MUSTLOCK( temporal ) ) { SDL_UnlockSurface( temporal ); } + + return temporal; + } +} + +Uint32 DrawManager::get_pixel32( SDL_Surface *surface, int x, int y ) +{ + Uint32 *pixels = (Uint32 *)surface->pixels; + return pixels[ ( y * surface->w ) + x ]; +} + +void DrawManager::put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel ) +{ + Uint32 *pixels = (Uint32 *)surface->pixels; + pixels[ ( y * surface->w ) + x ] = pixel; +} + diff --git a/DrawManager.h b/DrawManager.h new file mode 100644 index 0000000..2d1a96c --- /dev/null +++ b/DrawManager.h @@ -0,0 +1,42 @@ +#pragma once +#include "SDL/SDL.h" + +class DrawManager +{ +public: + DrawManager(int pMode); + ~DrawManager(void); + + bool Init(void); + bool Flip(void); + + SDL_Surface *LoadBitmap(char *bitmapfilename, bool doColorKey = false); + SDL_Surface *LoadMask(char *bitmapfilename); + void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ); + void Blit( int x, int y, SDL_Surface* source, SDL_Rect* clip = NULL ); + void Print( int x, int y, SDL_Surface* source, int w, int h, char *text, SDL_Surface* dest = NULL ); + void FadeOut(); + void FadeIn(); + void FadeOutGray(); + void FadeInGray(); + void DrawFadedBack(); + SDL_Surface *LoadFont(char *bitmapfilename, Uint32 color = 0xFFFFFFFF); + + int mode; + + Uint32 color_blanco; + Uint32 color_rojo; + Uint32 color_verde; + Uint32 color_azul; +private: + SDL_Surface *screen; + SDL_Surface *screenBig; + SDL_Surface *black; + SDL_Surface *temp; + SDL_Surface *faded; + int alpha; + + Uint32 get_pixel32( SDL_Surface *surface, int x, int y ); + void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel ); + +}; diff --git a/GameController.cpp b/GameController.cpp new file mode 100644 index 0000000..2a3fed2 --- /dev/null +++ b/GameController.cpp @@ -0,0 +1,422 @@ +#include "GameController.h" +#include "const.h" +#include "fileManager.h" + +GameController::GameController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +GameController::~GameController(void) { +} + +bool GameController::Init() +{ + char arxiuFondo[10] = "BKG00.GIF"; + arxiuFondo[4] = (gameInfo->fase % 10) + 48; + fondo = drawManager->LoadBitmap(arxiuFondo); + sprites = drawManager->LoadBitmap("sprites.gif", true); + font1 = drawManager->LoadFont("fuente1.gif"); + cursor = drawManager->LoadFont("cursor.gif"); + puerta = drawManager->LoadFont("puerta.gif"); + marca = drawManager->LoadFont("marca.gif"); + menu = drawManager->LoadFont("menu.gif"); + + aiguaProcesor = new AiguaProcesor(drawManager, gameInfo->fase); + marcadorProcesor = new MarcadorProcesor(drawManager); + + CarregarMapa(gameInfo->fase); + + primerArounder = new ArounderProcesor(drawManager, marcadorProcesor, sprites, mapa, (xInicial*16)+8, (yInicial*16)+8, (xFinal*16)+8, (yFinal*16)+8); + marcadorProcesor->numAroundersEixits ++; + arounderSeleccionat = primerArounder; + + if ( ((gameInfo->fase+1) % 5) == 0) { + musicManager->Load( "mus6.mp3"); + } else { + musicManager->Load( "mus4.mp3"); + } + + return true; +} + +void GameController::Go(GameInfo *pGameInfo) +{ + gameInfo = pGameInfo; + + bool salir = false; + + int mouseX = 0; + int mouseY = 0; + int nuevaAccion = -1; + + if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; } + + musicManager->Play(-1); + drawManager->Blit(0,0, fondo); + drawManager->Blit(0,0, mapa); + drawManager->FadeIn(); + + int arounderCount = SDL_GetTicks(); + startTicks = SDL_GetTicks(); + + while ( !salir ) { + + PintarEscena(); + PintarCursor(); + drawManager->Flip(); + + inputManager->Update(); + mouseX = inputManager->mouseX; + mouseY = inputManager->mouseY; + + if (inputManager->Pausa() || inputManager->BotoPulsat(SDL_BUTTON_MIDDLE) || !inputManager->finestraActiva) { + arounderCount = SDL_GetTicks() - arounderCount; + salir = Pausa(); + arounderCount = SDL_GetTicks() - arounderCount; + } + + if (inputManager->Menu()) { + arounderCount = SDL_GetTicks() - arounderCount; + salir = Menu(); + arounderCount = SDL_GetTicks() - arounderCount; + } + + if (inputManager->eixir) { + salir = true; + gameInfo->estado = ESTADO_SALIR; + } + + if (inputManager->BotoPulsat(SDL_BUTTON_RIGHT) && arounderSeleccionat != NULL) { + arounderSeleccionat->AbortarAccio(); + } + + if (inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + ArounderProcesor *nouSeleccionat = primerArounder->Seleccionar(mouseX, mouseY); + if (nouSeleccionat != NULL) { + arounderSeleccionat = nouSeleccionat; + } else if (mouseY < 165 && arounderSeleccionat != NULL && arounderSeleccionat->accio == ACCIO_CAMINAR) { + if (mouseX > arounderSeleccionat->X) { + arounderSeleccionat->O = ORIENT_DRETA; + } else { + arounderSeleccionat->O = ORIENT_ESQUERRA; + } + } + nuevaAccion = marcadorProcesor->Procesar(mouseX, mouseY); + } + + if (inputManager->BotoSoltat(SDL_BUTTON_LEFT)) { + if (nuevaAccion != -1 && arounderSeleccionat != NULL) { + if (nuevaAccion == arounderSeleccionat->prevista) { + arounderSeleccionat->prevista = arounderSeleccionat->accio; + } else { + arounderSeleccionat->prevista = nuevaAccion; + } + } + } + + currentTicks = SDL_GetTicks() - startTicks; + if( currentTicks >= marcadorProcesor->velocitat ) { + startTicks = SDL_GetTicks(); + aiguaProcesor->Procesar(); + if (primerArounder != NULL) { + primerArounder->Procesar(); + + ArounderProcesor *actual = primerArounder; + while (actual->siguiente != NULL) { + actual = actual->siguiente; + } + + while (actual != NULL) { + if (actual->accio == ACCIO_MORT) { + ArounderProcesor *borrar = actual; + if (borrar->siguiente != NULL) { + borrar->siguiente->anterior = borrar->anterior; + } + if (borrar->anterior != NULL) { + borrar->anterior->siguiente = borrar->siguiente; + } + if (borrar == primerArounder) primerArounder = borrar->siguiente; + if (borrar == arounderSeleccionat) arounderSeleccionat = NULL; + actual = borrar->anterior; + delete borrar; + } else { + actual = actual->anterior; + } + } + } + } + + if ( (SDL_GetTicks() - arounderCount) >= marcadorProcesor->velocitat*58) { + if (marcadorProcesor->numAroundersEixits < marcadorProcesor->numArounders) { + if (primerArounder != NULL) { + primerArounder->Afegir(); + } else { + primerArounder = new ArounderProcesor(drawManager, marcadorProcesor, sprites, mapa, (xInicial*16)+8, (yInicial*16)+8, (xFinal*16)+8, (yFinal*16)+8); + } + marcadorProcesor->numAroundersEixits ++; + arounderCount = SDL_GetTicks(); + } + } + + if (marcadorProcesor->numAroundersArrivats + marcadorProcesor->numAroundersMorts == marcadorProcesor->numArounders) { + if (marcadorProcesor->numAroundersArrivats >= marcadorProcesor->AroundersNec) { + salir = true; + gameInfo->estado = ESTADO_POSTFASE; + gameInfo->fase++; + } else { + salir = true; + gameInfo->estado = ESTADO_MORT; + } + } + + if (inputManager->BotoPulsat(SDL_BUTTON_MIDDLE)) { + salir = true; + gameInfo->estado = ESTADO_JUEGO; + gameInfo->fase++; + } + /*if (arounderSeleccionat != NULL && arounderSeleccionat->prevista == ACCIO_SUICIDI2) { + gameInfo->estado = ESTADO_MORT; + salir = true; + }*/ + + } + + musicManager->FadeOut(); + drawManager->FadeOut(); + + Finalize(); +} + +void GameController::PintarEscena() { + int accio = -1; + int prevista = -1; + + drawManager->Blit(0,0, fondo); + drawManager->Blit(0,0, mapa); + drawManager->Blit(xInicial*16, yInicial*16, puerta); + drawManager->Blit(xFinal*16, yFinal*16, puerta); + + if (primerArounder != NULL) primerArounder->Pintar(); + + aiguaProcesor->Pintar(); + + if (arounderSeleccionat != NULL) { + accio = arounderSeleccionat->accio; + prevista = arounderSeleccionat->prevista; + } else { + accio = -1; + prevista = -1; + } + marcadorProcesor->Pintar(font1, accio, prevista); + + if (arounderSeleccionat != NULL) { + drawManager->Blit(arounderSeleccionat->X-3, arounderSeleccionat->Y-3, marca); + } +} + +void GameController::PintarCursor() { + drawManager->Blit(inputManager->mouseX, inputManager->mouseY, cursor); +} + +bool GameController::Pausa() { + + PintarEscena(); + drawManager->FadeOutGray(); + + bool salir = false; + bool salirJuego = false; + + while (!salir) { + drawManager->DrawFadedBack(); + drawManager->Print(136,80, font1, 7, 5, "PAUSA"); + drawManager->Blit(inputManager->mouseX, inputManager->mouseY, cursor); + drawManager->Flip(); + + inputManager->Update(); + if (inputManager->eixir) { + salir = true; + gameInfo->estado = ESTADO_SALIR; + } + + if (inputManager->Menu()) { + salirJuego = Menu(true); + salir = salirJuego; + } + + if (inputManager->Pausa() || inputManager->BotoPulsat(SDL_BUTTON_MIDDLE)) salir = true; + } + + drawManager->FadeInGray(); + + return salirJuego; +} + +bool GameController::Menu(bool bypass) { + + if (!bypass) { + PintarEscena(); + drawManager->FadeOutGray(); + } + + bool salir = false; + bool salirJuego = false; + + while (!salir) { + drawManager->DrawFadedBack(); + drawManager->Blit(97, 52, menu); + drawManager->Print(129,60, font1, 7, 5, "CONTINUAR"); + drawManager->Print(129,71, font1, 7, 5, "REINICIAR"); + drawManager->Print(112,82, font1, 7, 5, "MENU PRINCIPAL"); + drawManager->Print(143,93, font1, 7, 5, "EIXIR"); + drawManager->Blit(inputManager->mouseX, inputManager->mouseY, cursor); + drawManager->Flip(); + + inputManager->Update(); + if (inputManager->eixir) { + salir = true; + gameInfo->estado = ESTADO_SALIR; + } + if (inputManager->Menu()) salir = true; + + if (inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + if (inputManager->mouseX >= 97 && inputManager->mouseX <= 223) { + if (inputManager->mouseY >= 60 && inputManager->mouseY <= 65) { + salir = true; + //salirJuego = true; + //gameInfo->fase++; + } + if (inputManager->mouseY >= 71 && inputManager->mouseY <= 76) { + salirJuego = true; + salir = true; + } + if (inputManager->mouseY >= 82 && inputManager->mouseY <= 87) { + salirJuego = true; + salir = true; + gameInfo->estado = ESTADO_MENU; + } + if (inputManager->mouseY >= 93 && inputManager->mouseY <= 98) { + salirJuego = true; + salir = true; + gameInfo->estado = ESTADO_SALIR; + } + } + } + } + + if (!bypass) { + drawManager->FadeInGray(); + } + + return salirJuego; +} + +void GameController::CarregarMapa(int numMapa) +{ + int filesize = 0; + char *buffer = GetBufferFromResource("MAPES.BAL", &filesize); + + int punter = numMapa * 212; + + int tileSet = buffer[punter++]; + punter++; + marcadorProcesor->orientacioInicial = buffer[punter++]; + marcadorProcesor->numArounders = buffer[punter++]; + marcadorProcesor->AroundersNec = buffer[punter++]; + + marcadorProcesor->numParar = buffer[punter++]; + marcadorProcesor->numCavar = buffer[punter++]; + marcadorProcesor->numEscalar = buffer[punter++]; + marcadorProcesor->numPerforar = buffer[punter++]; + marcadorProcesor->numEscalera = buffer[punter++]; + marcadorProcesor->numPasarela = buffer[punter++]; + marcadorProcesor->numCorda = buffer[punter++]; + + SDL_Surface *tiles = drawManager->LoadBitmap("tiles.gif", true); + mapa = drawManager->LoadBitmap("black.gif", true); + + unsigned char tileActual; + SDL_Rect clip; + clip.w = 16; + clip.h = 16; + + for (int x=0; x<20; x++) { + for (int y=0; y<10; y++) { + tileActual = buffer[punter++]; + switch (tileActual) { + case 255: + break; + case 254: + xFinal = x; + yFinal = y; + break; + case 253: + xInicial = x; + yInicial = y; + break; + default: + clip.x = tileActual*16; + clip.y = tileSet*16; + drawManager->apply_surface(x*16, y*16, tiles, mapa, &clip); + break; + } + } + } + + SDL_FreeSurface(tiles); + SDL_Surface *marcador = drawManager->LoadBitmap("marcador.gif", false); + drawManager->apply_surface(0, 165, marcador, mapa); + SDL_FreeSurface(marcador); + + drawManager->Print(188,188, font1, 7, 5, formatejar(gameInfo->fase+1), mapa); + + drawManager->Print(7,188, font1, 7, 5, "XX", mapa); + drawManager->Print(135,188, font1, 7, 5, "XX", mapa); + drawManager->Print(151,188, font1, 7, 5, "XX", mapa); + + drawManager->Print(224,171, font1, 7, 5, "ACTIUS", mapa); + drawManager->Print(224,177, font1, 7, 5, "TOTAL", mapa); + drawManager->Print(224,183, font1, 7, 5, "NECESSARIS", mapa); + drawManager->Print(224,189, font1, 7, 5, "ARRIVATS", mapa); + +} + + +void GameController::Finalize(void) +{ + SDL_FreeSurface(font1); + SDL_FreeSurface(mapa); + SDL_FreeSurface(fondo); + SDL_FreeSurface(marca); + SDL_FreeSurface(sprites); + SDL_FreeSurface(cursor); + SDL_FreeSurface(puerta); + SDL_FreeSurface(menu); + delete aiguaProcesor; + delete marcadorProcesor; + + if (primerArounder != NULL) { + while (primerArounder->siguiente != NULL) { + delete primerArounder->siguiente; + } + delete primerArounder; + } +} + +char *GameController::formatejar(int numero) { + char *resultat; + resultat = (char *) malloc(3); + + if (numero > 9) { + resultat[0] = (numero / 10) + 48; + resultat[1] = (numero % 10) + 48; + } else { + resultat[0] = 48; + resultat[1] = (numero % 10) + 48; + } + + resultat[2] = '\0'; + + return resultat; +} diff --git a/GameController.h b/GameController.h new file mode 100644 index 0000000..a63f125 --- /dev/null +++ b/GameController.h @@ -0,0 +1,58 @@ +#pragma once +#include +#include "SDL/SDL.h" +#include "GameInfo.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "AiguaProcesor.h" +#include "MarcadorProcesor.h" +#include "ArounderProcesor.h" + +class GameController +{ +public: + GameController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~GameController(void); + + bool Init(); + void Go(GameInfo *pGameInfo); + void Finalize(void); + +private: + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + AiguaProcesor *aiguaProcesor; + MarcadorProcesor *marcadorProcesor; + + ArounderProcesor *primerArounder; + ArounderProcesor *arounderSeleccionat; + + SDL_Surface *mapa; + SDL_Surface *fondo; + SDL_Surface *sprites; + SDL_Surface *puerta; + SDL_Surface *font1; + SDL_Surface *cursor; + SDL_Surface *marca; + SDL_Surface *menu; + + GameInfo *gameInfo; + + int startTicks; + int currentTicks; + + int xInicial; + int yInicial; + int xFinal; + int yFinal; + + void PintarEscena(); + void PintarCursor(); + bool Pausa(); + bool Menu(bool bypass = false); + void CarregarMapa(int numMapa); + char *formatejar(int numero); + +}; diff --git a/GameInfo.cpp b/GameInfo.cpp new file mode 100644 index 0000000..7706688 --- /dev/null +++ b/GameInfo.cpp @@ -0,0 +1,11 @@ +#include "GameInfo.h" +#include "const.h" + +GameInfo::GameInfo(int pModeGrafic) { + fase = -1; + estado = ESTADO_SEQUENCIA; + modeGrafic = pModeGrafic; +} + +GameInfo::~GameInfo(void) { +} diff --git a/GameInfo.h b/GameInfo.h new file mode 100644 index 0000000..6f1782c --- /dev/null +++ b/GameInfo.h @@ -0,0 +1,14 @@ +#pragma once + +class GameInfo +{ +public: + GameInfo(int pModeGrafic); + ~GameInfo(void); + + int fase; + int puntuacion; + int vidas; + int estado; + int modeGrafic; +}; diff --git a/InputManager.cpp b/InputManager.cpp new file mode 100644 index 0000000..473a27d --- /dev/null +++ b/InputManager.cpp @@ -0,0 +1,192 @@ +/* + * InputManager.cpp + * Arounders + * + * Created by Raimon Zamora on 21/02/09. + * Copyright 2009 __MyCompanyName__. All rights reserved. + * + */ + +#include "InputManager.h" +#include "const.h" + +InputManager::InputManager(GameInfo *pGameInfo) { + gameInfo = pGameInfo; + + eixir = false; + + mouseX = 0; + mouseY = 0; + + mouseButtonLeft = false; + mouseButtonRight = false; + mouseButtonMiddle = false; + + oldMouseButtonLeft = false; + oldMouseButtonRight = false; + oldMouseButtonMiddle = false; + + pausaPulsada = false; + menuPulsat = false; + +} + +InputManager::~InputManager(void) { + +} + +void InputManager::Update() { + keystates = SDL_GetKeyState( NULL ); + + teclaSoltada = false; + pausaPulsada = false; + menuPulsat = false; + + while ( SDL_PollEvent( &event ) ) { + if ( event.type == SDL_QUIT ) eixir = true; + if( event.type == SDL_MOUSEMOTION ) { + mouseX = event.motion.x; + mouseY = event.motion.y; + if (gameInfo->modeGrafic == MODE_ZOOMX2) { + mouseX = mouseX>>1; + mouseY = mouseY>>1; + } + } + if( event.type == SDL_MOUSEBUTTONDOWN ) { + mouseX = event.button.x; + mouseY = event.button.y; + if (gameInfo->modeGrafic == MODE_ZOOMX2) { + mouseX = mouseX>>1; + mouseY = mouseY>>1; + } + if (event.button.button == SDL_BUTTON_LEFT) { + oldMouseButtonLeft = mouseButtonLeft; + mouseButtonLeft = true; + } + if (event.button.button == SDL_BUTTON_MIDDLE) { + oldMouseButtonMiddle = mouseButtonMiddle; + mouseButtonMiddle = true; + } + if (event.button.button == SDL_BUTTON_RIGHT) { + oldMouseButtonRight = mouseButtonRight; + mouseButtonRight = true; + } + } + if( event.type == SDL_MOUSEBUTTONUP ) { + if (event.button.button == SDL_BUTTON_LEFT) { + oldMouseButtonLeft = mouseButtonLeft; + mouseButtonLeft = false; + } + if (event.button.button == SDL_BUTTON_MIDDLE) { + oldMouseButtonMiddle = mouseButtonMiddle; + mouseButtonMiddle = false; + } + if (event.button.button == SDL_BUTTON_RIGHT) { + oldMouseButtonRight = mouseButtonRight; + mouseButtonRight = false; + } + } + if( event.type == SDL_KEYDOWN ) { + cualquierTecla = true; + } else { + cualquierTecla = false; + } + + if( event.type == SDL_KEYUP ) { + teclaSoltada = true; + pausaPulsada = (event.key.keysym.sym == SDLK_p); + menuPulsat = (event.key.keysym.sym == SDLK_ESCAPE); + } + + if ( event.type == SDL_ACTIVEEVENT ) { + if (event.active.state & SDL_APPINPUTFOCUS) { + if (event.active.gain) { + finestraActiva = true; + } else { + finestraActiva = false; + } + } + } + } +} + +bool InputManager::BotoPulsat(int boto) { + switch (boto) { + case SDL_BUTTON_LEFT: + if (mouseButtonLeft && !oldMouseButtonLeft) { + oldMouseButtonLeft = true; + return true; + } else { + return false; + } + break; + case SDL_BUTTON_MIDDLE: + if (mouseButtonMiddle && !oldMouseButtonMiddle) { + oldMouseButtonMiddle = true; + return true; + } else { + return false; + } + break; + case SDL_BUTTON_RIGHT: + if (mouseButtonRight && !oldMouseButtonRight) { + oldMouseButtonRight = true; + return true; + } else { + return false; + } + break; + default: + return false; + break; + } +} + +bool InputManager::BotoSoltat(int boto) { + switch (boto) { + case SDL_BUTTON_LEFT: + if (!mouseButtonLeft && oldMouseButtonLeft) { + oldMouseButtonLeft = false; + return true; + } else { + return false; + } + break; + case SDL_BUTTON_MIDDLE: + if (!mouseButtonMiddle && oldMouseButtonMiddle) { + oldMouseButtonMiddle = false; + return true; + } else { + return false; + } + break; + case SDL_BUTTON_RIGHT: + if (!mouseButtonRight && oldMouseButtonRight) { + oldMouseButtonRight = false; + return true; + } else { + return false; + } + break; + default: + return false; + break; + } +} + +bool InputManager::TeclaPulsada(int tecla) { + if (keystates[tecla] != 0) { + return true; + } else { + return false; + } +} + +bool InputManager::Pausa() { + return pausaPulsada; +} + +bool InputManager::Menu() { + return menuPulsat; +} + diff --git a/InputManager.h b/InputManager.h new file mode 100644 index 0000000..f1a6226 --- /dev/null +++ b/InputManager.h @@ -0,0 +1,41 @@ +#pragma once +#include "SDL/SDL.h" +#include "GameInfo.h" + +class InputManager +{ +public: + InputManager(GameInfo *pGameInfo); + ~InputManager(void); + + void Update(); + bool Pausa(); + bool EixirPausa(); + bool Menu(); + bool BotoPulsat(int boto); + bool BotoSoltat(int boto); + + bool TeclaPulsada(int tecla); + + bool cualquierTecla; + bool teclaSoltada; + bool eixir; + int mouseX; + int mouseY; + bool mouseButtonLeft; + bool mouseButtonRight; + bool mouseButtonMiddle; + bool pausaPulsada; + bool menuPulsat; + bool finestraActiva; + +private: + Uint8 *keystates; + GameInfo *gameInfo; + + SDL_Event event; + bool oldMouseButtonLeft; + bool oldMouseButtonRight; + bool oldMouseButtonMiddle; + +}; \ No newline at end of file diff --git a/MarcadorProcesor.cpp b/MarcadorProcesor.cpp new file mode 100644 index 0000000..4e4500d --- /dev/null +++ b/MarcadorProcesor.cpp @@ -0,0 +1,110 @@ +#include "MarcadorProcesor.h" +#include "const.h" + +MarcadorProcesor::MarcadorProcesor(DrawManager *pDrawManager) +{ + drawManager = pDrawManager; + + numAroundersArrivats = 0; + numAroundersEixits = 0; + numAroundersMorts = 0; + + boto = drawManager->LoadBitmap("boto.gif", true); + + velocitat = 70; + contador = SDL_GetTicks(); +} + +MarcadorProcesor::~MarcadorProcesor(void) +{ + SDL_FreeSurface(boto); +} + +void MarcadorProcesor::Pintar(SDL_Surface *font, int accio, int prevista) { + drawManager->Print(23,188, font, 7, 5, formatejar(numParar)); + drawManager->Print(39,188, font, 7, 5, formatejar(numCavar)); + drawManager->Print(55,188, font, 7, 5, formatejar(numEscalar)); + drawManager->Print(71,188, font, 7, 5, formatejar(numPerforar)); + drawManager->Print(87,188, font, 7, 5, formatejar(numEscalera)); + drawManager->Print(103,188, font, 7, 5, formatejar(numPasarela)); + drawManager->Print(119,188, font, 7, 5, formatejar(numCorda)); + + drawManager->Print(301,171, font, 7, 5, formatejar(numAroundersEixits-numAroundersArrivats-numAroundersMorts)); + drawManager->Print(301,177, font, 7, 5, formatejar(numArounders)); + drawManager->Print(301,183, font, 7, 5, formatejar(AroundersNec)); + drawManager->Print(301,189, font, 7, 5, formatejar(numAroundersArrivats)); + + if (accio >= 10) accio = 0; + if (prevista >= 10) prevista = 0; + drawManager->Blit((accio*16)+5, 171, boto); + + if (prevista != accio && prevista != 0) { + if ((SDL_GetTicks()-contador) <= 200) { + drawManager->Blit((prevista*16)+5, 171, boto); + } else { + if ((SDL_GetTicks()-contador) >= 400) contador = SDL_GetTicks(); + } + } + + if (velocitat < 70) { + drawManager->Blit((ACCIO_SUICIDI2*16)+5, 171, boto); + } +} + +int MarcadorProcesor::Procesar(int mouseX, int mouseY) { + int accio = -1; + + if (mouseY >= 171 && mouseY <= 187 && mouseX >= 5 && mouseX <= 165) { + accio = (mouseX-5) / 16; + + switch(accio) { + case ACCIO_PARAR: + if (numParar == 0) accio = -1; + break; + case ACCIO_CAVAR: + if (numCavar == 0) accio = -1; + break; + case ACCIO_ESCALAR: + if (numEscalar == 0) accio = -1; + break; + case ACCIO_PERFORAR: + if (numPerforar == 0) accio = -1; + break; + case ACCIO_ESCALERA: + if (numEscalera == 0) accio = -1; + break; + case ACCIO_PASARELA: + if (numPasarela == 0) accio = -1; + break; + case ACCIO_CORDA: + if (numCorda == 0) accio = -1; + break; + case ACCIO_SUICIDI2: + if (velocitat == 70) { + velocitat = 10; + } else { + velocitat = 70; + } + accio = -1; + break; + } + } + return accio; +} + +char *MarcadorProcesor::formatejar(int numero) { + char *resultat; + resultat = (char *) malloc(3); + + if (numero > 9) { + resultat[0] = (numero / 10) + 48; + resultat[1] = (numero % 10) + 48; + } else { + resultat[0] = 48; + resultat[1] = (numero % 10) + 48; + } + + resultat[2] = '\0'; + + return resultat; +} diff --git a/MarcadorProcesor.h b/MarcadorProcesor.h new file mode 100644 index 0000000..3b6f360 --- /dev/null +++ b/MarcadorProcesor.h @@ -0,0 +1,38 @@ +#pragma once +#include "DrawManager.h" + +class MarcadorProcesor +{ +public: + MarcadorProcesor(DrawManager *pDrawManager); + ~MarcadorProcesor(void); + + void Pintar(SDL_Surface *font, int accio, int prevista); + int Procesar(int mouseX, int mouseY); + + int numArounders; + int AroundersNec; + int numAroundersArrivats; + int numAroundersEixits; + int numAroundersMorts; + int orientacioInicial; + + int numParar; + int numCavar; + int numEscalar; + int numPerforar; + int numEscalera; + int numPasarela; + int numCorda; + + int velocitat; + +private: + char *formatejar(int numero); + + DrawManager *drawManager; + SDL_Surface *boto; + + int contador; + +}; diff --git a/MenuController.cpp b/MenuController.cpp new file mode 100644 index 0000000..c6a5de9 --- /dev/null +++ b/MenuController.cpp @@ -0,0 +1,76 @@ +#include "MenuController.h" +#include "const.h" + +MenuController::MenuController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +MenuController::~MenuController(void) { +} + +bool MenuController::Init() { + fondo = drawManager->LoadBitmap("menuprin.gif"); + cursor = drawManager->LoadFont("cursor.gif"); + if (!musicManager->Sonant()) { + musicManager->Load( "mus3.mp3"); + musicManager->Play(-1); + } + return true; +} + +void MenuController::Go(GameInfo *gameInfo) { + bool salir = false; + + if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; } + + drawManager->Blit(0,0, fondo); + drawManager->FadeIn(); + + while ( !salir ) { + inputManager->Update(); + + drawManager->Blit(0,0, fondo); + drawManager->Blit(inputManager->mouseX, inputManager->mouseY, cursor); + drawManager->Flip(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + + if (inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + if (inputManager->mouseX >= 200 && + inputManager->mouseY >= 100 && + inputManager->mouseX <= 270 && + inputManager->mouseY <= 120 ) { + gameInfo->estado = ESTADO_SEQUENCIA; + gameInfo->fase = 0; + salir = true; + } + if (inputManager->mouseX >= 175 && + inputManager->mouseY >= 125 && + inputManager->mouseX <= 290 && + inputManager->mouseY <= 145 ) { + gameInfo->estado = ESTADO_PASSWORD; + gameInfo->fase = 0; + salir = true; + } + if (inputManager->mouseX >= 200 && + inputManager->mouseY >= 150 && + inputManager->mouseX <= 265 && + inputManager->mouseY <= 170 ) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + } + } + if (gameInfo->estado == ESTADO_SALIR) musicManager->FadeOut(); + drawManager->FadeOut(); +} + +void MenuController::Finalize(void) { + SDL_FreeSurface(fondo); + SDL_FreeSurface(cursor); +} diff --git a/MenuController.h b/MenuController.h new file mode 100644 index 0000000..159a473 --- /dev/null +++ b/MenuController.h @@ -0,0 +1,25 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class MenuController +{ +public: + MenuController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~MenuController(void); + + bool Init(); + void Go(GameInfo *gameInfo); + void Finalize(void); + +private: + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + + SDL_Surface *fondo; + SDL_Surface *cursor; +}; diff --git a/MortController.cpp b/MortController.cpp new file mode 100644 index 0000000..a828b2f --- /dev/null +++ b/MortController.cpp @@ -0,0 +1,72 @@ +#include "MortController.h" +#include "const.h" + +MortController::MortController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +MortController::~MortController(void) { +} + +bool MortController::Init() { + fondo = drawManager->LoadBitmap("mort.gif"); + cursor = drawManager->LoadFont("cursor.gif"); + musicManager->Load( "mus5.mp3"); + + return true; +} + +void MortController::Go(GameInfo *gameInfo) { + bool salir = false; + + if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; } + + musicManager->Play(-1); + drawManager->Blit(0,0, fondo); + drawManager->FadeIn(); + + while ( !salir ) { + inputManager->Update(); + + drawManager->Blit(0,0, fondo); + drawManager->Blit(inputManager->mouseX, inputManager->mouseY, cursor); + drawManager->Flip(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + + if (inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + if (inputManager->mouseX >= 100 && + inputManager->mouseY >= 50 && + inputManager->mouseX <= 210 && + inputManager->mouseY <= 70 ) { + gameInfo->estado = ESTADO_PREFASE; + salir = true; + } + if (inputManager->mouseX >= 120 && + inputManager->mouseY >= 72 && + inputManager->mouseX <= 190 && + inputManager->mouseY <= 95 ) { + gameInfo->estado = ESTADO_MENU; + salir = true; + } + if (inputManager->mouseX >= 120 && + inputManager->mouseY >= 95 && + inputManager->mouseX <= 190 && + inputManager->mouseY <= 115 ) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + } + } + drawManager->FadeOut(); +} + +void MortController::Finalize(void) { + SDL_FreeSurface(fondo); + SDL_FreeSurface(cursor); +} diff --git a/MortController.h b/MortController.h new file mode 100644 index 0000000..2038f17 --- /dev/null +++ b/MortController.h @@ -0,0 +1,25 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class MortController +{ +public: + MortController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~MortController(void); + + bool Init(); + void Go(GameInfo *gameInfo); + void Finalize(void); + +private: + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + + SDL_Surface *fondo; + SDL_Surface *cursor; +}; diff --git a/MusicManager.cpp b/MusicManager.cpp new file mode 100644 index 0000000..fab1b85 --- /dev/null +++ b/MusicManager.cpp @@ -0,0 +1,52 @@ +#include "MusicManager.h" +#include "const.h" +#include "fileManager.h" + +MusicManager::MusicManager(void) { + music = NULL; +} + +MusicManager::~MusicManager(void) { + Mix_FreeMusic(music); + Mix_CloseAudio(); +} + +bool MusicManager::Init() { + return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024); +} + +void MusicManager::Load(char *musicfilename) +{ + if (music != NULL) { + Mix_HaltMusic(); + Mix_FreeMusic(music); + } + Mix_VolumeMusic(MIX_MAX_VOLUME); + //Get the bitmap's buffer and size from the resource file + int filesize = 0; + char *buffer = GetBufferFromResource(musicfilename, &filesize); + + //Load the buffer into a surface using RWops + SDL_RWops *rw = SDL_RWFromMem(buffer, filesize); + //SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1); + music = Mix_LoadMUS_RW(rw); + + //Release the bitmap buffer memory + //free(buffer); +} + +void MusicManager::Play(int loops) { + Mix_PlayMusic(music, loops); +} + +void MusicManager::Pause() { + Mix_PauseMusic(); +} + +void MusicManager::FadeOut() { + Mix_FadeOutMusic(500); +} + +bool MusicManager::Sonant() { + return (Mix_PlayingMusic() == 1) && (Mix_FadingMusic() != MIX_FADING_OUT); +} \ No newline at end of file diff --git a/MusicManager.h b/MusicManager.h new file mode 100644 index 0000000..3551c51 --- /dev/null +++ b/MusicManager.h @@ -0,0 +1,18 @@ +#pragma once +#include "SDL/SDL_mixer.h" + +class MusicManager +{ +public: + MusicManager(void); + ~MusicManager(void); + + bool Init(void); + void Load(char *musicfilename); + void Play(int loops); + void Pause(); + void FadeOut(); + bool Sonant(); +private: + Mix_Music *music; +}; diff --git a/PasswordController.cpp b/PasswordController.cpp new file mode 100644 index 0000000..c818713 --- /dev/null +++ b/PasswordController.cpp @@ -0,0 +1,116 @@ +#include "PasswordController.h" +#include "const.h" +#include "fileManager.h" + +PasswordController::PasswordController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +PasswordController::~PasswordController(void) { +} + +bool PasswordController::Init() { + fondo = drawManager->LoadBitmap("prefase.gif"); + cursor = drawManager->LoadFont("cursor.gif"); + font = drawManager->LoadFont("fuente1.gif"); + + return true; +} + +void PasswordController::Go(GameInfo *gameInfo) { + bool salir = false; + char tecla = -1; + char password[11] = " "; + char indice = 0; + + if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; } + + drawManager->Blit(0,0, fondo); + drawManager->Print(95, 80, font, 7, 5, "ESCRIU EL PASSWORD"); + drawManager->FadeIn(); + + while ( !salir ) { + inputManager->Update(); + + drawManager->Blit(0,0, fondo); + drawManager->Print(95, 80, font, 7, 5, "ESCRIU EL PASSWORD"); + drawManager->Print(123, 140, font, 7, 5, password); + drawManager->Flip(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + + if (inputManager->cualquierTecla && tecla == -1) { + if (inputManager->TeclaPulsada(SDLK_BACKSPACE) && indice > 0) { + indice--; + password[indice] = 32; + tecla = SDLK_BACKSPACE; + } else { + tecla = ObtenerTecla(); + if (tecla != -1) { + password[indice] = tecla; + indice++; + if (indice == 10) { + gameInfo->fase = ObtenerFaseDePassword(password); + gameInfo->estado = ESTADO_SEQUENCIA; + salir = true; + } + } + } + } + if (inputManager->teclaSoltada) { + tecla = -1; + } + } + drawManager->FadeOut(); +} + +char PasswordController::ObtenerTecla() { + char tecla = -1; + for (int i=48; i<=57; i++) { + if (inputManager->TeclaPulsada(i)) tecla = i; + } + for (int i=97; i<=122; i++) { + if (inputManager->TeclaPulsada(i)) tecla = i-32; + } + return tecla; +} + +int PasswordController::ObtenerFaseDePassword(char *password) { + int filesize = 0; + char *buffer = GetBufferFromResource("offsets.bal", &filesize); + + int punter = 0; + + bool salir = false; + char passFile[11] = " "; + int numPassword = 0; + + while ( numPassword < 30 && !salir ) { + for (int i=0;i<10;i++) { + punter++; + passFile[i] = buffer[punter] - (101+i); + } + punter++; + + salir = true; + for (int i=0;i<10;i++) { + if (passFile[i] != password[i]) salir = false; + } + numPassword++; + } + + if (!salir) numPassword = 0; + + return numPassword; +} + +void PasswordController::Finalize(void) { + SDL_FreeSurface(fondo); + SDL_FreeSurface(cursor); + SDL_FreeSurface(font); +} diff --git a/PasswordController.h b/PasswordController.h new file mode 100644 index 0000000..76f85e9 --- /dev/null +++ b/PasswordController.h @@ -0,0 +1,30 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class PasswordController +{ +public: + PasswordController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~PasswordController(void); + + bool Init(); + void Go(GameInfo *gameInfo); + void Finalize(void); + +private: + char ObtenerTecla(); + int ObtenerFaseDePassword(char *password); + + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + + SDL_Surface *fondo; + SDL_Surface *cursor; + SDL_Surface *font; + +}; diff --git a/PostfaseController.cpp b/PostfaseController.cpp new file mode 100644 index 0000000..c56fa93 --- /dev/null +++ b/PostfaseController.cpp @@ -0,0 +1,137 @@ +#include "PostfaseController.h" +#include "const.h" +#include "fileManager.h" + +PostfaseController::PostfaseController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +PostfaseController::~PostfaseController(void) { +} + +bool PostfaseController::Init() { + fondo = drawManager->LoadBitmap("postfase.gif"); + font = drawManager->LoadFont("fuente2.gif", drawManager->color_rojo); + + return true; +} + +void PostfaseController::Go(GameInfo *gameInfo) { + bool salir = false; + + if (gameInfo->fase == 30) { + gameInfo->estado = ESTADO_SEQUENCIA; + return; + } else { + musicManager->Load( "mus3.mp3"); + musicManager->Play(-1); + } + + if (gameInfo->fase % 5 == 0 && gameInfo->fase != 30) { + salir = MostrarVictoria(gameInfo); + } + + if (salir) { + gameInfo->estado = ESTADO_SALIR; + return; + } + + char *password = ObtenerPasswordDeFase(gameInfo->fase); + if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; } + + drawManager->Blit(0,0, fondo); + drawManager->Print(175, 166, font, 7, 6, password); + drawManager->FadeIn(); + + while ( !salir ) { + inputManager->Update(); + + drawManager->Blit(0,0, fondo); + drawManager->Print(175, 166, font, 7, 6, password); + drawManager->Flip(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + + if (inputManager->cualquierTecla || inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + gameInfo->estado = ESTADO_SEQUENCIA; + salir = true; + } + } + drawManager->FadeOut(); +} + +char *PostfaseController::ObtenerPasswordDeFase(int fase) { + int filesize = 0; + char *buffer = GetBufferFromResource("offsets.bal", &filesize); + + int punter = (fase-1)*11; + + char *passFile = (char *) malloc(11); + + for (int i=0;i<10;i++) { + punter++; + passFile[i] = ((Uint8)buffer[punter]) - (101+i); + } + + return passFile; +} + +bool PostfaseController::MostrarVictoria(GameInfo *gameInfo) { + bool salir = false; + + switch (gameInfo->fase) { + case 5: + fondo = drawManager->LoadBitmap("final01.GIF"); + break; + case 10: + fondo = drawManager->LoadBitmap("final02.GIF"); + break; + case 15: + fondo = drawManager->LoadBitmap("final03.GIF"); + break; + case 20: + fondo = drawManager->LoadBitmap("final04.GIF"); + break; + case 25: + fondo = drawManager->LoadBitmap("final05.GIF"); + break; + } + + drawManager->Blit(0,0, fondo); + drawManager->FadeIn(); + + while ( !salir ) { + inputManager->Update(); + + drawManager->Blit(0,0, fondo); + drawManager->Flip(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + + if (inputManager->cualquierTecla || inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + gameInfo->estado = ESTADO_SEQUENCIA; + salir = true; + } + } + drawManager->FadeOut(); + + if (gameInfo->estado == ESTADO_SALIR) { + return true; + } else { + return false; + } +} + +void PostfaseController::Finalize(void) { + SDL_FreeSurface(fondo); + SDL_FreeSurface(font); +} + diff --git a/PostfaseController.h b/PostfaseController.h new file mode 100644 index 0000000..886bc86 --- /dev/null +++ b/PostfaseController.h @@ -0,0 +1,28 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class PostfaseController +{ +public: + PostfaseController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~PostfaseController(void); + + bool Init(); + void Go(GameInfo *gameInfo); + void Finalize(void); + +private: + char *ObtenerPasswordDeFase(int fase); + bool MostrarVictoria(GameInfo *gameInfo); + + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + + SDL_Surface *fondo; + SDL_Surface *font; +}; diff --git a/PrefaseController.cpp b/PrefaseController.cpp new file mode 100644 index 0000000..1a41324 --- /dev/null +++ b/PrefaseController.cpp @@ -0,0 +1,105 @@ +#include "PrefaseController.h" +#include "const.h" +#include "fileManager.h" + +PrefaseController::PrefaseController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +PrefaseController::~PrefaseController(void) { +} + +bool PrefaseController::Init() { + fondo = drawManager->LoadBitmap("prefase.gif"); + cursor = drawManager->LoadFont("cursor.gif"); + font = drawManager->LoadFont("fuente1.gif"); + + return true; +} + +void PrefaseController::Go(GameInfo *gameInfo) { + bool salir = false; + + if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; } + + CarregarMapa(gameInfo->fase); + + drawManager->Blit(0,0, fondo); + drawManager->Print(130, 60, font, 7, 5, "NIVELL"); + drawManager->Print(179, 60, font, 7, 5, formatejar(gameInfo->fase+1)); + + drawManager->Print(80, 100, font, 7, 5, formatejar(numArounders)); + drawManager->Print(101, 100, font, 7, 5, "AROUNDERS DISPONIBLES"); + + drawManager->Print(80, 110, font, 7, 5, formatejar(aroundersNec)); + drawManager->Print(101, 110, font, 7, 5, "AROUNDERS NECESSARIS"); + drawManager->FadeIn(); + + while ( !salir ) { + inputManager->Update(); + + drawManager->Blit(0,0, fondo); + + drawManager->Print(130, 60, font, 7, 5, "NIVELL"); + drawManager->Print(179, 60, font, 7, 5, formatejar(gameInfo->fase+1)); + + drawManager->Print(80, 100, font, 7, 5, formatejar(numArounders)); + drawManager->Print(101, 100, font, 7, 5, "AROUNDERS DISPONIBLES"); + + drawManager->Print(80, 110, font, 7, 5, formatejar(aroundersNec)); + drawManager->Print(101, 110, font, 7, 5, "AROUNDERS NECESSARIS"); + + drawManager->Blit(inputManager->mouseX, inputManager->mouseY, cursor); + drawManager->Flip(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + } + + if (inputManager->cualquierTecla || inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + gameInfo->estado = ESTADO_JUEGO; + salir = true; + } + } + musicManager->FadeOut(); + drawManager->FadeOut(); +} + +void PrefaseController::Finalize(void) { + SDL_FreeSurface(fondo); + SDL_FreeSurface(cursor); + SDL_FreeSurface(font); +} + +void PrefaseController::CarregarMapa(int numMapa) +{ + int filesize = 0; + char *buffer = GetBufferFromResource("MAPES.BAL", &filesize); + + int punter = numMapa * 212; + + int tileSet = buffer[punter++]; + punter += 2; + numArounders = buffer[punter++]; + aroundersNec = buffer[punter++]; +} + +char *PrefaseController::formatejar(int numero) { + char *resultat; + resultat = (char *) malloc(3); + + if (numero > 9) { + resultat[0] = (numero / 10) + 48; + resultat[1] = (numero % 10) + 48; + } else { + resultat[0] = 48; + resultat[1] = (numero % 10) + 48; + } + + resultat[2] = '\0'; + + return resultat; +} diff --git a/PrefaseController.h b/PrefaseController.h new file mode 100644 index 0000000..fa64a03 --- /dev/null +++ b/PrefaseController.h @@ -0,0 +1,32 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class PrefaseController +{ +public: + PrefaseController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~PrefaseController(void); + + bool Init(); + void Go(GameInfo *gameInfo); + void Finalize(void); + +private: + char *formatejar(int numero); + void CarregarMapa(int numMapa); + + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + + SDL_Surface *fondo; + SDL_Surface *cursor; + SDL_Surface *font; + + int numArounders; + int aroundersNec; +}; diff --git a/SequenceController.cpp b/SequenceController.cpp new file mode 100644 index 0000000..5a12c5e --- /dev/null +++ b/SequenceController.cpp @@ -0,0 +1,214 @@ +#include "SequenceController.h" +#include "const.h" +#include "fileManager.h" + +SequenceController::SequenceController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager) { + drawManager = p_drawManager; + inputManager = p_inputManager; + musicManager = p_musicManager; +} + +SequenceController::~SequenceController(void) { +} + +bool SequenceController::Init() { + return true; +} + +void SequenceController::Go(GameInfo *pGameInfo) { + bool salir = false; + int pantalla = 0; + char *file; + int filesize; + + gameInfo = pGameInfo; + + if (gameInfo->fase % 5 == 0 || gameInfo->fase < 0) { + switch (gameInfo->fase) { + case -1: + file = GetBufferFromResource("seqIN.seq", &filesize); + break; + case 0: + file = GetBufferFromResource("seq00.seq", &filesize); + break; + case 5: + file = GetBufferFromResource("seq05.seq", &filesize); + break; + case 10: + file = GetBufferFromResource("seq10.seq", &filesize); + break; + case 15: + file = GetBufferFromResource("seq15.seq", &filesize); + break; + case 20: + file = GetBufferFromResource("seq20.seq", &filesize); + break; + case 25: + file = GetBufferFromResource("seq25.seq", &filesize); + break; + case 30: + file = GetBufferFromResource("seq30.seq", &filesize); + break; + } + ProcesarSecuencia(file); + } + //drawManager->FadeOut(); + + if (gameInfo->estado != ESTADO_SALIR) { + gameInfo->estado = ESTADO_PREFASE; + if (gameInfo->fase == -1) gameInfo->estado = ESTADO_MENU; + if (gameInfo->fase == 30) gameInfo->estado = ESTADO_MENU; + } +} + +void SequenceController::ProcesarSecuencia(char *file) { + char numDiapositives = (char)file[0]; + int punter = 1; + char *filename; + char *texto; + char tamanyCadena; + Uint16 x; + Uint16 y; + Uint16 temps; + char colorTemp; + Uint32 color; + bool salir = false; + + for (int j=0; jcolor_blanco; + break; + case 1: + color = drawManager->color_rojo; + break; + case 2: + color = drawManager->color_verde; + break; + case 3: + color = drawManager->color_azul; + break; + } + tamanyCadena = file[punter++]; + texto = (char *) malloc(tamanyCadena + 1); + for (int i=0; iUpdate(); + + if (inputManager->eixir) { + gameInfo->estado = ESTADO_SALIR; + salir = true; + seguirIntro = false; + } + + if (inputManager->cualquierTecla || inputManager->BotoPulsat(SDL_BUTTON_LEFT)) { + salir = true; + if (inputManager->TeclaPulsada(SDLK_ESCAPE)) seguirIntro = false; + } + + if (SDL_GetTicks()-startTicks > temps) { + salir = true; + } + } + return seguirIntro; +} + +void SequenceController::FadeIn(char *archivo) { + fondo = drawManager->LoadBitmap( archivo); + drawManager->Blit(0,0, fondo); + drawManager->FadeIn(); + SDL_FreeSurface(fondo); +} + +void SequenceController::Show(char *archivo) { + fondo = drawManager->LoadBitmap( archivo); + drawManager->Blit(0,0, fondo); + drawManager->Flip(); + SDL_FreeSurface(fondo); +} + +void SequenceController::Print(int x, int y, Uint32 color, char *texto) { + font = drawManager->LoadFont( "fuente2.gif", color); + drawManager->Print(x, y, font, 7, 6, texto); + drawManager->Flip(); + SDL_FreeSurface(font); +} + +void SequenceController::FadeOut() { + drawManager->FadeOut(); +} + +void SequenceController::FadeOutWithMusic() { + drawManager->FadeOut(); + musicManager->FadeOut(); +} + +void SequenceController::Musica(char *archivo, int loop) { + musicManager->Load(archivo); + musicManager->Play(loop); +} + +void SequenceController::Finalize(void) { + +} diff --git a/SequenceController.h b/SequenceController.h new file mode 100644 index 0000000..d180699 --- /dev/null +++ b/SequenceController.h @@ -0,0 +1,36 @@ +#pragma once +#include "SDL/SDL.h" +#include "DrawManager.h" +#include "InputManager.h" +#include "MusicManager.h" +#include "GameInfo.h" + +class SequenceController +{ +public: + SequenceController(DrawManager *p_drawManager, InputManager *p_inputManager, MusicManager *p_musicManager); + ~SequenceController(void); + + bool Init(); + void Go(GameInfo *pGameInfo); + void Finalize(void); + +private: + void ProcesarSecuencia(char *file); + + bool Esperar(Uint32 temps); + void FadeIn(char *archivo); + void Show(char *archivo); + void Print(int x, int y, Uint32 color, char *texto); + void Musica(char *archivo, int loop); + void FadeOut(); + void FadeOutWithMusic(); + + DrawManager *drawManager; + InputManager *inputManager; + MusicManager *musicManager; + GameInfo *gameInfo; + + SDL_Surface *fondo; + SDL_Surface *font; +}; diff --git a/const.h b/const.h new file mode 100644 index 0000000..b7cf225 --- /dev/null +++ b/const.h @@ -0,0 +1,49 @@ +#pragma once +#ifndef _CONST_H_ + +#define _CONST_H_ + +const int SCREEN_WIDTH = 320; +const int SCREEN_HEIGHT = 200; +const int SCREEN_BPP = 32; +const char APPLICATION_NAME[12] = "Arounders"; + +const int ESTADO_SALIR = 0; +const int ESTADO_INTRO = 1; +const int ESTADO_SEQUENCIA = 2; +const int ESTADO_MENU = 3; +const int ESTADO_PASSWORD = 4; +const int ESTADO_PREFASE = 5; +const int ESTADO_JUEGO = 6; +const int ESTADO_POSTFASE = 7; +const int ESTADO_MORT = 8; +const int ESTADO_CREDITS = 9; + +const int ACCIO_CAMINAR = 0; +const int ACCIO_PARAR = 1; +const int ACCIO_CAVAR = 2; +const int ACCIO_ESCALAR = 3; +const int ACCIO_PERFORAR = 4; +const int ACCIO_ESCALERA = 5; +const int ACCIO_PASARELA = 6; +const int ACCIO_CORDA = 7; +const int ACCIO_SUICIDI = 8; +const int ACCIO_SUICIDI2 = 9; +const int ACCIO_CAURE = 10; +const int ACCIO_PUJARCORDA = 11; +const int ACCIO_BAIXARCORDA = 12; +const int ACCIO_MORT = 13; + +const int DIAPO_ESPERAR = 0; +const int DIAPO_FADEIN = 1; +const int DIAPO_SHOW = 2; +const int DIAPO_PRINT = 3; +const int DIAPO_MUSICA = 4; +const int DIAPO_FADEOUT = 5; +const int DIAPO_FADEMUSIC = 6; + +const int MODE_NORMAL = 0; +const int MODE_ZOOMX2 = 1; +const int MODE_FULLSCREEN = 2; + +#endif \ No newline at end of file diff --git a/fileManager.cpp b/fileManager.cpp new file mode 100644 index 0000000..fe3353c --- /dev/null +++ b/fileManager.cpp @@ -0,0 +1,90 @@ +#include "fileManager.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "fcntl.h" +#ifdef _WIN32 +#include "io.h" +#else +#include "unistd.h" +#endif + +char *resourceFileName = "data.jrf"; + +void setResourceFile(char *p_resourceFileName) { + resourceFileName = p_resourceFileName; +} + +char *GetBufferFromResource(char *resourcename, int *filesize) +{ + //Try to open the resource file in question + int fd = open(resourceFileName, O_RDONLY); + if (fd < 0) + { + perror("Error opening resource file"); + exit(1); + } + + //Make sure we're at the beginning of the file + lseek(fd, 0, SEEK_SET); + + //Read the first INT, which will tell us how many files are in this resource + int numfiles; + int resultat = read(fd, &numfiles, sizeof(int)); + +#ifdef _WIN32 + int final = eof(fd); +#endif + + //Get the pointers to the stored files + int *filestart = (int *) malloc(sizeof(int) * numfiles); + resultat = read(fd, filestart, sizeof(int) * numfiles); + + //Loop through the files, looking for the file in question + int filenamesize; + char *buffer; + int i; + for(i=0;i 1) { + for (int i=1;iGo(); + + delete appController; + + return 0; + +}