Files
arounders/source/gamestate_play.cpp

115 lines
3.5 KiB
C++

#include "gamestates.h"
#include "jgame.h"
#include <string>
#include "aux_font.h"
#include "proc_mapa.h"
namespace gamestate
{
namespace play
{
draw::surface *fondo = nullptr;
draw::surface *mapa = nullptr;
draw::surface *cursor = nullptr;
draw::surface *aigua = nullptr;
uint32_t arounderCount;
uint32_t startTicks;
uint32_t currentTicks;
int aigua_frame1 = 0;
int aigua_frame2 = 5;
bool loop();
void draw();
void draw_aigua();
void init()
{
const int fase = game::getConfig("fase");
// 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] = (fase % 10) + 48;
fondo = draw::loadSurface(arxiuFondo, true);
// Carregar la paleta estandar
uint32_t *pal = draw::loadPalette("tiles.gif");
draw::setPalette(pal, 128);
// [TODO] Carreagar la resta de gifs que facen falta
cursor = draw::loadSurface("cursor.gif");
aigua = draw::loadSurface("aigua.gif");
//menu = drawManager->LoadFont("menu.gif");
// [TODO] CREAR AIGUA PROCESSOR
// [TODO] CREAR MARCADOR PROCESSOR
// [TODO] Crear el primer Arounder
mapa::arounders::eixits++;
// arounder_seleccionat = primerArounders
audio::loadMusic((fase+1) % 5 == 0 ? "mus6.ogg" : "mus4.ogg");
audio::playMusic();
play::arounderCount = play::startTicks = game::getTicks();
draw::fadein();
game::setState(gamestate::play::loop);
}
bool loop()
{
play::draw();
currentTicks = game::getTicks() - startTicks;
if( currentTicks >= mapa::velocitat ) {
startTicks = game::getTicks();
aigua_frame1 = (aigua_frame1+1)%10;
aigua_frame2 = (aigua_frame2+1)%10;
}
return true;
}
void draw()
{
draw::draw(play::fondo);
int accio = 0;
int prevista = 0;
// [TODO] if (arounders::seleccionat) { accio = arounders::seleccionat->accio; prevista = arounders::seleccionat->prevista; }
// [QUESTION] Potser lo del seleccionat se deuria mirar dins de "mapa"?
mapa::pintar(accio, prevista); // [TODO] if (arounders::seleccionat) existeix, pillar la accio i la prevista de ell
void draw_aigua();
// [TODO] 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);
}
*/
draw::setSource(cursor);
draw::draw(input::mouseX(), input::mouseY());
draw::render();
}
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);
}
}
}
}