Compare commits
9 Commits
7b40d4fad4
...
65589d6ff1
| Author | SHA1 | Date | |
|---|---|---|---|
| 65589d6ff1 | |||
| 83e5234cb6 | |||
| 5cb0200b9f | |||
| 6a46966fe4 | |||
| 4a8505298b | |||
| cbbe4951bb | |||
| 65c4ef39a7 | |||
| 53dec7dfeb | |||
| 58c229c08c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
.vscode/*
|
||||
*.exe
|
||||
arounders
|
||||
arounders_debug
|
||||
27
Makefile
Normal file
27
Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
executable = arounders
|
||||
source = source/*.cpp
|
||||
|
||||
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"
|
||||
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"
|
||||
|
||||
macos:
|
||||
clang++ $(source) -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"
|
||||
|
||||
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)"
|
||||
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"
|
||||
BIN
data/fuente2.gif
BIN
data/fuente2.gif
Binary file not shown.
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 414 B |
BIN
data/mus1.mp3
BIN
data/mus1.mp3
Binary file not shown.
BIN
data/mus1.ogg
Normal file
BIN
data/mus1.ogg
Normal file
Binary file not shown.
BIN
data/mus2.mp3
BIN
data/mus2.mp3
Binary file not shown.
BIN
data/mus2.ogg
Normal file
BIN
data/mus2.ogg
Normal file
Binary file not shown.
BIN
data/mus3.mp3
BIN
data/mus3.mp3
Binary file not shown.
BIN
data/mus3.ogg
Normal file
BIN
data/mus3.ogg
Normal file
Binary file not shown.
BIN
data/mus4.mp3
BIN
data/mus4.mp3
Binary file not shown.
BIN
data/mus4.ogg
Normal file
BIN
data/mus4.ogg
Normal file
Binary file not shown.
BIN
data/mus5.mp3
BIN
data/mus5.mp3
Binary file not shown.
BIN
data/mus5.ogg
Normal file
BIN
data/mus5.ogg
Normal file
Binary file not shown.
BIN
data/mus6.mp3
BIN
data/mus6.mp3
Binary file not shown.
BIN
data/mus6.ogg
Normal file
BIN
data/mus6.ogg
Normal file
Binary file not shown.
@@ -30,7 +30,7 @@ namespace gamestate
|
||||
|
||||
uint16_t getWord()
|
||||
{
|
||||
return (getByte() << 8) + getByte();
|
||||
return getByte() + (getByte() << 8);
|
||||
}
|
||||
|
||||
std::string getString()
|
||||
@@ -46,18 +46,39 @@ namespace gamestate
|
||||
{
|
||||
draw::surface *pic = draw::loadSurface(filename);
|
||||
draw::setSource(pic);
|
||||
draw::loadPalette(filename);
|
||||
draw::draw(0, 0, 320, 200, 0, 0);
|
||||
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);
|
||||
draw::setPaletteEntry(64, 255, 255, 255);
|
||||
draw::setPaletteEntry(65, 255, 0, 0);
|
||||
draw::setPaletteEntry(66, 0, 255, 0);
|
||||
draw::setPaletteEntry(67, 0, 0, 255);
|
||||
draw::setPaletteEntry(68, 0, 0, 0);
|
||||
draw::swapcol(1, color+64);
|
||||
draw::swapcol(2, 68);
|
||||
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::restorecol(1);
|
||||
draw::restorecol(2);
|
||||
draw::freeSurface(pic);
|
||||
draw::render();
|
||||
}
|
||||
|
||||
bool loop()
|
||||
{
|
||||
if (wait_until>0 && SDL_GetTicks() < wait_until)
|
||||
if ( (wait_until > 0) && (SDL_GetTicks() < wait_until) )
|
||||
{
|
||||
if (input::anyKey() || input::mouseBtn(1))
|
||||
{
|
||||
@@ -65,44 +86,75 @@ namespace gamestate
|
||||
}
|
||||
else
|
||||
{
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const char tipo_diapositiva = *(sequence_file++);
|
||||
switch ( tipo_diapositiva )
|
||||
{
|
||||
case DIAPO_ESPERAR:
|
||||
wait_until = SDL_GetTicks() + getWord();
|
||||
{
|
||||
const uint16_t time = getWord();
|
||||
wait_until = SDL_GetTicks() + time;
|
||||
printf("- Esperar(%i)\n", time);
|
||||
break;
|
||||
}
|
||||
case DIAPO_FADEIN:
|
||||
drawPic(getString());
|
||||
{
|
||||
std::string filename = getString();
|
||||
drawPic(filename);
|
||||
draw::fadein();
|
||||
wait_until = SDL_GetTicks() + 250;
|
||||
draw::render();
|
||||
wait_until = SDL_GetTicks() + 500;
|
||||
printf("- FadeIn('%s')\n", filename.c_str());
|
||||
break;
|
||||
}
|
||||
case DIAPO_SHOW:
|
||||
drawPic(getString());
|
||||
{
|
||||
std::string filename = getString();
|
||||
drawPic(filename);
|
||||
draw::render();
|
||||
printf("- Show('%s')\n", filename.c_str());
|
||||
break;
|
||||
}
|
||||
case DIAPO_PRINT:
|
||||
drawText(getWord(), getWord(), getByte(), getString());
|
||||
{
|
||||
const uint16_t x = getWord();
|
||||
const uint16_t y = getWord();
|
||||
const uint8_t col = getByte();
|
||||
std::string text = getString();
|
||||
drawText(x, y, col, text);
|
||||
printf("- Print(%i, %i, %i, '%s')\n", x, y, col, text.c_str());
|
||||
break;
|
||||
}
|
||||
case DIAPO_MUSICA:
|
||||
audio::playMusic(audio::loadMusic(getString()));
|
||||
{
|
||||
std::string filename = getString();
|
||||
audio::playMusic(audio::loadMusic(filename));
|
||||
printf("- PlayMusic('%s')\n", filename.c_str());
|
||||
break;
|
||||
}
|
||||
case DIAPO_FADEOUT:
|
||||
{
|
||||
draw::fadeout();
|
||||
wait_until = SDL_GetTicks() + 250;
|
||||
wait_until = SDL_GetTicks() + 500;
|
||||
printf("- FadeOut()\n");
|
||||
break;
|
||||
}
|
||||
case DIAPO_FADEMUSIC:
|
||||
draw::fadeout();
|
||||
audio::fadeoutMusic();
|
||||
wait_until = SDL_GetTicks() + 250;
|
||||
wait_until = SDL_GetTicks() + 500;
|
||||
printf("- FadeOutMusic()\n");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
draw::setTrans(255);
|
||||
const int fase = game::getConfig("fase");
|
||||
std::string filename;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "jaudio.h"
|
||||
#include "jfile.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <stdio.h>
|
||||
@@ -19,7 +20,12 @@ namespace audio
|
||||
void init()
|
||||
{
|
||||
// Al final he ficat la configuració automàtica i au. Si en el futur necesitem canviar-ho pos se canvia
|
||||
Mix_OpenAudio(48000, AUDIO_S16, 2, 1024);
|
||||
if (Mix_Init(MIX_INIT_OGG)==0) {
|
||||
printf("Failed Mix_Init()\n");
|
||||
}
|
||||
if (Mix_OpenAudio(48000, AUDIO_S16, 2, 1024)!=0) {
|
||||
printf("Failed Mix_OpenAudio()\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Tanca el sistema de só (no shit, sherlock)
|
||||
@@ -31,13 +37,34 @@ namespace audio
|
||||
// Carrega un arxiu de música en format OGG
|
||||
const music *loadMusic(const std::string filename)
|
||||
{
|
||||
return (music *)Mix_LoadMUS(filename.c_str());
|
||||
size_t index = 0;
|
||||
index = filename.find("mp3", index);
|
||||
std::string peiv(filename);
|
||||
peiv.replace(index, 3, "ogg");
|
||||
|
||||
printf("Loading '%s'...", peiv.c_str());
|
||||
|
||||
int filesize=0;
|
||||
char *buffer = file::getFileBuffer(peiv, filesize);
|
||||
const music* m = (music *)Mix_LoadMUS_RW(SDL_RWFromMem(buffer, filesize), 1);
|
||||
|
||||
// [TODO] ATENCIÓ. Ací leakeja com un burro, algo hi ha que inventar, pero el buffer ha de sobreviure tot el temps que dure la musica viva
|
||||
//free(buffer);
|
||||
|
||||
if (m==nullptr) {
|
||||
printf("FAILED!\n");
|
||||
} else {
|
||||
printf("OK!\n");
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
// Comença a reproduïr la música en questió
|
||||
void playMusic(const music *mus, const int loop)
|
||||
{
|
||||
Mix_PlayMusic((Mix_Music *)mus, loop);
|
||||
if (Mix_PlayMusic((Mix_Music *)mus, loop) == -1) {
|
||||
printf("Failed Mix_PlayMusic()\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Pausa la música que està sonant ara
|
||||
@@ -61,7 +88,7 @@ namespace audio
|
||||
// Para la música que estava sonant fent un fade
|
||||
void fadeoutMusic()
|
||||
{
|
||||
Mix_FadeOutMusic(250);
|
||||
Mix_FadeOutMusic(500);
|
||||
}
|
||||
|
||||
// Obté el estat actual de la música
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace draw
|
||||
uint8_t sel_color = 0; // Color seleccionat per defecte
|
||||
uint8_t transparent = 0; // El color transparent
|
||||
|
||||
surface *textsurf = nullptr; // Surface on guardar el gif amb la font
|
||||
//surface *textsurf = nullptr; // Surface on guardar el gif amb la font
|
||||
|
||||
SDL_Rect viewport;
|
||||
|
||||
@@ -52,16 +52,19 @@ namespace draw
|
||||
// Creem la superficie "screen" i la establim com a superficie destinació
|
||||
screen = createSurface(width, height);
|
||||
destination = screen;
|
||||
viewport.x = viewport.y = 0;
|
||||
viewport.w = width;
|
||||
viewport.h = height;
|
||||
sel_color = transparent = 0;
|
||||
for (int i=0;i<256;++i) color_indices[i] = i;
|
||||
|
||||
textsurf = loadSurface("font.gif");
|
||||
//textsurf = loadSurface("font.gif");
|
||||
}
|
||||
|
||||
// Finalització del sistema
|
||||
void quit()
|
||||
{
|
||||
if (textsurf) freeSurface(textsurf);
|
||||
//if (textsurf) freeSurface(textsurf);
|
||||
|
||||
// Si la superficie "screen" existia, alliberem la seua memòria
|
||||
if (screen != nullptr)
|
||||
@@ -223,6 +226,12 @@ namespace draw
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
palette[index] = (r << 16) + (g << 8) + b;
|
||||
}
|
||||
|
||||
// Esborra la superficie "destination" amb el color especificat
|
||||
void cls(const uint8_t color)
|
||||
{
|
||||
@@ -251,7 +260,7 @@ namespace draw
|
||||
surface->pixels[(viewport.x+x) + (y+viewport.y) * surface->w] = color_indices[color];
|
||||
} else {
|
||||
// Si no es destinations, mirem que estiga dins de la surface, i sinó fora!
|
||||
if (x >= 0 && y >= 0 && x < destination->w && y < destination->h)
|
||||
if (x >= 0 && y >= 0 && x < surface->w && y < surface->h)
|
||||
surface->pixels[x + y * surface->w] = color_indices[color];
|
||||
}
|
||||
}
|
||||
@@ -265,7 +274,7 @@ namespace draw
|
||||
return surface->pixels[(viewport.x + x) + (viewport.y + y) * surface->w];
|
||||
} else {
|
||||
// Si no es "destination", si la coordenada està dins del rang que abarca la superficie,
|
||||
if (x >= 0 && y >= 0 && x < destination->w && y < destination->h)
|
||||
if (x >= 0 && y >= 0 && x < surface->w && y < surface->h)
|
||||
return surface->pixels[x + y * surface->w];
|
||||
}
|
||||
|
||||
@@ -398,40 +407,13 @@ namespace draw
|
||||
}
|
||||
}
|
||||
fading_in = false;
|
||||
for (int i=0; i<256; ++i) if (incPalEntry(i, 16)) fading_in = true;
|
||||
for (int i=0; i<256; ++i) if (incPalEntry(i, 8)) fading_in = true;
|
||||
}
|
||||
|
||||
void fadeout()
|
||||
{
|
||||
fading_out = false;
|
||||
for (int i=0; i<256; ++i) if (decPalEntry(i, 16)) fading_out = true;
|
||||
}
|
||||
|
||||
void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde)
|
||||
{
|
||||
surface* tmp = source;
|
||||
source = textsurf;
|
||||
swapcol(1, color);
|
||||
const int len = strlen(text);
|
||||
for (int i=0;i<len;++i)
|
||||
{
|
||||
char chr = text[i];
|
||||
if (borde!=0)
|
||||
{
|
||||
swapcol(1, borde);
|
||||
draw(-1+x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(1+x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(-1+x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(1+x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(-1+x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
draw(1+x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
swapcol(1, color);
|
||||
}
|
||||
draw(x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6);
|
||||
}
|
||||
source = tmp;
|
||||
for (int i=0; i<256; ++i) if (decPalEntry(i, 8)) fading_out = true;
|
||||
}
|
||||
|
||||
// Refresca la pantalla
|
||||
|
||||
@@ -67,6 +67,13 @@ namespace draw
|
||||
/// @param filename nom de l'arxiu GIF d'on carregar la paleta
|
||||
void loadPalette(const std::string &filename);
|
||||
|
||||
/// @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
|
||||
/// @param g la component verda de l'entrada de la paleta
|
||||
/// @param b la component blava de l'entrada de la paleta
|
||||
void setPaletteEntry(const uint8_t index, const uint8_t r, const uint8_t g, const uint8_t b);
|
||||
|
||||
/// @brief Esborra la superficie "destination" amb el color especificat
|
||||
/// @param color color a usar per a borrar la superficie de destinació
|
||||
void cls(const uint8_t color);
|
||||
@@ -96,7 +103,7 @@ namespace draw
|
||||
void fadein();
|
||||
void fadeout();
|
||||
|
||||
void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde);
|
||||
//void print(const char* text, const int x, const int y, const uint8_t color, const uint8_t borde);
|
||||
|
||||
/// @brief Refresca la pantalla
|
||||
void render();
|
||||
|
||||
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)
|
||||
{
|
||||
if (!game::loop()) should_exit = true;
|
||||
if (game::loop) if (!game::loop()) should_exit = true;
|
||||
input::updateKey(SDL_SCANCODE_UNKNOWN);
|
||||
input::updateKeypressed(SDL_SCANCODE_UNKNOWN);
|
||||
input::updateClk(0);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "jinput.h"
|
||||
#include "jaudio.h"
|
||||
|
||||
#include "gamestate_sequence.h"
|
||||
|
||||
void game::init()
|
||||
{
|
||||
draw::init("Arounders", 320, 200, 3);
|
||||
@@ -12,5 +14,14 @@ void game::init()
|
||||
game::setUpdateTicks(16);
|
||||
game::setConfig("fase", -1);
|
||||
|
||||
game::setState(nullptr);
|
||||
gamestate::sequence::init();
|
||||
|
||||
/*
|
||||
draw::surface *pic = draw::loadSurface("sprites.gif");
|
||||
draw::setSource(pic);
|
||||
draw::loadPalette("sprites.gif");
|
||||
draw::draw(0, 0, 320, 200, 0, 0);
|
||||
draw::freeSurface(pic);
|
||||
draw::render();
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user