diff --git a/.DS_Store b/.DS_Store index 83be099..230ec5b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/jni/Sounds.cpp b/jni/Sounds.cpp new file mode 100755 index 0000000..86512bd --- /dev/null +++ b/jni/Sounds.cpp @@ -0,0 +1,35 @@ +#include "Sounds.h" +#include + +static JNIEnv* env = NULL; +static jclass jSounds = NULL; + +/** BackgroundSound */ + +void playBackgroundSound() { + jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayBackgroundSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +void stopBackgroundSound () { + jmethodID method = env->GetStaticMethodID(jSounds, "JniStopBackgroundSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +/** GameSound - Gunshot */ + +void playGameSoundGunshot() { + jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayGunshotSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +void stopGameSoundGunshot() { + jmethodID method = env->GetStaticMethodID(jSounds, "JniStopGunshotSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +JNIEXPORT void JNICALL Java_com_fishrungames_crystalofrhylil_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis) { + env = pEnv; + jSounds = env->FindClass("com/fishrungames/crystalofrhyli/sounds/JniSoundCalls"); + playBackgroundSound(); +} \ No newline at end of file diff --git a/jni/Sounds.h b/jni/Sounds.h new file mode 100755 index 0000000..31d1ccd --- /dev/null +++ b/jni/Sounds.h @@ -0,0 +1,7 @@ +#include + +extern "C" { + +JNIEXPORT void JNICALL Java_com_fishrungames_crystalofrhylil_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis); + +} diff --git a/jni/main_code.cpp b/jni/main_code.cpp index a9c1745..eae69e9 100644 --- a/jni/main_code.cpp +++ b/jni/main_code.cpp @@ -74,27 +74,27 @@ void TMyApplication::InnerInit() *SE::Console << "APP INIT\n"; } - SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt"); - SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt"); - SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt"); - SE::Renderer->PushShader("DefaultShader"); - - const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black"; - const std::string CONST_LOADING_TEXTURE = "loading"; - const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small"; - - SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK); - SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE); - SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE); - - SE::ResourceManager->TexList.AddTexture("console_bkg.bmp"); - - SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512); - - Inited = true; - - SE::Renderer->SetOrthoProjection(); - + SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader_vertex.txt", "shader_fragment.txt"); + SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt"); + SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt"); + SE::Renderer->PushShader("DefaultShader"); + + const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black"; + const std::string CONST_LOADING_TEXTURE = "loading"; + const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small"; + + SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK); + SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE); + SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE); + + SE::ResourceManager->TexList.AddTexture("console_bkg.bmp"); + + SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512); + + Inited = true; + + SE::Renderer->SetOrthoProjection(); + SE::Renderer->SetFullScreenViewport(); diff --git a/proj.android-studio/.idea/caches/build_file_checksums.ser b/proj.android-studio/.idea/caches/build_file_checksums.ser index edbf434..9027225 100644 Binary files a/proj.android-studio/.idea/caches/build_file_checksums.ser and b/proj.android-studio/.idea/caches/build_file_checksums.ser differ diff --git a/proj.android-studio/app/CMakeLists.txt b/proj.android-studio/app/CMakeLists.txt index 8f7df09..2ad1c8b 100755 --- a/proj.android-studio/app/CMakeLists.txt +++ b/proj.android-studio/app/CMakeLists.txt @@ -60,6 +60,8 @@ add_library( # Sets the name of the library. ${JNI_PATH}/main_code.cpp ${JNI_PATH}/match3/match3field.cpp ${JNI_PATH}/android_api.cpp + ${JNI_PATH}/Sounds.cpp + ) add_library( engine diff --git a/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/GLView.java b/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/GLView.java index fcc8b00..6eb2233 100755 --- a/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/GLView.java +++ b/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/GLView.java @@ -5,6 +5,8 @@ import java.util.Calendar; import android.content.Context; import android.opengl.GLSurfaceView; +import com.fishrungames.crystalofrhylil.sounds.JniSoundCalls; + import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -58,6 +60,7 @@ class GLView extends GLViewAncestor public void onSurfaceChanged(GL10 gl, int width, int height) { JniWrapper.Init(width,height); + JniSoundCalls.init(); } public void onSurfaceCreated(GL10 gl, EGLConfig config) diff --git a/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/MainActivity.java b/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/MainActivity.java index c186e5b..72ce9a2 100755 --- a/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/MainActivity.java +++ b/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/MainActivity.java @@ -21,6 +21,8 @@ import android.view.MotionEvent; public class MainActivity extends Activity { + private static MainActivity instance; + GLView mView; @Override @@ -29,6 +31,8 @@ public class MainActivity extends Activity super.onCreate(icicle); + instance = this; + EngineWrapper.LoadSalmonEngineLibrary(); EngineWrapper.SetActivityInstance(this); EngineWrapper.SetupEnviroment(); @@ -88,6 +92,14 @@ public class MainActivity extends Activity EngineWrapper.ProcessKeyDown(keyCode, event); return super.onKeyDown(keyCode, event); } + + public static MainActivity getInstance() { + if (instance == null) { + throw new RuntimeException("error GL2JNIActivity getInstance() - you are trying to get activity instance when it is not created or already destroyed"); + } + return instance; + } + } //package com.fishrungames.crystalofrhylil; diff --git a/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/sounds/JniSoundCalls.java b/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/sounds/JniSoundCalls.java new file mode 100644 index 0000000..206f729 --- /dev/null +++ b/proj.android-studio/app/src/main/java/com/fishrungames/crystalofrhylil/sounds/JniSoundCalls.java @@ -0,0 +1,43 @@ +package com.fishrungames.crystalofrhylil.sounds; + +import android.media.MediaPlayer; + +import com.fishrungames.crystalofrhylil.MainActivity; +import com.fishrungames.crystalofrhylil.R; + +public class JniSoundCalls { + + native public static void initJniSounds(); + + private static MediaPlayer backgroundPlayer = null; + private static MediaPlayer gunshotPlayer = null; + + public static void init() { + initJniSounds(); + } + + public static void JniPlayBackgroundSound() { + backgroundPlayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.background_sound); + backgroundPlayer.setLooping(true); + backgroundPlayer.start(); + } + + public static void JniStopBackgroundSound() { + if (backgroundPlayer != null) { + backgroundPlayer.stop(); + } + } + + public static void JniPlayGunshotSound() { + gunshotPlayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.gunshot_sound); + gunshotPlayer.setLooping(false); + gunshotPlayer.start(); + } + + public static void JniStopGunshotSound() { + if (gunshotPlayer != null) { + gunshotPlayer.stop(); + } + } + +} diff --git a/proj.android-studio/app/src/main/res/raw/background_sound.mp3 b/proj.android-studio/app/src/main/res/raw/background_sound.mp3 new file mode 100755 index 0000000..ead9299 Binary files /dev/null and b/proj.android-studio/app/src/main/res/raw/background_sound.mp3 differ diff --git a/proj.android-studio/app/src/main/res/raw/gunshot_sound.mp3 b/proj.android-studio/app/src/main/res/raw/gunshot_sound.mp3 new file mode 100755 index 0000000..ae35066 Binary files /dev/null and b/proj.android-studio/app/src/main/res/raw/gunshot_sound.mp3 differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..4e5f999 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/fishrungames/.DS_Store b/src/fishrungames/.DS_Store new file mode 100644 index 0000000..5c84cc2 Binary files /dev/null and b/src/fishrungames/.DS_Store differ