- Lleve tots els arxius antics ja

This commit is contained in:
2023-10-22 11:18:35 +02:00
parent 185ee3797d
commit 7364890a9d
38 changed files with 0 additions and 9298 deletions

View File

@@ -1,47 +0,0 @@
#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;
}

View File

@@ -1,20 +0,0 @@
#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;
};

View File

@@ -1,95 +0,0 @@
#include <string>
#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);
if ( !drawManager->Init() ) { return false; }
music_init();
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);
sequenceController->Go(gameInfo);
delete sequenceController;
break;
case ESTADO_MENU:
MenuController *menuController;
menuController = new MenuController(drawManager, inputManager);
menuController->Go(gameInfo);
delete menuController;
break;
case ESTADO_PASSWORD:
PasswordController *passwordController;
passwordController = new PasswordController(drawManager, inputManager);
passwordController->Go(gameInfo);
delete passwordController;
break;
case ESTADO_PREFASE:
PrefaseController *prefaseController;
prefaseController = new PrefaseController(drawManager, inputManager);
prefaseController->Go(gameInfo);
delete prefaseController;
break;
case ESTADO_JUEGO:
GameController *gameController;
gameController = new GameController(drawManager, inputManager);
gameController->Go(gameInfo);
delete gameController;
break;
case ESTADO_POSTFASE:
PostfaseController *postfaseController;
postfaseController = new PostfaseController(drawManager, inputManager);
postfaseController->Go(gameInfo);
delete postfaseController;
break;
case ESTADO_MORT:
MortController *mortController;
mortController = new MortController(drawManager, inputManager);
mortController->Go(gameInfo);
delete mortController;
break;
}
}
Finalize();
}
void AppController::Finalize(void)
{
delete drawManager;
delete inputManager;
delete gameInfo;
SDL_Quit();
}

View File

@@ -1,24 +0,0 @@
#pragma once
#include "SDL2/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;
GameInfo *gameInfo;
};

View File

@@ -1,855 +0,0 @@
#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;
}
/*
#define COLOR 0xFFFFFFFF;
void vline(const int x, const int y1, const int y2) {
if (x < 0 || x > 319) return;
const int yy1 = y1 < 0 ? 0 : y1 > 239 ? 239 : y1;
const int yy2 = y2 < 0 ? 0 : y2 > 239 ? 239 : y2;
for (int y=yy1;y<=yy2;y++) pixels[x+y*pitch] = COLOR;
}
void hline(const int x1, const int x2, const int y) {
if (y < 0 || y > 239) return;
const int yy = y*pitch;
const int xx1 = x1 < 0 ? 0 : x1 > 319 ? 319 : x1;
const int xx2 = x2 < 0 ? 0 : x2 > 319 ? 319 : x2;
for (int x=xx1;x<=xx2;x++) pixels[x+yy] = COLOR;
}
void circle(const int x, const int y) {
hline(x+9, x+9+7, y+0); hline(x+9, x+9+7, y+24);
hline(x+7, x+7+11, y+1); hline(x+7, x+7+11, y+23);
hline(x+5, x+5+15, y+2); hline(x+5, x+5+15, y+22);
hline(x+4, x+4+17, y+3); hline(x+4, x+4+17, y+21);
hline(x+3, x+3+19, y+4); hline(x+3, x+3+19, y+20);
hline(x+2, x+2+21, y+5); hline(x+2, x+2+21, y+19);
hline(x+2, x+2+21, y+6); hline(x+2, x+2+21, y+18);
hline(x+1, x+1+23, y+7); hline(x+1, x+1+23, y+17);
hline(x+1, x+1+23, y+8); hline(x+1, x+1+23, y+16);
hline(x, x+25, y+9); hline(x, x+25, y+15);
hline(x, x+25, y+10); hline(x, x+25, y+14);
hline(x, x+25, y+11); hline(x, x+25, y+13);
hline(x, x+25, y+12);
}
*/

View File

@@ -1,106 +0,0 @@
#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 );
};

View File

@@ -1,283 +0,0 @@
#include "DrawManager.h"
#include "const.h"
#include "fileManager.h"
#include "SDL2/SDL_image.h"
SDL_Window *sdlWindow = NULL;
SDL_Renderer *sdlRenderer = NULL;
DrawManager::DrawManager(int pMode) {
mode = pMode;
screen = NULL;
}
DrawManager::~DrawManager(void) {
SDL_FreeSurface(temp);
SDL_FreeSurface(black);
SDL_FreeSurface(faded);
SDL_DestroyRenderer(sdlRenderer);
SDL_DestroyWindow(sdlWindow);
}
bool DrawManager::Init(void) {
sdlWindow = SDL_CreateWindow(APPLICATION_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
SDL_RenderSetLogicalSize(sdlRenderer, 320, 240);
SDL_ShowCursor(0);
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)
{
SDL_RenderPresent(sdlRenderer);
return true;
}
SDL_Surface *DrawManager::LoadBitmap(const char *bitmapfilename, const bool doColorKey)
{
//Get the bitmap's buffer and size from the resource file
int filesize = 0;
const char *buffer = file_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(const char *bitmapfilename)
{
//Get the bitmap's buffer and size from the resource file
int filesize = 0;
const char *buffer = file_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, const 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(const char *bitmapfilename, const 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; x<temporal->w; x++) {
for (int y=0; y<temporal->h; 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;
}

View File

@@ -1,41 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
class DrawManager
{
public:
DrawManager(int pMode);
~DrawManager(void);
bool Init(void);
bool Flip(void);
SDL_Surface *LoadBitmap(const char *bitmapfilename, const bool doColorKey = false);
SDL_Surface *LoadMask(const 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, const char *text, SDL_Surface* dest = NULL );
void FadeOut();
void FadeIn();
void FadeOutGray();
void FadeInGray();
void DrawFadedBack();
SDL_Surface *LoadFont(const char *bitmapfilename, const Uint32 color = 0xFFFFFFFF);
int mode;
Uint32 color_blanco;
Uint32 color_rojo;
Uint32 color_verde;
Uint32 color_azul;
private:
SDL_Surface *screen;
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 );
};

View File

@@ -1,421 +0,0 @@
#include "GameController.h"
#include "const.h"
#include "fileManager.h"
GameController::GameController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
GameController::~GameController() {
}
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) {
music_load( "mus6.mp3");
} else {
music_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; }
music_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;
}*/
}
music_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(const 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(const int numMapa)
{
int filesize = 0;
const char *buffer = file_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;
}
}
const char *GameController::formatejar(const 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;
}

View File

@@ -1,57 +0,0 @@
#pragma once
#include <list>
#include "SDL2/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);
~GameController();
bool Init();
void Go(GameInfo *pGameInfo);
void Finalize(void);
private:
DrawManager *drawManager;
InputManager *inputManager;
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(const bool bypass = false);
void CarregarMapa(const int numMapa);
const char *formatejar(const int numero);
};

View File

@@ -1,11 +0,0 @@
#include "GameInfo.h"
#include "const.h"
GameInfo::GameInfo(int pModeGrafic) {
fase = -1;
estado = ESTADO_SEQUENCIA;
modeGrafic = pModeGrafic;
}
GameInfo::~GameInfo(void) {
}

View File

@@ -1,14 +0,0 @@
#pragma once
class GameInfo
{
public:
GameInfo(int pModeGrafic);
~GameInfo(void);
int fase;
int puntuacion;
int vidas;
int estado;
int modeGrafic;
};

View File

@@ -1,187 +0,0 @@
/*
* 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_GetKeyboardState( 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_WINDOWEVENT ) {
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) finestraActiva = true;
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) 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;
}

View File

@@ -1,41 +0,0 @@
#pragma once
#include "SDL2/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:
const Uint8 *keystates;
GameInfo *gameInfo;
SDL_Event event;
bool oldMouseButtonLeft;
bool oldMouseButtonRight;
bool oldMouseButtonMiddle;
};

View File

@@ -1,110 +0,0 @@
#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;
}

View File

@@ -1,38 +0,0 @@
#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;
};

View File

@@ -1,75 +0,0 @@
#include "MenuController.h"
#include "const.h"
MenuController::MenuController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
MenuController::~MenuController(void) {
}
bool MenuController::Init() {
fondo = drawManager->LoadBitmap("menuprin.gif");
cursor = drawManager->LoadFont("cursor.gif");
if (!music_sonant()) {
music_load("mus3.mp3");
music_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) music_fadeOut();
drawManager->FadeOut();
}
void MenuController::Finalize(void) {
SDL_FreeSurface(fondo);
SDL_FreeSurface(cursor);
}

View File

@@ -1,24 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
#include "DrawManager.h"
#include "InputManager.h"
#include "MusicManager.h"
#include "GameInfo.h"
class MenuController
{
public:
MenuController(DrawManager *p_drawManager, InputManager *p_inputManager);
~MenuController(void);
bool Init();
void Go(GameInfo *gameInfo);
void Finalize(void);
private:
DrawManager *drawManager;
InputManager *inputManager;
SDL_Surface *fondo;
SDL_Surface *cursor;
};

View File

@@ -1,71 +0,0 @@
#include "MortController.h"
#include "const.h"
MortController::MortController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
MortController::~MortController(void) {
}
bool MortController::Init() {
fondo = drawManager->LoadBitmap("mort.gif");
cursor = drawManager->LoadFont("cursor.gif");
music_load( "mus5.mp3");
return true;
}
void MortController::Go(GameInfo *gameInfo) {
bool salir = false;
if ( !Init() ) { salir = true; gameInfo->estado = ESTADO_SALIR; }
music_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);
}

View File

@@ -1,24 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
#include "DrawManager.h"
#include "InputManager.h"
#include "MusicManager.h"
#include "GameInfo.h"
class MortController
{
public:
MortController(DrawManager *p_drawManager, InputManager *p_inputManager);
~MortController(void);
bool Init();
void Go(GameInfo *gameInfo);
void Finalize(void);
private:
DrawManager *drawManager;
InputManager *inputManager;
SDL_Surface *fondo;
SDL_Surface *cursor;
};

View File

@@ -1,43 +0,0 @@
#include "MusicManager.h"
#include "const.h"
#include "jail_audio.h"
#include "fileManager.h"
JA_Music music = NULL; //= JA_LoadMusic("intro2.ogg");
void music_init() {
JA_Init(48000, AUDIO_S16, 2);
//return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
}
void music_quit() {
if (music != NULL) JA_DeleteMusic(music);
}
void music_load(const char *musicfilename) {
if (music != NULL) {
JA_StopMusic();
JA_DeleteMusic(music);
}
int filesize = 0;
const char *buffer = file_getBufferFromResource(musicfilename, filesize);
music = JA_LoadMusic((Uint8*)buffer, filesize);
//free(buffer);
}
void music_play(const int loops) {
JA_PlayMusic(music, loops);
}
void music_pause() {
JA_PauseMusic();
}
void music_fadeOut() {
JA_StopMusic();
}
const bool music_sonant() {
return JA_GetMusicState() == JA_MUSIC_PLAYING;
}

View File

@@ -1,9 +0,0 @@
#pragma once
void music_init();
void music_quit();
void music_load(const char *musicfilename);
void music_play(const int loops);
void music_pause();
void music_fadeOut();
const bool music_sonant();

View File

@@ -1,115 +0,0 @@
#include "PasswordController.h"
#include "const.h"
#include "fileManager.h"
PasswordController::PasswordController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
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;
const char *buffer = file_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);
}

View File

@@ -1,29 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
#include "DrawManager.h"
#include "InputManager.h"
#include "MusicManager.h"
#include "GameInfo.h"
class PasswordController
{
public:
PasswordController(DrawManager *p_drawManager, InputManager *p_inputManager);
~PasswordController(void);
bool Init();
void Go(GameInfo *gameInfo);
void Finalize(void);
private:
char ObtenerTecla();
int ObtenerFaseDePassword(char *password);
DrawManager *drawManager;
InputManager *inputManager;
SDL_Surface *fondo;
SDL_Surface *cursor;
SDL_Surface *font;
};

View File

@@ -1,136 +0,0 @@
#include "PostfaseController.h"
#include "const.h"
#include "fileManager.h"
PostfaseController::PostfaseController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
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 {
music_load( "mus3.mp3");
music_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;
const char *buffer = file_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);
}

View File

@@ -1,27 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
#include "DrawManager.h"
#include "InputManager.h"
#include "MusicManager.h"
#include "GameInfo.h"
class PostfaseController
{
public:
PostfaseController(DrawManager *p_drawManager, InputManager *p_inputManager);
~PostfaseController(void);
bool Init();
void Go(GameInfo *gameInfo);
void Finalize(void);
private:
char *ObtenerPasswordDeFase(int fase);
bool MostrarVictoria(GameInfo *gameInfo);
DrawManager *drawManager;
InputManager *inputManager;
SDL_Surface *fondo;
SDL_Surface *font;
};

View File

@@ -1,104 +0,0 @@
#include "PrefaseController.h"
#include "const.h"
#include "fileManager.h"
PrefaseController::PrefaseController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
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;
}
}
music_fadeOut();
drawManager->FadeOut();
}
void PrefaseController::Finalize(void) {
SDL_FreeSurface(fondo);
SDL_FreeSurface(cursor);
SDL_FreeSurface(font);
}
void PrefaseController::CarregarMapa(const int numMapa)
{
int filesize = 0;
const char *buffer = file_getBufferFromResource("MAPES.BAL", filesize);
int punter = numMapa * 212;
int tileSet = buffer[punter++];
punter += 2;
numArounders = buffer[punter++];
aroundersNec = buffer[punter++];
}
const char *PrefaseController::formatejar(const 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;
}

View File

@@ -1,31 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
#include "DrawManager.h"
#include "InputManager.h"
#include "MusicManager.h"
#include "GameInfo.h"
class PrefaseController
{
public:
PrefaseController(DrawManager *p_drawManager, InputManager *p_inputManager);
~PrefaseController(void);
bool Init();
void Go(GameInfo *gameInfo);
void Finalize(void);
private:
const char *formatejar(const int numero);
void CarregarMapa(const int numMapa);
DrawManager *drawManager;
InputManager *inputManager;
SDL_Surface *fondo;
SDL_Surface *cursor;
SDL_Surface *font;
int numArounders;
int aroundersNec;
};

View File

@@ -1,213 +0,0 @@
#include "SequenceController.h"
#include "const.h"
#include "fileManager.h"
SequenceController::SequenceController(DrawManager *p_drawManager, InputManager *p_inputManager) {
drawManager = p_drawManager;
inputManager = p_inputManager;
}
SequenceController::~SequenceController(void) {
}
bool SequenceController::Init() {
return true;
}
void SequenceController::Go(GameInfo *pGameInfo) {
bool salir = false;
int pantalla = 0;
const char *file;
int filesize;
gameInfo = pGameInfo;
if (gameInfo->fase % 5 == 0 || gameInfo->fase < 0) {
switch (gameInfo->fase) {
case -1:
file = file_getBufferFromResource("seqIN.seq", filesize);
break;
case 0:
file = file_getBufferFromResource("seq00.seq", filesize);
break;
case 5:
file = file_getBufferFromResource("seq05.seq", filesize);
break;
case 10:
file = file_getBufferFromResource("seq10.seq", filesize);
break;
case 15:
file = file_getBufferFromResource("seq15.seq", filesize);
break;
case 20:
file = file_getBufferFromResource("seq20.seq", filesize);
break;
case 25:
file = file_getBufferFromResource("seq25.seq", filesize);
break;
case 30:
file = 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(const 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; j<numDiapositives; j++) {
if (salir) {
FadeOutWithMusic();
break;
}
char tipusDiapositiva = (char)file[punter++];
x = 0;
y = 0;
temps = 0;
switch (tipusDiapositiva) {
case DIAPO_ESPERAR:
temps = (Uint16)(((unsigned char)file[punter+1] << 8) + (unsigned char)file[punter]);
salir = !Esperar(temps);
punter += 2;
break;
case DIAPO_FADEIN:
tamanyCadena = file[punter++];
filename = (char *) malloc(tamanyCadena + 1);
for (int i=0; i<tamanyCadena; i++) filename[i] = file[punter++];
filename[tamanyCadena] = '\0';
FadeIn(filename);
break;
case DIAPO_SHOW:
tamanyCadena = file[punter++];
filename = (char *) malloc(tamanyCadena + 1);
for (int i=0; i<tamanyCadena; i++) filename[i] = file[punter++];
filename[tamanyCadena] = '\0';
Show(filename);
break;
case DIAPO_PRINT:
x = (Uint16)(((unsigned char)file[punter+1] << 8) + (unsigned char)file[punter]);
punter+=2;
y = (Uint16)(((unsigned char)file[punter+1] << 8) + (unsigned char)file[punter]);
punter+=2;
colorTemp = file[punter++];
switch (colorTemp) {
case 0:
color = drawManager->color_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; i<tamanyCadena; i++) texto[i] = file[punter++];
texto[tamanyCadena] = '\0';
Print(x, y, color, texto);
break;
case DIAPO_MUSICA:
tamanyCadena = file[punter++];
filename = (char *) malloc(tamanyCadena + 1);
for (int i=0; i<tamanyCadena; i++) filename[i] = file[punter++];
filename[tamanyCadena] = '\0';
Musica(filename, -1);
break;
case DIAPO_FADEOUT:
FadeOut();
break;
case DIAPO_FADEMUSIC:
FadeOutWithMusic();
break;
}
}
}
bool SequenceController::Esperar(Uint32 temps) {
bool seguirIntro = true;
bool salir = false;
Uint32 startTicks = SDL_GetTicks();
while ( !salir ) {
inputManager->Update();
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();
music_fadeOut();
}
void SequenceController::Musica(char *archivo, int loop) {
music_load(archivo);
music_play(loop);
}
void SequenceController::Finalize(void) {
}

View File

@@ -1,35 +0,0 @@
#pragma once
#include "SDL2/SDL.h"
#include "DrawManager.h"
#include "InputManager.h"
#include "MusicManager.h"
#include "GameInfo.h"
class SequenceController
{
public:
SequenceController(DrawManager *p_drawManager, InputManager *p_inputManager);
~SequenceController(void);
bool Init();
void Go(GameInfo *pGameInfo);
void Finalize(void);
private:
void ProcesarSecuencia(const 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;
GameInfo *gameInfo;
SDL_Surface *fondo;
SDL_Surface *font;
};

45
const.h
View File

@@ -1,45 +0,0 @@
#pragma once
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;

Binary file not shown.

View File

@@ -1,100 +0,0 @@
#include "fileManager.h"
#include <SDL2/SDL.h>
#include <fstream>
#pragma pack(push,1)
struct DATA_Header {
char magic[4];
Uint32 num_files;
Uint32 index_offset;
};
struct DATA_Info {
Uint32 offset;
Uint32 length;
char name[13];
};
struct DATA_Index {
DATA_Info* file_info;
};
struct DATA_File {
DATA_Header header;
DATA_Index index;
};
#pragma pack(pop)
static const char *resourceFileName = "data.jrf";
static DATA_File *data_file = NULL;
void file_setResourceFile(const char *p_resourceFileName) {
resourceFileName = p_resourceFileName;
}
static void getDataFile() {
std::ifstream fd( resourceFileName, std::ios::in | std::ios::binary );
if( fd.fail() ) {
perror("No s'ha pogut obrir l'arxiu de recursos");
exit(1);
}
data_file = (DATA_File*)malloc( sizeof( DATA_File ) );
fd.read( (char*)&data_file->header, sizeof( DATA_Header ) );
fd.seekg( data_file->header.index_offset );
data_file->index.file_info = (DATA_Info*)malloc( data_file->header.num_files * sizeof( DATA_Info ) );
fd.read( (char*)data_file->index.file_info, data_file->header.num_files * sizeof( DATA_Info ) );
fd.close();
}
const char *file_setBufferFromResource(const char *resourcename, int& filesize) {
if( data_file == NULL ) {
getDataFile();
}
bool found = false;
int count = 0;
while( !found && count < data_file->header.num_files ) {
found = ( strcmp( resourcename, data_file->index.file_info[count].name ) == 0 );
if( !found ) count++;
}
if( !found ) {
perror("El recurs no s'ha trobat en l'arxiu de recursos");
exit(1);
}
filesize = data_file->index.file_info[count].length;
std::ifstream fd( resourceFileName, std::ios::in | std::ios::binary );
if( fd.fail() ) {
perror("No s'ha pogut obrir l'arxiu de recursos");
exit(1);
}
fd.seekg( data_file->index.file_info[count].offset );
char* buffer = (char*)malloc( filesize );
fd.read( buffer, filesize );
fd.close();
return buffer;
}
void file_quit() {
if( data_file != NULL ) {
free( data_file->index.file_info );
free( data_file );
}
}

View File

@@ -1,7 +0,0 @@
#pragma once
void file_setResourceFile(const char *p_resourceFileName);
const char *file_getBufferFromResource(const char *resourcename, int& filesize);
void file_quit();

View File

@@ -1,240 +0,0 @@
#include "jail_audio.h"
#include "stb_vorbis.c"
#include <SDL2/SDL.h>
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
struct JA_Sound_t {
Uint32 length {0};
Uint8* buffer {NULL};
};
struct JA_Channel_t {
JA_Sound sound;
int pos {0};
int times {0};
JA_Channel_state state { JA_CHANNEL_FREE };
};
struct JA_Music_t {
int samples {0};
int pos {0};
int times {0};
short* output {NULL};
JA_Music_state state {JA_MUSIC_INVALID};
};
JA_Music current_music{NULL};
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
int JA_freq {48000};
SDL_AudioFormat JA_format {AUDIO_S16};
Uint8 JA_channels {2};
void audioCallback(void * userdata, uint8_t * stream, int len) {
SDL_memset(stream, 0, len);
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
SDL_memcpy(stream, current_music->output+current_music->pos, size);
current_music->pos += size/2;
if (size < len) {
if (current_music->times != 0) {
SDL_memcpy(stream+size, current_music->output, len-size);
current_music->pos = (len-size)/2;
if (current_music->times > 0) current_music->times--;
} else {
current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED;
}
}
}
// Mixar els channels mi amol
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state == JA_CHANNEL_PLAYING) {
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, 64);
channels[i].pos += size;
if (size < len) {
if (channels[i].times != 0) {
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, 64);
channels[i].pos = len-size;
if (channels[i].times > 0) channels[i].times--;
} else {
JA_StopChannel(i);
}
}
}
}
}
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
JA_freq = freq;
JA_format = format;
JA_channels = channels;
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
SDL_AudioDeviceID sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
SDL_PauseAudioDevice(sdlAudioDevice, 0);
}
JA_Music JA_LoadMusic(const char* filename) {
int chan, samplerate;
JA_Music music = new JA_Music_t();
music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
cvt.len = music->samples * chan * 2;
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
SDL_memcpy(cvt.buf, music->output, cvt.len);
SDL_ConvertAudio(&cvt);
free(music->output);
music->output = (short*)cvt.buf;
music->pos = 0;
music->state = JA_MUSIC_STOPPED;
return music;
}
JA_Music JA_LoadMusic(const Uint8* mem, int len) {
int chan, samplerate;
JA_Music music = new JA_Music_t();
music->samples = stb_vorbis_decode_memory(mem, len, &chan, &samplerate, &music->output);
SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
cvt.len = music->samples * chan * 2;
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
SDL_memcpy(cvt.buf, music->output, cvt.len);
SDL_ConvertAudio(&cvt);
free(music->output);
music->output = (short*)cvt.buf;
music->pos = 0;
music->state = JA_MUSIC_STOPPED;
return music;
}
void JA_PlayMusic(JA_Music music, const int loop) {
if (current_music != NULL) {
current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED;
}
current_music = music;
current_music->pos = 0;
current_music->state = JA_MUSIC_PLAYING;
current_music->times = loop;
}
void JA_PauseMusic() {
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
current_music->state = JA_MUSIC_PAUSED;
}
void JA_ResumeMusic() {
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
current_music->state = JA_MUSIC_PLAYING;
}
void JA_StopMusic() {
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED;
}
JA_Music_state JA_GetMusicState() {
if (current_music == NULL) return JA_MUSIC_INVALID;
return current_music->state;
}
void JA_DeleteMusic(JA_Music music) {
if (current_music == music) current_music = NULL;
SDL_free(music->output);
delete music;
}
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) {
JA_Sound sound = new JA_Sound_t();
sound->buffer = buffer;
sound->length = length;
return sound;
}
JA_Sound JA_LoadSound(const char* filename) {
JA_Sound sound = new JA_Sound_t();
SDL_AudioSpec wavSpec;
SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
cvt.len = sound->length;
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
SDL_ConvertAudio(&cvt);
SDL_FreeWAV(sound->buffer);
sound->buffer = cvt.buf;
sound->length = cvt.len_cvt;
return sound;
}
int JA_PlaySound(JA_Sound sound, const int loop) {
int channel = 0;
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
channels[channel].sound = sound;
channels[channel].times = loop;
channels[channel].pos = 0;
channels[channel].state = JA_CHANNEL_PLAYING;
return channel;
}
void JA_DeleteSound(JA_Sound sound) {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].sound == sound) JA_StopChannel(i);
}
SDL_free(sound->buffer);
delete sound;
}
void JA_PauseChannel(const int channel) {
if (channel == -1) {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED;
}
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
if (channels[channel].state == JA_CHANNEL_PLAYING) channels[channel].state = JA_CHANNEL_PAUSED;
}
}
void JA_ResumeChannel(const int channel) {
if (channel == -1) {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING;
}
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
if (channels[channel].state == JA_CHANNEL_PAUSED) channels[channel].state = JA_CHANNEL_PLAYING;
}
}
void JA_StopChannel(const int channel) {
if (channel == -1) {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
channels[i].state = JA_CHANNEL_FREE;
channels[i].pos = 0;
channels[i].sound = NULL;
}
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
channels[channel].state = JA_CHANNEL_FREE;
channels[channel].pos = 0;
channels[channel].sound = NULL;
}
}
JA_Channel_state JA_GetChannelState(const int channel) {
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
return channels[channel].state;
}

View File

@@ -1,28 +0,0 @@
#pragma once
#include <SDL2/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
typedef struct JA_Sound_t *JA_Sound;
typedef struct JA_Music_t *JA_Music;
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
JA_Music JA_LoadMusic(const char* filename);
JA_Music JA_LoadMusic(const Uint8* mem, int len);
void JA_PlayMusic(JA_Music music, const int loop = -1);
void JA_PauseMusic();
void JA_ResumeMusic();
void JA_StopMusic();
JA_Music_state JA_GetMusicState();
void JA_DeleteMusic(JA_Music music);
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length);
JA_Sound JA_LoadSound(const char* filename);
int JA_PlaySound(JA_Sound sound, const int loop = 0);
void JA_PauseChannel(const int channel);
void JA_ResumeChannel(const int channel);
void JA_StopChannel(const int channel);
JA_Channel_state JA_GetChannelState(const int channel);
void JA_DeleteSound(JA_Sound sound);

View File

@@ -1,27 +0,0 @@
#include "AppController.h"
#include "fileManager.h"
#include "const.h"
int main( int argc, char* args[] )
{
int modeGrafic = MODE_ZOOMX2;
const char *porDefecto = "data.jrf";
file_setResourceFile(porDefecto);
if (argc > 1) {
for (int i=1;i<argc;i++) {
if (!strcmp(args[i], "normal")) modeGrafic = MODE_NORMAL;
if (!strcmp(args[i], "fullscreen")) modeGrafic = MODE_FULLSCREEN;
if (args[i][4] == '.') file_setResourceFile(args[i]);
}
}
AppController *appController;
appController = new AppController(modeGrafic);
appController->Go();
delete appController;
return 0;
}

File diff suppressed because it is too large Load Diff