diff --git a/alienblaster/project/jni/application/Android.mk b/alienblaster/project/jni/application/Android.mk index 6a608047a..06ab14dcc 100644 --- a/alienblaster/project/jni/application/Android.mk +++ b/alienblaster/project/jni/application/Android.mk @@ -22,7 +22,7 @@ LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wil # Uncomment to also add C sources LOCAL_SRC_FILES += $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c)))) -LOCAL_SHARED_LIBRARIES := sdl sdl_mixer tremor sdl_ttf +LOCAL_SHARED_LIBRARIES := sdl sdl_mixer sdl_image tremor sdl_ttf LOCAL_STATIC_LIBRARIES := stlport diff --git a/alienblaster/project/jni/application/src/soundDB.cpp b/alienblaster/project/jni/application/src/soundDB.cpp index 0c1edb477..a6970f5da 100644 --- a/alienblaster/project/jni/application/src/soundDB.cpp +++ b/alienblaster/project/jni/application/src/soundDB.cpp @@ -21,6 +21,10 @@ using namespace std; #include "soundDB.h" #include "SDL_mixer.h" +#ifdef ANDROID +#include +#endif +#include SoundDB::SoundDB() {} @@ -37,9 +41,33 @@ Mix_Chunk *SoundDB::loadWav( string fn ) { if ( searchResult ) { return searchResult; } - + + // Check if file exist + FILE * inputFile = fopen( fn.c_str(), "rb"); + if (!inputFile) { + if( fn.size() > 4 && fn.find(".wav") != string::npos ) { + fn = fn.substr( 0, fn.size() - 4 ) + ".ogg"; + inputFile = fopen( fn.c_str(), "rb"); + } + if (!inputFile) { + cout << "ERROR: file " << fn << " does not exist!" << endl; +#ifdef ANDROID + __android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", (string( "Cannot load sound " ) + fn).c_str() ); +#endif + exit(1); + } + } + fclose(inputFile); + // TODO: error-handling Mix_Chunk *newSound = Mix_LoadWAV( fn.c_str() ); + if( !newSound ) { + cout << "ERROR: file " << fn << " cannot be loaded!" << endl; +#ifdef ANDROID + __android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", (string( "Cannot load sound " ) + fn).c_str() ); +#endif + exit(1); + } soundDB[ fn ] = newSound; return newSound; } diff --git a/alienblaster/project/jni/application/src/surfaceDB.cpp b/alienblaster/project/jni/application/src/surfaceDB.cpp index f3d892b09..f11c242b5 100644 --- a/alienblaster/project/jni/application/src/surfaceDB.cpp +++ b/alienblaster/project/jni/application/src/surfaceDB.cpp @@ -22,6 +22,7 @@ using namespace std; #include "surfaceDB.h" #include #include +#include #ifdef ANDROID #include #endif @@ -51,17 +52,26 @@ SDL_Surface *SurfaceDB::loadSurface( string fn, bool alpha ) { return searchResult; } - // open the file for reading - ifstream inputFile ( fn.c_str(), ios::in); - if (!inputFile.good()) { - cout << "ERROR: file " << fn << " does not exist!" << endl; + bool isPNG = false; + // Check if file exist + FILE * inputFile = fopen( fn.c_str(), "rb"); + if (!inputFile) { + if( fn.size() > 4 && fn.find(".bmp") != string::npos ) { + isPNG = true; + fn = fn.substr( 0, fn.size() - 4 ) + ".png"; + inputFile = fopen( fn.c_str(), "rb"); + } + if (!inputFile) { + cout << "ERROR: file " << fn << " does not exist!" << endl; #ifdef ANDROID - __android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", (string( "Cannot load image " ) + fn).c_str() ); + __android_log_print(ANDROID_LOG_ERROR, "Alien Blaster", (string( "Cannot load image " ) + fn).c_str() ); #endif - exit(1); + exit(1); + } } - - SDL_Surface *newSurface = SDL_LoadBMP( fn.c_str() ); + fclose(inputFile); + + SDL_Surface *newSurface = isPNG ? IMG_Load( fn.c_str() ) : SDL_LoadBMP( fn.c_str() ); if( newSurface == NULL ) { cout << "ERROR: Cannot load image " << fn << endl; diff --git a/alienblaster110_data.zip b/alienblaster110_data.zip index 979275a67..81c75eabe 100644 Binary files a/alienblaster110_data.zip and b/alienblaster110_data.zip differ