Files
aee/modulegame.cpp
Raimon Zamora 4a359c46f5 Primer commit
2014-12-30 22:46:46 +01:00

153 lines
3.4 KiB
C++
Executable File

#include "modulegame.h"
#include "jgame.h"
#include "jdraw8.h"
#include "jinput.h"
#include "jfile.h"
ModuleGame::ModuleGame( Info* info ) {
this->info = info;
this->gfx = JD8_LoadSurface( "frames.gif" );
JG_SetUpdateTicks(10);
this->sam = new Prota( this->gfx, this->info );
this->mapa = new Mapa( this->gfx, this->info, this->sam );
this->marcador = new Marcador( this->gfx, this->info, this->sam );
if( this->info->num_piramide == 2 ) {
this->bola = new Bola( this->gfx, this->info, this->sam );
} else {
this->bola = NULL;
}
this->momies = NULL;
this->final = 0;
this->iniciarMomies();
}
ModuleGame::~ModuleGame(void) {
JD8_FadeOut();
if( this->bola != NULL ) delete this->bola;
if( this->momies != NULL ) {
this->momies->clear();
delete this->momies;
}
delete this->marcador;
delete this->mapa;
delete this->sam;
JD8_FreeSurface( this->gfx );
}
int ModuleGame::Go() {
this->Draw();
JD8_FadeToPal( JD8_LoadPalette( "frames.gif" ) );
while (this->final == 0 && !JG_Quitting()) {
this->Draw();
this->Update();
}
if( this->final == 1 ) {
this->info->num_habitacio++;
if( this->info->num_habitacio == 6 ) {
this->info->num_habitacio = 1;
this->info->num_piramide++;
}
}
if( JG_Quitting() ) {
return -1;
} else {
if( this->info->num_habitacio == 1 ) {
return 1;
} else {
return 0;
}
}
}
void ModuleGame::Draw() {
this->mapa->draw();
this->marcador->draw();
this->sam->draw();
if( this->momies != NULL ) this->momies->draw();
if( this->bola != NULL ) this->bola->draw();
JD8_Flip();
}
void ModuleGame::Update() {
if (JG_ShouldUpdate()) {
JI_Update();
this->final = this->sam->update();
if( this->momies != NULL && this->momies->update() ) {
Momia* seguent = this->momies->next;
delete this->momies;
this->momies = seguent;
this->info->momies--;
}
if( this->bola != NULL ) this->bola->update();
this->mapa->update();
if( this->mapa->novaMomia() ) {
if( this->momies != NULL ) {
this->momies->insertar( new Momia( this->gfx, this->info, true, 0, 0, this->sam ) );
this->info->momies++;
} else {
this->momies = new Momia( this->gfx, this->info, true, 0, 0, this->sam );
this->info->momies++;
}
}
if( JI_CheatActivated( "reviu" ) ) this->info->vida = 5;
if( JI_CheatActivated( "alone" ) ) {
if( this->momies != NULL ) {
this->momies->clear();
delete this->momies;
this->momies = NULL;
this->info->momies = 0;
}
}
if( JI_CheatActivated( "obert" ) ) {
for( int i = 0; i < 16; i++ ) {
this->mapa->tombes[i].costat[0] = true;
this->mapa->tombes[i].costat[1] = true;
this->mapa->tombes[i].costat[2] = true;
this->mapa->tombes[i].costat[3] = true;
this->mapa->comprovaCaixa( i );
}
}
if( JI_KeyPressed( SDL_SCANCODE_ESCAPE ) ) {
JG_QuitSignal();
}
}
}
void ModuleGame::iniciarMomies() {
if( this->info->num_habitacio == 10 ) { this->info->momies = 1; } else { this->info->momies++; }
int x = 20;
int y = 170;
for( int i = 0; i < info->momies; i++ ) {
if( this->momies == NULL) {
this->momies = new Momia( this->gfx, this->info, false, x, y, this->sam );
} else {
this->momies->insertar( new Momia( this->gfx, this->info, false, x, y, this->sam ) );
}
x += 65;
if( x == 345 ) { x = 20; y -= 35; }
}
}