Compare commits

...

64 Commits

Author SHA1 Message Date
8df6a82b80 - Updatat el makefile amb els releases de mac i linux. A provar quan me sente davant de un mac o un linux. 2023-10-23 17:24:43 +02:00
7e84495701 Merge branch 'master' of https://gitea.sustancia.synology.me/JailDoctor/arounders 2023-10-23 16:51:22 +02:00
0981882fd3 - [FIX] Problema amb alguns arxius binaris que algú en tota la cadena se pensava que eren de text i canviava caracter 13 per 10+13 2023-10-23 16:50:23 +02:00
8c4233e90e - Ara la versió la dona el Makefile
- El Makefile ja inclou la generació de windows_release
2023-10-23 16:49:13 +02:00
f3f4639abe - Incloguem totes les DLL necessaries 2023-10-23 16:48:38 +02:00
60a0ca2b0e Update README.md 2023-10-23 16:13:53 +02:00
f21a4808f5 Afegits els screenshots 2023-10-23 15:15:30 +02:00
283f3f58f5 - [FIX] Ja funcionen els passwords 2023-10-22 22:29:52 +02:00
7cbf75ffd9 - [FIX] La segona vegada que entraves a ficar password, estaba l'antic 2023-10-22 20:06:45 +02:00
2bfe750ccc - Afegim arxius per al bundle de macOs 2023-10-22 18:04:10 +02:00
438e24ab9e - S'inclou el que fa falta pa ficar el iconet al compilar en windows_release 2023-10-22 17:25:54 +02:00
ccc4f760b2 Merge branch 'master' of https://gitea.sustancia.synology.me/JailDoctor/arounders 2023-10-22 16:45:00 +02:00
fd2b90fb3b - Afegit icono 2023-10-22 16:43:22 +02:00
f8b42bc986 Update README.md 2023-10-22 14:05:50 +02:00
f638d4e262 Update README.md 2023-10-22 14:02:00 +02:00
3a0cba54ba - [FIX] Quan se pillen les sequències del data.jf2 peta per que no hi ha EOF 2023-10-22 13:30:49 +02:00
e30bbc5f8c - Ignorar carpeta release 2023-10-22 13:12:46 +02:00
a69aa23490 - [FIX] Si s´usava arxiu de recursos, jfile no trobava res 2023-10-22 13:12:17 +02:00
24f693e357 - Llevada alguna traça que quedava 2023-10-22 13:11:49 +02:00
773b59be23 - Afegits els arxius readme i versions que acompanyen al Arounders des de fa 24 anys (mínimament actualitzats) 2023-10-22 11:19:50 +02:00
21b449ba45 - Inclosa la versió en el menú principal 2023-10-22 11:18:58 +02:00
7364890a9d - Lleve tots els arxius antics ja 2023-10-22 11:18:35 +02:00
185ee3797d - Creat mòdul proc_explosio per a vore pixels volant quan se trenca algo 2023-10-22 10:48:21 +02:00
cc862d2952 - [NEW] draw::putPixel() 2023-10-22 10:46:30 +02:00
76b440667b - [FIX] No funcionava el suicidi 2023-10-21 17:57:03 +02:00
ef93f2c3df - Canviat el copyright i la dedicatòria 2023-10-21 17:56:49 +02:00
8a0318b852 - gamestate_password implementat. 2023-10-21 17:32:27 +02:00
79e1d793e2 - [FIX] El nom de l'imatge de guanyar no se calculaba correctament. 2023-10-21 17:31:56 +02:00
851513f1d9 - [NEW] gamestate_mort
- Millorades les constants en gamestate_menu
2023-10-21 11:44:39 +02:00
6d9c902f2d - [FIX] En gamestate_postfase el text no eixia del color que tocaba 2023-10-21 10:50:09 +02:00
66fee27b50 - [FIX] Els arounders mai agafaven la corda 2023-10-21 10:39:41 +02:00
6b63dbd70a - Ja funcionen els arounders, pero la corda falla. A investigar. 2023-10-20 20:08:25 +02:00
136bc86f68 - [FIX] El modul arounders no s'inicialitzava
- [FIX] Quan reintentaves un mapa, no se recarregava
2023-10-20 20:07:57 +02:00
61b429eb8b - [FIX] El nom del fitxer de la cançò estava mal 2023-10-20 20:07:09 +02:00
5dcf2e582a - [FIX] Algunes variables no se reinicialitzaven 2023-10-20 20:06:25 +02:00
448ffa3597 - Modul dels arounders implementat, sense probar, cambie de comp i ho prove 2023-10-20 18:59:55 +02:00
b59e3bdd40 - Fem publics la surface del mapa i les coordenades d'inici i final 2023-10-20 18:59:05 +02:00
07d2f8b721 - Afegit a la paleta el color dels escalons que fan els arounders 2023-10-20 18:58:36 +02:00
e2187ffd5b - Cambiada la paleta del hueco de la explosió 2023-10-20 18:58:14 +02:00
98138344e6 - Millors comentaris 2023-10-20 14:52:06 +02:00
6472845333 - Millors missatges d'error en jfile 2023-10-20 13:13:00 +02:00
f9d2ac66e8 - Crec que ja està tot preparat per a implementar... EL MÒDUL "AROUNDERS"!!!! WOOOO!!!!! 2023-10-19 20:01:54 +02:00
0b80fc1674 - Acabat d'implementar el proces de triar el botó que s'ha polsat 2023-10-19 20:01:18 +02:00
d8404ce752 - Afegides constants per a quin numeret es cada botó del ratolí, que mai ho recorde 2023-10-19 20:00:38 +02:00
d391827fe1 - Arreglat el pintat de l'aigua
- Ja funciona la pausa i el menu de dins del joc
2023-10-19 18:58:19 +02:00
8d954ec2e0 - Canviat el tipus de mapa::velocitat per a que el compilaooooooor no renegue 2023-10-19 18:57:33 +02:00
720c15d03a - [NEW] game::windowHasFocus 2023-10-19 18:57:02 +02:00
ccb2f3fbca - [NEW] draw::getPalette() 2023-10-19 18:56:27 +02:00
ad1cceea5f - [FIX] Si eixim de la sequència inicial quan el logo o el thx, en el menu s'enchufa la musica correcta 2023-10-19 15:29:11 +02:00
70720e7e62 [NEW] music::whichMusic() 2023-10-19 15:27:53 +02:00
490dc1e5d6 -Arreglades les paletes del logo i thx. 2023-10-19 15:24:09 +02:00
5173edd7f0 - Intentant que l'aigua se pinte i tal 2023-10-18 20:04:10 +02:00
c9e1760698 - [FIX] nom de musica incorrecte
- [FIX] Al carregar el mapa nomes contaba fins a x=10 en compte de 20.
- Aplicats els nous draw::draw()
- Fora tots els draw::setTrans(), el color transparent no canvia en tot el joc.
2023-10-18 19:44:48 +02:00
c5499bf549 - Seguim amb l'implementació del modul de mapa i el gamestate_play 2023-10-18 19:00:56 +02:00
6b8a5213e6 - [NEW] game::getTicks() 2023-10-18 19:00:08 +02:00
8cb28f000d - [NEW] varies versions de draw::draw() 2023-10-18 18:59:52 +02:00
d237dd2019 - [FIX] El cursor pintava el color transparent 2023-10-18 17:25:52 +02:00
c6b994cc37 - Ja llig correctament el mapa en format text 2023-10-18 17:25:24 +02:00
fdc604be3c - [NEW] aux_textfile()
- Implementant la càrrega del nivell
2023-10-18 16:18:57 +02:00
3f203fee62 - Proves de lectura dels nivells en format text 2023-10-17 20:15:11 +02:00
771e7abb65 - [NEW] jfile::getFileStream() 2023-10-17 20:14:53 +02:00
8918c25b4e - Actualitzem tots els gamestate per a usar els nous mòduls. 2023-10-17 18:49:41 +02:00
bcd38a5a06 - El mòdul de marcador s'integra en el mòdul mapa 2023-10-17 18:49:22 +02:00
c1bbcace85 - [NEW] Modul de fonts 2023-10-17 18:48:35 +02:00
98 changed files with 2828 additions and 9637 deletions

3
.gitignore vendored
View File

@@ -2,4 +2,5 @@
*.exe
arounders
arounders_debug
*.dll
./*.dll
release/*

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;
};

44
Info.plist Normal file
View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19H2</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>arounders</string>
<key>CFBundleExecutable</key>
<string>arounders</string>
<key>CFBundleIconFile</key>
<string>arounders</string>
<key>CFBundleIconName</key>
<string>arounders</string>
<key>CFBundleIdentifier</key>
<string>net.jailers.arounders</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>arounders</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.2.0</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2023 JailDoctor</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
</dict>
</plist>

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;
};

129
Makefile
View File

@@ -1,27 +1,140 @@
executable = arounders
source = source/*.cpp
appName = arounders
releaseFolder = release
version = v1.2.1
# Release names
windowsRelease = $(executable)-$(version)-win32-x64.zip
macosIntelRelease = $(executable)-$(version)-macos-intel.dmg
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
linuxRelease = $(executable)-$(version)-linux.tar.gz
windows:
@echo off
g++ $(source) icon.res -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -mwindows -o "$(executable).exe"
windres icon.rc -O coff icon.res
g++ $(source) icon.res -D VERSION=\"$(version)\" -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -mwindows -o "$(executable).exe"
strip -s -R .comment -R .gnu.version --strip-unneeded "$(executable).exe"
windows_debug:
@echo off
g++ $(source) -D DEBUG -g -Wall -fvar-tracking -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -o "$(executable)_debug.exe"
g++ $(source) -D DEBUG -D VERSION=\"$(version)\" -g -Wall -fvar-tracking -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -o "$(executable)_debug.exe"
windows_release:
@echo off
# Fem el paquetet
respak2 -p
# Create release folder
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
powershell if (-not (Test-Path "$(releaseFolder)")) {New-Item "$(releaseFolder)" -ItemType Directory}
# Copy root files
powershell Copy-Item "data.jf2" -Destination "$(releaseFolder)"
powershell Copy-Item "versions.txt" -Destination "$(releaseFolder)"
powershell Copy-Item "README.md" -Destination "$(releaseFolder)"
powershell Copy-Item "bin\*.dll" -Destination "$(releaseFolder)"
# Build
windres icon.rc -O coff icon.res
g++ $(source) icon.res -D VERSION=\"$(version)\" -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -mwindows -o "$(releaseFolder)/$(executable).exe"
strip -s -R .comment -R .gnu.version --strip-unneeded "$(releaseFolder)/$(executable).exe"
# Create ZIP
powershell if (Test-Path $(windowsRelease)) {Remove-Item $(windowsRelease)}
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease)
# Remove folder
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
macos:
clang++ $(source) -Wall -Os -std=c++11 -ffunction-sections -fdata-sections -lSDL2 -lSDL2_mixer -o "$(executable)"
clang++ $(source) -D VERSION=\"$(version)\" -Wall -Os -std=c++11 -ffunction-sections -fdata-sections -lSDL2 -lSDL2_mixer -o "$(executable)"
macos_debug:
clang++ $(source) -D DEBUG -g -Wall -Os -std=c++11 -ffunction-sections -fdata-sections -lSDL2 -lSDL2_mixer -o "$(executable)_debug"
clang++ $(source) -D DEBUG -D VERSION=\"$(version)\" -g -Wall -std=c++11 -lSDL2 -lSDL2_mixer -o "$(executable)_debug"
macos_release:
# Remove data and possible data from previous builds
rm -rdf "$(releaseFolder)"
rm -rdf Frameworks
rm -f tmp.dmg
rm -f "$(macosIntelRelease)"
rm -f "$(macosAppleSiliconRelease)"
# Create folders
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Frameworks"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/MacOS"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Resources"
mkdir -p Frameworks
# Fem el paquetet
respak2 -p
# Copy folders
cp data.jf2 "$(releaseFolder)/$(appName).app/Contents/Resources"
cp -R bin/*.framework "$(releaseFolder)/$(appName).app/Contents/Frameworks"
cp -R bin/*.framework Frameworks
# Copy files
cp *.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
cp Info.plist "$(releaseFolder)/$(appName).app/Contents"
cp versions.txt "$(releaseFolder)"
cp README.md "$(releaseFolder)"
# Create links
ln -s /Applications "$(releaseFolder)"/Applications
# Build INTEL
clang++ $(source) -D MACOS_BUNDLE -D VERSION=\"$(version)\" -Wall -Os -std=c++11 -framework SDL2 -framework SDL2_mixer -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
# Build INTEL DMG
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
hdiutil convert tmp.dmg -format UDZO -o "$(macosIntelRelease)"
rm -f tmp.dmg
# Build APPLE SILICON
clang++ $(source) -D MACOS_BUNDLE -D VERSION=\"$(version)\" -std=c++11 -Wall -Os -framework SDL2 -framework SDL2_mixer -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
# Build APPLE SILICON DMG
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
hdiutil convert tmp.dmg -format UDZO -o "$(macosAppleSiliconRelease)"
rm -f tmp.dmg
# Remove data
rm -rdf Frameworks
rm -rdf "$(releaseFolder)"
macos_bundle:
clang++ $(source) -D MACOS_BUNDLE -Wall -Os -std=c++11 -framework SDL2 -framework SDL2_mixer -F /Library/Frameworks -ffunction-sections -fdata-sections -o mini_bundle -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
linux:
g++ $(source) -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(executable)"
g++ $(source) -D VERSION=\"$(version)\" -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(executable)"
strip -s -R .comment -R .gnu.version --strip-unneeded "$(executable)"
linux_debug:
g++ $(source) -D DEBUG -g -Wall -fvar-tracking -lSDL2 -lSDL2_mixer -o "$(executable)_debug"
g++ $(source) -D DEBUG -D VERSION=\"$(version)\" -g -Wall -fvar-tracking -lSDL2 -lSDL2_mixer -o "$(executable)_debug"
linux_release:
# Remove data
rm -rdf "$(releaseFolder)"
# Create folders
mkdir -p "$(releaseFolder)"
# Fem el paquetet
respak2 -p
# Copy data
cp data.jf2 "$(releaseFolder)"
cp versions.txt "$(releaseFolder)"
cp README.md "$(releaseFolder)"
# Build
g++ $(source) -D VERSION=\"$(version)\" -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -lSDL2 -lSDL2_mixer -o "$(releaseFolder)/$(executable)"
strip -s -R .comment -R .gnu.version --strip-unneeded "$(releaseFolder)/$(executable)"
# Pack files
rm -f "$(linuxRelease)"
cd "$(releaseFolder)" && tar -czvf "../$(linuxRelease)" *
# Remove data
rm -rdf "$(releaseFolder)"

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;
};

128
README.md Normal file
View File

@@ -0,0 +1,128 @@
# AROUNDERS
versió 1.2
![Menú del Arounders](https://php.sustancia.synology.me/images/arounders1.png)
## HISTÒRIA
Al principi dels temps l'univers era una massa concetrada de materia que va explotar i...
però avancem un poc en la història: Açò era baloo, barba peluda, el pelo pinxo i pantaló
bermuda, que se anava a menjar narantxes, se ana a dentr para hechar desmadre, però antes
se ana a fer-se un cortaet... i aixó pot ser FATAL...
## REQUERIMENTS TÈCNICS
[NOTA de 2023: Hui en dia açò va en qualsevol cosa que tinga CPU]
Aquest joc s'ha testejat en un Core2Duo 2.66GHz i 2Mb de RAM sense cap mena de problemes
Teòricament, deuria funcionar amb comps molt més xungos, pero no tinc temps ara de provar-ho.
- Targeta de só.
- Targeta de video.
- Ratolí.
- Teclat.
- Disc Dur.
- Monitor.
- Impresora (¿¿??)
OPCIONAL: Scanner, scanner!
![Una fase del Arounders](https://php.sustancia.synology.me/images/arounders2.png)
## INSTRUCCIONS
Has de dur a tots els arounders necessaris des d'una porta del nivell fins l'altra.
**Teclat**:
- **ESC**: Mostra el menú intern del joc, desde el qual pots:
- **CONTINUAR**: Continues jugant per on anaves
- **REINICIAR**: Reinicia el nivell actual
- **TORNAR AL MENU**: Pos aixó
- **EIXIR**: Eix del programa
- **P**: Pausa (tornar a apretar per a eixir de la Pausa)
**Ratolí**:
- Botó Esquerre: Seleccionar arounder / seleccionar acció
- Botó Dret: El arounder seleccionat deixa de fer el que està fent. Si te una acció en cua la executa.
- Boto del mig: Pausa
**Accions**: (ordenades d'esquerra a dreta de la barra)
- **Aroundar**:
Per defecte, no farà falta mai que apretem aquest botó. El arounder caminarà fins que
no puga seguir (i pegarà la volta) o fins la mort...
- **Parar**:
El arounder pararà de aroundar i, a més, farà pegar la volta a tots els arounders que
se li acosten. Aquesta acció es du a terme nomes pulsar el botó.
- **Cavar**:
El arounder farà un forat en la paret fins que no hi haja res més que foradar. Aquesta
acció es du a terme quan el arounder es trobe amb una paret.
- **Escalar**:
El arounder escalarà fins que arrive dalt del tot, o no puga seguir. Es dú a terme al
trobar-se una paret.
- **Perforar**:
Fà un forat en terra, fins que no puga seguir avall. Es dú a terme només pulsar el botó.
- **Escalera**:
Construeix una escalera fins que no puga seguir o s'acaven els escalons. Es dú a terme
nomes pulsar el botó.
- **Pasarela**:
Com la escalera però en horitzontal. Construeix un pont. Es dú a terme al trobar un precipici.
- **Corda**:
El arounder solta una corda desde un precipici fins a terra. Es dú a terme al trobar-se
un precipici. Tots els arounders que arriven a un precipici amb corda, baixaran per ella,
pero els que se troben baix pujaran per ella. Si pugen per el costat equivocat, cauran.
- **Suicidi**:
El arounder agarra i explota de rabia. La mort es immediata.
- **Fast Forward**:
No es una acció per al arounder seleccionat, sino que accelera la partida per a que els
arounders vagen més apresa.
Si el arounder ja està fent una acció i es pulsa en altra, es mantindrà en la cua fins que s'acave l'acció actual o s'aborte.
Si es vol anul·lar una acció en cua, es pot tornar a pulsar el botó corresponent.
Crec que tot lo demés ja parla per si sol...
## RECOMANACIONS
- El secret de la majoria dels nivells és començar bé. Deuràs tindre reflexos d'acer per a
completar els nivells !!!
- Nomes començar el nivell, apreta la pausa i mira-ho tot bé. La pausa serà una gran
aliada, ja que mentre estas en pausa pots moure el cursor.
- Els arounders no poden caure de molt alt, nomes soporten cuatre vegades la seua altura.
Un pixel de més i tindras tortilla de arounder.
- Alguns nivells es poden solventar de diverses formes, si t'atranques, prova altra forma.
Molts nivells son més facils del que pareix
- Però en altres nivells necessitaras apurar fins l'ultim pixel: Si no aconsegueixes
passar-te'l, pot ser no apures el suficient.
- Recorda que totes les accions es poden parar quan a tu t'interese pulsant el botó dret.
## BUGS & POLLS
Si trobes un polls, dis-me EXACTAMENT que has fet per a que passe. Si et dona
algun missatge d'error, apuntalo EXACTAMENT com el fica. Gracies.
Pots comunicar els polls que trobes ací: https://gitea.sustancia.synology.me/JailDoctor/arounders/issues
- La acció corda és molt sensible. Si la utilitzes, i abans del precipici hi ha un desnivell
d'uns pocs pixels, el arounder intentarà sense exit utilitzar la corda, perdent-la.
Dubtes, consultes, consells, polls, cheques al portador...
jaildoctor@gmail.com

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;
};

BIN
arounders.icns Normal file

Binary file not shown.

BIN
bin/SDL2.dll Normal file

Binary file not shown.

BIN
bin/SDL2_mixer.dll Normal file

Binary file not shown.

BIN
bin/libgcc_s_seh-1.dll Normal file

Binary file not shown.

BIN
bin/libogg-0.dll Normal file

Binary file not shown.

BIN
bin/libstdc++-6.dll Normal file

Binary file not shown.

BIN
bin/libwinpthread-1.dll Normal file

Binary file not shown.

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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -1,30 +1 @@
œ낯교말묻
쉴뉠Ч짰션
Фこ습껼
ス영렘
떽량갼읗
복Ш돌껙께
낮립쒜<EFBFBD>
뎃럇뭄뮌셈
뭍낙으꼰
무난<EFBFBD>뭇갗
섐낮엷뎅떵
뭔쓺런좋
내껑럽У뮐
<EFBFBD>객궁맏셉
껌렛떡벙
덴し<EFBFBD>신셌
<EFBFBD>뉵뮐
<EFBFBD><EFBFBD>
セこ<EFBFBD>Ц뮐
났난떱뉴늑
ЦŒ껀씔셈
<EFBFBD>윙뭄
ご맒<EFBFBD>Я뺏
괠キ뎔뉴<EFBFBD>
ご맒<EFBFBD>Ч꼰
났벱きМ<EFBFBD>
<EFBFBD>돗말뮤
<EFBFBD>Ф쓺영변
げ랭섹쨩엾
œ낯교말묻쉴뉠Ч짰션Фこ습껼ジス영렘떽량갼읗복Ш돌껙께낮립쒜<EFBFBD>뎃럇뭄뮌셈뭍낙으꼰무난<EFBFBD>뭇갗섐낮엷뎅떵뭔쓺런좋내껑럽У뮐<EFBFBD>객궁맏셉껌렛떡벙덴し<EFBFBD>신셌<EFBFBD>뉵뮐<EFBFBD><EFBFBD>セこ<EFBFBD>Ц뮐났난떱뉴늑ЦŒ껀씔셈<EFBFBD>윙뭄ご맒<EFBFBD>Я뺏괠キ뎔뉴<EFBFBD>ご맒<EFBFBD>Ч꼰났벱きМ<EFBFBD><EFBFBD>돗말뮤<EFBFBD>Ф쓺영변げ랭섹쨩엾

View File

@@ -34,3 +34,4 @@ PRINT 79 29 3 'ELS MEUS MAPES US ADORMIRE'
PRINT 79 39 3 'AMB UNA PRACTICA DE TAL!!'
ESPERAR 2000
FADEOUT
END

View File

@@ -11,3 +11,4 @@ PRINT 9 19 1 'ARA TINDREU QUE SUPERAR'
PRINT 9 29 1 '5 MAPES AMB COST EXPONENCIAL!'
ESPERAR 3000
FADEOUT
END

View File

@@ -14,3 +14,4 @@ ESPERAR 1000
PRINT 159 79 1 'SUPEREU ELS MEUS MAPES!'
ESPERAR 2000
FADEOUT
END

View File

@@ -15,3 +15,4 @@ PRINT 29 29 1 'QUE NO ELS SUPERA'
PRINT 29 39 1 'QUASI QUASI NINGU'
ESPERAR 3000
FADEOUT
END

View File

@@ -15,3 +15,4 @@ PRINT 29 29 1 'O ME COMPRAIS UNA PRECIOSA'
PRINT 29 39 1 'CHAQUETA DE CUERO O NADA DE NADA'
ESPERAR 3000
FADEOUT
END

View File

@@ -3,3 +3,4 @@ PRINT 159 19 0 'HI HA ALGU MES A QUI'
PRINT 159 29 0 'ET TENS QUE ENFRONTAR!'
ESPERAR 3000
FADEOUT
END

View File

@@ -25,7 +25,7 @@ ESPERAR 4000
FADEOUT
FADEIN 'SEQ74.GIF'
PRINT 169 119 0 'UN JOC DE'
PRINT 169 129 0 'JAILGAMES'
PRINT 169 129 0 'JAILGAMES 1999-2023'
ESPERAR 4000
SHOW 'SEQ74.GIF'
PRINT 169 99 0 'PROGRAMADOR'
@@ -52,9 +52,11 @@ PRINT 176 119 0 'CEDIR LA SEUA IMATGE'
ESPERAR 4000
SHOW 'SEQ74.GIF'
PRINT 169 119 0 'DEDICAT A'
PRINT 169 129 0 'MARIOLA I GUILLEM'
PRINT 169 129 0 'MARIOLA,'
PRINT 169 139 0 'GUILLEM I NURIA'
ESPERAR 4000
SHOW 'SEQ74.GIF'
PRINT 169 129 0 'FINS LA PROXIMA.'
ESPERAR 5000
FADEOUT
END

View File

@@ -46,3 +46,4 @@ PRINT 109 9 1 '"LA CAGAMOL!!!'
PRINT 109 16 1 'AHORAL QUE HAGOL!"'
ESPERAR 5000
FADEOUT
END

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

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();

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

1
icon.rc Normal file
View File

@@ -0,0 +1 @@
id ICON "icon.ico"

BIN
icon.res Normal file

Binary file not shown.

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;
}

56
source/aux_font.cpp Normal file
View File

@@ -0,0 +1,56 @@
#include "aux_font.h"
#include "jgame.h"
namespace font
{
static draw::surface *font1 = nullptr;
static draw::surface *font2 = nullptr;
static int mode = font::type::normal;
void init()
{
font::font1 = draw::loadSurface("fuente1.gif");
font::font2 = draw::loadSurface("fuente2.gif");
}
void selectFont(const int which)
{
font::mode = which;
}
void setColor(const int color)
{
switch (color) {
case font::color::white: draw::setPaletteEntry(63, 255, 255, 255); break;
case font::color::red: draw::setPaletteEntry(63, 255, 0, 0); break;
case font::color::green: draw::setPaletteEntry(63, 0, 255, 0); break;
case font::color::blue: draw::setPaletteEntry(63, 0, 0, 255); break;
}
}
void print(const int x, const int y, const std::string text)
{
draw::setSource(font::mode == font::type::colored ? font::font2 : font::font1);
if (font::mode == font::type::fade) for (int i=64;i<=67;++i) draw::swapcol(i, i+4);
const int len = text.length();
for (int i=0;i<len;++i)
{
char chr = text[i];
if (font::mode == font::type::colored)
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
else
draw::draw(x+i*7, y, 5, 5, (int(chr)-32)*7, 0);
}
for (int i=64;i<=67;++i) draw::restorecol(i);
}
void print(const int x, const int y, const int num)
{
const char txt[3] = { char(num/10 + 48), char(num%10 + 48), 0 };
print(x, y, txt);
}
}

28
source/aux_font.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include <string>
namespace font
{
namespace type
{
const int normal = 0;
const int colored = 1;
const int fade = 2;
}
namespace color
{
const int white = 0;
const int red = 1;
const int green = 2;
const int blue = 3;
}
void init();
void selectFont(const int which);
void setColor(const int color);
void print(const int x, const int y, const std::string text);
void print(const int x, const int y, const int num);
}

68
source/aux_textfile.cpp Normal file
View File

@@ -0,0 +1,68 @@
#include "aux_textfile.h"
#include "jgame.h"
#include <stdlib.h>
namespace textfile
{
char *buffer = nullptr;
int fsize = 0;
int p = 0;
const int toInt(std::string token)
{
int value = 0;
for (std::size_t i=0; i<token.length(); ++i)
{
if (token[i]<48 || token[i]>57) return 0;
value = (value*10) + (token[i]-48);
}
return value;
}
const bool open(std::string filename)
{
buffer = file::getFileBuffer(filename.c_str(), &fsize);
p = 0;
return true;
}
void close()
{
free(buffer);
}
std::string getNextToken()
{
char token[255];
int tpos = 0;
// Ignore whitespace
while (p<fsize && buffer[p]<=32 ) p++;
// Grab token
while (p<fsize && buffer[p]>32 ) token[tpos++]=buffer[p++];
token[tpos]=0;
return std::string(token);
}
const bool searchToken(std::string token)
{
while (p<fsize && getNextToken() != token) p++;
return p<fsize;
}
std::string getStringValue(std::string token)
{
textfile::searchToken(token);
textfile::searchToken("=");
return textfile::getNextToken();
}
const int getIntValue(std::string token)
{
return toInt(getStringValue(token));
}
}

20
source/aux_textfile.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <string>
namespace textfile
{
const int toInt(std::string token);
const bool open(std::string filename);
void close();
std::string getNextToken();
const bool searchToken(std::string token);
std::string getStringValue(std::string token);
const int getIntValue(std::string token);
}

View File

@@ -1,29 +1,37 @@
#include "gamestates.h"
#include "jgame.h"
#include "aux_font.h"
namespace gamestate
{
namespace menu
{
namespace eixir
{
const int no = 0;
const int sequence = 1;
const int password = 2;
}
draw::surface *fondo = nullptr;
draw::surface *cursor = nullptr;
int exit = 0;
bool loop();
void init()
{
exit = 0;
fondo = draw::loadSurface("menuprin.gif", true);
cursor = draw::loadSurface("cursor.gif");
menu::exit = menu::eixir::no;
menu::fondo = draw::loadSurface("menuprin.gif", true);
menu::cursor = draw::loadSurface("cursor.gif");
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING) {
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING || audio::whichMusic() != "mus3.ogg") {
audio::playMusic(audio::loadMusic("mus3.ogg"));
}
draw::setSource(fondo);
draw::draw(0,0,320,200,0,0);
font::selectFont(font::type::colored);
font::setColor(font::color::white);
draw::fadein();
game::setState(&gamestate::menu::loop);
@@ -35,8 +43,8 @@ namespace gamestate
if (!draw::isfading()) {
draw::freeSurface(fondo);
draw::freeSurface(cursor);
if (exit==1) gamestate::sequence::init();
//if (exit==2) gamestate::password::init();
if (exit==menu::eixir::sequence) gamestate::sequence::init();
if (exit==menu::eixir::password) gamestate::password::init();
}
draw::render();
return true;
@@ -44,13 +52,14 @@ namespace gamestate
const int x = input::mouseX();
const int y = input::mouseY();
draw::setTrans(255);
draw::setSource(fondo);
draw::draw(0, 0, 320, 200, 0, 0);
draw::draw(fondo);
#ifdef VERSION
font::print(277,192, VERSION);
#endif
draw::setTrans(0);
draw::setSource(cursor);
draw::draw(x, y, cursor->w, cursor->h, 0, 0);
draw::draw(x, y);
draw::render();
@@ -59,12 +68,12 @@ namespace gamestate
if (x >= 200 && y >= 100 && x <= 270 && y <= 120) {
draw::fadeout();
game::setConfig("fase", 0);
exit = 1;
exit = menu::eixir::sequence;
return true;
} else if (x >= 175 && y >= 125 && x <= 290 && y <= 145) {
draw::fadeout();
game::setConfig("fase", 0);
exit = 2;
exit = menu::eixir::password;
return true;
} else if (x >= 200 && y >= 150 && x <= 265 && y <= 170) {
return false;

75
source/gamestate_mort.cpp Normal file
View File

@@ -0,0 +1,75 @@
#include "gamestates.h"
#include "jgame.h"
namespace gamestate
{
namespace mort
{
namespace eixir
{
const int no = 0;
const int prefase = 1;
const int menu = 2;
}
draw::surface *fondo = nullptr;
draw::surface *cursor = nullptr;
int exit = 0;
bool loop();
void init()
{
exit = mort::eixir::no;
fondo = draw::loadSurface("mort.gif", true);
cursor = draw::loadSurface("cursor.gif");
audio::playMusic(audio::loadMusic("mus5.ogg"));
draw::fadein();
game::setState(&gamestate::mort::loop);
}
bool loop()
{
if (exit) {
if (!draw::isfading()) {
draw::freeSurface(fondo);
draw::freeSurface(cursor);
if (exit==mort::eixir::prefase) gamestate::prefase::init();
if (exit==mort::eixir::menu) gamestate::menu::init();
}
draw::render();
return true;
}
const int x = input::mouseX();
const int y = input::mouseY();
draw::draw(fondo);
draw::setSource(cursor);
draw::draw(x, y);
draw::render();
if (input::mouseClk(1))
{
if (x >= 100 && y >= 50 && x <= 210 && y <= 70) {
draw::fadeout();
exit = mort::eixir::prefase;
return true;
} else if (x >= 120 && y >= 72 && x <= 190 && y <= 95) {
draw::fadeout();
exit = mort::eixir::menu;
return true;
} else if (x >= 120 && y >= 95 && x <= 190 && y <= 115) {
return false;
}
}
return true;
}
}
}

View File

@@ -0,0 +1,148 @@
#include "gamestates.h"
#include "jgame.h"
#include <string>
#include "aux_font.h"
#include "proc_mapa.h"
#include <SDL2/SDL.h>
namespace gamestate
{
namespace password
{
namespace eixir
{
const int no = 0;
const int sequence = 1;
const int menu = 2;
}
// Variables del gamestate
draw::surface *fondo = nullptr;
draw::surface *cursor = nullptr;
int exit = password::eixir::no;
char password[11] = " ";
uint8_t indice = 0;
// Mètodes del gamestate
bool loop();
const int getFaseFromPassword();
void init()
{
exit = password::eixir::no;
for (int i=0; i<10; ++i) password[i] = 32;
password[10] = 0;
indice = 0;
// Carrega el gif del fondo
fondo = draw::loadSurface("prefase.gif", true);
cursor = draw::loadSurface("cursor.gif");
// Pinta el text en el fondo
draw::setDestination(fondo);
font::selectFont(font::type::normal);
font::print(95, 80, "ESCRIU EL PASSWORD");
draw::setDestination(nullptr);
// Comencem el bucle
draw::fadein();
game::setState(gamestate::password::loop);
}
bool loop()
{
draw::draw(fondo);
font::print(123, 140, password);
draw::setSource(cursor);
draw::draw(input::mouseX(), input::mouseY());
draw::render();
if (draw::isfading()) return true;
if (exit)
{
if (!draw::isfading()) {
draw::freeSurface(fondo);
draw::freeSurface(cursor);
if (exit==password::eixir::sequence) gamestate::sequence::init();
if (exit==password::eixir::menu) gamestate::menu::init();
}
draw::render();
return true;
}
if (input::anyKeyPressed())
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
{
draw::fadeout();
game::setConfig("fase", 0);
exit = password::eixir::menu;
return true;
}
else if (input::keyPressed(SDL_SCANCODE_BACKSPACE))
{
if (indice>0) password[--indice] = 32;
}
else
{
const uint8_t tecla = input::getKeyPressed();
if (tecla == SDL_SCANCODE_0) {
password[indice++] = '0';
}
else if (tecla >= SDL_SCANCODE_1 && tecla <= SDL_SCANCODE_9)
{
password[indice++] = tecla + 18;
}
else if (tecla >= SDL_SCANCODE_A && tecla <= SDL_SCANCODE_Z)
{
password[indice++] = tecla + 61;
}
if (indice == 10)
{
draw::fadeout();
game::setConfig("fase", password::getFaseFromPassword());
exit = password::eixir::sequence;
return true;
}
}
}
return true;
}
const int getFaseFromPassword()
{
password[10] = 0;
int filesize = 0;
const char *buffer = file::getFileBuffer("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++) {
passFile[i] = buffer[punter++] - (101+i);
}
salir = true;
for (int i=0;i<10;i++) {
if (passFile[i] != password[i]) salir = false;
}
numPassword++;
}
if (!salir) numPassword = 0;
return numPassword;
}
}
}

View File

@@ -1,54 +1,360 @@
#include "gamestates.h"
#include "jgame.h"
#include <SDL2/SDL.h>
#include <string>
#include "aux_font.h"
#include "proc_mapa.h"
#include "proc_arounders.h"
namespace gamestate
{
namespace play
{
draw::surface *fondo = nullptr;
draw::surface *mapa = nullptr;
namespace eixir
{
const int no = 0;
const int postfase = 1;
const int mort = 2;
}
void carregarMapa();
draw::surface *faded = nullptr;
draw::surface *fondo = nullptr;
draw::surface *cursor = nullptr;
draw::surface *aigua = nullptr;
uint32_t *original_palette = nullptr;
uint32_t arounderCount;
uint32_t startTicks;
uint32_t currentTicks;
int aigua_frame1 = 0;
int aigua_frame2 = 5;
int exit = 0;
bool loop();
bool loop_pause();
bool loop_menu();
void backToLoop();
void draw();
void draw_aigua();
void finalize();
void init()
{
// Ara comença tot, per tant no volem eixir
play::exit = play::eixir::no;
// Carregar el fondo que toque i la seua paleta (que nomes usa els colors del 128 al 255)
char arxiuFondo[10] = "BKG00.GIF";
arxiuFondo[4] = (game::getConfig("fase") % 10) + 48;
fondo = draw::loadSurface(arxiuFondo, true);
play::fondo = draw::loadSurface(arxiuFondo, true);
// Carregar la paleta estandar
// Carregar la paleta estandar (colors del 0 al 128)
uint32_t *pal = draw::loadPalette("tiles.gif");
draw::setPalette(pal, 128);
free(pal);
// [TODO] Carreagar la resta de gifs que facen falta
//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");
// Carregar els gifs auxiliars i crear la superficie per al fondo de la pausa i el menu
play::cursor = draw::loadSurface("cursor.gif");
play::aigua = draw::loadSurface("aigua.gif");
play::faded = draw::createSurface(320, 200);
// [TODO] CREAR AIGUA PROCESSOR
// [TODO] CREAR MARCADOR PROCESSOR
arounders::init();
// [TODO] Crear el primer Arounder
// REALMENT NO. PREFEREIXC QUE PASEN UNS SEGONS ABANS QUE ARRIBE EL PRIMER
// mapa::arounders::eixits++;
// arounder_seleccionat = primerArounders
carregarMapa();
// Enxufa el arradio
audio::loadMusic((game::getConfig("fase")+1) % 5 == 0 ? "mus6.ogg" : "mus4.ogg");
audio::playMusic();
// Fiquem a contar el cronómetre de arounders
play::arounderCount = play::startTicks = game::getTicks();
// Fade in i anem al bucle principal
draw::fadein();
game::setState(gamestate::play::loop);
}
void carregarMapa()
bool loop()
{
FILE *f = file::getFilePointer("mapes.txt");
// Si ja s'ha demanat l'eixida...
if (play::exit) {
// I si ja s'ha acabat el fadeout...
if (!draw::isfading()) {
// Alliberem memòria
play::finalize();
const int fase = game::getConfig("fase");
int val;
do {
fscanf(f, "LEVEL %i", &val);
} while (val != fase);
// I anem on toque
if (play::exit==play::eixir::postfase) gamestate::postfase::init();
else if (play::exit==play::eixir::mort) gamestate::mort::init();
}
// En qualsevol cas, renderitzem i eixim ja del bucle (fins que acabe el fadeout)
draw::render();
return true;
}
int tileset=0;
fscanf(f, "tileset = %i", &tileset);
// Pintar tot menys el cursor
play::draw();
// Si se pulsa 'P', o el botó del mig del ratolí, o si la finestra perd el foco...
if (input::keyPressed(SDL_SCANCODE_P) || input::mouseClk(input::mouse::button::middle) || !game::windowHasFocus)
{
// Parem el cronòmetre d'arounders
play::arounderCount = game::getTicks() - play::arounderCount;
// Pintem el que hi ha a la pantalla en la surface "faded", li afegim el text "PAUSA" i aixó es tot el que pintarem fins eixir de la pausa
draw::setSource(nullptr);
draw::setDestination(play::faded);
draw::draw();
font::selectFont(font::type::fade);
font::print(136, 80, "PAUSA");
draw::setDestination(nullptr);
// Reduïm tots els colors de la paleta (menys els epecials) a la meitat del seu color
play::original_palette = draw::getPalette();
for (int i=0; i<256; ++i) if ( i!=61 && i!= 62 && (i<68 || i >75) )
{
uint32_t p = play::original_palette[i];
uint8_t r = (p >> 16) & 0xff;
uint8_t g = (p >> 8) & 0xff;
uint8_t b = p & 0xff;
draw::setPaletteEntry(i, r >> 1, g >> 1, b >> 1);
}
// Canviem el bucle principal a "loop_pausa()"
game::setState(gamestate::play::loop_pause);
return true;
}
// Si se pulsa ESC...
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
{
// Parem el cronòmetre d'arounders
play::arounderCount = game::getTicks() - play::arounderCount;
// Pintem el que hi ha a la pantalla en la surface "faded", li afegim el menú i aixó es tot el que pintarem fins eixir del menú
draw::setSource(nullptr);
draw::setDestination(play::faded);
draw::draw();
draw::surface *menu = draw::loadSurface("menu.gif");
draw::setSource(menu);
draw::draw(97, 52);
draw::freeSurface(menu);
font::selectFont(font::type::fade);
font::print(129, 60, "CONTINUAR");
font::print(129, 71, "REINICIAR");
font::print(112, 82, "MENU PRINCIPAL");
font::print(143, 93, "EIXIR");
draw::setDestination(nullptr);
// Reduïm tots els colors de la paleta (menys els epecials) a la meitat del seu color
play::original_palette = draw::getPalette();
for (int i=0; i<256; ++i) if ( i!=61 && i!= 62 && (i<68 || i >75) )
{
uint32_t p = play::original_palette[i];
uint8_t r = (p >> 16) & 0xff;
uint8_t g = (p >> 8) & 0xff;
uint8_t b = p & 0xff;
draw::setPaletteEntry(i, r >> 1, g >> 1, b >> 1);
}
// Canviem el bucle principal a "loop_menu()"
game::setState(gamestate::play::loop_menu);
return true;
}
// Ara ja, pintem el cursor i enviem tot a pantalla
// No ho havem fet abans perque en el fondo de la pausa o el menú no volem que aparega el cursor
draw::setSource(cursor);
draw::draw(input::mouseX(), input::mouseY());
draw::render();
// Si pulsem el botó de la dreta, el arounder seleccionat deixa de fer l'acció que està fent
if (input::mouseClk(input::mouse::button::right))
{
arounders::abortarAccio();
}
if (input::mouseClk(input::mouse::button::left))
{
if (!arounders::seleccionar())
{
if (input::mouseY()<165 && arounders::seleccionat != nullptr && arounders::seleccionat->accio == arounders::accions::caminar)
{
arounders::seleccionat->orientacio = input::mouseX() > arounders::seleccionat->x ? arounders::orientacions::dreta : arounders::orientacions::esquerra;
}
}
const int botoPulsat = mapa::procesar();
if (botoPulsat != -1 && arounders::seleccionat != nullptr)
{
if (botoPulsat == arounders::seleccionat->prevista) {
arounders::seleccionat->prevista = arounders::seleccionat->accio;
} else {
arounders::seleccionat->prevista = botoPulsat;
}
}
}
currentTicks = game::getTicks() - startTicks;
if( currentTicks >= mapa::velocitat ) {
startTicks = game::getTicks();
aigua_frame1 = (aigua_frame1+1)%10;
aigua_frame2 = (aigua_frame2+1)%10;
arounders::procesar();
}
if ( (game::getTicks() - arounderCount) >= mapa::velocitat*58) {
if (mapa::arounders::eixits < mapa::arounders::totals) {
arounders::afegir();
mapa::arounders::eixits++;
arounderCount = game::getTicks();
}
}
if (mapa::arounders::arrivats + mapa::arounders::morts == mapa::arounders::totals) {
if (mapa::arounders::arrivats >= mapa::arounders::necessaris) {
game::setConfig("fase", game::getConfig("fase")+1);
draw::fadeout();
audio::fadeoutMusic();
play::exit = 1;
} else {
draw::fadeout();
audio::fadeoutMusic();
play::exit = 2;
}
}
return true;
}
bool loop_pause()
{
draw::draw(faded);
draw::setSource(cursor);
draw::draw(input::mouseX(), input::mouseY());
draw::render();
if (input::keyPressed(SDL_SCANCODE_P) || input::keyPressed(SDL_SCANCODE_ESCAPE))
{
play::backToLoop();
}
return true;
}
bool loop_menu()
{
if (play::exit) {
if (!draw::isfading()) {
play::finalize();
if (exit==1) {
mapa::carregar();
gamestate::play::init();
}
if (exit==2) gamestate::menu::init();
}
draw::render();
return true;
}
draw::draw(faded);
draw::setSource(cursor);
draw::draw(input::mouseX(), input::mouseY());
draw::render();
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
{
play::backToLoop();
}
if (input::mouseClk(input::mouse::button::left))
{
if (input::mouseX() >= 97 && input::mouseX() <= 223) {
if (input::mouseY() >= 60 && input::mouseY() <= 65) {
play::backToLoop();
}
if (input::mouseY() >= 71 && input::mouseY() <= 76) {
free(play::original_palette);
draw::fadeout();
audio::fadeoutMusic();
play::exit = 1;
}
if (input::mouseY() >= 82 && input::mouseY() <= 87) {
free(play::original_palette);
draw::fadeout();
audio::fadeoutMusic();
play::exit = 2;
}
if (input::mouseY() >= 93 && input::mouseY() <= 98) {
return false;
}
}
}
return true;
}
void backToLoop()
{
draw::setPalette(play::original_palette, 256);
free(play::original_palette);
game::setState(gamestate::play::loop);
arounderCount = game::getTicks() - arounderCount;
}
void draw()
{
draw::draw(play::fondo);
fclose(f);
int accio = 0;
int prevista = 0;
if (arounders::seleccionat) { accio = arounders::seleccionat->accio; prevista = arounders::seleccionat->prevista; }
mapa::pintar(accio, prevista);
draw_aigua();
arounders::pintar();
// [TODO] de fet, pintar la marca en el modul "arounders"
/*
if (arounders::seleccionat) {
draw::setSource(marca);
draw::draw(arounderSeleccionat->X-3, arounderSeleccionat->Y-3);
}
*/
}
void draw_aigua()
{
static int frames1[10] = {0,1,2,1,0,3,4,5,4,3};
static int frames2[10] = {6,7,8,7,6,9,10,11,10,9};
int *frames;
frames = (game::getConfig("fase")+1) % 5 == 0 ? frames2 : frames1;
draw::setSource(aigua);
for (int i=0;i<10;i++) {
draw::draw(i*32, 150, 16, 15, frames[aigua_frame1]*16, 0);
draw::draw(16+i*32, 150, 16, 15, frames[aigua_frame2]*16, 0);
}
}
void finalize()
{
draw::freeSurface(faded);
draw::freeSurface(fondo);
draw::freeSurface(cursor);
draw::freeSurface(aigua);
}
}
}

View File

@@ -1,87 +1,74 @@
#include "gamestates.h"
#include "jgame.h"
#include <string>
#define POSTFASE_INITIAL 0
#define POSTFASE_VICTORIA 1
#define POSTFASE_PASSWORD 2
#include "aux_font.h"
namespace gamestate
{
namespace postfase
{
namespace state
{
const int initial = 0;
const int victoria = 1;
const int password = 2;
}
// Variables del gamestate
static int sub_state = POSTFASE_INITIAL;
static int sub_state = postfase::state::initial;
void init_victoria();
void init_password();
void initVictoria();
void initPassword();
bool loop();
void drawText(const int x, const int y, const uint8_t color, std::string text);
char *ObtenerPasswordDeFase();
std::string getPassword();
void init()
{
sub_state = POSTFASE_INITIAL;
sub_state = postfase::state::initial;
if (game::getConfig("fase") == 30) {
gamestate::sequence::init();
return;
} else {
audio::loadMusic("mus3.mp3");
audio::loadMusic("mus3.ogg");
audio::playMusic();
}
if (game::getConfig("fase") % 5 == 0) {
gamestate::postfase::init_victoria();
gamestate::postfase::initVictoria();
} else {
gamestate::postfase::init_password();
gamestate::postfase::initPassword();
}
}
void init_victoria()
void initVictoria()
{
sub_state = POSTFASE_VICTORIA;
draw::surface *fondo = nullptr;
sub_state = postfase::state::victoria;
switch (game::getConfig("fase")) {
case 5:
fondo = draw::loadSurface("final01.GIF", true);
break;
case 10:
fondo = draw::loadSurface("final02.GIF", true);
break;
case 15:
fondo = draw::loadSurface("final03.GIF", true);
break;
case 20:
fondo = draw::loadSurface("final04.GIF", true);
break;
case 25:
fondo = draw::loadSurface("final05.GIF", true);
break;
}
draw::setSource(fondo);
draw::draw(0,0,320,200,0,0);
char filename[12] = "final00.GIF";
filename[6]= 48 + (game::getConfig("fase") / 5);
draw::surface *fondo = draw::loadSurface(filename, true);
draw::draw(fondo);
draw::freeSurface(fondo);
draw::fadein();
game::setState(gamestate::postfase::loop);
}
void init_password()
void initPassword()
{
sub_state = POSTFASE_PASSWORD;
sub_state = postfase::state::password;
std::string password = getPassword();
draw::surface *fondo = draw::loadSurface("postfase.gif", true);
char *password = ObtenerPasswordDeFase();
draw::setSource(fondo);
draw::draw(0,0,320,200,0,0);
draw::draw(fondo);
draw::freeSurface(fondo);
drawText(175, 166, 1, password);
free(password);
font::selectFont(font::type::colored);
font::setColor(font::color::red);
font::print(175, 166, password);
draw::fadein();
game::setState(gamestate::postfase::loop);
@@ -98,8 +85,8 @@ namespace gamestate
if (salir)
{
salir = false;
if (sub_state == POSTFASE_VICTORIA) {
gamestate::postfase::init_password();
if (sub_state == postfase::state::victoria) {
gamestate::postfase::initPassword();
} else {
gamestate::sequence::init();
}
@@ -115,41 +102,15 @@ namespace gamestate
return true;
}
void drawText(const int x, const int y, const uint8_t color, std::string text)
std::string getPassword()
{
draw::surface *pic = draw::loadSurface("fuente2.gif");
draw::setSource(pic);
draw::setTrans(0);
switch (color) {
case 0: draw::setPaletteEntry(63, 255, 255, 255); break;
case 1: draw::setPaletteEntry(63, 255, 0, 0); break;
case 2: draw::setPaletteEntry(63, 0, 255, 0); break;
case 3: draw::setPaletteEntry(63, 0, 0, 255); break;
}
const int len = text.length();
for (int i=0;i<len;++i)
{
char chr = text[i];
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
}
draw::setTrans(255);
draw::freeSurface(pic);
draw::render();
}
char *buffer = file::getFileBuffer("offsets.bal");
char *ObtenerPasswordDeFase()
{
int filesize = 0;
const char *buffer = file::getFileBuffer("offsets.bal", &filesize);
int punter = (game::getConfig("fase")-1)*11;
char *passFile = (char*)malloc(11);
for (int i=0;i<10;i++) {
punter++;
passFile[i] = uint8_t(buffer[punter]) - (101+i);
}
int punter = (game::getConfig("fase")-1)*10;
char passFile[11];
for (int i=0;i<10;i++) passFile[i] = uint8_t(buffer[punter++]) - (101+i);
passFile[10] = 0;
free(buffer);
return passFile;
}

View File

@@ -1,6 +1,8 @@
#include "gamestates.h"
#include "jgame.h"
#include <string>
#include "aux_font.h"
#include "proc_mapa.h"
namespace gamestate
{
@@ -9,30 +11,35 @@ namespace gamestate
// Variables del gamestate
draw::surface *fondo = nullptr;
draw::surface *cursor = nullptr;
draw::surface *font = nullptr;
uint8_t num_arounders = 0;
uint8_t arounders_necessaris = 0;
// Mètodes del gamestate
void carregarMapa();
std::string formatejar(const int numero);
void drawText(const int x, const int y, std::string text);
bool loop();
void init()
{
// Carrega el gif del fondo
fondo = draw::loadSurface("prefase.gif", true);
cursor = draw::loadSurface("cursor.gif");
font = draw::loadSurface("fuente1.gif");
//int size=0;
//uint32_t *font_pal = draw::loadPalette("fuente1.gif", &size);
//draw::setPalette(font_pal+1, 5, 80);
// Carrega el mapa
mapa::carregar();
carregarMapa();
// Pinta el text en el fondo
draw::setDestination(fondo);
font::selectFont(font::type::normal);
font::print(130, 60, "NIVELL");
font::print(179, 60, game::getConfig("fase")+1);
font::print(80, 100, mapa::arounders::totals);
font::print(101, 100, "AROUNDERS DISPONIBLES");
font::print(80, 110, mapa::arounders::necessaris);
font::print(101, 110, "AROUNDERS NECESSARIS");
draw::setDestination(nullptr);
// Comencem el bucle
draw::fadein();
game::setState(gamestate::prefase::loop);
}
@@ -41,27 +48,10 @@ namespace gamestate
{
static bool salir = false;
const int x = input::mouseX();
const int y = input::mouseY();
draw::setTrans(255);
draw::setSource(fondo);
draw::draw(0, 0, 320, 200, 0, 0);
draw::setTrans(0);
draw::setSource(font);
drawText(130, 60, "NIVELL");
drawText(179, 60, formatejar(game::getConfig("fase")+1));
drawText(80, 100, formatejar(num_arounders));
drawText(101, 100, "AROUNDERS DISPONIBLES");
drawText(80, 110, formatejar(arounders_necessaris));
drawText(101, 110, "AROUNDERS NECESSARIS");
draw::draw(fondo);
draw::setSource(cursor);
draw::draw(x, y, cursor->w, cursor->h, 0, 0);
draw::draw(input::mouseX(), input::mouseY());
draw::render();
@@ -83,49 +73,5 @@ namespace gamestate
return true;
}
void carregarMapa()
{
int filesize = 0;
char *buffer = file::getFileBuffer("MAPES.BAL", &filesize);
char *punter = buffer + (game::getConfig("fase") * 212) + 3;
num_arounders = *(punter++);
arounders_necessaris = *punter;
free(buffer);
}
std::string formatejar(const int numero)
{
char resultat[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 std::string(resultat);
}
void drawText(const int x, const int y, std::string text)
{
draw::setSource(font);
draw::setTrans(0);
//for (int i=1;i<=5;++i) draw::swapcol(i, 79+i);
const int len = text.length();
for (int i=0;i<len;++i)
{
char chr = text[i];
draw::draw(x+i*7, y, 5, 5, (int(chr)-32)*7, 0);
}
//for (int i=1;i<=5;++i) draw::restorecol(i);
}
}
}

View File

@@ -2,14 +2,7 @@
#include "jgame.h"
#include <string>
#include <SDL2/SDL.h>
#define DIAPO_ESPERAR 0
#define DIAPO_FADEIN 1
#define DIAPO_SHOW 2
#define DIAPO_PRINT 3
#define DIAPO_MUSICA 4
#define DIAPO_FADEOUT 5
#define DIAPO_FADEMUSIC 6
#include "aux_font.h"
namespace gamestate
{
@@ -19,17 +12,15 @@ namespace gamestate
uint32_t wait_until = 0;
void drawPic(std::string filename);
void drawText(const int x, const int y, const uint8_t color, std::string text);
bool loop();
void init()
{
draw::setTrans(255);
const int fase = game::getConfig("fase");
font::selectFont(font::type::colored);
std::string filename;
switch (fase)
switch (game::getConfig("fase"))
{
case -1: filename = "seqIN.txt"; break;
case 0: filename = "seq00.txt"; break;
@@ -39,11 +30,10 @@ namespace gamestate
case 20: filename = "seq20.txt"; break;
case 25: filename = "seq25.txt"; break;
case 30: filename = "seq30.txt"; break;
default: gamestate::prefase::init();
default: gamestate::prefase::init(); return; break;
}
int filesize;
sequence_file = file::getFilePointer(filename, &filesize);
sequence_file = file::getFilePointer(filename);
game::setState(&gamestate::sequence::loop);
}
@@ -54,6 +44,7 @@ namespace gamestate
draw::render();
return true;
}
if ( (wait_until > 0) && (SDL_GetTicks() < wait_until) )
{
if (input::anyKeyPressed() || input::mouseBtn(1)) {
@@ -87,30 +78,25 @@ namespace gamestate
std::string command(text);
if (command=="ESPERAR") {
//int res =
fscanf(sequence_file, "%i", &val);
printf("ESPERAR %i\n", val);
wait_until = SDL_GetTicks() + val;
} else if (command=="FADEIN") {
//int res =
fscanf(sequence_file, " '%[^']'", text);
drawPic(text);
draw::fadein();
} else if (command=="SHOW") {
//int res =
fscanf(sequence_file, " '%[^']'", text);
drawPic(text);
draw::render();
} else if (command=="PRINT") {
//int res =
fscanf(sequence_file, " %i %i %i '%[^']'", &x, &y, &val, text);
drawText(x, y, val, text);
font::setColor(val);
font::print(x, y, text);
} else if (command=="PLAYMUSIC") {
//int res =
fscanf(sequence_file, " '%[^']'", text);
audio::loadMusic(text);
audio::playMusic();
@@ -121,6 +107,16 @@ namespace gamestate
} else if (command=="FADEOUTMUSIC") {
draw::fadeout();
audio::fadeoutMusic();
} else if (command=="END") {
fclose(sequence_file);
const int fase = game::getConfig("fase");
if ( fase == -1 || fase == 30) {
gamestate::menu::init();
} else {
gamestate::prefase::init();
}
return true;
}
}
}
@@ -130,32 +126,9 @@ namespace gamestate
void drawPic(std::string filename)
{
draw::surface *pic = draw::loadSurface(filename, true);
draw::setSource(pic);
draw::draw(0, 0, 320, 200, 0, 0);
draw::draw(pic);
draw::freeSurface(pic);
}
void drawText(const int x, const int y, const uint8_t color, std::string text)
{
draw::surface *pic = draw::loadSurface("fuente2.gif");
draw::setSource(pic);
draw::setTrans(0);
switch (color) {
case 0: draw::setPaletteEntry(63, 255, 255, 255); break;
case 1: draw::setPaletteEntry(63, 255, 0, 0); break;
case 2: draw::setPaletteEntry(63, 0, 255, 0); break;
case 3: draw::setPaletteEntry(63, 0, 0, 255); break;
}
const int len = text.length();
for (int i=0;i<len;++i)
{
char chr = text[i];
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
}
draw::setTrans(255);
draw::freeSurface(pic);
draw::render();
}
}
}

View File

@@ -7,4 +7,6 @@ namespace gamestate
namespace prefase { void init(); }
namespace play { void init(); }
namespace postfase { void init(); }
namespace mort { void init(); }
namespace password { void init(); }
}

View File

@@ -15,6 +15,7 @@ namespace audio
static char *buffer = nullptr;
static Mix_Music *music = nullptr;
static std::string music_filename = "";
// Inicialitza el sistema de só
void init()
@@ -47,6 +48,7 @@ namespace audio
if (music==nullptr) return false;
music_filename = filename;
return true;
}
@@ -99,6 +101,12 @@ namespace audio
}
}
// Obté el nom de l'arxiu de música actual
std::string whichMusic()
{
return music_filename;
}
// Carrega un só des d'un arxiu WAV
const sound *loadSound(const std::string filename)
{

View File

@@ -55,6 +55,10 @@ namespace audio
/// @return estat actual de la música (MUSIC_INVALID, MUSIC_PLAYING, MUSIC_PAUSED o MUSIC_STOPPED)
const music_state getMusicState();
/// @brief Obté el nom de l'arxiu de música actual
/// @return el nom de l'arxiu
std::string whichMusic();
/// @brief Carrega un só des d'un arxiu WAV
/// @param filename nom de l'arxiu
/// @return un punter al só

View File

@@ -252,6 +252,14 @@ namespace draw
}
}
//Recupera la paleta del sistema, o part de ella, a un array
uint32_t *getPalette()
{
uint32_t *p = (uint32_t*)malloc(256*sizeof(uint32_t));
for (int i=0; i<256; ++i) p[i] = palette[i];
return p;
}
// Estableix una entrada de la paleta del sistema
void setPaletteEntry(const uint8_t index, const uint8_t r, const uint8_t g, const uint8_t b)
{
@@ -307,6 +315,11 @@ namespace draw
return 0;
}
void putPixel(const int x, const int y, const uint8_t color)
{
pset(screen, x, y, color);
}
// Pinta un troç de la superficie "source" en la superficie "destination".
void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip)
{
@@ -351,6 +364,25 @@ namespace draw
}
}
// Pinta tota la superficie "source" en la superficie "destination", posició (x,y).
void draw(const int x, const int y)
{
draw(x, y, source->w, source->h, 0, 0);
}
// Pinta tota la superficie "source" en la superficie "destination", posició (0,0)
void draw()
{
draw(0,0,source->w, source->h, 0, 0);
}
// Carrega la superficie especificada en "source" i la pinta tota en la superficie "destination", posició (0,0).
void draw(draw::surface* surf)
{
setSource(surf);
draw();
}
void swapcol(const Uint8 c1, const Uint8 c2)
{
color_indices[c1] = c2;

View File

@@ -75,6 +75,10 @@ namespace draw
/// @param pos des de quina posició de la paleta de sistema comencem a copiar
void setPalette(const uint32_t *pal, const int len, const int pos=0);
/// @brief Recupera la paleta del sistema, o part de ella, a un array
/// @return un array de uint32_t
uint32_t *getPalette();
/// @brief Estableix una entrada de la paleta del sistema
/// @param index l'index de l'entrada de la paleta
/// @param r la component roja de l'entrada de la paleta
@@ -90,6 +94,8 @@ namespace draw
/// @param color color a usar com a transparent
void setTrans(const uint8_t color);
void putPixel(const int x, const int y, const uint8_t color);
/// @brief Pinta un troç de la superficie "source" en la superficie "destination".
/// @param dx coordenada x de la destinació
/// @param dy coordenada y de la destinació
@@ -100,6 +106,17 @@ namespace draw
/// @param flip si s'ha de fer flip en hortizontal o vertical (o ambdos)
void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip = DRAW_FLIP_NONE);
/// @brief Pinta tota la superficie "source" en la superficie "destination", posició (x,y).
/// @param x coordenada x de la destinació
/// @param y coordenada y de la destinació
void draw(const int x, const int y);
/// @brief Pinta tota la superficie "source" en la superficie "destination", posició (0,0).
void draw();
/// @brief Carrega la superficie especificada en "source" i la pinta tota en la superficie "destination", posició (0,0).
void draw(draw::surface* surf);
void swapcol(const uint8_t c1, const uint8_t c2);
void restorecol(const uint8_t c);
void color(const uint8_t col);

View File

@@ -104,8 +104,8 @@ namespace file
// Variables
// ===============================================================================================================================
static std::string resource_filename = ""; // Nom de l'arxiu de recursos
static std::string resource_folder = ""; // Nom de la carpeta de recursos
static std::string resource_filename = DEFAULT_FILENAME; // Nom de l'arxiu de recursos
static std::string resource_folder = DEFAULT_FOLDER; // Nom de la carpeta de recursos
static int file_source = SOURCE_FILE; // D'on anem a pillar els recursos, arxiu o carpeta
static std::string config_folder; // Nom de la carpeta on guardar la configuració
std::vector<keyvalue_t> config; // Vector amb els valors guardats a l'arxiu de configuració
@@ -131,7 +131,7 @@ namespace file
file_source = src % 2; // mod 2 de forma que sempre es un valor vàlid, 0 (arxiu) o 1 (carpeta)
// Si volem que busque en carpeta i encara no haviem especificat una carpeta, usem la per defecte
if (src == SOURCE_FOLDER && resource_folder == "")
if (/*src == SOURCE_FOLDER && */resource_folder == "")
{
setResourceFolder(DEFAULT_FOLDER);
}
@@ -165,7 +165,7 @@ namespace file
// Per a cada arxiu inclos en l'arxiu de recursos...
for (unsigned int i = 0; i < num_files; ++i)
{
// Llegim en quina posició està i quant copua
// Llegim en quina posició està i quant ocupa
uint32_t file_offset, file_size;
fi.read((char *)&file_offset, 4);
fi.read((char *)&file_size, 4);
@@ -192,6 +192,77 @@ namespace file
}
}
// Obté un "std::ifstream" al arxiu que se li demana, independentment de la font (arxius individual en carpeta, o arxiu de recursos)
std::ifstream getFileStream(const std::string resourcename, int *filesize, const bool binary)
{
// Si tenim configurat agafar els recursos de arxiu, pero encara no tenim la taula de continguts carregada...
if (file_source == SOURCE_FILE and toc.size() == 0)
{
// Si fallem al intentar carregar la taula de continguts de l'arxiu de recursos, canviem a pillar els recursos de carpeta
if (not getTableOfContents())
{
setSource(SOURCE_FOLDER);
}
}
std::ifstream f;
// Si estem pillant els recursos de un arxiu de recursos...
if (file_source == SOURCE_FILE)
{
// Busquem el recurs en la taula de continguts usant la ruta
bool found = false;
uint32_t count = 0;
while (!found && count < toc.size())
{
found = (resource_folder + resourcename == toc[count].path);
if (!found)
{
count++;
}
}
// Si no trobem el recurs, petem el mame
if (!found)
{
printf("ERROR FATAL: No s'ha trobat el recurs '%s' a l'arxiu de recursos '%s'\n", resourcename.c_str(), resource_filename.c_str());
exit(1);
}
// Agafem el tamany del recurs de la taula de continguts
if (filesize) *filesize = toc[count].size;
// obrim l'arxiu de recursos
f.open(resource_filename.c_str(), binary ? std::ios::binary : std::ios::in);
if (!f.is_open()) // En el raruno cas de que a este altures pete al obrir el arxiu de recursos, petem el mame
{
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu de recursos '%s'\n", resource_filename.c_str());
exit(1);
}
// Anem a la posició on està el recurs que volem. Amb açò "f" ja està preparat per a ser tornar.
// Ojo, realment estic tornant un FILE* al arxiu de recursos, pero ja apuntant al moment en que comença el recurs que volem.
// Ho dic perque si fem fseek(f, 0, SEEK_SET) tornarà al principi de l'arxiu de recursos, no del recurs. Tindre-ho en compte.
f.seekg(toc[count].offset);
}
else
{
// Si estem pillant els recursos de carpeta, simplement obrim el arxiu en questió i tornem el FILE* associat.
f.open((resource_folder + resourcename), binary ? std::ios::binary : std::ios::in);
if (f.rdstate() & std::ios_base::failbit)
{
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu '%s/%s'\n", resource_folder.c_str(), resourcename.c_str());
exit(1);
}
f.seekg(0, std::ios_base::end);
if (filesize) *filesize = f.tellg();
f.seekg(0, std::ios_base::beg);
}
// Tornar el punter FILE* al arxiu. OJO! Tenim que tancar-lo quan acabem amb ell
return f;
}
// Obté un "FILE*" al arxiu que se li demana, independentment de la font (arxius individual en carpeta, o arxiu de recursos)
FILE *getFilePointer(const std::string resourcename, int *filesize, const bool binary)
{
@@ -215,7 +286,7 @@ namespace file
uint32_t count = 0;
while (!found && count < toc.size())
{
found = (resourcename == toc[count].path);
found = (resource_folder + resourcename == toc[count].path);
if (!found)
{
count++;
@@ -225,8 +296,7 @@ namespace file
// Si no trobem el recurs, petem el mame
if (!found)
{
// [TODO] Donar mes informació de quin recurs no havem trobat
perror("El recurs no s'ha trobat en l'arxiu de recursos");
printf("ERROR FATAL: No s'ha trobat el recurs '%s' a l'arxiu de recursos '%s'\n", resourcename.c_str(), resource_filename.c_str());
exit(1);
}
@@ -237,8 +307,7 @@ namespace file
f = fopen(resource_filename.c_str(), binary ? "rb" : "r");
if (!f) // En el raruno cas de que a este altures pete al obrir el arxiu de recursos, petem el mame
{
// [TODO] Donar mes informació de quin recurs no havem trobat
perror("No s'ha pogut obrir l'arxiu de recursos");
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu de recursos '%s'\n", resource_filename.c_str());
exit(1);
}
@@ -251,6 +320,12 @@ namespace file
{
// Si estem pillant els recursos de carpeta, simplement obrim el arxiu en questió i tornem el FILE* associat.
f = fopen((resource_folder + resourcename).c_str(), binary ? "rb" : "r");
if(!f)
{
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu '%s/%s'\n", resource_folder.c_str(), resourcename.c_str());
exit(1);
}
fseek(f, 0, SEEK_END);
if (filesize) *filesize = ftell(f);
fseek(f, 0, SEEK_SET);

View File

@@ -1,5 +1,6 @@
#pragma once
#include <stdio.h>
#include <fstream>
#include <string>
#define SOURCE_FILE 0
@@ -23,6 +24,13 @@ namespace file
/// @param src SOURCE_FILE o SOURCE_FOLDER, si es vol que se pillen recursos de arxiu o de carpeta
void setSource(const int src);
/// @brief Obté un "std::ifstream" al arxiu que se li demana, independentment de la font (arxius individual en carpeta, o arxiu de recursos). Recordar tancar-lo al acabar amb ell.
/// @param resourcename el nom de l'arxiu que volem obrir
/// @param filesize paràmetre de retorn. Ací es torna el tamany de l'arxiu
/// @param binary si volem obrir el arxiu en format binary
/// @return un std::ifstream al arxiu
std::ifstream getFileStream(const std::string resourcename, int *filesize = nullptr, const bool binary = false);
/// @brief Obté un "FILE*" al arxiu que se li demana, independentment de la font (arxius individual en carpeta, o arxiu de recursos). Recordar tancar-lo al acabar amb ell.
/// @param resourcename el nom de l'arxiu que volem obrir
/// @param filesize paràmetre de retorn. Ací es torna el tamany de l'arxiu

View File

@@ -6,6 +6,8 @@
namespace game
{
bool windowHasFocus = true;
static bool (*loop)() = nullptr;
static unsigned int ticks_per_frame = 1000/60;
static std::map<std::string, int> config;
@@ -29,10 +31,17 @@ namespace game
{
return config[key];
}
const uint32_t getTicks()
{
return SDL_GetTicks();
}
}
int main(int argc, char *argv[])
{
game::windowHasFocus = true;
game::init();
input::init(draw::getZoom());
@@ -61,6 +70,10 @@ int main(int argc, char *argv[])
{
input::updateWheel(e.wheel.y);
}
if ( e.type == SDL_WINDOWEVENT ) {
if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) game::windowHasFocus = true;
if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) game::windowHasFocus = false;
}
}
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)

View File

@@ -6,6 +6,8 @@
#include "jfile.h"
namespace game
{
extern bool windowHasFocus;
void setUpdateTicks(const int ticks);
void init();
@@ -15,4 +17,6 @@ namespace game
void setConfig(const char* key, const int value);
const int getConfig(const char* key);
const uint32_t getTicks();
}

View File

@@ -3,6 +3,16 @@
namespace input
{
namespace mouse
{
namespace button
{
const int left = 1;
const int middle = 2;
const int right = 3;
}
}
/// @brief Inicialitza els sistemes de teclat, ratolí i gamepad
void init(const int zoom);

View File

@@ -1,12 +1,17 @@
#include "jgame.h"
#include "gamestates.h"
#include "aux_font.h"
void game::init()
{
draw::init("Arounders", 320, 200, 3);
draw::setTrans(0);
input::init(3);
audio::init();
font::init();
game::setUpdateTicks(16);
game::setConfig("fase", -1);

927
source/proc_arounders.cpp Normal file
View File

@@ -0,0 +1,927 @@
#include "proc_arounders.h"
#include "jgame.h"
#include "proc_mapa.h"
#include "proc_explosio.h"
namespace arounders
{
arounder *first {nullptr};
arounder *seleccionat {nullptr};
draw::surface *sprites { nullptr };
draw::surface *marca { nullptr };
draw::surface *explosio { nullptr };
uint8_t colorEscalo = 76;
uint8_t colorCorda = 4;
void initMort(arounder *a);
void initArrivat(arounder *a);
void initCaminar(arounder *a);
void initCaure(arounder *a);
void initParar(arounder *a);
void initCavar(arounder *a);
void initEscalar(arounder *a);
void initPerforar(arounder *a);
void initEscalera(arounder *a);
void initPasarela(arounder *a);
void initCorda(arounder *a);
void initPujarCorda(arounder *a);
void initBaixarCorda(arounder *a);
void initSuicidi(arounder *a);
void procesarCaminar(arounder *a);
void procesarCaure(arounder *a);
void procesarParar(arounder *a);
void procesarCavar(arounder *a);
void procesarEscalar(arounder *a);
void procesarPerforar(arounder *a);
void procesarEscalera(arounder *a);
void procesarPasarela(arounder *a);
void procesarCorda(arounder *a);
void procesarPujarCorda(arounder *a);
void procesarBaixarCorda(arounder *a);
void procesarSuicidi(arounder *a);
bool blockCaure(arounder *a, int desfase = 0);
bool blockCaminar(arounder *a);
bool blockArounder(arounder *a);
bool blockParet(arounder *a, int desfase = 0);
bool blockTecho(arounder *a, int desfase = 0);
bool blockPrecipici(arounder *a);
bool blockPrecipiciPasarela(arounder *a);
bool blockNovaCorda(arounder *a);
bool blockCordaBaixar(arounder *a, int desfase = 0);
bool blockCordaPujar(arounder *a, int desfase = 0);
bool pujarEscalo(arounder *a);
bool baixarEscalo(arounder *a);
bool checkArounderAnt(arounder *a, int x, int y, int o);
bool checkArounderSig(arounder *a, int x, int y, int o);
void doCavar(arounder *a);
void doPerforar(arounder *a);
void doEscalera(arounder *a, int desfase = 0);
void doCorda(arounder *a);
void init()
{
if (!sprites) sprites = draw::loadSurface("sprites.gif");
if (!marca) marca = draw::loadSurface("marca.gif");
if (!explosio) explosio = draw::loadSurface("explosio.gif");
arounders::first = arounders::seleccionat = nullptr;
}
void afegir()
{
arounder *a = new arounder();
a->x = mapa::ini_x*16+8;
a->y = mapa::ini_y*16+8;
a->orientacio = mapa::arounders::orientacio_inicial;
a->frame = a->frameX = a->frameY = a->altura = 0;
a->accio = a->prevista = accions::caminar;
a->siguiente = a->anterior = nullptr;
if (!arounders::first) {
arounders::first = a;
} else {
arounder *pare = arounders::first;
while (pare->siguiente) pare = pare->siguiente;
pare->siguiente = a;
a->anterior = pare;
}
}
void pintar()
{
arounder *a = arounders::first;
draw::setSource(sprites);
while (a)
{
draw::draw(a->x, a->y, 8, 8, a->frameX*8, a->frameY);
a = a->siguiente;
}
if (arounders::seleccionat) {
draw::setSource(marca);
draw::draw(arounders::seleccionat->x-3, arounders::seleccionat->y-3);
}
explosio::pintar();
}
const bool seleccionar()
{
const int mx = input::mouseX();
const int my = input::mouseY();
arounder *a = arounders::first;
while (a)
{
if (a->x <= mx && (a->x+8) >= mx && a->y <= my && (a->y+8) >= my)
{
arounders::seleccionat = a;
return true;
}
a = a->siguiente;
}
return false;
}
void abortarAccio()
{
arounder *a = arounders::seleccionat;
if (!a) return;
if (a->accio == arounders::accions::escalar)
{
if (a->orientacio == arounders::orientacions::dreta) a->x-=5; else a->x+=5;
}
if (a->accio != arounders::accions::caminar &&
a->accio != arounders::accions::caure &&
a->accio != arounders::accions::pujarcorda &&
a->accio != arounders::accions::baixarcorda )
{
a->accio = arounders::accions::caminar;
}
}
void procesar()
{
arounder *a = arounders::first;
while (a)
{
switch (a->accio)
{
case arounders::accions::caminar: procesarCaminar(a); break;
case arounders::accions::caure: procesarCaure(a); break;
case arounders::accions::cavar: procesarCavar(a); break;
case arounders::accions::escalar: procesarEscalar(a); break;
case arounders::accions::perforar: procesarPerforar(a); break;
case arounders::accions::escalera: procesarEscalera(a); break;
case arounders::accions::pasarela: procesarPasarela(a); break;
case arounders::accions::corda: procesarCorda(a); break;
case arounders::accions::pujarcorda: procesarPujarCorda(a); break;
case arounders::accions::baixarcorda: procesarBaixarCorda(a); break;
case arounders::accions::suicidi: procesarSuicidi(a); break;
}
if (a->x == (mapa::fin_x*16)+8 && a->y == (mapa::fin_y*16)+8) initArrivat(a);
a = a->siguiente;
}
a = arounders::first;
if (a)
{
while (a->siguiente) a = a->siguiente;
while (a) {
if (a->accio == arounders::accions::mort) {
arounder *borrar = a;
if (borrar->siguiente) borrar->siguiente->anterior = borrar->anterior;
if (borrar->anterior) borrar->anterior->siguiente = borrar->siguiente;
if (borrar == arounders::first) arounders::first = borrar->siguiente;
if (borrar == arounders::seleccionat) arounders::seleccionat = nullptr;
a = borrar->anterior;
delete borrar;
} else {
a = a->anterior;
}
}
}
}
uint8_t get_pixel(const int x, const int y)
{
return mapa::mapa->pixels[x+y*320];
}
void put_pixel(const int x, const int y, const uint8_t pixel )
{
mapa::mapa->pixels[x+y*320] = pixel;
}
void initMort(arounder *a)
{
a->accio = arounders::accions::mort;
draw::setDestination(mapa::mapa);
draw::setSource(explosio);
draw::setTrans(1);
draw::draw(a->x-9, a->y-12);
draw::setTrans(0);
draw::setDestination(nullptr);
explosio::crear(a->x+4, a->y+3, 20, 200, 20, 0);
mapa::arounders::morts++;
}
void initArrivat(arounder *a)
{
a->accio = arounders::accions::mort;
mapa::arounders::arrivats++;
}
void initCaminar(arounder *a)
{
a->frame = 0;
a->accio = arounders::accions::caminar;
procesarCaminar(a);
}
void initCaure(arounder *a)
{
a->frame = 0;
a->accio = arounders::accions::caure;
a->altura = 0;
procesarCaure(a);
}
void initParar(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
if (mapa::accions::parar > 0) {
a->accio = arounders::accions::parar;
mapa::accions::parar--;
procesarParar(a);
} else {
initCaminar(a);
}
}
void initCavar(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
if (mapa::accions::cavar > 0) {
a->accio = arounders::accions::cavar;
mapa::accions::cavar--;
procesarCavar(a);
} else {
initCaminar(a);
}
}
void initEscalar(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
if (mapa::accions::escalar > 0) {
a->accio = arounders::accions::escalar;
mapa::accions::escalar--;
a->x = a->orientacio == arounders::orientacions::dreta ? a->x + 5 : a->x - 5;
procesarEscalar(a);
} else {
initCaminar(a);
}
}
void initPerforar(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
if (mapa::accions::perforar > 0) {
a->accio = arounders::accions::perforar;
mapa::accions::perforar--;
procesarPerforar(a);
} else {
initCaminar(a);
}
}
void initEscalera(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
a->accio = arounders::accions::escalera;
procesarEscalera(a);
}
void initPasarela(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
a->accio = arounders::accions::pasarela;
procesarPasarela(a);
}
void initCorda(arounder *a)
{
a->frame = 0;
a->prevista = arounders::accions::caminar;
if (mapa::accions::corda > 0) {
a->accio = arounders::accions::corda;
mapa::accions::corda--;
procesarCorda(a);
} else {
initCaminar(a);
}
}
void initPujarCorda(arounder *a)
{
a->frame = 0;
a->accio = arounders::accions::pujarcorda;
a->x = a->orientacio == arounders::orientacions::dreta ? a->x + 3 : a->x - 3;
procesarPujarCorda(a);
}
void initBaixarCorda(arounder *a)
{
a->frame = 0;
a->accio = arounders::accions::baixarcorda;
if (a->orientacio == arounders::orientacions::dreta) {
a->x += 2;
} else {
a->x -= 2;
}
procesarBaixarCorda(a);
}
void initSuicidi(arounder *a)
{
a->frame = 0;
a->accio = a->prevista = arounders::accions::suicidi;
procesarSuicidi(a);
}
void procesarCaminar(arounder *a)
{
const int frames[4] = {3,4,3,5};
a->frame++;
if (a->frame >= 4) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (blockCaure(a)) {
initCaure(a);
} else {
switch ( a->prevista ) {
case arounders::accions::parar:
initParar(a);
break;
case arounders::accions::perforar:
initPerforar(a);
break;
case arounders::accions::escalera:
initEscalera(a);
break;
case arounders::accions::suicidi:
initSuicidi(a);
break;
default:
if (blockCordaPujar(a)) {
initPujarCorda(a);
} else if (blockCaminar(a)) {
if (a->prevista == arounders::accions::cavar) {
initCavar(a);
} else if (a->prevista == arounders::accions::escalar) {
initEscalar(a);
} else {
a->orientacio = a->orientacio ^ arounders::orientacions::esquerra;
}
} else {
if (blockArounder(a)) {
a->orientacio = a->orientacio ^ arounders::orientacions::esquerra;
} else {
if (blockPrecipici(a) && (a->prevista == arounders::accions::pasarela || a->prevista == arounders::accions::corda)) {
if (a->prevista == arounders::accions::pasarela) {
initPasarela(a);
} else {
initCorda(a);
}
} else {
if (blockCordaBaixar(a)) {
initBaixarCorda(a);
} else if (blockCordaPujar(a)) {
initPujarCorda(a);
} else {
if (pujarEscalo(a)) a->y--;
a->x += ((((a->orientacio ^ 8) << 1) >> 3) - 1);
if (baixarEscalo(a)) a->y++;
}
}
}
}
}
}
}
void procesarCaure(arounder *a)
{
a->frame = 0;
a->frameX = 11;
a->frameY = a->orientacio;
if (!blockCaure(a)) {
if (a->altura >= 32) {
initMort(a);
} else {
initCaminar(a);
}
} else {
if (a->y > 151) {
initMort(a);
} else {
a->y++;
a->altura++;
}
}
}
void procesarParar(arounder *a)
{
a->frame = 0;
a->frameX = 2;
a->frameY = 8;
}
void procesarCavar(arounder *a)
{
const int frames[3] = {6,7,8};
a->frame++;
if (a->frame == 3) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (blockCaure(a)) {
initCaure(a);
} else {
if (!blockCaminar(a)) {
initCaminar(a);
} else {
if (a->frame == 2) {
doCavar(a);
if (a->orientacio == arounders::orientacions::dreta) {
a->x++;
} else {
a->x--;
}
}
}
}
}
void procesarEscalar(arounder *a)
{
const int frames[2] = {9,10};
a->frame++;
if (a->frame == 2) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (!blockParet(a, 5)) {
if (a->orientacio == arounders::orientacions::dreta) {
a->x = a->x - 1;
} else {
a->x = a->x + 1;
}
a->y = a->y - 1;
initCaminar(a);
} else {
if (blockTecho(a, 5)) {
if (a->orientacio == arounders::orientacions::dreta) {
a->x = a->x - 5;
} else {
a->x = a->x + 5;
}
initCaminar(a);
} else {
a->y--;
}
}
}
void procesarPerforar(arounder *a)
{
const int frames[2] = {0,1};
a->frame++;
if (a->frame == 2) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = 8;
if (blockCaure(a)) {
initCaure(a);
} else {
if (a->frame == 1) {
doPerforar(a);
a->y++;
}
}
}
void procesarEscalera(arounder *a)
{
const int frames[5] = {12,13,14,15,4};
a->frame++;
if (a->frame == 5) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (blockParet(a) || blockTecho(a) || mapa::accions::escalera == 0) {
initCaminar(a);
} else {
if (a->frame == 3) {
doEscalera(a);
mapa::accions::escalera--;
}
if (a->frame == 4) {
a->y--;
if (a->orientacio == arounders::orientacions::dreta) {
a->x++;
} else {
a->x--;
}
}
}
}
void procesarPasarela(arounder *a)
{
const int frames[5] = {12,13,14,15,4};
a->frame++;
if (a->frame == 5) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (blockParet(a) || !blockPrecipiciPasarela(a) || mapa::accions::pasarela == 0) {
initCaminar(a);
} else {
if (a->frame == 3) {
doEscalera(a, 1);
mapa::accions::pasarela--;
}
if (a->frame == 4) {
if (a->orientacio == arounders::orientacions::dreta) {
a->x = a->x + 2;
} else {
a->x = a->x - 2;
}
}
}
}
void procesarCorda(arounder *a)
{
const int frames[4] = {12,13,14,15};
if (a->frame < 3) a->frame++;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (a->frame == 3 ) {
if (!blockNovaCorda(a)) {
initCaminar(a);
} else {
doCorda(a);
a->altura++;
}
}
}
void procesarPujarCorda(arounder *a)
{
const int frames[2] = {9,10};
a->frame++;
if (a->frame == 2) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = a->orientacio;
if (!blockCordaPujar(a, 3)) {
a->y = a->y - 2;
initCaminar(a);
} else {
if (blockTecho(a, 3)) {
if (a->orientacio == arounders::orientacions::dreta) {
a->x = a->x - 3;
} else {
a->x = a->x + 3;
}
initCaminar(a);
} else {
a->y--;
}
}
}
void procesarBaixarCorda(arounder *a)
{
const int frames[2] = {9,10};
a->frame++;
if (a->frame == 2) a->frame = 0;
a->frameX = frames[a->frame];
a->frameY = arounders::orientacions::esquerra - a->orientacio;
if (!blockCordaBaixar(a, 2)) {
initCaminar(a);
} else {
if (!blockCaure(a, 3)) {
if (a->orientacio == arounders::orientacions::dreta) {
a->x = a->x - 2;
} else {
a->x = a->x + 2;
}
initCaminar(a);
} else {
a->y++;
}
}
}
void procesarSuicidi(arounder *a)
{
const int frames[5] = {0,1,2,1,2};
a->frameX = frames[a->frame];
a->frameY = 0;
if (a->frame == 4) initMort(a);
a->frame++;
}
bool blockCaure(arounder *a, int desfase)
{
if ( a->orientacio == arounders::orientacions::esquerra) desfase = -desfase;
return ((get_pixel(a->x+desfase , a->y+8) == 0 || get_pixel(a->x+desfase , a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+1, a->y+8) == 0 || get_pixel(a->x+desfase+1, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+2, a->y+8) == 0 || get_pixel(a->x+desfase+2, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+3, a->y+8) == 0 || get_pixel(a->x+desfase+3, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+4, a->y+8) == 0 || get_pixel(a->x+desfase+4, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+5, a->y+8) == 0 || get_pixel(a->x+desfase+5, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+6, a->y+8) == 0 || get_pixel(a->x+desfase+6, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase+7, a->y+8) == 0 || get_pixel(a->x+desfase+7, a->y+8) == colorCorda) &&
(get_pixel(a->x+desfase , a->y+9) == 0 || get_pixel(a->x+desfase , a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+1, a->y+9) == 0 || get_pixel(a->x+desfase+1, a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+2, a->y+9) == 0 || get_pixel(a->x+desfase+2, a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+3, a->y+9) == 0 || get_pixel(a->x+desfase+3, a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+4, a->y+9) == 0 || get_pixel(a->x+desfase+4, a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+5, a->y+9) == 0 || get_pixel(a->x+desfase+5, a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+6, a->y+9) == 0 || get_pixel(a->x+desfase+6, a->y+9) == colorCorda) &&
(get_pixel(a->x+desfase+7, a->y+9) == 0 || get_pixel(a->x+desfase+7, a->y+9) == colorCorda)
);
}
bool blockCaminar(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
return (get_pixel(a->x+8, a->y+6) != 0 && get_pixel(a->x+8, a->y+7) != 0 && get_pixel(a->x+8, a->y+6) != colorEscalo);
} else {
return (get_pixel(a->x-1, a->y+6) != 0 && get_pixel(a->x-1, a->y+7) != 0 && get_pixel(a->x-1, a->y+6) != colorEscalo);
}
}
bool blockArounder(arounder *a)
{
bool resultado = false;
if (a->anterior) resultado = checkArounderAnt(a->anterior, a->x, a->y, a->orientacio);
if (a->siguiente) resultado = resultado || checkArounderSig(a->siguiente, a->x, a->y, a->orientacio);
return resultado;
}
bool blockParet(arounder *a, int desfase)
{
if (a->orientacio == arounders::orientacions::dreta) {
return (get_pixel(a->x+8-desfase, a->y ) != 0 ||
get_pixel(a->x+8-desfase, a->y+1) != 0 ||
get_pixel(a->x+8-desfase, a->y+2) != 0 ||
get_pixel(a->x+8-desfase, a->y+3) != 0 ||
get_pixel(a->x+8-desfase, a->y+4) != 0 ||
get_pixel(a->x+8-desfase, a->y+5) != 0 ||
get_pixel(a->x+8-desfase, a->y+6) != 0// ||
//get_pixel(X+8-desfase, Y+7) != 0
);
} else {
return (get_pixel(a->x-1+desfase, a->y ) != 0 ||
get_pixel(a->x-1+desfase, a->y+1) != 0 ||
get_pixel(a->x-1+desfase, a->y+2) != 0 ||
get_pixel(a->x-1+desfase, a->y+3) != 0 ||
get_pixel(a->x-1+desfase, a->y+4) != 0 ||
get_pixel(a->x-1+desfase, a->y+5) != 0 ||
get_pixel(a->x-1+desfase, a->y+6) != 0// ||
//get_pixel(X-1+desfase, Y+7) != 0
);
}
}
bool blockTecho(arounder *a, int desfase)
{
if (a->orientacio == arounders::orientacions::dreta) desfase = -desfase;
return ((get_pixel(a->x+desfase , a->y-1) != 0 && get_pixel(a->x+desfase , a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+1, a->y-1) != 0 && get_pixel(a->x+desfase+1, a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+2, a->y-1) != 0 && get_pixel(a->x+desfase+2, a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+3, a->y-1) != 0 && get_pixel(a->x+desfase+3, a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+4, a->y-1) != 0 && get_pixel(a->x+desfase+4, a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+5, a->y-1) != 0 && get_pixel(a->x+desfase+5, a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+6, a->y-1) != 0 && get_pixel(a->x+desfase+6, a->y-1) != colorCorda) ||
(get_pixel(a->x+desfase+7, a->y-1) != 0 && get_pixel(a->x+desfase+7, a->y-1) != colorCorda)
);
}
bool blockPrecipici(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
return (get_pixel(a->x+7, a->y+8) == 0 &&
get_pixel(a->x+6, a->y+8) == 0 &&
get_pixel(a->x+5, a->y+8) == 0 &&
get_pixel(a->x+7, a->y+9) == 0 &&
get_pixel(a->x+6, a->y+9) == 0 &&
get_pixel(a->x+5, a->y+9) == 0
);
} else {
return (get_pixel(a->x , a->y+8) == 0 &&
get_pixel(a->x+1, a->y+8) == 0 &&
get_pixel(a->x+2, a->y+8) == 0 &&
get_pixel(a->x , a->y+9) == 0 &&
get_pixel(a->x+1, a->y+9) == 0 &&
get_pixel(a->x+2, a->y+9) == 0
);
}
}
bool blockPrecipiciPasarela(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
return ((get_pixel(a->x+7, a->y+8) == 0 || get_pixel(a->x+7, a->y+8) == colorEscalo) &&
(get_pixel(a->x+6, a->y+8) == 0 || get_pixel(a->x+6, a->y+8) == colorEscalo) &&
(get_pixel(a->x+5, a->y+8) == 0 || get_pixel(a->x+5, a->y+8) == colorEscalo) &&
(get_pixel(a->x+7, a->y+9) == 0 || get_pixel(a->x+7, a->y+9) == colorEscalo) &&
(get_pixel(a->x+6, a->y+9) == 0 || get_pixel(a->x+6, a->y+9) == colorEscalo) &&
(get_pixel(a->x+5, a->y+9) == 0 || get_pixel(a->x+5, a->y+9) == colorEscalo)
);
} else {
return ((get_pixel(a->x , a->y+8) == 0 || get_pixel(a->x , a->y+8) == colorEscalo) &&
(get_pixel(a->x+1, a->y+8) == 0 || get_pixel(a->x+1, a->y+8) == colorEscalo) &&
(get_pixel(a->x+2, a->y+8) == 0 || get_pixel(a->x+2, a->y+8) == colorEscalo) &&
(get_pixel(a->x , a->y+9) == 0 || get_pixel(a->x , a->y+9) == colorEscalo) &&
(get_pixel(a->x+1, a->y+9) == 0 || get_pixel(a->x+1, a->y+9) == colorEscalo) &&
(get_pixel(a->x+2, a->y+9) == 0 || get_pixel(a->x+2, a->y+9) == colorEscalo)
);
}
}
bool blockNovaCorda(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
return (get_pixel(a->x+6, a->y+8+a->altura) == 0 &&
get_pixel(a->x+6, a->y+9+a->altura) == 0 &&
get_pixel(a->x+6, a->y+10+a->altura) == 0
);
} else {
return (get_pixel(a->x+1, a->y+8+a->altura) == 0 &&
get_pixel(a->x+1, a->y+9+a->altura) == 0 &&
get_pixel(a->x+1, a->y+10+a->altura) == 0
);
}
}
bool blockCordaBaixar(arounder *a, int desfase)
{
if (a->orientacio == arounders::orientacions::dreta) {
return (get_pixel(a->x+6-desfase, a->y+8) == colorCorda);
} else {
return (get_pixel(a->x+1+desfase, a->y+8) == colorCorda);
}
}
bool blockCordaPujar(arounder *a, int desfase)
{
if (a->orientacio == arounders::orientacions::dreta) {
return (get_pixel(a->x+6-desfase, a->y+5) == colorCorda);
} else {
return (get_pixel(a->x+1+desfase, a->y+5) == colorCorda);
}
}
bool pujarEscalo(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
return ( (get_pixel(a->x+8, a->y+6) == 0 || get_pixel(a->x+8, a->y+6) == colorEscalo) && get_pixel(a->x+8, a->y+7) != 0);
} else {
return ( (get_pixel(a->x-1, a->y+6) == 0 || get_pixel(a->x-1, a->y+6) == colorEscalo) && get_pixel(a->x-1, a->y+7) != 0);
}
}
bool baixarEscalo(arounder *a)
{
return (get_pixel(a->x , a->y+8) == 0 &&
get_pixel(a->x+1, a->y+8) == 0 &&
get_pixel(a->x+2, a->y+8) == 0 &&
get_pixel(a->x+3, a->y+8) == 0 &&
get_pixel(a->x+4, a->y+8) == 0 &&
get_pixel(a->x+5, a->y+8) == 0 &&
get_pixel(a->x+6, a->y+8) == 0 &&
get_pixel(a->x+7, a->y+8) == 0 &&
(get_pixel(a->x , a->y+9) != 0 ||
get_pixel(a->x+1, a->y+9) != 0 ||
get_pixel(a->x+2, a->y+9) != 0 ||
get_pixel(a->x+3, a->y+9) != 0 ||
get_pixel(a->x+4, a->y+9) != 0 ||
get_pixel(a->x+5, a->y+9) != 0 ||
get_pixel(a->x+6, a->y+9) != 0 ||
get_pixel(a->x+7, a->y+9) != 0
)
);
}
bool checkArounderAnt(arounder *a, int x, int y, int o)
{
if ( a->accio == arounders::accions::parar && (y >= a->y-8) && (y <= a->y+8) && ( (o == arounders::orientacions::dreta && a->x == x+8) || (o == arounders::orientacions::esquerra && a->x == x-8) ) ) {
return true;
} else {
if (a->anterior) {
return checkArounderAnt(a->anterior, x, y, o);
} else {
return false;
}
}
}
bool checkArounderSig(arounder *a, int x, int y, int o)
{
if ( a->accio == arounders::accions::parar && (y >= a->y-8) && (y <= a->y+8) && ( (o == arounders::orientacions::dreta && a->x == x+8) || (o == arounders::orientacions::esquerra && a->x == x-8) ) ) {
return true;
} else {
if (a->siguiente) {
return checkArounderSig(a->siguiente, x, y, o);
} else {
return false;
}
}
}
void doCavar(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
explosio::crear(a->x+8, a->y, 10, 200, 10, 3);
put_pixel(a->x+8, a->y, 0);
put_pixel(a->x+8, a->y+1, 0);
put_pixel(a->x+8, a->y+2, 0);
put_pixel(a->x+8, a->y+3, 0);
put_pixel(a->x+8, a->y+4, 0);
put_pixel(a->x+8, a->y+5, 0);
put_pixel(a->x+8, a->y+6, 0);
put_pixel(a->x+8, a->y+7, 0);
} else {
explosio::crear(a->x-1, a->y, 10, 200, 10, 3);
put_pixel(a->x-1, a->y, 0);
put_pixel(a->x-1, a->y+1, 0);
put_pixel(a->x-1, a->y+2, 0);
put_pixel(a->x-1, a->y+3, 0);
put_pixel(a->x-1, a->y+4, 0);
put_pixel(a->x-1, a->y+5, 0);
put_pixel(a->x-1, a->y+6, 0);
put_pixel(a->x-1, a->y+7, 0);
}
}
void doPerforar(arounder *a)
{
explosio::crear(a->x+4, a->y+8, 10, 200, 10, 3);
put_pixel(a->x , a->y+8, 0);
put_pixel(a->x+1, a->y+8, 0);
put_pixel(a->x+2, a->y+8, 0);
put_pixel(a->x+3, a->y+8, 0);
put_pixel(a->x+4, a->y+8, 0);
put_pixel(a->x+5, a->y+8, 0);
put_pixel(a->x+6, a->y+8, 0);
put_pixel(a->x+7, a->y+8, 0);
}
void doEscalera(arounder *a, int desfase)
{
if (a->orientacio == arounders::orientacions::dreta) {
put_pixel(a->x+5, a->y+7+desfase, colorEscalo);
put_pixel(a->x+6, a->y+7+desfase, colorEscalo);
put_pixel(a->x+7, a->y+7+desfase, colorEscalo);
} else {
put_pixel(a->x+2, a->y+7+desfase, colorEscalo);
put_pixel(a->x+1, a->y+7+desfase, colorEscalo);
put_pixel(a->x , a->y+7+desfase, colorEscalo);
}
}
void doCorda(arounder *a)
{
if (a->orientacio == arounders::orientacions::dreta) {
put_pixel(a->x+6, a->y+8+a->altura, colorCorda);
} else {
put_pixel(a->x+1, a->y+8+a->altura, colorCorda);
}
}
}

52
source/proc_arounders.h Normal file
View File

@@ -0,0 +1,52 @@
#pragma once
namespace arounders
{
namespace accions
{
const int caminar = 0;
const int parar = 1;
const int cavar = 2;
const int escalar = 3;
const int perforar = 4;
const int escalera = 5;
const int pasarela = 6;
const int corda = 7;
const int suicidi = 8;
const int fastforward = 9;
const int caure = 10;
const int pujarcorda = 11;
const int baixarcorda = 12;
const int mort = 13;
}
namespace orientacions
{
const int dreta = 0;
const int esquerra = 8;
}
struct arounder
{
int x, y, orientacio;
int accio, prevista;
int frame, frameX, frameY, altura;
arounder *anterior;
arounder *siguiente;
};
extern arounder *first;
extern arounder *seleccionat;
void init();
void afegir();
void pintar();
const bool seleccionar();
void abortarAccio();
void procesar();
}

74
source/proc_explosio.cpp Normal file
View File

@@ -0,0 +1,74 @@
#include "proc_explosio.h"
#include <stdlib.h>
#include "jgame.h"
namespace explosio
{
struct tipo_pix // Cada pixel de la explosió
{
float x, y;
float xa, ya;
float g;
uint8_t c;
};
struct tipo_exp // Tipo per a les explosions
{
int numpix;
tipo_pix pix[50];
int count;
};
static tipo_exp exp[10];
static int numexp {0};
void crear(const int x, const int y, const int num, const int c1, const int c2, const int c3)
{
if ( numexp >= 9 || numexp < 0 ) return;
exp[numexp].count = 0;
exp[numexp].numpix = num*2;
const int expansio = c2*100;
for (int i=0; i<=exp[numexp].numpix; ++i)
{
exp[numexp].pix[i].x = x;
exp[numexp].pix[i].y = y;
exp[numexp].pix[i].xa = float((rand()%expansio) - (expansio >> 1))/1000.0f;
exp[numexp].pix[i].ya = float((rand()%expansio) - (expansio >> 1))/1000.0f;
exp[numexp].pix[i].g = 0.05;
exp[numexp].pix[i].c = rand()%60;
}
numexp++;
}
void pintar()
{
int c1 = 0;
while (c1 != numexp)
{
for (int c2=0; c2<=exp[c1].numpix; ++c2)
{
exp[c1].pix[c2].x = exp[c1].pix[c2].x + exp[c1].pix[c2].xa;
exp[c1].pix[c2].ya = exp[c1].pix[c2].ya + exp[c1].pix[c2].g;
exp[c1].pix[c2].y = exp[c1].pix[c2].y + exp[c1].pix[c2].ya;
//if ((exp[c1].pix[c2].x > 0) && (exp[c1].pix[c2].x < 319) && (exp[c1].pix[c2].y > 0) && (exp[c1].pix[c2].y < 199))
draw::putPixel(exp[c1].pix[c2].x, exp[c1].pix[c2].y, exp[c1].pix[c2].c);
}
exp[c1].count++;
c1++;
if (exp[c1-1].count == 80)
{
numexp--;
c1--;
if (c1 != numexp)
{
exp[c1] = exp[numexp];
}
}
}
}
}

8
source/proc_explosio.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
namespace explosio
{
void crear(const int x, const int y, const int num, const int c1, const int c2, const int c3);
void pintar();
}

208
source/proc_mapa.cpp Normal file
View File

@@ -0,0 +1,208 @@
#include "proc_mapa.h"
#include "jgame.h"
#include "aux_textfile.h"
#include "aux_font.h"
namespace mapa
{
namespace botons
{
const int caminar = 0;
const int parar = 1;
const int cavar = 2;
const int escalar = 3;
const int perforar = 4;
const int escalera = 5;
const int pasarela = 6;
const int corda = 7;
const int suicidi = 8;
const int fastforward = 9;
}
namespace arounders
{
int orientacio_inicial {0};
int totals {0};
int necessaris {0};
int arrivats {0};
int eixits {0};
int morts {0};
}
namespace accions
{
int parar {0};
int cavar {0};
int escalar {0};
int perforar {0};
int escalera {0};
int pasarela {0};
int corda {0};
}
int ini_x, ini_y;
int fin_x, fin_y;
uint32_t velocitat;
draw::surface *mapa = nullptr;
draw::surface *porta = nullptr;
draw::surface *boto = nullptr;
int contador;
void carregar()
{
mapa::velocitat = 70;
mapa::contador = game::getTicks();
textfile::open("mapes.txt");
do {
textfile::searchToken("LEVEL");
} while (textfile::toInt(textfile::getNextToken()) != game::getConfig("fase"));
const int tileset = textfile::getIntValue("tileset");
arounders::orientacio_inicial = textfile::getIntValue("orientacio");
arounders::totals = textfile::getIntValue("arounders");
arounders::necessaris = textfile::getIntValue("necessaris");
accions::parar = textfile::getIntValue("parar");
accions::cavar = textfile::getIntValue("cavar");
accions::escalar = textfile::getIntValue("escalar");
accions::perforar = textfile::getIntValue("perforar");
accions::escalera = textfile::getIntValue("escalera");
accions::pasarela = textfile::getIntValue("pasarela");
accions::corda = textfile::getIntValue("corda");
ini_x = textfile::getIntValue("inici");
ini_y = textfile::toInt(textfile::getNextToken());
fin_x = textfile::getIntValue("final");
fin_y = textfile::toInt(textfile::getNextToken());
arounders::arrivats = arounders::eixits = arounders::morts = 0;
//int tilemap[200];
//for (int y=0; y<10; ++y) for (int x=0; x<10; ++x) fscanf(f, "%i", &tilemap[x+y*20]);
draw::surface *tiles = draw::loadSurface("tiles.gif");
draw::setSource(tiles);
if (mapa) draw::freeSurface(mapa);
mapa = draw::createSurface(320, 200);
draw::setDestination(mapa);
draw::cls(0);
for (int y=0; y<10; ++y)
for (int x=0; x<20; ++x)
{
int tile = textfile::toInt(textfile::getNextToken());
if (tile > 0) draw::draw(x*16, y*16, 16, 16, (tile-1)*16, tileset*16);
}
draw::freeSurface(tiles);
textfile::close();
draw::surface *marcador = draw::loadSurface("marcador.gif");
draw::setSource(marcador);
draw::draw(0, 165, marcador->w, marcador->h, 0, 0);
draw::freeSurface(marcador);
font::selectFont(font::type::normal);
font::print(188,188, game::getConfig("fase")+1);
font::print(7,188, "XX");
font::print(135,188, "XX");
font::print(151,188, "XX");
font::print(224,171, "ACTIUS");
font::print(224,177, "TOTAL");
font::print(224,183, "NECESSARIS");
font::print(224,189, "ARRIVATS");
draw::setDestination(nullptr);
if (mapa::porta == nullptr) mapa::porta = draw::loadSurface("puerta.gif");
if (mapa::boto == nullptr) mapa::boto = draw::loadSurface("boto.gif");
}
void pintar(int accio, int prevista)
{
draw::draw(mapa);
draw::setSource(porta);
draw::draw(ini_x*16, ini_y*16);
draw::draw(fin_x*16, fin_y*16);
font::selectFont(font::type::normal);
font::print(23,188, mapa::accions::parar);
font::print(39,188, mapa::accions::cavar);
font::print(55,188, mapa::accions::escalar);
font::print(71,188, mapa::accions::perforar);
font::print(87,188, mapa::accions::escalera);
font::print(103,188, mapa::accions::pasarela);
font::print(119,188, mapa::accions::corda);
font::print(301,171, mapa::arounders::eixits-mapa::arounders::arrivats-mapa::arounders::morts);
font::print(301,177, mapa::arounders::totals);
font::print(301,183, mapa::arounders::necessaris);
font::print(301,189, mapa::arounders::arrivats);
if (accio >= 10) accio = 0;
if (prevista >= 10) prevista = 0;
draw::setSource(boto);
draw::draw((accio*16)+5, 171);
if (prevista != accio && prevista != 0) {
if ((game::getTicks()-contador) <= 200) {
draw::draw((prevista*16)+5, 171);
} else {
if ((game::getTicks()-contador) >= 400) contador = game::getTicks();
}
}
if (velocitat < 70) {
draw::draw((9*16)+5, 171); // Pintar el botó de accelerat com pulsat
}
}
const int procesar()
{
int boto = -1;
if (input::mouseY() >= 171 && input::mouseY() <= 187 && input::mouseX() >= 5 && input::mouseX() <= 165) {
boto = (input::mouseX()-5) / 16;
switch(boto) {
case mapa::botons::parar:
if (mapa::accions::parar == 0) boto = -1;
break;
case mapa::botons::cavar:
if (mapa::accions::cavar == 0) boto = -1;
break;
case mapa::botons::escalar:
if (mapa::accions::escalar == 0) boto = -1;
break;
case mapa::botons::perforar:
if (mapa::accions::perforar == 0) boto = -1;
break;
case mapa::botons::escalera:
if (mapa::accions::escalera == 0) boto = -1;
break;
case mapa::botons::pasarela:
if (mapa::accions::pasarela == 0) boto = -1;
break;
case mapa::botons::corda:
if (mapa::accions::corda == 0) boto = -1;
break;
case botons::fastforward:
if (mapa::velocitat == 70) {
mapa::velocitat = 10;
} else {
mapa::velocitat = 70;
}
boto = -1;
break;
}
}
return boto;
}
}

39
source/proc_mapa.h Normal file
View File

@@ -0,0 +1,39 @@
#pragma once
#include "jgame.h"
#include <stdint.h>
namespace mapa
{
namespace arounders
{
extern int orientacio_inicial;
extern int totals;
extern int necessaris;
extern int arrivats;
extern int eixits;
extern int morts;
}
namespace accions
{
extern int parar;
extern int cavar;
extern int escalar;
extern int perforar;
extern int escalera;
extern int pasarela;
extern int corda;
}
extern draw::surface *mapa;
extern int ini_x;
extern int ini_y;
extern int fin_x;
extern int fin_y;
extern uint32_t velocitat;
void carregar();
void pintar(int accio, int prevista);
const int procesar();
}

View File

@@ -1,36 +0,0 @@
#include "proc_marcador.h"
namespace marcador
{
int orientacioInicial;
int numArounders;
int AroundersNec;
int numAroundersArrivats;
int numAroundersEixits;
int numAroundersMorts;
int numParar;
int numCavar;
int numEscalar;
int numPerforar;
int numEscalera;
int numPasarela;
int numCorda;
int velocitat;
//SDL_Surface *boto;
int contador;
char *formatejar(int numero);
void pintar(int accio, int prevista);
int procesar(int mousex, int mousey);
void setAroundersNum(const int orient, const int total, const int necessaris);
void setActions(const int parar, const int cavar, const int escalar, const int perforar, const int escalera, const int pasarela, const int corda);
}

View File

@@ -1,11 +0,0 @@
#pragma once
namespace marcador
{
void pintar(int accio, int prevista);
int procesar(int mousex, int mousey);
void setAroundersNum(const int orient, const int total, const int necessaris);
void setActions(const int parar, const int cavar, const int escalar, const int perforar, const int escalera, const int pasarela, const int corda);
}

File diff suppressed because it is too large Load Diff

99
tools/level_reader.cpp Normal file
View File

@@ -0,0 +1,99 @@
#include <stdio.h>
#include <stdlib.h>
#include <string>
namespace textfile
{
char *buffer = nullptr;
int fsize = 0;
int p = 0;
const bool open(std::string filename)
{
FILE *f = fopen(filename.c_str(), "rb");
if (!f) { printf("ERROR AL OBRIR EL ARXIU\n"); return false; }
fseek(f, 0, SEEK_END);
fsize = ftell(f);
fseek(f, 0, SEEK_SET);
buffer = (char*)malloc(fsize);
fread(buffer, fsize, 1, f);
fclose(f);
p = 0;
return true;
}
void close()
{
free(buffer);
}
std::string getNextToken()
{
char token[255];
int tpos = 0;
// Ignore whitespace
while (p<fsize && buffer[p]<=32 ) p++;
// Grab token
while (p<fsize && buffer[p]>32 ) token[tpos++]=buffer[p++];
token[tpos]=0;
return std::string(token);
}
const bool searchToken(std::string token)
{
while (p<fsize && getNextToken() != token) p++;
return p<fsize;
}
std::string getStringValue(std::string token)
{
textfile::searchToken(token);
textfile::searchToken("=");
return textfile::getNextToken();
}
const int getIntValue(std::string token)
{
return std::stoi(getStringValue(token));
}
}
int main(int argc, char *argv[])
{
textfile::open("../data/mapes.txt");
int num;
do {
textfile::searchToken("LEVEL");
std::string token = textfile::getNextToken();
num = std::stoi(token);
} while (num != std::stoi(std::string(argv[1])));
printf("tileset = %i\n", textfile::getIntValue("tileset") );
printf("orientacio = %i\n", textfile::getIntValue("orientacio") );
printf("arounders = %i\n", textfile::getIntValue("arounders") );
printf("necessaris = %i\n", textfile::getIntValue("necessaris") );
printf("parar = %i\n", textfile::getIntValue("parar") );
printf("cavar = %i\n", textfile::getIntValue("cavar") );
printf("escalar = %i\n", textfile::getIntValue("escalar") );
printf("perforar = %i\n", textfile::getIntValue("perforar") );
printf("escalera = %i\n", textfile::getIntValue("escalera") );
printf("pasarela = %i\n", textfile::getIntValue("pasarela") );
printf("corda = %i\n", textfile::getIntValue("corda") );
int a = textfile::getIntValue("inici");
int b = std::stoi(textfile::getNextToken());
printf("inici = %i, %i\n", a, b );
a = textfile::getIntValue("final");
b = std::stoi(textfile::getNextToken());
printf("final = %i, %i\n", a, b );
textfile::close();
return 0;
}

94
versions.txt Normal file
View File

@@ -0,0 +1,94 @@
VERSIONS:
=========
v1.2:
- Reescrit tot el codi usant SDL2 i paletes com antanyo
- Música pasada a format OGG
- Torna a haber pixels volant, com la versió original en Pascal
- He llevat lo de accedir al menu des de la pausa
- Sequències i mapes pasades a format text
v1.1 RELEASE CANDIDATE 2:
- Solventat els polls detectats en la versió 1.0
- Ara es pot accedir al menu desde la pausa
- Si la finestra perd el focus el joc es fica en pausa
- Al pulsar ESC durant una sequència la pasa totalment
v1.00 RELEASE CANDIDATE 1:
- Codi passat a SDL
- Recursos reunits en un únic arxiu
- Música pasada a format MP3
- Llevada acció "suicidi col·lectiu"
- Afegida acció "fast forward"
- Arreglats several polls pel camí
- Afegit menú al pulsar ESC
- Més coses que no recorde...
v0.99 RELEASE 1:
- Canviats i arreglats TOTS els nivells
- Ampliat el nombre de nivells a...
- Llevats els "hidden Decorats" per falta de memòria, temps, diners i ganes.
- Anyadides mogolló de "intros" i grafics més entre mig del joc.
- No he anyadit més midis, per un nou projecte.
- Solucionat un poll en la acció "PERFORAR".
- Solucionat un poll del WAVPlayer que feia un "fuck'em all" amb la memòria.
v0.97 BETA 7:
- Si passes per darrere d'una escalera, ja no gires com si fora una paret.
- Anyadida la opció "DESCENS". Explicada en el "lligme.txt".
- Canviats i millorats la majoria dels nivells.
- Millorat el AroundED i passat a la versió 1.0
- Anyadits a lot of gràfics nous.
- Anyadits els "Hidden Decorats".
- Acabada la història del final.
v0.94 BETA 6:
- Canviades un poc les fonts i altres pijades.
- Solucionat el poll que feia que explotaren nomes començar.
- Solucionat un poll que quan arrives amb més baloos dels necesaris perds.
- Anyadit el programa SETUP.EXE per a configurar la targeta de só.
- El programa ja no es penja quan no tens targeta de só.
- Solucionat un poll en el .TXT que ficava que era la versió BETA 15 !!!
v0.91 PUBLIC BETA 5:
- Primera beta feta pública.
- He llevat alguns WAVs per a que no bote cada dos per tres un error.
- Sol·lucionats uns quants polls en les unitats WAVPlay(c) i MIDPlay(c).
- Grafics, só i música en format .BAL
- Alguns polls de "error de pila" sol·lucionats.
v0.9 BETA 4
- El joc ja no utilitza la interrupció del rellotge.
- Sol·lucionats alguns polls de les unitats WAVPlay(c) i MIDPlay(c).
- Só digital en format .WAV amb la unitat WAVPlay(c).
- Xicotetes millores en alguns gràfics.
v0.85 BETA 3
- Música soportada en format .MID amb la unitat MIDPlay(c).
- Sol·lucionat un poll enorme amb la pila i el heap.
- Grafics en format .GIF amb la unitat GIFLoad(c).
- Millora en els menús, els gràfics i en una animalada de coses.
v0.76 BETA 2
- polls menors referents al timer sol·lucionats
- Música en format .XMI amb una unitat anomenada MIDPack.
- Solucionats alguns polls dels nivells.
- Nou format .BAL per als nivells. Ara tots junts.
- Passwords encriptats, per a que els hackers de turno se jodan.
- Solucionats diversos polls del AroundED.
v0.7 BETA 1
- Solucionats diversos polls en el tema dels passwords.
- Música en format .DWM amb una unitat anomenada DWM.
v0.61 ALPHA 6
- Solucionat un poll en la acció "escalera"
- Nova intro i millora en els menus.
- Solucionat un poll que no alliberaba la memòria al eixir.
- Detectat algun que altre poll en el timer.
- Nou format de nivells individuals .LEV
- Creat el AroundED(c), un editor de nivells per al Arounders(c).
v0.61 ALPHA 5
- Solucionats uns quants polls en les accions "escalar" i "perforar"
- Anyadida la acció "pasarela"
- Solucionat un poll enorme amb el timer.
- Menú Passwords ja operatiu.
- Anyadida l'aigua que es veu baix de cada nivell.
- Anyadits molts gràfics nous per als nivells.
v0.6 ALPHA 4
- Anyadides les accions "suicidi", "suicidi colectiu" i "escalera"
- Anyadida la barra de botons i d'informació.
- Motor del joc MOLT millorat
No hi ha historial sobre versions anteriors...