Compare commits
4 Commits
ad1cceea5f
...
d391827fe1
| Author | SHA1 | Date | |
|---|---|---|---|
| d391827fe1 | |||
| 8d954ec2e0 | |||
| 720c15d03a | |||
| ccb2f3fbca |
@@ -3,16 +3,19 @@
|
||||
#include <string>
|
||||
#include "aux_font.h"
|
||||
#include "proc_mapa.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
namespace play
|
||||
{
|
||||
draw::surface *faded = nullptr;
|
||||
draw::surface *fondo = nullptr;
|
||||
draw::surface *mapa = nullptr;
|
||||
draw::surface *cursor = nullptr;
|
||||
draw::surface *aigua = nullptr;
|
||||
|
||||
uint32_t *original_palette = nullptr;
|
||||
|
||||
uint32_t arounderCount;
|
||||
uint32_t startTicks;
|
||||
uint32_t currentTicks;
|
||||
@@ -20,26 +23,36 @@ namespace gamestate
|
||||
int aigua_frame1 = 0;
|
||||
int aigua_frame2 = 5;
|
||||
|
||||
int exit = 0;
|
||||
|
||||
bool loop();
|
||||
|
||||
bool loop_pause();
|
||||
bool loop_menu();
|
||||
|
||||
void draw();
|
||||
void draw_aigua();
|
||||
|
||||
void finalize();
|
||||
|
||||
void init()
|
||||
{
|
||||
play::exit = 0;
|
||||
|
||||
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);
|
||||
play::fondo = draw::loadSurface(arxiuFondo, true);
|
||||
|
||||
// Carregar la paleta estandar
|
||||
uint32_t *pal = draw::loadPalette("tiles.gif");
|
||||
draw::setPalette(pal, 128);
|
||||
free(pal);
|
||||
|
||||
// [TODO] Carreagar la resta de gifs que facen falta
|
||||
cursor = draw::loadSurface("cursor.gif");
|
||||
aigua = draw::loadSurface("aigua.gif");
|
||||
//menu = drawManager->LoadFont("menu.gif");
|
||||
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
|
||||
@@ -61,6 +74,59 @@ namespace gamestate
|
||||
{
|
||||
play::draw();
|
||||
|
||||
if (input::keyPressed(SDL_SCANCODE_P) || input::mouseClk(2) || !game::windowHasFocus)
|
||||
{
|
||||
draw::setSource(nullptr);
|
||||
draw::setDestination(play::faded);
|
||||
draw::draw();
|
||||
font::selectFont(font::type::fade);
|
||||
font::print(136, 80, "PAUSA");
|
||||
draw::setDestination(nullptr);
|
||||
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);
|
||||
}
|
||||
game::setState(gamestate::play::loop_pause);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
|
||||
{
|
||||
draw::setSource(nullptr);
|
||||
draw::setDestination(play::faded);
|
||||
draw::draw();
|
||||
draw::surface *menu = draw::loadSurface("menu.gif");
|
||||
draw::setSource(menu);
|
||||
draw::draw(97, 52);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
game::setState(gamestate::play::loop_menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
draw::setSource(cursor);
|
||||
draw::draw(input::mouseX(), input::mouseY());
|
||||
|
||||
draw::render();
|
||||
|
||||
currentTicks = game::getTicks() - startTicks;
|
||||
if( currentTicks >= mapa::velocitat ) {
|
||||
startTicks = game::getTicks();
|
||||
@@ -71,6 +137,77 @@ namespace gamestate
|
||||
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))
|
||||
{
|
||||
draw::setPalette(play::original_palette, 256);
|
||||
free(play::original_palette);
|
||||
game::setState(gamestate::play::loop);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loop_menu()
|
||||
{
|
||||
if (play::exit) {
|
||||
if (!draw::isfading()) {
|
||||
play::finalize();
|
||||
if (exit==1) 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))
|
||||
{
|
||||
draw::setPalette(play::original_palette, 256);
|
||||
free(play::original_palette);
|
||||
game::setState(gamestate::play::loop);
|
||||
}
|
||||
|
||||
if (input::mouseClk(1))
|
||||
{
|
||||
if (input::mouseX() >= 97 && input::mouseX() <= 223) {
|
||||
if (input::mouseY() >= 60 && input::mouseY() <= 65) {
|
||||
draw::setPalette(play::original_palette, 256);
|
||||
free(play::original_palette);
|
||||
game::setState(gamestate::play::loop);
|
||||
}
|
||||
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 draw()
|
||||
{
|
||||
draw::draw(play::fondo);
|
||||
@@ -81,7 +218,7 @@ namespace gamestate
|
||||
// [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();
|
||||
draw_aigua();
|
||||
// [TODO] arounders::pintar();
|
||||
|
||||
// [TODO] de fet, pintar la marca en el modul "arounders"
|
||||
@@ -92,10 +229,6 @@ namespace gamestate
|
||||
}
|
||||
*/
|
||||
|
||||
draw::setSource(cursor);
|
||||
draw::draw(input::mouseX(), input::mouseY());
|
||||
|
||||
draw::render();
|
||||
}
|
||||
|
||||
void draw_aigua()
|
||||
@@ -111,5 +244,13 @@ namespace gamestate
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -39,6 +41,7 @@ namespace game
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
game::windowHasFocus = true;
|
||||
game::init();
|
||||
input::init(draw::getZoom());
|
||||
|
||||
@@ -67,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)
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "jfile.h"
|
||||
namespace game
|
||||
{
|
||||
extern bool windowHasFocus;
|
||||
|
||||
void setUpdateTicks(const int ticks);
|
||||
|
||||
void init();
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace mapa
|
||||
|
||||
int ini_x, ini_y;
|
||||
int fin_x, fin_y;
|
||||
int velocitat;
|
||||
uint32_t velocitat;
|
||||
|
||||
draw::surface *mapa = nullptr;
|
||||
draw::surface *porta = nullptr;
|
||||
@@ -116,6 +116,7 @@ namespace mapa
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
namespace mapa
|
||||
{
|
||||
namespace arounders
|
||||
@@ -24,7 +24,7 @@ namespace mapa
|
||||
extern int corda;
|
||||
}
|
||||
|
||||
extern int velocitat;
|
||||
extern uint32_t velocitat;
|
||||
|
||||
void carregar();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user