clang-format

This commit is contained in:
2026-04-04 13:03:20 +02:00
parent 6a09d7219d
commit baee62b375
36 changed files with 2576 additions and 2408 deletions

22
.clang-format Normal file
View File

@@ -0,0 +1,22 @@
BasedOnStyle: Google
IndentWidth: 4
NamespaceIndentation: All
IndentAccessModifiers: false
ColumnLimit: 0 # Sin límite de longitud de línea
BreakBeforeBraces: Attach # Llaves en la misma línea
AllowShortIfStatementsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlignOperands: DontAlign
AlignAfterOpenBracket: DontAlign
BinPackArguments: false
BinPackParameters: false
ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 4
IndentWrappedFunctionNames: false
Cpp11BracedListStyle: true
BreakConstructorInitializers: BeforeColon
AllowAllConstructorInitializersOnNextLine: false
PackConstructorInitializers: Never
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false

View File

@@ -66,3 +66,35 @@ endif()
# Ejecutable en la raíz del proyecto # Ejecutable en la raíz del proyecto
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
# --- CLANG-FORMAT TARGETS ---
find_program(CLANG_FORMAT_EXE NAMES clang-format)
# Recopilar todos los archivos fuente para formateo (excluir external/)
file(GLOB_RECURSE ALL_SOURCE_FILES
"${CMAKE_SOURCE_DIR}/source/*.cpp"
"${CMAKE_SOURCE_DIR}/source/*.hpp"
"${CMAKE_SOURCE_DIR}/source/*.h"
)
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX ".*/external/.*")
if(CLANG_FORMAT_EXE)
add_custom_target(format
COMMAND ${CLANG_FORMAT_EXE}
-i
${ALL_SOURCE_FILES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running clang-format..."
)
add_custom_target(format-check
COMMAND ${CLANG_FORMAT_EXE}
--dry-run
--Werror
${ALL_SOURCE_FILES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Checking clang-format..."
)
else()
message(STATUS "clang-format no encontrado - targets 'format' y 'format-check' no disponibles")
endif()

View File

@@ -1,20 +1,20 @@
#ifndef JA_USESDLMIXER #ifndef JA_USESDLMIXER
#include "core/jail_audio.hpp" #include "core/jail_audio.hpp"
#include "external/stb_vorbis.h"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <stdio.h> #include <stdio.h>
#include "external/stb_vorbis.h"
#define JA_MAX_SIMULTANEOUS_CHANNELS 5 #define JA_MAX_SIMULTANEOUS_CHANNELS 5
struct JA_Sound_t struct JA_Sound_t {
{
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000}; SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
Uint32 length{0}; Uint32 length{0};
Uint8 *buffer{NULL}; Uint8 *buffer{NULL};
}; };
struct JA_Channel_t struct JA_Channel_t {
{
JA_Sound_t *sound{nullptr}; JA_Sound_t *sound{nullptr};
int pos{0}; int pos{0};
int times{0}; int times{0};
@@ -22,8 +22,7 @@ struct JA_Channel_t
JA_Channel_state state{JA_CHANNEL_FREE}; JA_Channel_state state{JA_CHANNEL_FREE};
}; };
struct JA_Music_t struct JA_Music_t {
{
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000}; SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
Uint32 length{0}; Uint32 length{0};
Uint8 *buffer{nullptr}; Uint8 *buffer{nullptr};
@@ -89,10 +88,8 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
} }
*/ */
Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval) Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval) {
{ if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING) {
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING)
{
if (fading) { if (fading) {
int time = SDL_GetTicks(); int time = SDL_GetTicks();
if (time > (fade_start_time + fade_duration)) { if (time > (fade_start_time + fade_duration)) {
@@ -106,44 +103,34 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
} }
} }
if (current_music->times != 0) if (current_music->times != 0) {
{
if (SDL_GetAudioStreamAvailable(current_music->stream) < int(current_music->length / 2)) { if (SDL_GetAudioStreamAvailable(current_music->stream) < int(current_music->length / 2)) {
SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length); SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length);
} }
if (current_music->times > 0) current_music->times--; if (current_music->times > 0) current_music->times--;
} } else {
else
{
if (SDL_GetAudioStreamAvailable(current_music->stream) == 0) JA_StopMusic(); if (SDL_GetAudioStreamAvailable(current_music->stream) == 0) JA_StopMusic();
} }
} }
if (JA_soundEnabled) if (JA_soundEnabled) {
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i) for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i)
if (channels[i].state == JA_CHANNEL_PLAYING) if (channels[i].state == JA_CHANNEL_PLAYING) {
{ if (channels[i].times != 0) {
if (channels[i].times != 0)
{
if (SDL_GetAudioStreamAvailable(channels[i].stream) < int(channels[i].sound->length / 2)) { if (SDL_GetAudioStreamAvailable(channels[i].stream) < int(channels[i].sound->length / 2)) {
SDL_PutAudioStreamData(channels[i].stream, channels[i].sound->buffer, channels[i].sound->length); SDL_PutAudioStreamData(channels[i].stream, channels[i].sound->buffer, channels[i].sound->length);
if (channels[i].times > 0) channels[i].times--; if (channels[i].times > 0) channels[i].times--;
} }
} } else {
else
{
if (SDL_GetAudioStreamAvailable(channels[i].stream) == 0) JA_StopChannel(i); if (SDL_GetAudioStreamAvailable(channels[i].stream) == 0) JA_StopChannel(i);
} }
} }
} }
return 30; return 30;
} }
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) {
{
#ifdef DEBUG #ifdef DEBUG
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif #endif
@@ -158,16 +145,14 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channel
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr); JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
} }
void JA_Quit() void JA_Quit() {
{
if (JA_timerID) SDL_RemoveTimer(JA_timerID); if (JA_timerID) SDL_RemoveTimer(JA_timerID);
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice); if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = 0; sdlAudioDevice = 0;
} }
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename) JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length, const char *filename) {
{
JA_Music_t *music = new JA_Music_t(); JA_Music_t *music = new JA_Music_t();
int chan, samplerate; int chan, samplerate;
@@ -190,8 +175,7 @@ JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename)
return music; return music;
} }
JA_Music_t *JA_LoadMusic(const char* filename) JA_Music_t *JA_LoadMusic(const char *filename) {
{
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid. // [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
FILE *f = fopen(filename, "rb"); FILE *f = fopen(filename, "rb");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
@@ -208,8 +192,7 @@ JA_Music_t *JA_LoadMusic(const char* filename)
return music; return music;
} }
void JA_PlayMusic(JA_Music_t *music, const int loop) void JA_PlayMusic(JA_Music_t *music, const int loop) {
{
if (!JA_musicEnabled) return; if (!JA_musicEnabled) return;
JA_StopMusic(); JA_StopMusic();
@@ -226,14 +209,12 @@ void JA_PlayMusic(JA_Music_t *music, const int loop)
// SDL_ResumeAudioStreamDevice(current_music->stream); // SDL_ResumeAudioStreamDevice(current_music->stream);
} }
char *JA_GetMusicFilename(JA_Music_t *music) char *JA_GetMusicFilename(JA_Music_t *music) {
{
if (!music) music = current_music; if (!music) music = current_music;
return music->filename; return music->filename;
} }
void JA_PauseMusic() void JA_PauseMusic() {
{
if (!JA_musicEnabled) return; if (!JA_musicEnabled) return;
if (!current_music || current_music->state == JA_MUSIC_INVALID) return; if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
@@ -242,8 +223,7 @@ void JA_PauseMusic()
SDL_UnbindAudioStream(current_music->stream); SDL_UnbindAudioStream(current_music->stream);
} }
void JA_ResumeMusic() void JA_ResumeMusic() {
{
if (!JA_musicEnabled) return; if (!JA_musicEnabled) return;
if (!current_music || current_music->state == JA_MUSIC_INVALID) return; if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
@@ -252,8 +232,7 @@ void JA_ResumeMusic()
SDL_BindAudioStream(sdlAudioDevice, current_music->stream); SDL_BindAudioStream(sdlAudioDevice, current_music->stream);
} }
void JA_StopMusic() void JA_StopMusic() {
{
if (!JA_musicEnabled) return; if (!JA_musicEnabled) return;
if (!current_music || current_music->state == JA_MUSIC_INVALID) return; if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
@@ -266,8 +245,7 @@ void JA_StopMusic()
current_music->filename = nullptr; current_music->filename = nullptr;
} }
void JA_FadeOutMusic(const int milliseconds) void JA_FadeOutMusic(const int milliseconds) {
{
if (!JA_musicEnabled) return; if (!JA_musicEnabled) return;
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return; if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
@@ -277,78 +255,64 @@ void JA_FadeOutMusic(const int milliseconds)
fade_initial_volume = JA_musicVolume; fade_initial_volume = JA_musicVolume;
} }
JA_Music_state JA_GetMusicState() JA_Music_state JA_GetMusicState() {
{
if (!JA_musicEnabled) return JA_MUSIC_DISABLED; if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
if (!current_music) return JA_MUSIC_INVALID; if (!current_music) return JA_MUSIC_INVALID;
return current_music->state; return current_music->state;
} }
void JA_DeleteMusic(JA_Music_t *music) void JA_DeleteMusic(JA_Music_t *music) {
{
if (current_music == music) current_music = nullptr; if (current_music == music) current_music = nullptr;
SDL_free(music->buffer); SDL_free(music->buffer);
if (music->stream) SDL_DestroyAudioStream(music->stream); if (music->stream) SDL_DestroyAudioStream(music->stream);
delete music; delete music;
} }
float JA_SetMusicVolume(float volume) float JA_SetMusicVolume(float volume) {
{
JA_musicVolume = SDL_clamp(volume, 0.0f, 1.0f); JA_musicVolume = SDL_clamp(volume, 0.0f, 1.0f);
if (current_music) SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume); if (current_music) SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
return JA_musicVolume; return JA_musicVolume;
} }
void JA_SetMusicPosition(float value) void JA_SetMusicPosition(float value) {
{
if (!current_music) return; if (!current_music) return;
current_music->pos = value * current_music->spec.freq; current_music->pos = value * current_music->spec.freq;
} }
float JA_GetMusicPosition() float JA_GetMusicPosition() {
{
if (!current_music) return 0; if (!current_music) return 0;
return float(current_music->pos) / float(current_music->spec.freq); return float(current_music->pos) / float(current_music->spec.freq);
} }
void JA_EnableMusic(const bool value) void JA_EnableMusic(const bool value) {
{
if (!value && current_music && (current_music->state == JA_MUSIC_PLAYING)) JA_StopMusic(); if (!value && current_music && (current_music->state == JA_MUSIC_PLAYING)) JA_StopMusic();
JA_musicEnabled = value; JA_musicEnabled = value;
} }
JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length) {
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length)
{
JA_Sound_t *sound = new JA_Sound_t(); JA_Sound_t *sound = new JA_Sound_t();
sound->buffer = buffer; sound->buffer = buffer;
sound->length = length; sound->length = length;
return sound; return sound;
} }
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) JA_Sound_t *JA_LoadSound(uint8_t *buffer, uint32_t size) {
{
JA_Sound_t *sound = new JA_Sound_t(); JA_Sound_t *sound = new JA_Sound_t();
SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &sound->buffer, &sound->length); SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &sound->buffer, &sound->length);
return sound; return sound;
} }
JA_Sound_t *JA_LoadSound(const char* filename) JA_Sound_t *JA_LoadSound(const char *filename) {
{
JA_Sound_t *sound = new JA_Sound_t(); JA_Sound_t *sound = new JA_Sound_t();
SDL_LoadWAV(filename, &sound->spec, &sound->buffer, &sound->length); SDL_LoadWAV(filename, &sound->spec, &sound->buffer, &sound->length);
return sound; return sound;
} }
int JA_PlaySound(JA_Sound_t *sound, const int loop) int JA_PlaySound(JA_Sound_t *sound, const int loop) {
{
if (!JA_soundEnabled) return -1; if (!JA_soundEnabled) return -1;
int channel = 0; int channel = 0;
@@ -368,8 +332,7 @@ int JA_PlaySound(JA_Sound_t *sound, const int loop)
return channel; return channel;
} }
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop) int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop) {
{
if (!JA_soundEnabled) return -1; if (!JA_soundEnabled) return -1;
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1; if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1;
@@ -387,8 +350,7 @@ int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
return channel; return channel;
} }
void JA_DeleteSound(JA_Sound_t *sound) void JA_DeleteSound(JA_Sound_t *sound) {
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].sound == sound) JA_StopChannel(i); if (channels[i].sound == sound) JA_StopChannel(i);
} }
@@ -396,24 +358,18 @@ void JA_DeleteSound(JA_Sound_t *sound)
delete sound; delete sound;
} }
void JA_PauseChannel(const int channel) void JA_PauseChannel(const int channel) {
{
if (!JA_soundEnabled) return; if (!JA_soundEnabled) return;
if (channel == -1) if (channel == -1) {
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if (channels[i].state == JA_CHANNEL_PLAYING) if (channels[i].state == JA_CHANNEL_PLAYING) {
{
channels[i].state = JA_CHANNEL_PAUSED; channels[i].state = JA_CHANNEL_PAUSED;
// SDL_PauseAudioStreamDevice(channels[i].stream); // SDL_PauseAudioStreamDevice(channels[i].stream);
SDL_UnbindAudioStream(channels[i].stream); SDL_UnbindAudioStream(channels[i].stream);
} }
} } else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) if (channels[channel].state == JA_CHANNEL_PLAYING) {
{
if (channels[channel].state == JA_CHANNEL_PLAYING)
{
channels[channel].state = JA_CHANNEL_PAUSED; channels[channel].state = JA_CHANNEL_PAUSED;
// SDL_PauseAudioStreamDevice(channels[channel].stream); // SDL_PauseAudioStreamDevice(channels[channel].stream);
SDL_UnbindAudioStream(channels[channel].stream); SDL_UnbindAudioStream(channels[channel].stream);
@@ -421,24 +377,18 @@ void JA_PauseChannel(const int channel)
} }
} }
void JA_ResumeChannel(const int channel) void JA_ResumeChannel(const int channel) {
{
if (!JA_soundEnabled) return; if (!JA_soundEnabled) return;
if (channel == -1) if (channel == -1) {
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if (channels[i].state == JA_CHANNEL_PAUSED) if (channels[i].state == JA_CHANNEL_PAUSED) {
{
channels[i].state = JA_CHANNEL_PLAYING; channels[i].state = JA_CHANNEL_PLAYING;
// SDL_ResumeAudioStreamDevice(channels[i].stream); // SDL_ResumeAudioStreamDevice(channels[i].stream);
SDL_BindAudioStream(sdlAudioDevice, channels[i].stream); SDL_BindAudioStream(sdlAudioDevice, channels[i].stream);
} }
} } else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) if (channels[channel].state == JA_CHANNEL_PAUSED) {
{
if (channels[channel].state == JA_CHANNEL_PAUSED)
{
channels[channel].state = JA_CHANNEL_PLAYING; channels[channel].state = JA_CHANNEL_PLAYING;
// SDL_ResumeAudioStreamDevice(channels[channel].stream); // SDL_ResumeAudioStreamDevice(channels[channel].stream);
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream); SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
@@ -446,12 +396,10 @@ void JA_ResumeChannel(const int channel)
} }
} }
void JA_StopChannel(const int channel) void JA_StopChannel(const int channel) {
{
if (!JA_soundEnabled) return; if (!JA_soundEnabled) return;
if (channel == -1) if (channel == -1) {
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[i].stream); if (channels[i].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[i].stream);
channels[i].stream = nullptr; channels[i].stream = nullptr;
@@ -459,9 +407,7 @@ void JA_StopChannel(const int channel)
channels[i].pos = 0; channels[i].pos = 0;
channels[i].sound = NULL; channels[i].sound = NULL;
} }
} } else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
if (channels[channel].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[channel].stream); if (channels[channel].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[channel].stream);
channels[channel].stream = nullptr; channels[channel].stream = nullptr;
channels[channel].state = JA_CHANNEL_FREE; channels[channel].state = JA_CHANNEL_FREE;
@@ -470,8 +416,7 @@ void JA_StopChannel(const int channel)
} }
} }
JA_Channel_state JA_GetChannelState(const int channel) JA_Channel_state JA_GetChannelState(const int channel) {
{
if (!JA_soundEnabled) return JA_SOUND_DISABLED; if (!JA_soundEnabled) return JA_SOUND_DISABLED;
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
@@ -479,8 +424,7 @@ JA_Channel_state JA_GetChannelState(const int channel)
return channels[channel].state; return channels[channel].state;
} }
float JA_SetSoundVolume(float volume) float JA_SetSoundVolume(float volume) {
{
JA_soundVolume = SDL_clamp(volume, 0.0f, 1.0f); JA_soundVolume = SDL_clamp(volume, 0.0f, 1.0f);
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
@@ -490,17 +434,14 @@ float JA_SetSoundVolume(float volume)
return JA_soundVolume; return JA_soundVolume;
} }
void JA_EnableSound(const bool value) void JA_EnableSound(const bool value) {
{ for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
{
if (channels[i].state == JA_CHANNEL_PLAYING) JA_StopChannel(i); if (channels[i].state == JA_CHANNEL_PLAYING) JA_StopChannel(i);
} }
JA_soundEnabled = value; JA_soundEnabled = value;
} }
float JA_SetVolume(float volume) float JA_SetVolume(float volume) {
{
JA_SetSoundVolume(JA_SetMusicVolume(volume) / 2.0f); JA_SetSoundVolume(JA_SetMusicVolume(volume) / 2.0f);
return JA_musicVolume; return JA_musicVolume;

View File

@@ -1,8 +1,16 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED }; enum JA_Channel_state { JA_CHANNEL_INVALID,
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED }; JA_CHANNEL_FREE,
JA_CHANNEL_PLAYING,
JA_CHANNEL_PAUSED,
JA_SOUND_DISABLED };
enum JA_Music_state { JA_MUSIC_INVALID,
JA_MUSIC_PLAYING,
JA_MUSIC_PAUSED,
JA_MUSIC_STOPPED,
JA_MUSIC_DISABLED };
struct JA_Sound_t; struct JA_Sound_t;
struct JA_Music_t; struct JA_Music_t;

View File

@@ -1,8 +1,10 @@
#include "core/jdraw8.hpp" #include "core/jdraw8.hpp"
#include "core/jfile.hpp"
#include <fstream> #include <fstream>
#include "external/gif.h"
#include "core/jfile.hpp"
#include "core/jshader.hpp" #include "core/jshader.hpp"
#include "external/gif.h"
#define SCREEN_WIDTH 960 #define SCREEN_WIDTH 960
#define SCREEN_HEIGHT 720 #define SCREEN_HEIGHT 720
@@ -212,9 +214,18 @@ void JD8_SetPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b) {
void JD8_FadeOut() { void JD8_FadeOut() {
for (int j = 0; j < 32; j++) { for (int j = 0; j < 32; j++) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
if( main_palette[i].r >= 8 ) main_palette[i].r-=8; else main_palette[i].r=0; if (main_palette[i].r >= 8)
if( main_palette[i].g >= 8 ) main_palette[i].g-=8; else main_palette[i].g=0; main_palette[i].r -= 8;
if( main_palette[i].b >= 8 ) main_palette[i].b-=8; else main_palette[i].b=0; else
main_palette[i].r = 0;
if (main_palette[i].g >= 8)
main_palette[i].g -= 8;
else
main_palette[i].g = 0;
if (main_palette[i].b >= 8)
main_palette[i].b -= 8;
else
main_palette[i].b = 0;
} }
JD8_Flip(); JD8_Flip();
} }
@@ -225,9 +236,18 @@ void JD8_FadeOut() {
void JD8_FadeToPal(JD8_Palette pal) { void JD8_FadeToPal(JD8_Palette pal) {
for (int j = 0; j < 32; j++) { for (int j = 0; j < 32; j++) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
if( main_palette[i].r <= int(pal[i].r)-8 ) main_palette[i].r+=8; else main_palette[i].r=pal[i].r; if (main_palette[i].r <= int(pal[i].r) - 8)
if( main_palette[i].g <= int(pal[i].g)-8 ) main_palette[i].g+=8; else main_palette[i].g=pal[i].g; main_palette[i].r += 8;
if( main_palette[i].b <= int(pal[i].b)-8 ) main_palette[i].b+=8; else main_palette[i].b=pal[i].b; else
main_palette[i].r = pal[i].r;
if (main_palette[i].g <= int(pal[i].g) - 8)
main_palette[i].g += 8;
else
main_palette[i].g = pal[i].g;
if (main_palette[i].b <= int(pal[i].b) - 8)
main_palette[i].b += 8;
else
main_palette[i].b = pal[i].b;
} }
JD8_Flip(); JD8_Flip();
} }

View File

@@ -1,13 +1,15 @@
#include "core/jfile.hpp"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "core/jfile.hpp"
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <iostream>
#include <fstream>
#include <filesystem> #include <filesystem>
#include <fstream>
#include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -19,8 +21,7 @@
#define DEFAULT_FOLDER "data/" #define DEFAULT_FOLDER "data/"
#define CONFIG_FILENAME "config.txt" #define CONFIG_FILENAME "config.txt"
struct file_t struct file_t {
{
std::string path; std::string path;
uint32_t size; uint32_t size;
uint32_t offset; uint32_t offset;
@@ -69,8 +70,7 @@ bool file_getdictionary() {
fi.read((char *)&toc_offset, 4); fi.read((char *)&toc_offset, 4);
fi.seekg(toc_offset); fi.seekg(toc_offset);
for (uint32_t i=0; i<num_files; ++i) for (uint32_t i = 0; i < num_files; ++i) {
{
uint32_t file_offset, file_size; uint32_t file_offset, file_size;
fi.read((char *)&file_offset, 4); fi.read((char *)&file_offset, 4);
fi.read((char *)&file_size, 4); fi.read((char *)&file_size, 4);
@@ -93,7 +93,6 @@ char *file_getfilenamewithfolder(const char* filename) {
} }
FILE *file_getfilepointer(const char *resourcename, int &filesize, const bool binary) { FILE *file_getfilepointer(const char *resourcename, int &filesize, const bool binary) {
if (file_source == SOURCE_FILE and toc.size() == 0) { if (file_source == SOURCE_FILE and toc.size() == 0) {
if (not file_getdictionary()) file_setsource(SOURCE_FOLDER); if (not file_getdictionary()) file_setsource(SOURCE_FOLDER);
} }
@@ -141,8 +140,7 @@ char *file_getfilebuffer(const char *resourcename, int& filesize, const bool zer
// Crea la carpeta del sistema donde guardar datos. // Crea la carpeta del sistema donde guardar datos.
// Acepta rutas con subdirectorios (ej: "jailgames/aee") y crea toda la jerarquía. // Acepta rutas con subdirectorios (ej: "jailgames/aee") y crea toda la jerarquía.
void file_setconfigfolder(const char *foldername) void file_setconfigfolder(const char *foldername) {
{
#ifdef _WIN32 #ifdef _WIN32
config_folder = std::string(getenv("APPDATA")) + "/" + foldername; config_folder = std::string(getenv("APPDATA")) + "/" + foldername;
#elif __APPLE__ #elif __APPLE__
@@ -174,7 +172,8 @@ void file_loadconfigvalues() {
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
char *value = strchr(line, '='); char *value = strchr(line, '=');
if (value) { if (value) {
*value='\0'; value++; *value = '\0';
value++;
value[strlen(value) - 1] = '\0'; value[strlen(value) - 1] = '\0';
config.push_back({line, value}); config.push_back({line, value});
} }

View File

@@ -6,7 +6,6 @@ Uint32 updateTime = 0;
Uint32 cycle_counter = 0; Uint32 cycle_counter = 0;
void JG_Init() { void JG_Init() {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
// SDL_WM_SetCaption( title, NULL ); // SDL_WM_SetCaption( title, NULL );
updateTime = SDL_GetTicks(); updateTime = SDL_GetTicks();

View File

@@ -1,7 +1,9 @@
#include "core/jinput.hpp" #include "core/jinput.hpp"
#include "core/jgame.hpp"
#include <string> #include <string>
#include "core/jgame.hpp"
const bool* keystates; // = SDL_GetKeyboardState( NULL ); const bool* keystates; // = SDL_GetKeyboardState( NULL );
SDL_Event event; SDL_Event event;
Uint8 cheat[5]; Uint8 cheat[5];

View File

@@ -3,9 +3,10 @@
#include <iostream> #include <iostream>
#ifdef __APPLE__ #ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
#include "CoreFoundation/CoreFoundation.h"
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 #if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
#include <OpenGL/gl3.h> #include <OpenGL/gl3.h>
#else #else
@@ -16,8 +17,7 @@
#include <SDL3/SDL_opengl_glext.h> #include <SDL3/SDL_opengl_glext.h>
#endif #endif
namespace shader namespace shader {
{
SDL_Window* win = nullptr; SDL_Window* win = nullptr;
SDL_Renderer* renderer = nullptr; SDL_Renderer* renderer = nullptr;
GLuint programId = 0; GLuint programId = 0;
@@ -82,13 +82,11 @@ namespace shader
// Check vertex shader for errors // Check vertex shader for errors
GLint shaderCompiled = GL_FALSE; GLint shaderCompiled = GL_FALSE;
glGetShaderiv(result, GL_COMPILE_STATUS, &shaderCompiled); glGetShaderiv(result, GL_COMPILE_STATUS, &shaderCompiled);
if (shaderCompiled != GL_TRUE) if (shaderCompiled != GL_TRUE) {
{
std::cout << "Error en la compilación: " << result << "!" << std::endl; std::cout << "Error en la compilación: " << result << "!" << std::endl;
GLint logLength; GLint logLength;
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength); glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) if (logLength > 0) {
{
GLchar* log = (GLchar*)malloc(logLength); GLchar* log = (GLchar*)malloc(logLength);
glGetShaderInfoLog(result, logLength, &logLength, log); glGetShaderInfoLog(result, logLength, &logLength, log);
std::cout << "Shader compile log:" << log << std::endl; std::cout << "Shader compile log:" << log << std::endl;
@@ -100,8 +98,7 @@ namespace shader
return result; return result;
} }
GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource) GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource) {
{
GLuint programId = 0; GLuint programId = 0;
GLuint vtxShaderId, fragShaderId; GLuint vtxShaderId, fragShaderId;
@@ -110,8 +107,7 @@ namespace shader
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER); vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
fragShaderId = compileShader(fragmentShaderSource ? fragmentShaderSource : vertexShaderSource, GL_FRAGMENT_SHADER); fragShaderId = compileShader(fragmentShaderSource ? fragmentShaderSource : vertexShaderSource, GL_FRAGMENT_SHADER);
if(vtxShaderId && fragShaderId) if (vtxShaderId && fragShaderId) {
{
// Associate shader with program // Associate shader with program
glAttachShader(programId, vtxShaderId); glAttachShader(programId, vtxShaderId);
glAttachShader(programId, fragShaderId); glAttachShader(programId, fragShaderId);
@@ -121,12 +117,12 @@ namespace shader
// Check the status of the compile/link // Check the status of the compile/link
GLint logLen; GLint logLen;
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen); glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
if (logLen > 0) if (logLen > 0) {
{
char* log = (char*)malloc(logLen * sizeof(char)); char* log = (char*)malloc(logLen * sizeof(char));
// Show any errors as appropriate // Show any errors as appropriate
glGetProgramInfoLog(programId, logLen, &logLen, log); glGetProgramInfoLog(programId, logLen, &logLen, log);
std::cout << "Prog Info Log: " << std::endl << log << std::endl; std::cout << "Prog Info Log: " << std::endl
<< log << std::endl;
free(log); free(log);
} }
} }
@@ -135,8 +131,7 @@ namespace shader
return programId; return programId;
} }
const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader) const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader) {
{
shader::win = win; shader::win = win;
shader::renderer = SDL_GetRenderer(win); shader::renderer = SDL_GetRenderer(win);
shader::backBuffer = backBuffer; shader::backBuffer = backBuffer;
@@ -150,8 +145,7 @@ namespace shader
nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1); nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1);
printf("texture target number: %i\n", nose); printf("texture target number: %i\n", nose);
if (access != SDL_TEXTUREACCESS_TARGET) if (access != SDL_TEXTUREACCESS_TARGET) {
{
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl; std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
exit(1); exit(1);
} }
@@ -180,19 +174,16 @@ namespace shader
unsigned char pixels[512 * 240 * 4]; unsigned char pixels[512 * 240 * 4];
void render() void render() {
{
SDL_FlushRenderer(renderer); SDL_FlushRenderer(renderer);
SDL_SetRenderTarget(renderer, NULL); SDL_SetRenderTarget(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
SDL_FlushRenderer(renderer); SDL_FlushRenderer(renderer);
if (usingOpenGL) if (usingOpenGL) {
{
GLint oldProgramId; GLint oldProgramId;
if (programId != 0) if (programId != 0) {
{
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId); glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
glUseProgram(programId); glUseProgram(programId);
} }
@@ -226,6 +217,9 @@ namespace shader
SDL_RenderTexture(renderer, backBuffer, NULL, NULL); SDL_RenderTexture(renderer, backBuffer, NULL, NULL);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
if (glGetError()) { printf("GLERROR!\n"); exit(1); } if (glGetError()) {
printf("GLERROR!\n");
exit(1);
} }
} }
} // namespace shader

View File

@@ -35,10 +35,8 @@
// Ah! una cosa mes: al compilar, en Linux afegir "-lGL", en Windows afegir "-lopengl32". // Ah! una cosa mes: al compilar, en Linux afegir "-lGL", en Windows afegir "-lopengl32".
// En Mac ni idea // En Mac ni idea
namespace shader namespace shader {
{ const bool init(SDL_Window* win, SDL_Texture* backBuffer, const char* vertexShader, const char* fragmentShader = nullptr);
const bool init(SDL_Window* win, SDL_Texture* backBuffer,
const char* vertexShader, const char* fragmentShader=nullptr);
void render(); void render();
} } // namespace shader

2
source/external/.clang-format vendored Normal file
View File

@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never

View File

@@ -1,8 +1,11 @@
#include "game/bola.hpp" #include "game/bola.hpp"
#include "core/jgame.hpp"
#include <stdlib.h> #include <stdlib.h>
Bola::Bola( JD8_Surface gfx, Prota* sam ) : Sprite( gfx ) { #include "core/jgame.hpp"
Bola::Bola(JD8_Surface gfx, Prota* sam)
: Sprite(gfx) {
this->sam = sam; this->sam = sam;
this->entitat = (Entitat*)malloc(sizeof(Entitat)); this->entitat = (Entitat*)malloc(sizeof(Entitat));
@@ -32,17 +35,13 @@ Bola::Bola( JD8_Surface gfx, Prota* sam ) : Sprite( gfx ) {
this->x = 20; this->x = 20;
this->y = 100; this->y = 100;
this->contador = 0; this->contador = 0;
} }
void Bola::draw() { void Bola::draw() {
if (this->contador == 0) Sprite::draw(); if (this->contador == 0) Sprite::draw();
} }
void Bola::update() { void Bola::update() {
if (this->contador == 0) { if (this->contador == 0) {
// Augmentem la x // Augmentem la x
this->x++; this->x++;
@@ -64,5 +63,4 @@ void Bola::update() {
this->contador--; this->contador--;
if (this->contador == 0) this->x = 20; if (this->contador == 0) this->x = 20;
} }
} }

View File

@@ -1,22 +1,17 @@
#pragma once #pragma once
#include "game/sprite.hpp"
#include "game/prota.hpp"
#include "game/info.hpp" #include "game/info.hpp"
#include "game/prota.hpp"
#include "game/sprite.hpp"
class Bola : public Sprite { class Bola : public Sprite {
public: public:
Bola(JD8_Surface gfx, Prota* sam); Bola(JD8_Surface gfx, Prota* sam);
void draw(); void draw();
void update(); void update();
protected: protected:
Uint8 contador; Uint8 contador;
Prota* sam; Prota* sam;
}; };

View File

@@ -1,9 +1,11 @@
#include "game/engendro.hpp" #include "game/engendro.hpp"
#include "core/jgame.hpp"
#include <stdlib.h> #include <stdlib.h>
Engendro::Engendro( JD8_Surface gfx, Uint16 x, Uint16 y ) : Sprite( gfx ) { #include "core/jgame.hpp"
Engendro::Engendro(JD8_Surface gfx, Uint16 x, Uint16 y)
: Sprite(gfx) {
this->entitat = (Entitat*)malloc(sizeof(Entitat)); this->entitat = (Entitat*)malloc(sizeof(Entitat));
// Frames // Frames
this->entitat->num_frames = 4; this->entitat->num_frames = 4;
@@ -38,17 +40,13 @@ Engendro::Engendro( JD8_Surface gfx, Uint16 x, Uint16 y ) : Sprite( gfx ) {
this->y = y; this->y = y;
this->o = 0; this->o = 0;
this->cycles_per_frame = 30; this->cycles_per_frame = 30;
} }
void Engendro::draw() { void Engendro::draw() {
Sprite::draw(); Sprite::draw();
} }
bool Engendro::update() { bool Engendro::update() {
bool mort = false; bool mort = false;
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
@@ -57,7 +55,6 @@ bool Engendro::update() {
this->vida--; this->vida--;
} }
if (vida == 0) mort = true; if (vida == 0) mort = true;
return mort; return mort;

View File

@@ -3,16 +3,12 @@
#include "game/sprite.hpp" #include "game/sprite.hpp"
class Engendro : public Sprite { class Engendro : public Sprite {
public: public:
Engendro(JD8_Surface gfx, Uint16 x, Uint16 y); Engendro(JD8_Surface gfx, Uint16 x, Uint16 y);
void draw(); void draw();
bool update(); bool update();
protected: protected:
Uint8 vida; Uint8 vida;
}; };

View File

@@ -1,7 +1,6 @@
#include "game/info.hpp" #include "game/info.hpp"
namespace info namespace info {
{
int num_piramide; int num_piramide;
int num_habitacio; int num_habitacio;
int diners; int diners;
@@ -11,4 +10,4 @@ namespace info
int engendros; int engendros;
bool nou_personatge; bool nou_personatge;
bool pepe_activat; bool pepe_activat;
}; }; // namespace info

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
namespace info namespace info {
{
extern int num_piramide; extern int num_piramide;
extern int num_habitacio; extern int num_habitacio;
extern int diners; extern int diners;
@@ -11,4 +10,4 @@ namespace info
extern int engendros; extern int engendros;
extern bool nou_personatge; extern bool nou_personatge;
extern bool pepe_activat; extern bool pepe_activat;
}; }; // namespace info

View File

@@ -1,11 +1,11 @@
#include "game/mapa.hpp" #include "game/mapa.hpp"
#include <stdlib.h>
#include "core/jgame.hpp" #include "core/jgame.hpp"
#include "core/jinput.hpp" #include "core/jinput.hpp"
#include <stdlib.h>
Mapa::Mapa(JD8_Surface gfx, Prota* sam) { Mapa::Mapa(JD8_Surface gfx, Prota* sam) {
this->gfx = gfx; this->gfx = gfx;
this->sam = sam; this->sam = sam;
@@ -19,17 +19,13 @@ Mapa::Mapa( JD8_Surface gfx, Prota* sam ) {
this->clau = false; this->clau = false;
this->porta_oberta = false; this->porta_oberta = false;
this->nova_momia = false; this->nova_momia = false;
} }
Mapa::~Mapa(void) { Mapa::~Mapa(void) {
JD8_FreeSurface(this->fondo); JD8_FreeSurface(this->fondo);
} }
void Mapa::draw() { void Mapa::draw() {
if (info::num_piramide != 4) { if (info::num_piramide != 4) {
switch (sam->o) { switch (sam->o) {
case 0: // Down case 0: // Down
@@ -60,11 +56,9 @@ void Mapa::draw() {
JD8_BlitCK(95, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255); JD8_BlitCK(95, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
JD8_BlitCK(195, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255); JD8_BlitCK(195, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
JD8_BlitCK(245, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255); JD8_BlitCK(245, 15, this->gfx, 30 + (this->frame_torxes * 25), 80, 25, 15, 255);
}; };
void Mapa::update() { void Mapa::update() {
if (((sam->x - 20) % 65 == 0) && ((sam->y - 30) % 35 == 0) && ((this->ultim_vertex.columna != (sam->x - 20) / 65) || (this->ultim_vertex.fila != (sam->y - 30) / 35))) { if (((sam->x - 20) % 65 == 0) && ((sam->y - 30) % 35 == 0) && ((this->ultim_vertex.columna != (sam->x - 20) / 65) || (this->ultim_vertex.fila != (sam->y - 30) / 35))) {
this->vertex.columna = (sam->x - 20) / 65; this->vertex.columna = (sam->x - 20) / 65;
this->vertex.fila = (sam->y - 30) / 35; this->vertex.fila = (sam->y - 30) / 35;
@@ -83,7 +77,6 @@ void Mapa::update() {
this->frame_torxes++; this->frame_torxes++;
this->frame_torxes = this->frame_torxes % 4; this->frame_torxes = this->frame_torxes % 4;
} }
} }
bool Mapa::novaMomia() { bool Mapa::novaMomia() {
@@ -93,13 +86,11 @@ bool Mapa::novaMomia() {
} }
void Mapa::preparaFondoEstatic() { void Mapa::preparaFondoEstatic() {
// Prepara el fondo est<73>tic de l'habitaci<63> // Prepara el fondo est<73>tic de l'habitaci<63>
this->fondo = JD8_NewSurface(); this->fondo = JD8_NewSurface();
if (info::num_piramide == 6) { if (info::num_piramide == 6) {
JD8_BlitToSurface(9, 2, this->gfx, 227, 185, 92, 7, this->fondo); // Text "SECRETA" JD8_BlitToSurface(9, 2, this->gfx, 227, 185, 92, 7, this->fondo); // Text "SECRETA"
} } else {
else {
JD8_BlitToSurface(9, 2, this->gfx, 60, 185, 39, 7, this->fondo); // Text "NIVELL" JD8_BlitToSurface(9, 2, this->gfx, 60, 185, 39, 7, this->fondo); // Text "NIVELL"
JD8_BlitToSurface(72, 6, this->gfx, 153, 189, 3, 1, this->fondo); // Ralleta entre num piramide i num habitacio JD8_BlitToSurface(72, 6, this->gfx, 153, 189, 3, 1, this->fondo); // Ralleta entre num piramide i num habitacio
} }
@@ -133,7 +124,6 @@ void Mapa::preparaFondoEstatic() {
} }
} }
// Pinta vores de les parets // Pinta vores de les parets
JD8_BlitCKToSurface(5, 15, this->gfx, 30, 110, 15, 15, this->fondo, 255); JD8_BlitCKToSurface(5, 15, this->gfx, 30, 110, 15, 15, this->fondo, 255);
JD8_BlitCKToSurface(295, 15, this->gfx, 45, 110, 15, 15, this->fondo, 255); JD8_BlitCKToSurface(295, 15, this->gfx, 45, 110, 15, 15, this->fondo, 255);
@@ -197,7 +187,6 @@ Uint8 minim( Uint8 a, Uint8 b ) {
} }
void Mapa::comprovaUltimCami() { void Mapa::comprovaUltimCami() {
Uint8 col_aux = abs(this->vertex.columna - this->ultim_vertex.columna); Uint8 col_aux = abs(this->vertex.columna - this->ultim_vertex.columna);
Uint8 fil_aux = abs(this->vertex.fila - this->ultim_vertex.fila); Uint8 fil_aux = abs(this->vertex.fila - this->ultim_vertex.fila);
@@ -234,20 +223,19 @@ void Mapa::comprovaUltimCami() {
} }
} }
void Mapa::comprovaCaixa( Uint8 num ) void Mapa::comprovaCaixa(Uint8 num) {
{
// Si la tomba ja està oberta, no hi ha res que mirar // Si la tomba ja està oberta, no hi ha res que mirar
if (this->tombes[num].oberta) return; if (this->tombes[num].oberta) return;
// Si algun costat encara no està passat, no hi ha res que fer // Si algun costat encara no està passat, no hi ha res que fer
for( int i = 0; i < 4; i++ ) if( !this->tombes[num].costat[i] ) return; for (int i = 0; i < 4; i++)
if (!this->tombes[num].costat[i]) return;
// Sinó, pos la acabem d'obrir // Sinó, pos la acabem d'obrir
this->tombes[num].oberta = true; this->tombes[num].oberta = true;
// Comprobem el premi del kinder sorpresa // Comprobem el premi del kinder sorpresa
switch( this->tombes[num].contingut ) switch (this->tombes[num].contingut) {
{
case CONTE_RES: case CONTE_RES:
this->tombes[num].x = 50; this->tombes[num].x = 50;
break; break;
@@ -283,10 +271,8 @@ void Mapa::comprovaCaixa( Uint8 num )
} }
void Mapa::comprovaPorta() { void Mapa::comprovaPorta() {
if (this->clau && this->farao) { if (this->clau && this->farao) {
JD8_BlitCKToSurface(150, 18, this->gfx, 15, 143, 15, 12, this->fondo, 255); JD8_BlitCKToSurface(150, 18, this->gfx, 15, 143, 15, 12, this->fondo, 255);
porta_oberta = true; porta_oberta = true;
} }
} }

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include "core/jdraw8.hpp" #include "core/jdraw8.hpp"
#include "game/info.hpp" #include "game/info.hpp"
#include "game/prota.hpp" #include "game/prota.hpp"
@@ -27,9 +26,7 @@ struct Vertex {
}; };
class Mapa { class Mapa {
public: public:
Mapa(JD8_Surface gfx, Prota* sam); Mapa(JD8_Surface gfx, Prota* sam);
~Mapa(void); ~Mapa(void);
@@ -41,7 +38,6 @@ public:
Tomba tombes[16]; Tomba tombes[16];
protected: protected:
void preparaFondoEstatic(); void preparaFondoEstatic();
void preparaTombes(); void preparaTombes();
@@ -60,5 +56,4 @@ protected:
bool clau; bool clau;
bool porta_oberta; bool porta_oberta;
bool nova_momia; bool nova_momia;
}; };

View File

@@ -1,7 +1,6 @@
#include "game/marcador.hpp" #include "game/marcador.hpp"
Marcador::Marcador(JD8_Surface gfx, Prota* sam) { Marcador::Marcador(JD8_Surface gfx, Prota* sam) {
this->gfx = gfx; this->gfx = gfx;
this->sam = sam; this->sam = sam;
} }
@@ -10,7 +9,6 @@ Marcador::~Marcador(void) {
} }
void Marcador::draw() { void Marcador::draw() {
if (info::num_piramide < 6) { if (info::num_piramide < 6) {
this->pintaNumero(55, 2, info::num_piramide); this->pintaNumero(55, 2, info::num_piramide);
this->pintaNumero(80, 2, info::num_habitacio); this->pintaNumero(80, 2, info::num_habitacio);

View File

@@ -5,19 +5,15 @@
#include "game/prota.hpp" #include "game/prota.hpp"
class Marcador { class Marcador {
public: public:
Marcador(JD8_Surface gfx, Prota* sam); Marcador(JD8_Surface gfx, Prota* sam);
~Marcador(void); ~Marcador(void);
void draw(); void draw();
protected: protected:
void pintaNumero(Uint16 x, Uint16 y, Uint8 num); void pintaNumero(Uint16 x, Uint16 y, Uint8 num);
JD8_Surface gfx; JD8_Surface gfx;
Prota* sam; Prota* sam;
}; };

View File

@@ -1,13 +1,12 @@
#include "game/modulegame.hpp" #include "game/modulegame.hpp"
#include "core/jgame.hpp"
#include "core/jdraw8.hpp"
#include "core/jail_audio.hpp" #include "core/jail_audio.hpp"
#include "core/jinput.hpp" #include "core/jdraw8.hpp"
#include "core/jfile.hpp" #include "core/jfile.hpp"
#include "core/jgame.hpp"
#include "core/jinput.hpp"
ModuleGame::ModuleGame() { ModuleGame::ModuleGame() {
this->gfx = JD8_LoadSurface(info::pepe_activat ? "frames2.gif" : "frames.gif"); this->gfx = JD8_LoadSurface(info::pepe_activat ? "frames2.gif" : "frames.gif");
JG_SetUpdateTicks(10); JG_SetUpdateTicks(10);
@@ -23,11 +22,9 @@ ModuleGame::ModuleGame() {
this->final = 0; this->final = 0;
this->iniciarMomies(); this->iniciarMomies();
} }
ModuleGame::~ModuleGame(void) { ModuleGame::~ModuleGame(void) {
JD8_FadeOut(); JD8_FadeOut();
if (this->bola != NULL) delete this->bola; if (this->bola != NULL) delete this->bola;
@@ -40,11 +37,9 @@ ModuleGame::~ModuleGame(void) {
delete this->sam; delete this->sam;
JD8_FreeSurface(this->gfx); JD8_FreeSurface(this->gfx);
} }
int ModuleGame::Go() { int ModuleGame::Go() {
this->Draw(); this->Draw();
const char* music = info::num_piramide == 3 ? "00000008.ogg" : (info::num_piramide == 2 ? "00000007.ogg" : (info::num_piramide == 6 ? "00000002.ogg" : "00000006.ogg")); const char* music = info::num_piramide == 3 ? "00000008.ogg" : (info::num_piramide == 2 ? "00000007.ogg" : (info::num_piramide == 6 ? "00000002.ogg" : "00000006.ogg"));
@@ -58,7 +53,6 @@ int ModuleGame::Go() {
JD8_FadeToPal(JD8_LoadPalette(info::pepe_activat ? "frames2.gif" : "frames.gif")); JD8_FadeToPal(JD8_LoadPalette(info::pepe_activat ? "frames2.gif" : "frames.gif"));
while (this->final == 0 && !JG_Quitting()) { while (this->final == 0 && !JG_Quitting()) {
this->Draw(); this->Draw();
this->Update(); this->Update();
} }
@@ -88,7 +82,6 @@ int ModuleGame::Go() {
} }
void ModuleGame::Draw() { void ModuleGame::Draw() {
this->mapa->draw(); this->mapa->draw();
this->marcador->draw(); this->marcador->draw();
this->sam->draw(); this->sam->draw();
@@ -147,8 +140,11 @@ void ModuleGame::Update() {
} }
void ModuleGame::iniciarMomies() { void ModuleGame::iniciarMomies() {
if (info::num_habitacio == 1) {
if( info::num_habitacio == 1 ) { info::momies = 1; } else { info::momies++; } info::momies = 1;
} else {
info::momies++;
}
if (info::num_piramide == 6) info::momies = 8; if (info::num_piramide == 6) info::momies = 8;
int x = 20; int x = 20;
@@ -161,6 +157,9 @@ void ModuleGame::iniciarMomies() {
this->momies->insertar(new Momia(this->gfx, dimonis, x, y, this->sam)); this->momies->insertar(new Momia(this->gfx, dimonis, x, y, this->sam));
} }
x += 65; x += 65;
if( x == 345 ) { x = 20; y -= 35; } if (x == 345) {
x = 20;
y -= 35;
}
} }
} }

View File

@@ -1,23 +1,20 @@
#pragma once #pragma once
#include "game/bola.hpp"
#include "game/info.hpp" #include "game/info.hpp"
#include "game/mapa.hpp" #include "game/mapa.hpp"
#include "game/prota.hpp"
#include "game/marcador.hpp" #include "game/marcador.hpp"
#include "game/momia.hpp" #include "game/momia.hpp"
#include "game/bola.hpp" #include "game/prota.hpp"
class ModuleGame { class ModuleGame {
public: public:
ModuleGame(); ModuleGame();
~ModuleGame(void); ~ModuleGame(void);
int Go(); int Go();
private: private:
void Draw(); void Draw();
void Update(); void Update();
@@ -31,5 +28,4 @@ private:
Marcador* marcador; Marcador* marcador;
Momia* momies; Momia* momies;
Bola* bola; Bola* bola;
}; };

View File

@@ -1,13 +1,15 @@
#include "game/modulesequence.hpp" #include "game/modulesequence.hpp"
#include "core/jgame.hpp"
#include "core/jdraw8.hpp"
#include "core/jinput.hpp"
#include "core/jfile.hpp"
#include "core/jail_audio.hpp"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include "core/jail_audio.hpp"
#include "core/jdraw8.hpp"
#include "core/jfile.hpp"
#include "core/jgame.hpp"
#include "core/jinput.hpp"
ModuleSequence::ModuleSequence() { ModuleSequence::ModuleSequence() {
} }
@@ -15,7 +17,6 @@ ModuleSequence::~ModuleSequence(void) {
} }
int ModuleSequence::Go() { int ModuleSequence::Go() {
if (info::num_piramide == 6 && info::diners < 200) info::num_piramide = 7; if (info::num_piramide == 6 && info::diners < 200) info::num_piramide = 7;
switch (info::num_piramide) { switch (info::num_piramide) {
@@ -71,17 +72,19 @@ int ModuleSequence::Go() {
} else { } else {
return 0; return 0;
} }
} }
return 0; return 0;
} }
const int minim(const int a, const int b) { const int minim(const int a, const int b) {
if( b < a ) { return b; } else { return a; } if (b < a) {
return b;
} else {
return a;
}
} }
void play_music(const char *music, bool loop = -1) void play_music(const char* music, bool loop = -1) {
{
int size; int size;
char* buffer = file_getfilebuffer(music, size); char* buffer = file_getfilebuffer(music, size);
JA_PlayMusic(JA_LoadMusic((Uint8*)buffer, size, music), loop); JA_PlayMusic(JA_LoadMusic((Uint8*)buffer, size, music), loop);
@@ -98,82 +101,178 @@ void ModuleSequence::doIntro() {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JG_SetUpdateTicks(100); JG_SetUpdateTicks(100);
JD8_Blit(43, 78, gfx, 43, 155, 27, 45); JD8_Blit(43, 78, gfx, 43, 155, 27, 45);
JD8_Blit(68, 78, gfx, 274, 155, 27, 45); JD8_Blit(68, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 53, 45); JD8_Blit(43, 78, gfx, 43, 155, 53, 45);
JD8_Blit(96, 78, gfx, 274, 155, 27, 45); JD8_Blit(96, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 66, 45); JD8_Blit(43, 78, gfx, 43, 155, 66, 45);
JD8_Blit(109, 78, gfx, 274, 155, 27, 45); JD8_Blit(109, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JG_SetUpdateTicks(200); JG_SetUpdateTicks(200);
JD8_Blit(43, 78, gfx, 43, 155, 92, 45); JD8_Blit(43, 78, gfx, 43, 155, 92, 45);
JD8_Blit(136, 78, gfx, 274, 155, 27, 45); JD8_Blit(136, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 92, 45); JD8_Blit(43, 78, gfx, 43, 155, 92, 45);
// JD8_Blit( 136, 78, gfx, 274, 155, 27, 45 ); // JD8_Blit( 136, 78, gfx, 274, 155, 27, 45 );
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JG_SetUpdateTicks(100); JG_SetUpdateTicks(100);
JD8_Blit(43, 78, gfx, 43, 155, 118, 45); JD8_Blit(43, 78, gfx, 43, 155, 118, 45);
JD8_Blit(160, 78, gfx, 274, 155, 27, 45); JD8_Blit(160, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 145, 45); JD8_Blit(43, 78, gfx, 43, 155, 145, 45);
JD8_Blit(188, 78, gfx, 274, 155, 27, 45); JD8_Blit(188, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 178, 45); JD8_Blit(43, 78, gfx, 43, 155, 178, 45);
JD8_Blit(221, 78, gfx, 274, 155, 27, 45); JD8_Blit(221, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 205, 45); JD8_Blit(43, 78, gfx, 43, 155, 205, 45);
JD8_Blit(248, 78, gfx, 274, 155, 27, 45); JD8_Blit(248, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JG_SetUpdateTicks(200); JG_SetUpdateTicks(200);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
JD8_Blit(274, 78, gfx, 274, 155, 27, 45); JD8_Blit(274, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
JD8_Blit(274, 78, gfx, 274, 155, 27, 45); JD8_Blit(274, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
JD8_Blit(274, 78, gfx, 274, 155, 27, 45); JD8_Blit(274, 78, gfx, 274, 155, 27, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
for (int j = 0; j < 256; j++) { for (int j = 0; j < 256; j++) {
for (int i = 16; i < 32; i++) { for (int i = 16; i < 32; i++) {
@@ -190,7 +289,13 @@ void ModuleSequence::doIntro() {
JD8_Flip(); JD8_Flip();
} }
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
JG_SetUpdateTicks(20); JG_SetUpdateTicks(20);
Uint16 fr1 = 13; Uint16 fr1 = 13;
@@ -239,72 +344,96 @@ void ModuleSequence::doIntro() {
// camina cap a la DRETA } // camina cap a la DRETA }
for (int i = 0; i <= 200; i++) { for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150); // Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 0); JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// trau el MAPA DRETA } // trau el MAPA DRETA }
for (int i = 0; i <= 200; i++) { for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150); // Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_3[minim((i / 5), fr3 - 1)], 30, 15, 15, 0); JD8_BlitCK(200, 150, gfx, fr_ani_3[minim((i / 5), fr3 - 1)], 30, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// guarda el MAPA } // guarda el MAPA }
for (int i = 200; i >= 0; i--) { for (int i = 200; i >= 0; i--) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150); // Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_3[minim((i / 5), fr3 - 1)], 30, 15, 15, 0); JD8_BlitCK(200, 150, gfx, fr_ani_3[minim((i / 5), fr3 - 1)], 30, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// camina cap a la ESQUERRA } // camina cap a la ESQUERRA }
for (int i = 200; i >= 80; i--) { for (int i = 200; i >= 80; i--) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_2[(i div 5) mod fr2],15,15,i,150); // Put_sprite(from,where,fr_ani_2[(i div 5) mod fr2],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_2[(i / 5) % fr2], 15, 15, 15, 0); JD8_BlitCK(i, 150, gfx, fr_ani_2[(i / 5) % fr2], 15, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// trau el MAPA ESQUERRA } // trau el MAPA ESQUERRA }
for (int i = 0; i <= 200; i++) { for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_4[minim((i div 5),fr4-1)],15,15,80,150); // Put_sprite(from,where,fr_ani_4[minim((i div 5),fr4-1)],15,15,80,150);
JD8_BlitCK(80, 150, gfx, fr_ani_4[minim((i / 5), fr4 - 1)], 45, 15, 15, 0); JD8_BlitCK(80, 150, gfx, fr_ani_4[minim((i / 5), fr4 - 1)], 45, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// momia cap a la ESQUERRA } // momia cap a la ESQUERRA }
for (int i = 300; i >= 95; i--) { for (int i = 300; i >= 95; i--) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_6[(i div 10) mod fr6],15,15,i,150); // Put_sprite(from,where,fr_ani_6[(i div 10) mod fr6],15,15,i,150);
@@ -313,13 +442,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(80, 150, gfx, fr_ani_4[fr4 - 1], 45, 15, 15, 0); JD8_BlitCK(80, 150, gfx, fr_ani_4[fr4 - 1], 45, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// girar-se } // girar-se }
for (int i = 0; i <= 50; i++) { for (int i = 0; i <= 50; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_1[1],15,15,80,150); // Put_sprite(from,where,fr_ani_1[1],15,15,80,150);
@@ -330,13 +464,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(80, 133, gfx, 0, interrogant, 15, 15, 0); JD8_BlitCK(80, 133, gfx, 0, interrogant, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// bot de SUSTO } // bot de SUSTO }
for (int i = 0; i <= 49; i++) { for (int i = 0; i <= 49; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_5[minim((i div 5),fr5-1)],15,15,80,150-((i mod 50) div 5)); // Put_sprite(from,where,fr_ani_5[minim((i div 5),fr5-1)],15,15,80,150-((i mod 50) div 5));
@@ -345,13 +484,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0); JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// bot de SUSTO } // bot de SUSTO }
for (int i = 50; i <= 99; i++) { for (int i = 50; i <= 99; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_5[minim((i div 5),fr5-1)],15,15,80,140+((i mod 50) div 5)); // Put_sprite(from,where,fr_ani_5[minim((i div 5),fr5-1)],15,15,80,140+((i mod 50) div 5));
@@ -360,13 +504,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0); JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// camina cap a la ESQUERRA } // camina cap a la ESQUERRA }
for (int i = 80; i >= 0; i--) { for (int i = 80; i >= 0; i--) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_2[(i div 5) mod fr2],15,15,i,150); // Put_sprite(from,where,fr_ani_2[(i div 5) mod fr2],15,15,i,150);
@@ -375,13 +524,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0); JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// final } // final }
for (int i = 0; i <= 150; i++) { for (int i = 0; i <= 150; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_6[4],15,15,95,150); // Put_sprite(from,where,fr_ani_6[4],15,15,95,150);
@@ -393,12 +547,10 @@ void ModuleSequence::doIntro() {
} }
//-----} //-----}
break; break;
case 1: case 1:
// camina cap a la DRETA } // camina cap a la DRETA }
for (int i = 0; i <= 200; i++) { for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -407,13 +559,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 255); JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// trau el MAPA DRETA } // trau el MAPA DRETA }
for (int i = 0; i <= 300; i++) { for (int i = 0; i <= 300; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -422,13 +579,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(200, 150, gfx, fr_ani_3[minim(i / 5, fr3 - 1)], 30, 15, 15, 255); JD8_BlitCK(200, 150, gfx, fr_ani_3[minim(i / 5, fr3 - 1)], 30, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// INTERROGANT } // INTERROGANT }
for (int i = 0; i <= 100; i++) { for (int i = 0; i <= 100; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -439,13 +601,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(200, 150, gfx, fr_ani_3[fr3 - 1], 30, 15, 15, 255); JD8_BlitCK(200, 150, gfx, fr_ani_3[fr3 - 1], 30, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// deixa caure el MAPA i SOMBRA } // deixa caure el MAPA i SOMBRA }
for (int i = 0; i <= 200; i++) { for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -458,13 +625,18 @@ void ModuleSequence::doIntro() {
} }
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// SOMBRA i PEDRA } // SOMBRA i PEDRA }
for (int i = 0; i <= 75; i++) { for (int i = 0; i <= 75; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -475,13 +647,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(200, i * 2, gfx, fr_ani_8[0], 75, 15, 15, 255); JD8_BlitCK(200, i * 2, gfx, fr_ani_8[0], 75, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// trencar PEDRA } // trencar PEDRA }
for (int i = 0; i <= 19; i++) { for (int i = 0; i <= 19; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -490,13 +667,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(200, 150, gfx, fr_ani_8[i / 10], 75, 15, 15, 255); JD8_BlitCK(200, 150, gfx, fr_ani_8[i / 10], 75, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// FINAL } // FINAL }
for (int i = 0; i <= 200; i++) { for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,creu,15,15,200,155); // Put_sprite(from,where,creu,15,15,200,155);
@@ -509,13 +691,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(215, 150, gfx, fr_ani_8[3], 75, 15, 15, 255); JD8_BlitCK(215, 150, gfx, fr_ani_8[3], 75, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
break; break;
case 2: case 2:
// camina cap a la DRETA } // camina cap a la DRETA }
for (int i = 0; i <= 145; i++) { for (int i = 0; i <= 145; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150); // Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150);
@@ -524,13 +711,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(304 - i, 150, gfx, fr_ani_6[(i / 10) % fr6], 60, 15, 15, 255); JD8_BlitCK(304 - i, 150, gfx, fr_ani_6[(i / 10) % fr6], 60, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// els dos quets } // els dos quets }
for (int i = 0; i <= 100; i++) { for (int i = 0; i <= 100; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_1[1],15,15,145,150); // Put_sprite(from,where,fr_ani_1[1],15,15,145,150);
@@ -539,13 +731,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(160, 150, gfx, fr_ani_6[1], 60, 15, 15, 255); JD8_BlitCK(160, 150, gfx, fr_ani_6[1], 60, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// aparicio altaveu } // aparicio altaveu }
for (int i = 0; i <= 50; i++) { for (int i = 0; i <= 50; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_11[(i div 10) mod 2],15,15,125,150); // Put_sprite(from,where,fr_ani_11[(i div 10) mod 2],15,15,125,150);
@@ -556,13 +753,18 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(160, 150, gfx, fr_ani_6[1], 60, 15, 15, 255); JD8_BlitCK(160, 150, gfx, fr_ani_6[1], 60, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
// BALL } // BALL }
for (int i = 0; i <= 800; i++) { for (int i = 0; i <= 800; i++) {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 231, 45); JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
// Put_sprite(from,where,fr_ani_9[(i div 10) mod fr9],15,15,145,150); // Put_sprite(from,where,fr_ani_9[(i div 10) mod fr9],15,15,145,150);
@@ -573,17 +775,21 @@ void ModuleSequence::doIntro() {
JD8_BlitCK(125, 150, gfx, fr_ani_11[((i / 5) % 4) + 2], 90, 15, 15, 255); JD8_BlitCK(125, 150, gfx, fr_ani_11[((i / 5) % 4) + 2], 90, 15, 15, 255);
JD8_Flip(); JD8_Flip();
while( !JG_ShouldUpdate() ) { JI_Update(); if( JI_AnyKey() || JG_Quitting() ) { JD8_FreeSurface( gfx ); return; } } while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) {
JD8_FreeSurface(gfx);
return;
}
}
} }
break; break;
} }
JD8_FreeSurface(gfx); JD8_FreeSurface(gfx);
} }
void ModuleSequence::doMenu() { void ModuleSequence::doMenu() {
JG_SetUpdateTicks(20); JG_SetUpdateTicks(20);
JD8_Surface fondo = JD8_LoadSurface("menu.gif"); JD8_Surface fondo = JD8_LoadSurface("menu.gif");
@@ -603,7 +809,6 @@ void ModuleSequence::doMenu() {
JI_Update(); JI_Update();
while (!JI_AnyKey() && !JG_Quitting() && !JI_KeyPressed(SDL_SCANCODE_P)) { while (!JI_AnyKey() && !JG_Quitting() && !JI_KeyPressed(SDL_SCANCODE_P)) {
JD8_Blit(0, 0, fondo, 0, 0, 320, 100); // fondo sol estatic JD8_Blit(0, 0, fondo, 0, 0, 320, 100); // fondo sol estatic
JD8_BlitCK(horitzo, 100, fondo, 0, 100, 320 - horitzo, 100, 255); // fondo moviment JD8_BlitCK(horitzo, 100, fondo, 0, 100, 320 - horitzo, 100, 255); // fondo moviment
@@ -624,9 +829,18 @@ void ModuleSequence::doMenu() {
JD8_Flip(); JD8_Flip();
if (JG_ShouldUpdate()) { if (JG_ShouldUpdate()) {
if( contador%4 == 0 ) { palmeres--; if( palmeres < 0 ) palmeres = 319; } if (contador % 4 == 0) {
if( contador%8 == 0 ) { camello++; if( camello == 4 ) camello = 0; } palmeres--;
if( contador%16 == 0 ) { horitzo--; if( horitzo < 0 ) horitzo = 319; } if (palmeres < 0) palmeres = 319;
}
if (contador % 8 == 0) {
camello++;
if (camello == 4) camello = 0;
}
if (contador % 16 == 0) {
horitzo--;
if (horitzo < 0) horitzo = 319;
}
contador++; contador++;
JI_Update(); JI_Update();
} }
@@ -641,7 +855,6 @@ void ModuleSequence::doMenu() {
void ModuleSequence::doSlides() { void ModuleSequence::doSlides() {
JG_SetUpdateTicks(20); JG_SetUpdateTicks(20);
const char* arxiu; const char* arxiu;
if (info::num_piramide == 7) { if (info::num_piramide == 7) {
play_music("00000005.ogg", 1); play_music("00000005.ogg", 1);
@@ -695,7 +908,10 @@ void ModuleSequence::doSlides() {
case 4: case 4:
case 7: case 7:
contador--; contador--;
if (contador == -150) { contador = 0; step++; } if (contador == -150) {
contador = 0;
step++;
}
break; break;
case 2: case 2:
case 5: case 5:
@@ -849,8 +1065,9 @@ void ModuleSequence::doSecreta() {
} }
void ModuleSequence::doCredits() { void ModuleSequence::doCredits() {
struct {
struct { Uint16 x, y; } frames_coche[8] = { { 214, 152 }, { 214, 104 }, { 214, 56 }, { 214, 104 }, { 214, 152 }, { 214, 8 }, { 108, 152 }, { 214, 8 } }; Uint16 x, y;
} frames_coche[8] = {{214, 152}, {214, 104}, {214, 56}, {214, 104}, {214, 152}, {214, 8}, {108, 152}, {214, 8}};
const Uint32 n_frames_coche = 8; const Uint32 n_frames_coche = 8;
const Uint32 velocitat_coche = 3; const Uint32 velocitat_coche = 3;
@@ -945,4 +1162,3 @@ void ModuleSequence::doMort() {
} }
play_music("00000003.ogg"); play_music("00000003.ogg");
} }

View File

@@ -3,16 +3,13 @@
#include "game/info.hpp" #include "game/info.hpp"
class ModuleSequence { class ModuleSequence {
public: public:
ModuleSequence(); ModuleSequence();
~ModuleSequence(void); ~ModuleSequence(void);
int Go(); int Go();
private: private:
void doIntro(); void doIntro();
void doMenu(); void doMenu();
void doSlides(); void doSlides();

View File

@@ -1,8 +1,11 @@
#include "game/momia.hpp" #include "game/momia.hpp"
#include "core/jgame.hpp"
#include <stdlib.h> #include <stdlib.h>
Momia::Momia( JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam ) : Sprite( gfx ) { #include "core/jgame.hpp"
Momia::Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam)
: Sprite(gfx) {
this->dimoni = dimoni; this->dimoni = dimoni;
this->sam = sam; this->sam = sam;
@@ -20,7 +23,6 @@ Momia::Momia( JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam ) : S
if (this->dimoni) this->entitat->frames[frame].x += 75; if (this->dimoni) this->entitat->frames[frame].x += 75;
this->entitat->frames[frame].y = 20 + (y * 15); this->entitat->frames[frame].y = 20 + (y * 15);
frame++; frame++;
} }
} }
// Animacions // Animacions
@@ -65,7 +67,6 @@ Momia::Momia( JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam ) : S
this->x = x; this->x = x;
this->y = y; this->y = y;
} }
} }
void Momia::clear() { void Momia::clear() {
@@ -75,11 +76,9 @@ void Momia::clear() {
} }
void Momia::draw() { void Momia::draw() {
if (this->engendro != NULL) { if (this->engendro != NULL) {
this->engendro->draw(); this->engendro->draw();
} else { } else {
Sprite::draw(); Sprite::draw();
if (info::num_piramide == 4) { if (info::num_piramide == 4) {
@@ -94,7 +93,6 @@ void Momia::draw() {
} }
bool Momia::update() { bool Momia::update() {
bool morta = false; bool morta = false;
if (this->engendro != NULL) { if (this->engendro != NULL) {
@@ -104,19 +102,28 @@ bool Momia::update() {
} }
} else { } else {
if (this->sam->o < 4 && (this->dimoni || info::num_piramide == 5 || JG_GetCycleCounter() % 2 == 0)) { if (this->sam->o < 4 && (this->dimoni || info::num_piramide == 5 || JG_GetCycleCounter() % 2 == 0)) {
if ((this->x - 20) % 65 == 0 && (this->y - 30) % 35 == 0) { if ((this->x - 20) % 65 == 0 && (this->y - 30) % 35 == 0) {
if (this->dimoni) { if (this->dimoni) {
if (rand() % 2 == 0) { if (rand() % 2 == 0) {
if( this->x > this->sam->x ) { this->o = 3; } if (this->x > this->sam->x) {
else if( this->x < this->sam->x ) { this->o = 2; } this->o = 3;
else if( this->y < this->sam->y ) { this->o = 0; } } else if (this->x < this->sam->x) {
else if( this->y > this->sam->y ) { this->o = 1; } this->o = 2;
} else if (this->y < this->sam->y) {
this->o = 0;
} else if (this->y > this->sam->y) {
this->o = 1;
}
} else { } else {
if( this->y < this->sam->y ) { this->o = 0; } if (this->y < this->sam->y) {
else if( this->y > this->sam->y ) { this->o = 1; } this->o = 0;
else if( this->x > this->sam->x ) { this->o = 3; } } else if (this->y > this->sam->y) {
else if( this->x < this->sam->x ) { this->o = 2; } this->o = 1;
} else if (this->x > this->sam->x) {
this->o = 3;
} else if (this->x < this->sam->x) {
this->o = 2;
}
} }
} else { } else {
this->o = rand() % 4; this->o = rand() % 4;
@@ -168,7 +175,6 @@ bool Momia::update() {
} }
void Momia::insertar(Momia* momia) { void Momia::insertar(Momia* momia) {
if (this->next != NULL) { if (this->next != NULL) {
this->next->insertar(momia); this->next->insertar(momia);
} else { } else {

View File

@@ -1,14 +1,12 @@
#pragma once #pragma once
#include "game/sprite.hpp"
#include "game/prota.hpp"
#include "game/engendro.hpp" #include "game/engendro.hpp"
#include "game/info.hpp" #include "game/info.hpp"
#include "game/prota.hpp"
#include "game/sprite.hpp"
class Momia : public Sprite { class Momia : public Sprite {
public: public:
Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam); Momia(JD8_Surface gfx, bool dimoni, Uint16 x, Uint16 y, Prota* sam);
void clear(); void clear();
@@ -20,8 +18,6 @@ public:
Momia* next; Momia* next;
protected: protected:
Prota* sam; Prota* sam;
Engendro* engendro; Engendro* engendro;
}; };

View File

@@ -1,10 +1,12 @@
#include "game/prota.hpp" #include "game/prota.hpp"
#include "core/jgame.hpp"
#include "core/jinput.hpp"
#include <stdlib.h> #include <stdlib.h>
Prota::Prota( JD8_Surface gfx ) : Sprite( gfx ) { #include "core/jgame.hpp"
#include "core/jinput.hpp"
Prota::Prota(JD8_Surface gfx)
: Sprite(gfx) {
this->entitat = (Entitat*)malloc(sizeof(Entitat)); this->entitat = (Entitat*)malloc(sizeof(Entitat));
this->entitat->num_frames = 82; this->entitat->num_frames = 82;
this->entitat->frames = (Frame*)malloc(this->entitat->num_frames * sizeof(Frame)); this->entitat->frames = (Frame*)malloc(this->entitat->num_frames * sizeof(Frame));
@@ -17,7 +19,6 @@ Prota::Prota( JD8_Surface gfx ) : Sprite( gfx ) {
this->entitat->frames[frame].x = x * 15; this->entitat->frames[frame].x = x * 15;
this->entitat->frames[frame].y = 20 + (y * 15); this->entitat->frames[frame].y = 20 + (y * 15);
frame++; frame++;
} }
} }
for (int y = 95; y < 185; y += 30) { for (int y = 95; y < 185; y += 30) {
@@ -76,7 +77,6 @@ Prota::Prota( JD8_Surface gfx ) : Sprite( gfx ) {
} }
void Prota::draw() { void Prota::draw() {
Sprite::draw(); Sprite::draw();
if (info::num_piramide == 4 && this->o != 4) { if (info::num_piramide == 4 && this->o != 4) {
@@ -89,7 +89,6 @@ void Prota::draw() {
} }
Uint8 Prota::update() { Uint8 Prota::update() {
Uint8 eixir = 0; Uint8 eixir = 0;
if (this->o < 4) { if (this->o < 4) {
@@ -141,10 +140,13 @@ Uint8 Prota::update() {
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
if (this->cur_frame == this->entitat->animacions[this->o].num_frames) { if (this->cur_frame == this->entitat->animacions[this->o].num_frames) {
if( this->o == 4 ) { eixir = 1; } else { eixir = 2; } if (this->o == 4) {
eixir = 1;
} else {
eixir = 2;
}
} }
} }
} }
return eixir; return eixir;
} }

View File

@@ -1,12 +1,10 @@
#pragma once #pragma once
#include "game/sprite.hpp"
#include "game/info.hpp" #include "game/info.hpp"
#include "game/sprite.hpp"
class Prota : public Sprite { class Prota : public Sprite {
public: public:
Prota(JD8_Surface gfx); Prota(JD8_Surface gfx);
void draw(); void draw();
@@ -16,6 +14,4 @@ public:
bool pergami; bool pergami;
protected: protected:
}; };

View File

@@ -1,17 +1,14 @@
#include "game/sprite.hpp" #include "game/sprite.hpp"
#include <stdlib.h> #include <stdlib.h>
Sprite::Sprite(JD8_Surface gfx) { Sprite::Sprite(JD8_Surface gfx) {
this->gfx = gfx; this->gfx = gfx;
this->entitat = NULL; this->entitat = NULL;
} }
Sprite::~Sprite(void) { Sprite::~Sprite(void) {
if (this->entitat != NULL) { if (this->entitat != NULL) {
if (this->entitat->num_frames > 0) free(this->entitat->frames); if (this->entitat->num_frames > 0) free(this->entitat->frames);
if (this->entitat->num_animacions > 0) { if (this->entitat->num_animacions > 0) {
@@ -22,17 +19,8 @@ Sprite::~Sprite(void) {
free(this->entitat); free(this->entitat);
} }
} }
void Sprite::draw() { void Sprite::draw() {
JD8_BlitCK(this->x, this->y, this->gfx, this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].x, this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].y, this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].w, this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].h, 255);
JD8_BlitCK( this->x, this->y, this->gfx, this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].x,
this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].y,
this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].w,
this->entitat->frames[this->entitat->animacions[this->o].frames[this->cur_frame]].h,
255);
} }

View File

@@ -22,9 +22,7 @@ struct Entitat {
}; };
class Sprite { class Sprite {
public: public:
Sprite(JD8_Surface gfx); Sprite(JD8_Surface gfx);
~Sprite(void); ~Sprite(void);
@@ -37,8 +35,6 @@ public:
Uint16 o; Uint16 o;
protected: protected:
JD8_Surface gfx; JD8_Surface gfx;
Uint8 cycles_per_frame; Uint8 cycles_per_frame;
}; };

View File

@@ -1,17 +1,17 @@
#include "core/jgame.hpp" #include <ctime>
#include "core/jdraw8.hpp" #include <string>
#include "core/jail_audio.hpp" #include "core/jail_audio.hpp"
#include "core/jdraw8.hpp"
#include "core/jfile.hpp" #include "core/jfile.hpp"
#include "core/jgame.hpp"
#include "game/defines.hpp" #include "game/defines.hpp"
#include "game/info.hpp" #include "game/info.hpp"
#include "game/modulegame.hpp" #include "game/modulegame.hpp"
#include "game/modulesequence.hpp" #include "game/modulesequence.hpp"
#include "game/options.hpp" #include "game/options.hpp"
#include <ctime>
#include <string>
int main(int argc, char* args[]) { int main(int argc, char* args[]) {
srand(unsigned(time(NULL))); srand(unsigned(time(NULL)));
// Crea la carpeta de configuració i carrega les opcions // Crea la carpeta de configuració i carrega les opcions