diff --git a/assets/back_btn.png b/assets/back_btn.png old mode 100644 new mode 100755 diff --git a/assets/ball.png b/assets/ball.png old mode 100644 new mode 100755 diff --git a/assets/ball_glow.png b/assets/ball_glow.png old mode 100644 new mode 100755 diff --git a/assets/block1.png b/assets/block1.png old mode 100644 new mode 100755 diff --git a/assets/block2.png b/assets/block2.png old mode 100644 new mode 100755 diff --git a/assets/block3.png b/assets/block3.png old mode 100644 new mode 100755 diff --git a/assets/bonus_floor.png b/assets/bonus_floor.png old mode 100644 new mode 100755 diff --git a/assets/bonus_gothrough.png b/assets/bonus_gothrough.png old mode 100644 new mode 100755 diff --git a/assets/bonus_multiplier.png b/assets/bonus_multiplier.png old mode 100644 new mode 100755 diff --git a/assets/brickshader_fragment.txt b/assets/brickshader_fragment.txt old mode 100644 new mode 100755 diff --git a/assets/brickshader_vertex.txt b/assets/brickshader_vertex.txt old mode 100644 new mode 100755 diff --git a/assets/console_bkg.bmp b/assets/console_bkg.bmp old mode 100644 new mode 100755 diff --git a/assets/credits.png b/assets/credits.png old mode 100644 new mode 100755 diff --git a/assets/droid_sans14_font_bitmap.png b/assets/droid_sans14_font_bitmap.png old mode 100644 new mode 100755 diff --git a/assets/droid_sans14_font_charmap.txt b/assets/droid_sans14_font_charmap.txt old mode 100644 new mode 100755 diff --git a/assets/frameshader_fragment.txt b/assets/frameshader_fragment.txt old mode 100644 new mode 100755 diff --git a/assets/frameshader_vertex.txt b/assets/frameshader_vertex.txt old mode 100644 new mode 100755 diff --git a/assets/game_end.png b/assets/game_end.png old mode 100644 new mode 100755 diff --git a/assets/level1.txt b/assets/level1.txt old mode 100644 new mode 100755 diff --git a/assets/level10.txt b/assets/level10.txt old mode 100644 new mode 100755 diff --git a/assets/level11.txt b/assets/level11.txt old mode 100644 new mode 100755 diff --git a/assets/level12.txt b/assets/level12.txt old mode 100644 new mode 100755 diff --git a/assets/level1ogg.ogg b/assets/level1ogg.ogg old mode 100644 new mode 100755 diff --git a/assets/level2.txt b/assets/level2.txt old mode 100644 new mode 100755 diff --git a/assets/level3.txt b/assets/level3.txt old mode 100644 new mode 100755 diff --git a/assets/level4.txt b/assets/level4.txt old mode 100644 new mode 100755 diff --git a/assets/level5.txt b/assets/level5.txt old mode 100644 new mode 100755 diff --git a/assets/level6.txt b/assets/level6.txt old mode 100644 new mode 100755 diff --git a/assets/level7.txt b/assets/level7.txt old mode 100644 new mode 100755 diff --git a/assets/level8.txt b/assets/level8.txt old mode 100644 new mode 100755 diff --git a/assets/level9.txt b/assets/level9.txt old mode 100644 new mode 100755 diff --git a/assets/levelshot1.png b/assets/levelshot1.png old mode 100644 new mode 100755 diff --git a/assets/levelshot10.png b/assets/levelshot10.png old mode 100644 new mode 100755 diff --git a/assets/levelshot11.png b/assets/levelshot11.png old mode 100644 new mode 100755 diff --git a/assets/levelshot12.png b/assets/levelshot12.png old mode 100644 new mode 100755 diff --git a/assets/levelshot2.png b/assets/levelshot2.png old mode 100644 new mode 100755 diff --git a/assets/levelshot3.png b/assets/levelshot3.png old mode 100644 new mode 100755 diff --git a/assets/levelshot4.png b/assets/levelshot4.png old mode 100644 new mode 100755 diff --git a/assets/levelshot5.png b/assets/levelshot5.png old mode 100644 new mode 100755 diff --git a/assets/levelshot6.png b/assets/levelshot6.png old mode 100644 new mode 100755 diff --git a/assets/levelshot7.png b/assets/levelshot7.png old mode 100644 new mode 100755 diff --git a/assets/levelshot8.png b/assets/levelshot8.png old mode 100644 new mode 100755 diff --git a/assets/levelshot9.png b/assets/levelshot9.png old mode 100644 new mode 100755 diff --git a/assets/loading.png b/assets/loading.png old mode 100644 new mode 100755 diff --git a/assets/logo_small.png b/assets/logo_small.png old mode 100644 new mode 100755 diff --git a/assets/main_menu_bkg_left.png b/assets/main_menu_bkg_left.png old mode 100644 new mode 100755 diff --git a/assets/main_menu_bkg_right.png b/assets/main_menu_bkg_right.png old mode 100644 new mode 100755 diff --git a/assets/reflector.png b/assets/reflector.png old mode 100644 new mode 100755 diff --git a/assets/select_level.png b/assets/select_level.png old mode 100644 new mode 100755 diff --git a/assets/shader1fragment.txt b/assets/shader1fragment.txt old mode 100644 new mode 100755 diff --git a/assets/shader1vertex.txt b/assets/shader1vertex.txt old mode 100644 new mode 100755 diff --git a/assets/shutterstock1.png b/assets/shutterstock1.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock10.png b/assets/shutterstock10.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock11.png b/assets/shutterstock11.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock12.png b/assets/shutterstock12.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock2.png b/assets/shutterstock2.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock3.png b/assets/shutterstock3.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock4.png b/assets/shutterstock4.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock5.png b/assets/shutterstock5.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock6.png b/assets/shutterstock6.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock7.png b/assets/shutterstock7.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock8.png b/assets/shutterstock8.png old mode 100644 new mode 100755 diff --git a/assets/shutterstock9.png b/assets/shutterstock9.png old mode 100644 new mode 100755 diff --git a/assets/slide_up_btn.png b/assets/slide_up_btn.png old mode 100644 new mode 100755 diff --git a/assets/tap_to_continue_btn.png b/assets/tap_to_continue_btn.png old mode 100644 new mode 100755 diff --git a/assets/wall_bonus.png b/assets/wall_bonus.png old mode 100644 new mode 100755 diff --git a/assets/wall_left.png b/assets/wall_left.png old mode 100644 new mode 100755 diff --git a/assets/wall_right.png b/assets/wall_right.png old mode 100644 new mode 100755 diff --git a/assets/wall_up.png b/assets/wall_up.png old mode 100644 new mode 100755 diff --git a/game/Android.mk b/game/Android.mk new file mode 100644 index 0000000..53c2935 --- /dev/null +++ b/game/Android.mk @@ -0,0 +1,77 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +LPATH := $(call my-dir) + +ENGINE_PATH = $(SalmonEnginePathCygwin) + +#BOOST_PATH = $(LibsPathCygwin)/boost_1_47_0 +BOOST_PATH = $(LibsPathCygwin)/boost_1_52_0 + +OGG_PATH = $(LibsPathCygwin)/libogg-1.3.0 + +VORBIS_PATH = $(LibsPathCygwin)/libvorbis-1.3.2 + +SQUIRREL_PATH = $(LibsPathCygwin)/sqplus + +LIBPNG_PATH = $(LibsPathCygwin)/libpng_1.4.1_android + +ZIP_PATH = $(LibsPathCygwin)/julienr-libzip-android/jni + +#====== ENGINE AND LIBS ===================== + +include $(ENGINE_PATH)/Android_Salmon_Engine.mk + +#================= THE GAME ======================= + + +LOCAL_PATH:= $(LPATH) + +include $(CLEAR_VARS) + +LOCAL_CFLAGS := -DTARGET_ANDROID -std=gnu++11 --std=c++11 +LOCAL_STATIC_LIBRARIES := boost +LOCAL_STATIC_LIBRARIES += squirrel +LOCAL_STATIC_LIBRARIES += png_lib +LOCAL_STATIC_LIBRARIES += zip +LOCAL_SHARED_LIBRARIES := SalmonEngine +LOCAL_SHARED_LIBRARIES += gnustl_shared +LOCAL_C_INCLUDES := $(ENGINE_PATH) +LOCAL_C_INCLUDES += $(BOOST_PATH) +LOCAL_C_INCLUDES += $(VORBIS_PATH)/include +LOCAL_C_INCLUDES += $(VORBIS_PATH)/include/vorbis +LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib +LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/books +LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/modes +LOCAL_C_INCLUDES += $(OGG_PATH)/include +LOCAL_C_INCLUDES += $(OGG_PATH)/include/ogg +LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/include +LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/sqplus +LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/squirrel +LOCAL_C_INCLUDES += $(SQUIRREL_PATH)/sqstdlib +LOCAL_C_INCLUDES += $(LIBPNG_PATH) +LOCAL_C_INCLUDES += $(ZIP_PATH) +LOCAL_MODULE := gl2jni +LOCAL_SRC_FILES := main_code.cpp +LOCAL_SRC_FILES += android_api.cpp +LOCAL_SRC_FILES += menucode.cpp +LOCAL_SRC_FILES += gamecode.cpp +LOCAL_SRC_FILES += loadingcode.cpp +LOCAL_SRC_FILES += creditscode.cpp +LOCAL_LDLIBS := -lGLESv2 +LOCAL_LDLIBS += -llog -Wl,-s + +include $(BUILD_SHARED_LIBRARY) diff --git a/game/Application.mk b/game/Application.mk new file mode 100644 index 0000000..824acab --- /dev/null +++ b/game/Application.mk @@ -0,0 +1,3 @@ +APP_STL := gnustl_static +APP_CPPFLAGS += -fexceptions +APP_CPPFLAGS += -frtti \ No newline at end of file diff --git a/game/DoubleHitBalls.dev b/game/DoubleHitBalls.dev new file mode 100644 index 0000000..4298a40 --- /dev/null +++ b/game/DoubleHitBalls.dev @@ -0,0 +1,179 @@ +[Project] +FileName=DoubleHitBalls.dev +Name=DoubleHitBalls +UnitCount=13 +Type=1 +Ver=1 +ObjFiles= +Includes=C:\Workplace\Projects\Engine;C:\Workplace\android-ndk-r6b\platforms\android-8\arch-arm\usr\include;C:\Workplace\libs\boost_1_47_0;C:\Workplace\libs\openal;C:\Workplace\libs\libvorbis-1.3.2\include;C:\Workplace\libs\libogg-1.3.0\include +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler=-DTARGET_ANDROID_@@_ +CppCompiler=-DTARGET_ANDROID_@@_ +Linker= +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=DoubleHitBalls.exe +HostApplication= +Folders= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[Unit1] +FileName=main_code.cpp +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=main_code.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=menucode.cpp +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=menucode.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit5] +FileName=gamecode.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=gamecode.cpp +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=game_area_interface.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=creditscode.cpp +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=creditscode.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=loadingcode.cpp +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=loadingcode.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=android_api.cpp +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=android_api.h +CompileCpp=1 +Folder=DoubleHitBalls +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/game/android_api.cpp b/game/android_api.cpp new file mode 100644 index 0000000..4c7f210 --- /dev/null +++ b/game/android_api.cpp @@ -0,0 +1,10 @@ +#include "android_api.h" + +#include "main_code.h" + +JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height) +{ + JniInitApp(width, height, 480.f, 320.f); +} + + diff --git a/game/android_api.h b/game/android_api.h new file mode 100644 index 0000000..5e6f4c3 --- /dev/null +++ b/game/android_api.h @@ -0,0 +1,25 @@ +#ifndef ANDROID_API_H_INCLUDED +#define ANDROID_API_H_INCLUDED + +#include +#include + +#include +#include +#include + +#include "boost/shared_ptr.hpp" + +#include "main_code.h" + +#include "include/Engine.h" + +using namespace SE; + +extern "C" +{ + JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height); +}; + + +#endif diff --git a/game/creditscode.cpp b/game/creditscode.cpp new file mode 100644 index 0000000..3e0e010 --- /dev/null +++ b/game/creditscode.cpp @@ -0,0 +1,79 @@ +#include "creditscode.h" +#include "include/Engine.h" + +#include "main_code.h" + +const int TGameCredits::CONST_STATE_APPEARING = 0; +const int TGameCredits::CONST_STATE_APPEARED = 1; +const int TGameCredits::CONST_STATE_DISAPPEARING = 2; +const int TGameCredits::CONST_STATE_DISAPPEARED = 3; + +const float TGameCredits::CONST_APPEAR_TIME = 150.f; + +TGameCredits::TGameCredits() + : TGameAreaAncestor() + , StateTimer(0) + , State(CONST_STATE_DISAPPEARED) +{ +} + +void TGameCredits::Draw() +{ + + float transparency = StateTimer/CONST_APPEAR_TIME; + + + RenderUniform1f("Transparency", transparency); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList["main_menu_bkg_left"]); + Renderer->DrawRect(vec2(0, 0.f), vec2(480.f, 320.f)); + + const vec2 creditsPos(140.f, 130.f); + + const vec2 creditsHalfSize(128.f, 128.f); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_CREDITS_TEXTURE]); + Renderer->DrawRect(creditsPos-creditsHalfSize, creditsPos+creditsHalfSize); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_LOGO_SMALL_TEXTURE]); + Renderer->DrawRect(vec2(240.f-128.f+15.f, 320.f-64.f), vec2(240.f+128.f+15.f, 320.f)); + + CheckGlError("Draw TGameCredits"); +} + +void TGameCredits::Update(cardinal dt) +{ + if (State == CONST_STATE_APPEARING) + { + StateTimer += dt; + if (StateTimer >= CONST_APPEAR_TIME) + { + StateTimer = CONST_APPEAR_TIME; + State = CONST_STATE_APPEARED; + } + } + else if (State == CONST_STATE_DISAPPEARING) + { + StateTimer -= dt; + if (StateTimer <= 0.f) + { + StateTimer = 0.f; + State = CONST_STATE_DISAPPEARED; + } + } +} + +void TGameCredits::OnTapDown(vec2 p) +{ + Application->GoFromCreditsToMenu(); +} + +void TGameCredits::StartAppear() +{ + State = CONST_STATE_APPEARING; +} + +void TGameCredits::StartDisappear() +{ + State = CONST_STATE_DISAPPEARING; +} diff --git a/game/creditscode.h b/game/creditscode.h new file mode 100644 index 0000000..e77114b --- /dev/null +++ b/game/creditscode.h @@ -0,0 +1,34 @@ +#ifndef CREDITSCODE_H_INCLUDED +#define CREDITSCODE_H_INCLUDED + +#include "game_area_interface.h" + +using namespace SE; + + +class TGameCredits : public TGameAreaAncestor +{ + static const int CONST_STATE_APPEARING; + static const int CONST_STATE_APPEARED; + static const int CONST_STATE_DISAPPEARING; + static const int CONST_STATE_DISAPPEARED; + static const float CONST_APPEAR_TIME; + + + int State; + float StateTimer; + +public: + + TGameCredits(); + + virtual void Draw(); + virtual void Update(cardinal dt); + virtual void OnTapDown(vec2 p); + + void StartAppear(); + void StartDisappear(); +}; + + +#endif diff --git a/game/game_area_interface.h b/game/game_area_interface.h new file mode 100644 index 0000000..2a549af --- /dev/null +++ b/game/game_area_interface.h @@ -0,0 +1,23 @@ +#ifndef GAME_AREA_INTERFACE_H_INCLUDED +#define GAME_AREA_INTERFACE_H_INCLUDED + +#include "include/Engine.h" + +using namespace SE; + + +class TGameAreaAncestor +{ +public: + virtual void Draw() { } + virtual void Update(cardinal) { } + virtual void OnTapUp(vec2) { } + virtual void OnTapDown(vec2) { } + virtual void OnFling(vec2) { } + virtual void OnScroll(vec2) { } + + virtual ~TGameAreaAncestor() { } //By default destructor is not virtual +}; + + +#endif diff --git a/game/gamecode.cpp b/game/gamecode.cpp new file mode 100644 index 0000000..8bee1b9 --- /dev/null +++ b/game/gamecode.cpp @@ -0,0 +1,1560 @@ +#include "gamecode.h" +#include "main_code.h" + +const int CONST_LEVELSTATE_STANDBY = 0; +const int CONST_LEVELSTATE_PLAYING = 1; +const int CONST_LEVELSTATE_GO_TO_PAUSE = 2; +const int CONST_LEVELSTATE_PAUSE = 3; +const int CONST_LEVELSTATE_LOADING = 4; +const int CONST_LEVELSTATE_NODRAW = 5; +const int CONST_LEVELSTATE_FINISH_FREEZE = 6; +const int CONST_LEVELSTATE_FINISHED = 7; + +const float CONST_TIMER_LOADING = 150.f; + +const float CONST_PAUSE_APPEAR_TIME = 150.f; + +const float CONST_FINISH_FREEZE_TIME = 1000.f; +const float CONST_FINISHING_TIME = 250.f; + +const float CONST_BALL_VELOCITY = 200.f; + +const vec2 CONST_SLIDE_UP_POS(240.f, 64.f); + +const vec2 CONST_TAP_TO_CONTINUE_POS(240.f, 200.f); + +bool operator<(const PairColorTexture& p1, const PairColorTexture& p2) +{ + if (p1.second == p2.second) + { + if (p1.first.v[0] == p2.first.v[0]) + { + if (p1.first.v[1] == p2.first.v[1]) + { + if (p1.first.v[2] == p2.first.v[2]) + { + return p1.first.v[3] < p2.first.v[3]; + } + else + { + return p1.first.v[2] < p2.first.v[2]; + } + } + else + { + return p1.first.v[1] < p2.first.v[1]; + } + } + else + { + return p1.first.v[0] < p2.first.v[0]; + } + } + + return (p1.second < p2.second); +} + + +TBrick::TBrick() + : State(CONST_BRICKSTATE_VISIBLE) + , StateTimer(0.f) + , Color(vec4(0.f, 0.f, 0.f, 1.f)) + , Locked(0) + , InitialLocked(0) +{ +} + +void TBrick::SetVisible(vec4 color, int locked) +{ + State = CONST_BRICKSTATE_VISIBLE; + Color = color; + InitialLocked = locked; + Locked = InitialLocked; +} + +void TBrick::SetInvisible() +{ + State = CONST_BRICKSTATE_INVISIBLE; +} + +void TBrick::TryDrawAppear(int ipos, int jpos) +{ + vec2 centerPos = GetPosFrom(ipos, jpos); + + vec2 blockHalfSize = vec2(0.5f*CONST_BRICK_WIDTH, 0.5f*CONST_BRICK_HEIGHT); + + std::string texName; + if (Locked == 2) + { + texName = CONST_BLOCK_TEXTURE3; + } + else if (Locked == 1) + { + texName = CONST_BLOCK_TEXTURE2; + } + else + { + texName = CONST_BLOCK_TEXTURE1; + } + + if (State == CONST_BRICKSTATE_DISAPPEAR) + { + + RenderUniform1f("Transparency", StateTimer/CONST_BRICK_DISAPPEAR_TIME); + RenderUniform4fv("BrickColor", Color.v); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[texName]); + Renderer->DrawRect(centerPos - blockHalfSize, centerPos + blockHalfSize); + } + else if (State == CONST_BRICKSTATE_APPEAR) + { + + RenderUniform1f("Transparency", 1.f - StateTimer/CONST_BRICK_APPEAR_TIME); + RenderUniform4fv("BrickColor", Color.v); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[texName]); + Renderer->DrawRect(centerPos - blockHalfSize, centerPos + blockHalfSize); + } +} + +void TBrick::Update(cardinal dt) +{ + if (State == CONST_BRICKSTATE_DISAPPEAR) + { + StateTimer -= dt; + if (StateTimer < 0.f) + { + StateTimer = 0.f; + State = CONST_BRICKSTATE_INVISIBLE; + } + } + + if (State == CONST_BRICKSTATE_APPEAR) + { + StateTimer -= dt; + if (StateTimer < 0.f) + { + StateTimer = 0.f; + State = CONST_BRICKSTATE_VISIBLE; + } + } +} + +vec4 TBrick::GetColor() +{ + return Color; +} + +vec2 TBrick::GetPosFrom(int ipos, int jpos) +{ + const vec2 BorderShift(CONST_BRICK_SHIFT_X, CONST_BRICK_SHIFT_Y); + + return BorderShift+vec2(CONST_BRICK_WIDTH*ipos + 0.5f*CONST_BRICK_WIDTH, 320.f - CONST_BRICK_HEIGHT*(jpos)-0.5f*CONST_BRICK_HEIGHT); + +} + +void TBrick::Disappear() +{ + StateTimer = CONST_BRICK_DISAPPEAR_TIME; + State = CONST_BRICKSTATE_DISAPPEAR; +} + +void TBrick::Hit() +{ + if (Locked == 0) + { + Disappear(); + } + else + { + Locked--; + } +} + +void TBrick::Appear(vec4 color, int locked) +{ + StateTimer = CONST_BRICK_APPEAR_TIME; + State = CONST_BRICKSTATE_APPEAR; + Color = color; + InitialLocked = locked; + Locked = InitialLocked; +} + +void TBrick::Appear() +{ + Appear(Color, InitialLocked); +} + +int TBrick::GetLocked() +{ + return Locked; +} + +bool TBrick::CanReact() +{ + return (State == CONST_BRICKSTATE_VISIBLE) || (State == CONST_BRICKSTATE_APPEAR); +} + +//=========================================== +//=========================================== +//=========================================== + +TBonusFalling::TBonusFalling(vec2 pos) + : BonusType(rand() % 3) + , Pos(pos) + , Lifetime(0.f) +{ + + if (BonusType == 0) + { + TexName = CONST_BONUS_MULTIPLIER_TEXTURE; + } + + if (BonusType == 1) + { + TexName = CONST_BONUS_GOTHROUGH_TEXTURE; + } + + if (BonusType == 2) + { + TexName = CONST_BONUS_FLOOR_TEXTURE; + } + +} + +vec2 TBonusFalling::GetPos() +{ + return Pos; +} + +int TBonusFalling::GetType() +{ + return BonusType; +} + + +void TBonusFalling::Draw() +{ + vec2 BonusHalfSize = vec2(16.f, 16.f); + + float transparency = min(Lifetime/CONST_BONUS_APPEAR_TIME , 1.f); + + RenderUniform4fv("BrickColor", vec4(1.0f, 1.0f, 1.0f, 1.0f).v); + RenderUniform1f("Transparency", transparency); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[TexName]); + Renderer->DrawRect(Pos - BonusHalfSize, Pos + BonusHalfSize); + +} + + +void TBonusFalling::Update(cardinal dt) +{ + Lifetime += dt; + Pos.v[1] -= dt * CONST_BONUS_FALL_SPEED / 1000.f; +} + +//=========================================== +//=========================================== +//=========================================== + + +TBall::TBall(vec2 pos, vec2 velocity, vec4 color) + : Pos(pos) + , Velocity(velocity) + , Color(color) +{ + //must be 5 + TalePos.push_back(Pos); + TalePos.push_back(Pos); + TalePos.push_back(Pos); + TalePos.push_back(Pos); + TalePos.push_back(Pos); +} + +vec2 TBall::GetPos() +{ + return Pos; +} + +vec2 TBall::GetVelocityVector() +{ + return Velocity; +} + +void TBall::Go() +{ + Velocity = Normalize(vec2(2.f, 1.f)); +} + +void TBall::ReflectToLeft() +{ + if (Velocity.v[0] > 0.f) + { + Velocity.v[0] = - Velocity.v[0]; + } +} + +void TBall::ReflectToRight() +{ + if (Velocity.v[0] < 0.f) + { + Velocity.v[0] = - Velocity.v[0]; + } +} + +void TBall::ReflectToUp() +{ + if (Velocity.v[1] < 0.f) + { + Velocity.v[1] = - Velocity.v[1]; + } +} + +void TBall::ReflectToDown() +{ + if (Velocity.v[1] > 0.f) + { + Velocity.v[1] = - Velocity.v[1]; + } +} + +//function for reflector surface. +float ReflectorPlaneFunction(float shift) +{ + /* _______ + / \ + | | + Something like this + + */ + + if (shift>=-70.f && shift < -40.f) + { + float t = (shift+70.f)/30.f; //0 to 1 + return 9.f + 21.f * t; + } + + if (shift>=-40.f && shift < 40.f) + { + return 30.f; + } + + + if (shift >= 40.f && shift <= 70.f) + { + float t = (70.f - shift)/30.f; //1 to 0 + return 9.f + 21.f * t; + } + + return 0.f; +} + +void TBall::TryReflectOnReflector(vec2 refPos) +{ + const float reflectionShiftY = 13.f; + const float reflectionMaxHeight = 30.f; + + + + if ((Pos.v[1] < reflectionMaxHeight + reflectionShiftY) && Pos.v[1] > 0.0f && Velocity.v[1] < 0) + { + float dy = ReflectorPlaneFunction(Pos.v[0] - refPos.v[0]); + + if (dy > 0 && (dy + reflectionShiftY > Pos.v[1])) + { + float shift = (Pos.v[0] - refPos.v[0]) / 128.f; + shift = min(shift, 0.5f); + shift = max(shift, -0.5f); + vec2 n = Normalize(vec2(shift, 1.0f)); + + Velocity = Velocity - n * 2.f * (Velocity.v[0]*n.v[0] + Velocity.v[1]*n.v[1]); + if ((Velocity.v[1] <= 0) || (fabs(Velocity.v[0]/Velocity.v[1]) > 4.f)) + { + Velocity.v[0] = 4.f*sign(Velocity.v[0]); + Velocity.v[1] = 1.f; + Velocity = Normalize(Velocity); + } + } + } +} + + +void TBall::Update(cardinal dt) +{ + Pos += Velocity * (CONST_BALL_VELOCITY * dt / 1000.f); + + TalePos.push_back(Pos); + + if (TalePos.size() > 4) + { + TalePos.erase(TalePos.begin()); + } +} + +//=========================================== +//=========================================== +//=========================================== + + +TGameLevel::TGameLevel() +{ + + BkgTexture = "bkg"; + + RenderBufferReady = false; + PrevLevelStateIsStandby = false; + + OutScale = 1.f; + OutScaleVelocity = 0.f; + + StateTimer = 0.f; + + LevelState = CONST_LEVELSTATE_NODRAW; + + BallColor = vec4(0.2f, 0.8f, 1.0f, 1.0f); + + BonusFloorPosY = 0.f; + +} + +TGameLevel::~TGameLevel() +{ +} + + + +void TGameLevel::ReloadBlockInstansingList() +{ + std::map ConstTextureBlockMap = boost::assign::map_list_of (0,CONST_BLOCK_TEXTURE1) (1,CONST_BLOCK_TEXTURE2) (2,CONST_BLOCK_TEXTURE3); + + std::pair tempPair; + BlockInstansingList.ColorBlockList.clear(); + + for (int i=0; i>::iterator itr = BlockInstansingList.ColorBlockList.end(); + + for (auto b = BlockInstansingList.ColorBlockList.begin(); b != BlockInstansingList.ColorBlockList.end(); ++b) + { + if (b->first == tempPair) + { + itr = b; + } + } + + if (itr == BlockInstansingList.ColorBlockList.end()) + { + BlockInstansingList.ColorBlockList.push_back(std::pair(tempPair, TTriangleList())); + itr = BlockInstansingList.ColorBlockList.end(); + + itr--; + } + + vec2 posFrom = BlockMatrix[i][j].GetPosFrom(i,j) + vec2(-0.5f*CONST_BRICK_WIDTH, -0.5f*CONST_BRICK_HEIGHT); + vec2 posTo = BlockMatrix[i][j].GetPosFrom(i,j) + vec2(+0.5f*CONST_BRICK_WIDTH, +0.5f*CONST_BRICK_HEIGHT); + + itr->second.Data += MakeDataTriangleList(posFrom, posTo); + + } + } + } + + for (auto it = BlockInstansingList.ColorBlockList.begin(); it != BlockInstansingList.ColorBlockList.end(); ++it) + { + it->second.RefreshBuffer(); + } + +} + +vec2 TGameLevel::GetBlock(const vec2& pos) +{ + + int x = static_cast((pos.v[0] - CONST_BRICK_SHIFT_X) / CONST_BRICK_WIDTH); + int y = static_cast((320.0f + CONST_BRICK_SHIFT_Y - pos.v[1]) / CONST_BRICK_HEIGHT); + + if (x < 0) + x = 0; + + if (x > CONST_BRICKMATRIX_WIDTH-1) + x = CONST_BRICKMATRIX_WIDTH-1; + + if (y < 0) + y = 0; + + if (y > CONST_BRICKMATRIX_HEIGHT-1) + y = CONST_BRICKMATRIX_HEIGHT-1; + + return vec2(x, y); +} + +bool TGameLevel::TapInBackBtnArea(const vec2& pos) +{ + return (pos.v[1] > 320.f - 64.f) && (pos.v[0]>=240.f-75.f) && (pos.v[0]<=240.f+75.f); +} + +void TGameLevel::SetFinishFreeze() +{ + StateTimer = CONST_FINISH_FREEZE_TIME; + + LevelState = CONST_LEVELSTATE_FINISH_FREEZE; + +} + +void TGameLevel::SetFinished() +{ + StateTimer = CONST_FINISHING_TIME; + + LevelState = CONST_LEVELSTATE_FINISHED; + + OutScale = 1.f; +} + +vec4 TGameLevel::ParseColor(const std::string& s) +{ + vec4 r; + std::string ss(s); + + int i = ss.find(", "); + int c = toint(ss.substr(0, i)); + ss.erase(0, i+2); + r.v[0] = c / 255.f; + + i = ss.find(", "); + c = toint(ss.substr(0, i)); + ss.erase(0, i+2); + r.v[1] = c / 255.f; + + i = ss.find(", "); + c = toint(ss.substr(0, i)); + ss.erase(0, i+2); + r.v[2] = c / 255.f; + + c = toint(ss); + r.v[3] = c / 255.f; + + return r; +} + +void TGameLevel::ReloadLevel() +{ + cardinal byteCount; + boost::shared_array file = CreateMemFromFile(LevelFileName, byteCount); + std::string fileString(&file[0]); + char c; + //int n = 0; + + + std::vector rows; + int rowLen; + while (fileString.size() > 0) + { + rowLen = fileString.find(fendl); + rows.push_back(fileString.substr(0, rowLen)); + fileString.erase(0, rowLen+2); + } + + std::vector::iterator rowIterator = rows.begin(); + BallColor = ParseColor(*rowIterator); + ++rowIterator; + + std::vector colors; + + vec4 tc; + + while (*rowIterator != "Colormap") + { + tc = ParseColor(*rowIterator); + colors.push_back(tc); + ++rowIterator; + } + + std::vector::iterator rowColorIterator; + std::vector::iterator rowLockIterator; + + rowColorIterator = rowIterator + 1; + + rowLockIterator = rowColorIterator + 14; + + + + for (int j=0; jBallInBlock = GetBlock(ballPos); + BallList.begin()->PrevBallInBlock = BallList.begin()->BallInBlock; + + BonusGothroughTimer = 0.f; + BonusFloorTimer = 0.f; + + BonusFallingList.clear(); + + RenderBufferReady = false; + + ReloadBallInstancingList(); + + BonusFloorPosY = 0.f; + +} + +bool TGameLevel::IsLoaded() +{ + return (LevelState == CONST_LEVELSTATE_STANDBY); +} + +void TGameLevel::Draw() +{ + + if (LevelState == CONST_LEVELSTATE_NODRAW) + { + CheckGlError(); + return; + } + + if (LevelState == CONST_LEVELSTATE_LOADING) + { + Renderer->PushMatrix(); + float scale = 1.f - 0.5f*StateTimer/CONST_TIMER_LOADING; + if (scale < 0.5f) + scale = 0.5f; + + if (scale > 1.f) + scale = 1.f; + + Renderer->TranslateMatrix(vec3(Renderer->GetMatrixWidth() * 0.5f, Renderer->GetMatrixHeight() * 0.5f, 0)); + Renderer->ScaleMatrix(scale); + Renderer->TranslateMatrix(-vec3(Renderer->GetMatrixWidth() * 0.5f, Renderer->GetMatrixHeight() * 0.5f, 0)); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[LevelScreenTexture]); + Renderer->DrawRect(vec2(0, 0), vec2(480.f, 320.f)); + Renderer->PopMatrix(); + CheckGlError(); + return; + } + + + bool mustShowButtons = ((LevelState == CONST_LEVELSTATE_PAUSE) || (LevelState == CONST_LEVELSTATE_GO_TO_PAUSE)); + + bool pause = (mustShowButtons || (LevelState == CONST_LEVELSTATE_FINISHED)); + + + bool renderBufferReady = RenderBufferReady; + + if (pause && renderBufferReady) + { + + //See also below (same method) + Renderer->PushMatrix(); + Renderer->TranslateMatrix(vec3(Renderer->GetMatrixWidth() * 0.5f, Renderer->GetMatrixHeight() * 0.5f, 0)); + Renderer->ScaleMatrix(OutScale); + Renderer->TranslateMatrix(-vec3(Renderer->GetMatrixWidth() * 0.5f, Renderer->GetMatrixHeight() * 0.5f, 0)); + DrawBuffer(); + + if (mustShowButtons) + { + DrawPauseButtons(); + } + Renderer->PopMatrix(); + CheckGlError(); + return; + } + + if (pause && !renderBufferReady) + { + + Renderer->SwitchToFrameBuffer("LevelBuffer"); + Renderer->SetProjectionMatrix(480.f, 320.f); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + CheckGlError(); + } + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[BkgTexture]); + Renderer->DrawRect(vec2(0, 0), vec2(480.f, 320.f)); + + std::list::iterator iBall; + + Renderer->PushShader("BrickShader"); + + + for (int i=0; i>::iterator colorBlockIterator; + for (colorBlockIterator = BlockInstansingList.ColorBlockList.begin(); colorBlockIterator != BlockInstansingList.ColorBlockList.end(); ++colorBlockIterator) + { + RenderUniform4fv("BrickColor", colorBlockIterator->first.first.v); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[colorBlockIterator->first.second]); + + Renderer->DrawTriangleList(colorBlockIterator->second); + } + + std::list::iterator iBonus; + + for (iBonus = BonusFallingList.begin(); iBonus != BonusFallingList.end(); ++iBonus) + { + iBonus->Draw(); + } + + DrawBallInstancingList(); + + Renderer->PopShader(); + + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_REFLECTOR_TEXTURE]); + Renderer->DrawRect(vec2(-128.f, -16.f)+ReflectorPos, vec2(128.f, 16.f)+ReflectorPos); + + + const vec2 wallUpPos1(240.f-256.f, 320.f-64.f); + const vec2 wallUpPos2(240.f+256.f, 320.f); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_WALL_UP_TEXTURE]); + Renderer->DrawRect(wallUpPos1, wallUpPos2); + + const vec2 wallLeftPos1(0.f, 320.f - 512.f); + const vec2 wallLeftPos2(32.f, 320.f); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_WALL_LEFT_TEXTURE]); + Renderer->DrawRect(wallLeftPos1, wallLeftPos2); + + const vec2 wallRightPos1(480.f-32.f, 320.f - 512.f); + const vec2 wallRightPos2(480.f, 320.f); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_WALL_RIGHT_TEXTURE]); + Renderer->DrawRect(wallRightPos1, wallRightPos2); + + + if (BonusFloorTimer>0.f) + { + + const vec2 wallDownPos(240.f, BonusFloorPosY); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_WALL_BONUS_TEXTURE]); + + Renderer->DrawRect(vec2(-256.f, -16.f)+wallDownPos, vec2(256.f, 16.f)+wallDownPos); + } + + + if (!pause) + { + RenderUniform1f("Transparency", 1.f); + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_BACK_BTN_TEXTURE]); + const vec2 BackBtnPos(240.f, 320.f - 32.f - 20.f); + Renderer->DrawRect(vec2(-128.f, -32.f)+BackBtnPos, vec2(128.f, 32.f)+BackBtnPos); + } + + if (pause && !renderBufferReady) + { + + //ololo + //See also above (same method) + Renderer->SwitchToScreen(); + Renderer->SetFullScreenViewport(); + + Renderer->PushMatrix(); + //Renderer->LoadIdentity(); + Renderer->TranslateMatrix(vec3(Renderer->GetMatrixWidth() * 0.5f, Renderer->GetMatrixHeight() * 0.5f, 0)); + Renderer->ScaleMatrix(OutScale); + Renderer->TranslateMatrix(-vec3(Renderer->GetMatrixWidth() * 0.5f, Renderer->GetMatrixHeight() * 0.5f, 0)); + DrawBuffer(); + if (mustShowButtons) + { + DrawPauseButtons(); + } + Renderer->PopMatrix(); + RenderBufferReady = true; + CheckGlError(); + } + CheckGlError(); +} + +void TGameLevel::DrawPauseButtons() +{ + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_SLIDE_UP_BTN_TEXTURE]); + Renderer->DrawRect(vec2(-128.f, -64.f)+CONST_SLIDE_UP_POS, vec2(128.f, 64.f)+CONST_SLIDE_UP_POS); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_TAP_TO_CONTINUE_BTN_TEXTURE]); + Renderer->DrawRect(vec2(-128.f, -128.f)+CONST_TAP_TO_CONTINUE_POS, vec2(128.f, 128.f)+CONST_TAP_TO_CONTINUE_POS); + +} + +void TGameLevel::DrawBallInstancingList() +{ + RenderUniform1f("Transparency", 1.f); + RenderUniform4fv("BrickColor", BallColor.v); + + if (BonusGothroughTimer > 0.f) + { + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_BALLGLOW_TEXTURE]); + + Renderer->DrawTriangleList(BallInstancingList.BallAndGlowList[1]); + } + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_BALL_TEXTURE]); + + Renderer->DrawTriangleList(BallInstancingList.BallAndGlowList[0]); + +} + +void TGameLevel::DrawBuffer() +{ + + Renderer->PushShader("FrameShader"); + float brightness; + if (CONST_LEVELSTATE_GO_TO_PAUSE) + { + brightness = 0.3f + 0.7f * StateTimer / CONST_PAUSE_APPEAR_TIME; + } + else + { + brightness = 0.3f; + } + + RenderUniform1f("Brightness", brightness); + glBindTexture(GL_TEXTURE_2D,ResourceManager->FrameManager.GetFrameTexture("LevelBuffer")); + + //Matrix switched to identity + //vec2 RectPos = vec2(-1, -1); + //vec2 RectSize = vec2(2, 2); + vec2 RectPos = vec2(240.f, 160.f); + vec2 RectSize = vec2(240.f, 160.f); + + Renderer->DrawRect(RectPos-RectSize, RectPos+RectSize); + + Renderer->PopShader(); + + CheckGlError(); +} + +void TGameLevel::SetPause() +{ + OutScaleVelocity = 0.f; + OutScale = 1.f; + RenderBufferReady = false; + LevelState = CONST_LEVELSTATE_GO_TO_PAUSE; + StateTimer = CONST_PAUSE_APPEAR_TIME; + Application->MarkSetGameLevelPause(); +} + +void TGameLevel::ReleasePause() +{ + RenderBufferReady = false; + + if (PrevLevelStateIsStandby) + { + LevelState = CONST_LEVELSTATE_STANDBY; + PrevLevelStateIsStandby = false; + } + else + { + LevelState = CONST_LEVELSTATE_PLAYING; + } + Application->MarkReleaseGameLevelPause(); +} + +bool TGameLevel::IsPaused() +{ + return ((LevelState == CONST_LEVELSTATE_PAUSE) || (LevelState == CONST_LEVELSTATE_GO_TO_PAUSE) || (LevelState == CONST_LEVELSTATE_FINISHED)); +} + +void TGameLevel::Update(cardinal dt) +{ + + if (LevelState == CONST_LEVELSTATE_NODRAW) + { + return; + } + + if (LevelState == CONST_LEVELSTATE_GO_TO_PAUSE) + { + StateTimer -= dt; + if (StateTimer <= 0.f) + { + StateTimer = 0.f; + LevelState = CONST_LEVELSTATE_PAUSE; + } + + return; + } + + if (LevelState == CONST_LEVELSTATE_PAUSE) + { + OutScale += OutScaleVelocity * dt; + TryGoToMenu(); + CheckGlError(); + return; + } + + if (LevelState == CONST_LEVELSTATE_FINISHED) + { + StateTimer -= dt; + + OutScale = StateTimer/CONST_FINISHING_TIME; + + if (StateTimer <= 0.f) + { + TryGoToMenu(); + } + CheckGlError(); + return; + } + + + if (LevelState == CONST_LEVELSTATE_LOADING) + { + StateTimer -= dt; + if (StateTimer <= 0.f) + { + StateTimer = 0.f; + RenderBufferReady = false; + LevelState = CONST_LEVELSTATE_STANDBY; + } + } + + if (LevelState == CONST_LEVELSTATE_FINISH_FREEZE) + { + StateTimer -= dt; + + if (StateTimer <= 0.f) + { + SetFinished(); + CheckGlError(); + return; + } + + //To make the whole scene like freeze + dt = static_cast(dt / max((CONST_FINISH_FREEZE_TIME-StateTimer)/100.f, 1.f)); + + } + + if (BonusGothroughTimer > 0.f) + { + BonusGothroughTimer -= dt; + BonusGothroughTimer = max(BonusGothroughTimer, 0.f); + } + + if (BonusFloorTimer > 0.f) + { + BonusFloorTimer -= dt; + BonusFloorTimer = max(BonusFloorTimer, 0.f); + } + + UpdateBallList(dt); + + + for (int i=0; i::iterator iBonus = BonusFallingList.begin(); + + while (iBonus != BonusFallingList.end()) + { + iBonus->Update(dt); + + if ((fabs(ReflectorPos.v[0] - iBonus->GetPos().v[0])GetPos().v[1])GetType(); + iBonus = BonusFallingList.erase(iBonus); + + + if (bonusType == CONST_BONUS_TYPE_GOTHROUGH) + { + BonusGothroughTimer = CONST_BONUS_GOTHROUGH_TIME; + } + else if (bonusType == CONST_BONUS_TYPE_MULTIPLIER) + { + vec2 pos = BallList.begin()->GetPos(); + vec2 velocity = BallList.begin()->GetVelocityVector(); + MultiplyBalls(pos, velocity); + } + else if (bonusType == CONST_BONUS_TYPE_FLOOR) + { + BonusFloorTimer = CONST_BONUS_FLOOR_TIME; + } + + } + else if (iBonus->GetPos().v[1] < -15.f) + { + iBonus = BonusFallingList.erase(iBonus); + } + + if (iBonus != BonusFallingList.end()) + { + ++iBonus; + } + } + + //Bonus floor pos + if (BonusFloorTimer/CONST_BONUS_GOTHROUGH_TIME < 0.2f) + { + //Bonus must go down until 0.f + if (BonusFloorPosY > 0.f) + { + BonusFloorPosY -= CONST_BONUS_FLOOR_APPEAR_SPEED * dt / 1000.f; + BonusFloorPosY = max(BonusFloorPosY, 0.f); + } + + } + else + { + //Bonus must go up until 16.f + if (BonusFloorPosY < 16.f) + { + BonusFloorPosY += CONST_BONUS_FLOOR_APPEAR_SPEED * dt / 1000.f; + BonusFloorPosY = min(BonusFloorPosY, 16.f); + } + } + + + bool noMoreBlocks = true; + + for (int i=0; iOpenNextLevel(); + Application->MarkSetGameLevelPause(); + SetFinishFreeze(); + CheckGlError(); + + } + + if (BallList.size() == 0 && LevelState != CONST_LEVELSTATE_FINISH_FREEZE) + { + SetStandBy(); + } + +} + + + +void TGameLevel::ReloadBallInstancingList() +{ + //Changing this function? Don't forget to change next one! + + BallInstancingList.BallAndGlowList.clear(); + + std::list::iterator i; + /* + vec3 p1; + vec3 p2; + vec3 p3; + vec3 p4; + + vec2 t1 = vec2(0.0f, 0.0f); + vec2 t2 = vec2(0.0f, 1.0f); + vec2 t3 = vec2(1.0f, 1.0f); + vec2 t4 = vec2(1.0f, 0.0f); + */ + + + for (i = BallList.begin(); i != BallList.end(); ++i) + { + /* + p1 = vec3(i->Pos, 0.f) + vec3(-8.f, -8.f, 0.f); + p2 = vec3(i->Pos, 0.f) + vec3(-8.f, +8.f, 0.f); + p3 = vec3(i->Pos, 0.f) + vec3(+8.f, +8.f, 0.f); + p4 = vec3(i->Pos, 0.f) + vec3(+8.f, -8.f, 0.f); + + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1); + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p2); + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3); + + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3); + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p4); + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1); + + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t1); + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t2); + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t3); + + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t3); + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t4); + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t1); + */ + + BallInstancingList.BallAndGlowList[0].Data += MakeDataTriangleList(i->Pos + vec2(-8.f, -8.f), i->Pos + vec2(8.f, 8.f)); + + //Replace6PointsInTriangleList(BallInstancingList.BallAndGlowList[0].Data, n, i->Pos + vec2(-8.f, -8.f), i->Pos + vec2(8.f, 8.f)); + + //n += 6; + } + + std::list::iterator j; + + for (i = BallList.begin(); i != BallList.end(); ++i) + { + for (j = i->TalePos.begin(); j != i->TalePos.end(); ++j) + { + /* + p1 = vec3(*j, 0.f) + vec3(-16.f, -16.f, 0.f); + p2 = vec3(*j, 0.f) + vec3(-16.f, +16.f, 0.f); + p3 = vec3(*j, 0.f) + vec3(+16.f, +16.f, 0.f); + p4 = vec3(*j, 0.f) + vec3(+16.f, -16.f, 0.f); + + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1); + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p2); + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3); + + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3); + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p4); + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1); + + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t1); + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t2); + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t3); + + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t3); + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t4); + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(t1); + */ + BallInstancingList.BallAndGlowList[1].Data += MakeDataTriangleList(*j + vec2(-16.f, -16.f), *j + vec2(16.f, 16.f)); + //Replace6PointsInTriangleList(BallInstancingList.BallAndGlowList[1].Data, n, *j + vec2(-16.f, -16.f), *j + vec2(16.f, 16.f)); + + //n += 6; + } + } + + //std::map::iterator it; + + auto it = BallInstancingList.BallAndGlowList.begin(); + + for (; it != BallInstancingList.BallAndGlowList.end(); ++it) + //for (auto it = BallInstancingList.BallAndGlowList.begin(); it != BallInstancingList.BallAndGlowList.end(); ++it) + + { + it->second.RefreshBuffer(); + } + +} + +void TGameLevel::RefreshBallInstancingList() +{ + //Changing this function? Don't forget to change previous one! + /* + vec3 p1; + vec3 p2; + vec3 p3; + vec3 p4; + + vec2 t1 = vec2(0.0f, 0.0f); + vec2 t2 = vec2(0.0f, 1.0f); + vec2 t3 = vec2(1.0f, 1.0f); + vec2 t4 = vec2(1.0f, 0.0f); + */ + int n = 0; + int m = 0; + + std::list::iterator i; + + for (i = BallList.begin(); i != BallList.end(); ++i) + { + /* + p1 = vec3(i->Pos, 0.f) + vec3(-8.f, -8.f, 0.f); + p2 = vec3(i->Pos, 0.f) + vec3(-8.f, +8.f, 0.f); + p3 = vec3(i->Pos, 0.f) + vec3(+8.f, +8.f, 0.f); + p4 = vec3(i->Pos, 0.f) + vec3(+8.f, -8.f, 0.f); + + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p1; + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p2; + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p3; + + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p3; + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p4; + BallInstancingList.BallAndGlowList[0].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p1; + + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t1; + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t2; + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t3; + + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t3; + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t4; + BallInstancingList.BallAndGlowList[0].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t1; + */ + + Replace6PointsInTriangleList(BallInstancingList.BallAndGlowList[0].Data, n, i->Pos + vec2(-8.f, -8.f), i->Pos + vec2(8.f, 8.f)); + + n += 6; + } + + std::list::iterator j; + + n = 0; + m = 0; + + for (i = BallList.begin(); i != BallList.end(); ++i) + { + for (j = i->TalePos.begin(); j != i->TalePos.end(); ++j) + { + /* + p1 = vec3(*j, 0.f) + vec3(-16.f, -16.f, 0.f); + p2 = vec3(*j, 0.f) + vec3(-16.f, +16.f, 0.f); + p3 = vec3(*j, 0.f) + vec3(+16.f, +16.f, 0.f); + p4 = vec3(*j, 0.f) + vec3(+16.f, -16.f, 0.f); + + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p1; + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p2; + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p3; + + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p3; + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p4; + BallInstancingList.BallAndGlowList[1].Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][n++] = p1; + + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t1; + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t2; + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t3; + + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t3; + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t4; + BallInstancingList.BallAndGlowList[1].Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB][m++] = t1;*/ + //BallInstancingList.BallAndGlowList[1].Data += MakeDataTriangleList(); + + Replace6PointsInTriangleList(BallInstancingList.BallAndGlowList[1].Data, n, *j + vec2(-16.f, -16.f), *j + vec2(16.f, 16.f)); + + n += 6; + + } + } + + std::map::iterator it; + + for (it = BallInstancingList.BallAndGlowList.begin(); it != BallInstancingList.BallAndGlowList.end(); ++it) + { + it->second.RefreshBuffer(); + } + +} + + +void TGameLevel::UpdateBallList(cardinal dt) +{ + std::list::iterator iBall; + + bool mustReloadBalls = false; + + //If not loaded - force load + if (BallInstancingList.BallAndGlowList.size() == 0) + { + mustReloadBalls = true; + } + + if (BonusFloorTimer == 0.f) + { + vec2 ballPos; + + iBall = BallList.begin(); + + while (iBall != BallList.end()) + { + ballPos = iBall->GetPos(); + + if (ballPos.v[1]<0.f) + { + iBall = BallList.erase(iBall); + mustReloadBalls = true; + } + + if (iBall != BallList.end()) + { + ++iBall; + } + } + + } + + bool blockListChanged = false; + + for (iBall = BallList.begin(); iBall != BallList.end(); ++iBall) + { + + + iBall->Update(dt); + + vec2 ballPos = iBall->GetPos(); + + + if (ballPos.v[0] > 480.f-15.f) + { + iBall->ReflectToLeft(); + } + + if (ballPos.v[0] < 15.f) + { + iBall->ReflectToRight(); + } + + if (ballPos.v[1] > 320.0f-16.f) + { + iBall->ReflectToDown(); + } + + if (BonusFloorTimer > 0.f) + { + if (ballPos.v[1] < 13.0f) + { + iBall->ReflectToUp(); + } + } + + iBall->TryReflectOnReflector(ReflectorPos); + + vec2 ipos = GetBlock(ballPos); + if (!(ipos == iBall->BallInBlock)) + { + iBall->PrevBallInBlock = iBall->BallInBlock; + iBall->BallInBlock = ipos; + + int i = static_cast(iBall->BallInBlock.v[0]); + int j = static_cast(iBall->BallInBlock.v[1]); + + int iprev = static_cast(iBall->PrevBallInBlock.v[0]); + int jprev = static_cast(iBall->PrevBallInBlock.v[1]); + + + if (BlockMatrix[i][j].CanReact()) + { + bool canThrowBonus; + + blockListChanged = true; + + if (BonusGothroughTimer > 0.f) + { + BlockMatrix[i][j].Disappear(); + canThrowBonus = true; + + } + else + { + canThrowBonus = (BlockMatrix[i][j].GetLocked() == 0); + + BlockMatrix[i][j].Hit(); + + } + + vec2 blockPos = BlockMatrix[i][j].GetPosFrom(i, j); + + + if (canThrowBonus && rand() % 20 == 0) + { + BonusFallingList.push_back(TBonusFalling(blockPos)); + } + + + if (BonusGothroughTimer == 0.f) + { + if (j < jprev) + { + iBall->ReflectToDown(); + } + else + if (j > jprev) + { + iBall->ReflectToUp(); + } + else + if (i < iprev) + { + iBall->ReflectToRight(); + } + else + if (i > iprev) + { + iBall->ReflectToLeft(); + } + } + + + } + + } + + } + + if (blockListChanged) + { + ReloadBlockInstansingList(); + } + + if (mustReloadBalls) + { + ReloadBallInstancingList(); + } + else + { + RefreshBallInstancingList(); + } +} + +void TGameLevel::MultiplyBalls(vec2 pos, vec2 velocity) +{ + mat2 r; + vec2 v; + + for (int i = -2; i<=2; i++) + { + r = mat2(i*pi/4.f); + v = r*velocity; + + v.v[1] = max(static_cast(fabs(v.v[1])), 0.2f) * sign(v.v[1]); //Prevent velocityY from being ~= 0 + + BallList.push_back(TBall(pos, v, BallColor)); + } + + ReloadBallInstancingList(); +} + + +void TGameLevel::OnTapDown(vec2 pos) +{ + if (LevelState == CONST_LEVELSTATE_STANDBY) + { + if (TapInBackBtnArea(pos)) + { + SetPause(); + PrevLevelStateIsStandby = true; + } + else + { + + LevelState = CONST_LEVELSTATE_PLAYING; + BallList.begin()->Go(); + } + } + else if (LevelState == CONST_LEVELSTATE_PLAYING) + { + + + if (TapInBackBtnArea(pos)) + { + SetPause(); + } + else if (fabs(ReflectorPos.v[0] - pos.v[0])>64.f) + { + ReflectorPos.v[0] = pos.v[0]; + } + + } + else if (LevelState == CONST_LEVELSTATE_PAUSE) + { + if (pos.v[1] > 128.f) + { + ReleasePause(); + } + } +} + +void TGameLevel::OnTapUp(vec2 pos) +{ +} + +void TGameLevel::OnFling(vec2 slideSpeed) +{ + if (LevelState == CONST_LEVELSTATE_PAUSE) + { + OutScaleVelocity = slideSpeed.v[1]/320.f; + } +} + +void TGameLevel::OnScroll(vec2 shift) +{ + const float CONST_SCROLL_SCALE = 1.1f; + if (LevelState == CONST_LEVELSTATE_PLAYING || LevelState == CONST_LEVELSTATE_STANDBY) + { + ReflectorPos.v[0] -= CONST_SCROLL_SCALE*shift.v[0]; + } + else if (LevelState == CONST_LEVELSTATE_PAUSE) + { + + + OutScale += shift.v[1]/320.f; + + TryGoToMenu(); + } +} + +void TGameLevel::TryGoToMenu() +{ + if (OutScale < 0.5f) + { + OutScale = 0.5f; + LevelState = CONST_LEVELSTATE_NODRAW; + Application->GoFromGameToMenu(); + } + if (OutScale > 1.f) + { + OutScale = 1.f; + } +} diff --git a/game/gamecode.h b/game/gamecode.h new file mode 100644 index 0000000..dc624e9 --- /dev/null +++ b/game/gamecode.h @@ -0,0 +1,205 @@ +#ifndef GAMECODE_H_INCLUDED +#define GAMECODE_H_INCLUDED + +#include "include/Engine.h" +#include "game_area_interface.h" + +#include + +using namespace SE; + + +const int CONST_BRICKSTATE_VISIBLE = 3; +const int CONST_BRICKSTATE_DISAPPEAR = 2; +const int CONST_BRICKSTATE_INVISIBLE = 1; +const int CONST_BRICKSTATE_APPEAR = 0; + +const float CONST_BRICK_DISAPPEAR_TIME = 200.f; +const float CONST_BRICK_APPEAR_TIME = 200.f; + +const int CONST_BRICKMATRIX_WIDTH = 12; +const int CONST_BRICKMATRIX_HEIGHT = 13; +const float CONST_BRICK_WIDTH = 37.5f; +const float CONST_BRICK_HEIGHT = 0.5f*CONST_BRICK_WIDTH; +const float CONST_BRICK_SHIFT_X = 15.f; +const float CONST_BRICK_SHIFT_Y = -16.f; + +const float CONST_BONUS_APPEAR_TIME = 400.f; +const float CONST_BONUS_FALL_SPEED = 100.f; +const float CONST_BONUS_GOTHROUGH_TIME = 8000.f; +const float CONST_BONUS_CATCH_DISTANCE_X = 65.f; +const float CONST_BONUS_CATCH_DISTANCE_Y = 20.f; + +const float CONST_BONUS_FLOOR_TIME = 8000.f; +const float CONST_BONUS_FLOOR_APPEAR_SPEED = 50.f; + +const int CONST_BONUS_TYPE_MULTIPLIER = 0; +const int CONST_BONUS_TYPE_GOTHROUGH = 1; +const int CONST_BONUS_TYPE_FLOOR = 2; + + +class TBrick +{ +protected: + int InitialLocked; + int Locked; //0, 1 or 2 + int State; + float StateTimer; + vec4 Color; +public: + TBrick(); + void SetVisible(vec4 color, int locked); + void SetInvisible(); + void TryDrawAppear(int ipos, int jpos); + void Update(cardinal dt); + vec2 GetPosFrom(int ipos, int jpos); + vec4 GetColor(); + void Appear(vec4 color, int locked); + void Appear(); + void Hit(); + void Disappear(); + int GetLocked(); + bool CanReact(); +}; + +class TBonusFalling +{ +protected: + float Lifetime; + vec2 Pos; + std::string TexName; + int BonusType; //0 - multiplier, 1 - Go-through, 2 - floor +public: + TBonusFalling(vec2 pos); + vec2 GetPos(); + int GetType(); + void Draw(); + void Update(cardinal dt); +}; + +struct TBall +{ + vec2 Pos; + vec2 Velocity; + vec4 Color; + std::list TalePos; + + vec2 BallInBlock; + vec2 PrevBallInBlock; + + TBall(vec2 pos, vec2 velocity, vec4 color); + vec2 GetPos(); + vec2 GetVelocityVector(); + + void Go(); + + void ReflectToLeft(); + void ReflectToRight(); + void ReflectToUp(); + void ReflectToDown(); + + void TryReflectOnReflector(vec2 refPos); + + void Update(cardinal dt); +}; + +typedef std::pair PairColorTexture; + +struct TBlockInstansingList +{ + //color-texture ---> and list of triangles for this color + std::list> ColorBlockList; +}; + + +struct TBallInstancingList +{ + std::map BallAndGlowList; +}; + +class TGameLevel : public TGameAreaAncestor +{ +protected: + std::string BkgTexture; + std::string LevelScreenTexture; + std::string LevelFileName; + + vec2 ReflectorPos; + + int LevelState; + bool PrevLevelStateIsStandby; + float StateTimer; + + TBrick BlockMatrix[CONST_BRICKMATRIX_WIDTH][CONST_BRICKMATRIX_HEIGHT]; + TBlockInstansingList BlockInstansingList; + + bool TapInBackBtnArea(const vec2& pos); + + void ReloadBlockInstansingList(); + void SetFinished(); + void SetFinishFreeze(); + + void DrawBuffer(); + void DrawPauseButtons(); + + void DrawBallInstancingList(); + + bool RenderBufferReady; + + float OutScale; + + float OutScaleVelocity; + + void TryGoToMenu(); + + std::list BonusFallingList; + + std::list BallList; + + TBallInstancingList BallInstancingList; + + vec4 BallColor; + + void ReloadBallInstancingList(); + void RefreshBallInstancingList(); + + + void UpdateBallList(cardinal dt); + void MultiplyBalls(vec2 pos, vec2 velocity); + + vec2 GetBlock(const vec2& pos); + void InitLevel(); + + float BonusGothroughTimer; + float BonusFloorTimer; + float BonusFloorPosY; + + vec4 ParseColor(const std::string& s); + void ReloadLevel(); + +public: + TGameLevel(); + ~TGameLevel(); + + void FillWithFile(const std::string& filename); + + void SetStandBy(); + void SetLoading(const std::string& bkg, const std::string& levelscreen); + bool IsLoaded(); + + virtual void Draw(); + + void SetPause(); + bool IsPaused(); + void ReleasePause(); + + virtual void Update(cardinal dt); + virtual void OnTapDown(vec2 pos); + virtual void OnTapUp(vec2 pos); + virtual void OnFling(vec2 slideSpeed); + virtual void OnScroll(vec2 shift); +}; + + + +#endif diff --git a/game/loadingcode.cpp b/game/loadingcode.cpp new file mode 100644 index 0000000..94f3308 --- /dev/null +++ b/game/loadingcode.cpp @@ -0,0 +1,16 @@ +#include "loadingcode.h" +#include "include/Engine.h" +#include "main_code.h" + +void TGameLoading::Draw() +{ + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_LOADING_TEXTURE]); + Renderer->DrawRect(vec2(240.f - 128.f, 10.f), vec2(240.f + 128.f, 10.f + 64.f)); + + glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[CONST_LOGO_SMALL_TEXTURE]); + Renderer->DrawRect(vec2(480.f - 256.f+50.f, 320.f - 64.f), vec2(480.f+50.f, 320.f)); + + CheckGlError(); + +} diff --git a/game/loadingcode.h b/game/loadingcode.h new file mode 100644 index 0000000..6ea2411 --- /dev/null +++ b/game/loadingcode.h @@ -0,0 +1,15 @@ +#ifndef LOADINGCODE_H_INCLUDED +#define LOADINGCODE_H_INCLUDED + +#include "game_area_interface.h" + +using namespace SE; + +class TGameLoading : public TGameAreaAncestor +{ +public: + virtual void Draw(); +}; + + +#endif diff --git a/game/main_code.cpp b/game/main_code.cpp new file mode 100644 index 0000000..7133518 --- /dev/null +++ b/game/main_code.cpp @@ -0,0 +1,475 @@ +#include "main_code.h" + +#include +#include +#include +#include + +#include "include/Engine.h" + +#include "menucode.h" + +#include "main_code.h" + +boost::signal OnTapUpSignal; +boost::signal OnTapDownSignal; +boost::signal OnFlingSignal; +boost::signal OnScrollSignal; + +boost::signal OnDrawSignal; + + +const std::string CONST_BLOCK_TEXTURE1 = "block1"; +const std::string CONST_BLOCK_TEXTURE2 = "block2"; +const std::string CONST_BLOCK_TEXTURE3 = "block3"; + +const std::string CONST_BONUS_GOTHROUGH_TEXTURE = "bonus_gothrough"; +const std::string CONST_BONUS_MULTIPLIER_TEXTURE = "bonus_multiplier"; +const std::string CONST_BONUS_FLOOR_TEXTURE = "bonus_floor"; + +const std::string CONST_BALL_TEXTURE = "ball"; +const std::string CONST_BALLGLOW_TEXTURE = "ball_glow"; + +const std::string CONST_REFLECTOR_TEXTURE = "reflector"; + +const std::string CONST_WALL_LEFT_TEXTURE = "wall_left"; +const std::string CONST_WALL_RIGHT_TEXTURE = "wall_right"; +const std::string CONST_WALL_UP_TEXTURE = "wall_up"; +const std::string CONST_WALL_BONUS_TEXTURE = "wall_bonus"; + +const std::string CONST_BACK_BTN_TEXTURE = "back_btn"; +const std::string CONST_SLIDE_UP_BTN_TEXTURE = "slide_up_btn"; +const std::string CONST_TAP_TO_CONTINUE_BTN_TEXTURE = "tap_to_continue_btn"; +const std::string CONST_LOADING_TEXTURE = "loading"; +const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small"; +const std::string CONST_CREDITS_TEXTURE = "credits"; + +const float CONST_CREDITS_SHOW_TIME = 150.f; + +TAndroidApplication* Application; + +void TAndroidApplication::InnerInit() +{ + + Application = this; + +#ifdef TARGET_WIN32 +#ifdef NDEBUG + ST::PathToResources = "resources/"; +#else + ST::PathToResources = "../../../assets/"; +#endif +#endif + +#ifdef TARGET_IOS + ST::PathToResources = "assets/"; +#endif + + if (Console != NULL) + { + *Console<<"APP INIT\n"; + } + srand (static_cast(time(NULL))); + GameState = CONST_GAMESTATE_PRELOADING; + StateTimer = 0.f; + + + ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt"); + ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt"); + ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt"); + Renderer->PushShader("DefaultShader"); + + ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE); + ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE); + + ResourceManager->TexList.AddTexture("console_bkg.bmp"); + + ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512); + + OnDrawSignal.connect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading))); + Inited = true; + + Renderer->SetOrthoProjection(); + + Renderer->SetFullScreenViewport(); + + + +} + +void TAndroidApplication::InnerDeinit() +{ + Inited = false; + Loaded = false; + if (Console != NULL) + { + *Console<<"APP DEINIT\n"; + } + + OnTapUpSignal.disconnect(boost::bind(&TGameLevel::OnTapUp, boost::ref(GameLevel), _1)); + OnTapUpSignal.disconnect(boost::bind(&TGameMenu::OnTapUp, boost::ref(Menu), _1)); + + OnFlingSignal.disconnect(boost::bind(&TGameLevel::OnFling, boost::ref(GameLevel), _1)); + OnFlingSignal.disconnect(boost::bind(&TGameMenu::OnFling, boost::ref(Menu), _1)); + + OnScrollSignal.disconnect(boost::bind(&TGameLevel::OnScroll, boost::ref(GameLevel), _1)); + OnScrollSignal.disconnect(boost::bind(&TGameMenu::OnScroll, boost::ref(Menu), _1)); + + OnTapDownSignal.disconnect(boost::bind(&TGameLevel::OnTapDown, boost::ref(GameLevel), _1)); + OnTapDownSignal.disconnect(boost::bind(&TGameMenu::OnTapDown, boost::ref(Menu), _1)); + OnTapDownSignal.disconnect(boost::bind(&TGameCredits::OnTapDown, boost::ref(GameCredits), _1)); + + + OnDrawSignal.disconnect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading))); + OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu))); + OnDrawSignal.disconnect(boost::bind(&TGameLevel::Draw, boost::ref(GameLevel))); + OnDrawSignal.disconnect(boost::bind(&TGameCredits::Draw, boost::ref(GameCredits))); + +} + +void TAndroidApplication::InnerOnTapDown(vec2 p) +{ + OnTapDownSignal(vec2(p.v[0], p.v[1])); +} + +void TAndroidApplication::InnerOnTapUp(vec2 p) +{ + OnTapUpSignal(vec2(p.v[0], p.v[1])); +} + +void TAndroidApplication::InnerOnMove(vec2 shift) +{ + OnScrollSignal(shift); +} + +void TAndroidApplication::OnFling(vec2 v) +{ +} + + +void TAndroidApplication::ApplySignalsToMenu() +{ + + OnTapUpSignal.connect(boost::bind(&TGameMenu::OnTapUp, boost::ref(Menu), _1)); + OnFlingSignal.connect(boost::bind(&TGameMenu::OnFling, boost::ref(Menu), _1)); + OnScrollSignal.connect(boost::bind(&TGameMenu::OnScroll, boost::ref(Menu), _1)); + OnTapDownSignal.connect(boost::bind(&TGameMenu::OnTapDown, boost::ref(Menu), _1)); + +} + + +void TAndroidApplication::DisapplySignalsToMenu() +{ + OnTapUpSignal.disconnect(boost::bind(&TGameMenu::OnTapUp, boost::ref(Menu), _1)); + OnFlingSignal.disconnect(boost::bind(&TGameMenu::OnFling, boost::ref(Menu), _1)); + OnScrollSignal.disconnect(boost::bind(&TGameMenu::OnScroll, boost::ref(Menu), _1)); + OnTapDownSignal.disconnect(boost::bind(&TGameMenu::OnTapDown, boost::ref(Menu), _1)); +} + +void TAndroidApplication::ApplySignalsToGame() +{ + + OnTapUpSignal.connect(boost::bind(&TGameLevel::OnTapUp, boost::ref(GameLevel), _1)); + OnFlingSignal.connect(boost::bind(&TGameLevel::OnFling, boost::ref(GameLevel), _1)); + OnScrollSignal.connect(boost::bind(&TGameLevel::OnScroll, boost::ref(GameLevel), _1)); + OnTapDownSignal.connect(boost::bind(&TGameLevel::OnTapDown, boost::ref(GameLevel), _1)); + +} + +void TAndroidApplication::DisapplySignalsToGame() +{ + OnTapUpSignal.disconnect(boost::bind(&TGameLevel::OnTapUp, boost::ref(GameLevel), _1)); + OnFlingSignal.disconnect(boost::bind(&TGameLevel::OnFling, boost::ref(GameLevel), _1)); + OnScrollSignal.disconnect(boost::bind(&TGameLevel::OnScroll, boost::ref(GameLevel), _1)); + OnTapDownSignal.disconnect(boost::bind(&TGameLevel::OnTapDown, boost::ref(GameLevel), _1)); + +} + +void TAndroidApplication::ApplySignalsToCredits() +{ + OnTapDownSignal.connect(boost::bind(&TGameCredits::OnTapDown, boost::ref(GameCredits), _1)); +} + + +void TAndroidApplication::DisapplySignalsToCredits() +{ + OnTapDownSignal.disconnect(boost::bind(&TGameCredits::OnTapDown, boost::ref(GameCredits), _1)); +} + +void TAndroidApplication::LoadResources() +{ + + TextureNamesToLoad.clear(); + + TextureNamesToLoad.push_back(std::pair("main_menu_bkg_left.png", "main_menu_bkg_left")); + TextureNamesToLoad.push_back(std::pair("main_menu_bkg_right.png", "main_menu_bkg_right")); + TextureNamesToLoad.push_back(std::pair("select_level.png", "select_level")); + TextureNamesToLoad.push_back(std::pair("shutterstock1.png", "shutterstock1")); + TextureNamesToLoad.push_back(std::pair("shutterstock2.png", "shutterstock2")); + TextureNamesToLoad.push_back(std::pair("shutterstock3.png", "shutterstock3")); + TextureNamesToLoad.push_back(std::pair("shutterstock4.png", "shutterstock4")); + TextureNamesToLoad.push_back(std::pair("shutterstock5.png", "shutterstock5")); + TextureNamesToLoad.push_back(std::pair("shutterstock6.png", "shutterstock6")); + TextureNamesToLoad.push_back(std::pair("shutterstock7.png", "shutterstock7")); + TextureNamesToLoad.push_back(std::pair("shutterstock8.png", "shutterstock8")); + TextureNamesToLoad.push_back(std::pair("shutterstock9.png", "shutterstock9")); + + TextureNamesToLoad.push_back(std::pair("shutterstock10.png", "shutterstock10")); + TextureNamesToLoad.push_back(std::pair("shutterstock11.png", "shutterstock11")); + TextureNamesToLoad.push_back(std::pair("shutterstock12.png", "shutterstock12")); + TextureNamesToLoad.push_back(std::pair("levelshot1.png", "levelshot1")); + TextureNamesToLoad.push_back(std::pair("levelshot2.png", "levelshot2")); + TextureNamesToLoad.push_back(std::pair("levelshot3.png", "levelshot3")); + TextureNamesToLoad.push_back(std::pair("levelshot4.png", "levelshot4")); + TextureNamesToLoad.push_back(std::pair("levelshot5.png", "levelshot5")); + TextureNamesToLoad.push_back(std::pair("levelshot6.png", "levelshot6")); + TextureNamesToLoad.push_back(std::pair("levelshot7.png", "levelshot7")); + TextureNamesToLoad.push_back(std::pair("levelshot8.png", "levelshot8")); + TextureNamesToLoad.push_back(std::pair("levelshot9.png", "levelshot9")); + TextureNamesToLoad.push_back(std::pair("levelshot10.png", "levelshot10")); + TextureNamesToLoad.push_back(std::pair("levelshot11.png", "levelshot11")); + TextureNamesToLoad.push_back(std::pair("levelshot12.png", "levelshot12")); + TextureNamesToLoad.push_back(std::pair("game_end.png", "game_end")); + + TextureNamesToLoad.push_back(std::pair(CONST_BLOCK_TEXTURE1 + ".png", CONST_BLOCK_TEXTURE1)); + TextureNamesToLoad.push_back(std::pair(CONST_BLOCK_TEXTURE2 + ".png", CONST_BLOCK_TEXTURE2)); + TextureNamesToLoad.push_back(std::pair(CONST_BLOCK_TEXTURE3 + ".png", CONST_BLOCK_TEXTURE3)); + TextureNamesToLoad.push_back(std::pair(CONST_BONUS_GOTHROUGH_TEXTURE + ".png", CONST_BONUS_GOTHROUGH_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_BONUS_MULTIPLIER_TEXTURE + ".png", CONST_BONUS_MULTIPLIER_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_BONUS_FLOOR_TEXTURE + ".png", CONST_BONUS_FLOOR_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_BALL_TEXTURE + ".png", CONST_BALL_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_BALLGLOW_TEXTURE + ".png", CONST_BALLGLOW_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_WALL_LEFT_TEXTURE + ".png", CONST_WALL_LEFT_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_WALL_RIGHT_TEXTURE + ".png", CONST_WALL_RIGHT_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_WALL_UP_TEXTURE + ".png", CONST_WALL_UP_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_WALL_BONUS_TEXTURE + ".png", CONST_WALL_BONUS_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_REFLECTOR_TEXTURE + ".png", CONST_REFLECTOR_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_BACK_BTN_TEXTURE + ".png", CONST_BACK_BTN_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_SLIDE_UP_BTN_TEXTURE + ".png", CONST_SLIDE_UP_BTN_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_TAP_TO_CONTINUE_BTN_TEXTURE + ".png", CONST_TAP_TO_CONTINUE_BTN_TEXTURE)); + TextureNamesToLoad.push_back(std::pair(CONST_CREDITS_TEXTURE + ".png", CONST_CREDITS_TEXTURE)); + +#ifdef TARGET_IOS + ResourceManager->SoundManager.LoadMusicLooped("level1ogg.ogg"); +#else + ResourceManager->SoundManager.LoadMusic("level1ogg.ogg"); +#endif + + ResourceManager->FontManager.AddFont("droid_sans14", "droid_sans14_font_bitmap.png", "droid_sans14_font_charmap.txt"); + ResourceManager->FontManager.PushFont("droid_sans14"); + + TryLoadSavedGame(); + +} + +void TAndroidApplication::TryLoadSavedGame() +{ + + std::string fileName = GetFilePathUserData("progress.txt"); + + FILE* file = fopen(fileName.c_str(), "r"); + if (file != NULL) + { + char line[100]; + char* r; + r = fgets(line, 100, file); + if (r != NULL) + { + Menu.SetMenuItemCount(toint(r)); + } + fclose(file); + } +} + +void TAndroidApplication::TrySaveGame() +{ + + std::string fileName = GetFilePathUserData("progress.txt"); + + std::string s = tostr(Menu.GetMenuItemCount()); + FILE* file = fopen(fileName.c_str(), "w"); + if (file != NULL) + { + fputs(s.c_str(), file); + fflush(file); + fclose(file); + } + +} + + + +void TAndroidApplication::InnerDraw() +{ + + glDisable(GL_DEPTH_TEST); + + + OnDrawSignal(); + + +} + + +void TAndroidApplication::InnerUpdate(cardinal dt) +{ + + if (GameState == CONST_GAMESTATE_PRELOADING) + { + StateTimer += dt/1000.f; + if (StateTimer >= 1.f) + { + LoadResources(); + GameState = CONST_GAMESTATE_LOADING; + StateTimer = 0.f; + } + } + else if (GameState == CONST_GAMESTATE_LOADING) + { + StateTimer += dt/1000.f; + if (StateTimer >= 1.f) + { + StateTimer -= 1.f; + } + + if (TextureNamesToLoad.size() != 0) + { + ResourceManager->TexList.AddTexture(TextureNamesToLoad.begin()->first, TextureNamesToLoad.begin()->second); + TextureNamesToLoad.erase(TextureNamesToLoad.begin()); + } + else + { + GameState = CONST_GAMESTATE_MENU; + ApplySignalsToMenu(); + OnDrawSignal.disconnect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading))); + OnDrawSignal.connect(0, boost::bind(&TGameMenu::Draw, boost::ref(Menu))); + StateTimer = 0.f; + Loaded = true; + } + } + else if (GameState == CONST_GAMESTATE_LEVEL) + { + GameLevel.Update(dt); + } + else if (GameState == CONST_GAMESTATE_MENU) + { + Menu.Update(dt); + } + else if (GameState == CONST_GAMESTATE_FROM_MENU_TO_LEVEL) + { + GameLevel.Update(dt); + if (GameLevel.IsLoaded()) + { + GameState = CONST_GAMESTATE_LEVEL; + OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu))); + //CONNECT SLOT + DisapplySignalsToMenu(); + ApplySignalsToGame(); + } + } + else if (GameState == CONST_GAMESTATE_FROM_MENU_TO_CREDITS) + { + Menu.Update(dt); + GameCredits.Update(dt); + StateTimer -= dt; + if (StateTimer <= 0.f) + { + GameState = CONST_GAMESTATE_CREDITS; + OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu))); + ApplySignalsToCredits(); + StateTimer = 0.f; + } + } + else if (GameState == CONST_GAMESTATE_CREDITS) + { + GameCredits.Update(dt); + } + else if (GameState == CONST_GAMESTATE_FROM_CREDITS_TO_MENU) + { + Menu.Update(dt); + GameCredits.Update(dt); + StateTimer -= dt; + if (StateTimer <= 0.f) + { + GameState = CONST_GAMESTATE_MENU; + StateTimer = 0.f; + ApplySignalsToMenu(); + OnDrawSignal.disconnect(boost::bind(&TGameCredits::Draw, boost::ref(GameCredits))); + } + } +} + + +void TAndroidApplication::GoFromMenuToGame(int level) +{ + //#ifndef TARGET_IOS + ResourceManager->SoundManager.PlayMusicLooped("level1ogg.ogg"); + +//#endif + GameLevel.FillWithFile(ST::PathToResources + "level"+tostr(level+1)+".txt"); + GameLevel.SetLoading("shutterstock" + tostr(level+1), "levelshot"+tostr(level+1)); + GameState = CONST_GAMESTATE_FROM_MENU_TO_LEVEL; + OnDrawSignal.connect(1, boost::bind(&TGameLevel::Draw, boost::ref(GameLevel))); + + DisapplySignalsToMenu(); + +} + +void TAndroidApplication::GoFromGameToMenu() +{ + //#ifndef TARGET_IOS + ResourceManager->SoundManager.StopMusic("level1ogg.ogg"); +//#endif + TrySaveGame(); + DisapplySignalsToGame(); + ApplySignalsToMenu(); + GameState = CONST_GAMESTATE_MENU; + OnDrawSignal.disconnect(boost::bind(&TGameLevel::Draw, boost::ref(GameLevel))); +} + +void TAndroidApplication::GoFromMenuToCredits() +{ + GameState = CONST_GAMESTATE_FROM_MENU_TO_CREDITS; + StateTimer = CONST_CREDITS_SHOW_TIME; + GameCredits.StartAppear(); + OnDrawSignal.connect(1, boost::bind(&TGameCredits::Draw, boost::ref(GameCredits))); + DisapplySignalsToMenu(); + +} + +void TAndroidApplication::GoFromCreditsToMenu() +{ + + GameState = CONST_GAMESTATE_FROM_CREDITS_TO_MENU; + StateTimer = CONST_CREDITS_SHOW_TIME; + GameCredits.StartDisappear(); + OnDrawSignal.connect(0, boost::bind(&TGameMenu::Draw, boost::ref(Menu))); + + DisapplySignalsToCredits(); +} + +void TAndroidApplication::MarkSetGameLevelPause() +{ + OnDrawSignal.connect(0, boost::bind(&TGameMenu::Draw, boost::ref(Menu))); +} + +void TAndroidApplication::MarkReleaseGameLevelPause() +{ + OnDrawSignal.disconnect(boost::bind(&TGameMenu::Draw, boost::ref(Menu))); +} + + +void TAndroidApplication::OpenNextLevel() +{ + Menu.OpenNextLevel(); +} + +bool TAndroidApplication::IsLoaded() +{ + return Loaded; +} + +bool TAndroidApplication::IsInited() +{ + return Inited; +} diff --git a/game/main_code.h b/game/main_code.h new file mode 100644 index 0000000..1df873e --- /dev/null +++ b/game/main_code.h @@ -0,0 +1,153 @@ +#ifndef MAIN_CODE_H_INCLUDED +#define MAIN_CODE_H_INCLUDED + +#ifdef TARGET_ANDROID +#include "android_api.h" +#endif + +#ifdef TARGET_WIN32 +#define NOMINMAX 1 +#include +#undef NOMINMAX +#endif + +#include +#include +#include + +#include "boost/shared_ptr.hpp" +#include "boost/thread/thread.hpp" +#include "boost/assign.hpp" +#include "boost/bind.hpp" + +#include "include/Engine.h" + +#include "boost/signal.hpp"//Signal must be included after asio + +#include "gamecode.h" +#include "menucode.h" +#include "creditscode.h" +#include "loadingcode.h" + +using namespace SE; + + +extern boost::signal OnTapUpSignal; +extern boost::signal OnTapDownSignal; +extern boost::signal OnFlingSignal; +extern boost::signal OnScrollSignal; + +extern boost::signal OnDrawSignal; + +extern const std::string CONST_BLOCK_TEXTURE1; +extern const std::string CONST_BLOCK_TEXTURE2; +extern const std::string CONST_BLOCK_TEXTURE3; + +extern const std::string CONST_BONUS_GOTHROUGH_TEXTURE; +extern const std::string CONST_BONUS_MULTIPLIER_TEXTURE; +extern const std::string CONST_BONUS_FLOOR_TEXTURE; + +extern const std::string CONST_BALL_TEXTURE; +extern const std::string CONST_BALLGLOW_TEXTURE; + +extern const std::string CONST_WALL_LEFT_TEXTURE; +extern const std::string CONST_WALL_RIGHT_TEXTURE; +extern const std::string CONST_WALL_UP_TEXTURE; +extern const std::string CONST_WALL_BONUS_TEXTURE; + + +extern const std::string CONST_REFLECTOR_TEXTURE; + +extern const std::string CONST_BACK_BTN_TEXTURE; + +extern const std::string CONST_SLIDE_UP_BTN_TEXTURE; +extern const std::string CONST_TAP_TO_CONTINUE_BTN_TEXTURE; + +extern const std::string CONST_BACK_BTN_TEXTURE; +extern const std::string CONST_SLIDE_UP_BTN_TEXTURE; +extern const std::string CONST_TAP_TO_CONTINUE_BTN_TEXTURE; +extern const std::string CONST_LOADING_TEXTURE; +extern const std::string CONST_LOGO_SMALL_TEXTURE; +extern const std::string CONST_CREDITS_TEXTURE; + + + +const int CONST_GAMESTATE_LEVEL = 1; +const int CONST_GAMESTATE_MENU = 0; +const int CONST_GAMESTATE_FROM_MENU_TO_LEVEL = 2; +const int CONST_GAMESTATE_FROM_MENU_TO_CREDITS = 3; +const int CONST_GAMESTATE_CREDITS = 4; +const int CONST_GAMESTATE_FROM_CREDITS_TO_MENU = 5; +const int CONST_GAMESTATE_LOADING = 6; +const int CONST_GAMESTATE_PRELOADING = 7; + + +class TAndroidApplication : public TApplication +{ +protected: + TGameMenu Menu; + TGameLevel GameLevel; + TGameCredits GameCredits; + TGameLoading GameLoading; + + int GameState; + float StateTimer; + + void TryLoadSavedGame(); + void TrySaveGame(); + + bool Inited; + + std::vector > TextureNamesToLoad; + + void ApplySignalsToMenu(); + void DisapplySignalsToMenu(); + void ApplySignalsToGame(); + void DisapplySignalsToGame(); + void ApplySignalsToCredits(); + void DisapplySignalsToCredits(); + +public: + bool Loaded; + + TAndroidApplication() : TApplication(), Loaded(false), Inited(false) { } + + virtual void InnerInit(); + + virtual void InnerDeinit(); + + virtual void InnerDraw(); + + virtual void InnerUpdate(cardinal dt); + + void GoFromMenuToGame(int level); + void GoFromGameToMenu(); + void GoFromMenuToCredits(); + void GoFromCreditsToMenu(); + void MarkSetGameLevelPause(); + void MarkReleaseGameLevelPause(); + + void OpenNextLevel(); + + bool IsLoaded(); + + bool IsInited(); + + void LoadResources(); + + virtual void InnerOnTapDown(vec2 p); + + virtual void InnerOnTapUp(vec2 p); + + virtual void InnerOnMove(vec2 shift); + + virtual void OnFling(vec2 v); + +}; + + +extern TAndroidApplication* Application; + + + +#endif diff --git a/game/menucode.cpp b/game/menucode.cpp new file mode 100644 index 0000000..7225427 --- /dev/null +++ b/game/menucode.cpp @@ -0,0 +1,207 @@ +#include "menucode.h" +#include "main_code.h" + +const float CONST_SPEED_NEG_ACCELERATION_K = 0.03f; + +const float CONST_MENU_POS_K = 0.25f; + +const float CONST_MENU_WINDOW_DISTANCE = 240.f + 40.f; + +const float CONST_SHIFT_ON_SIDE = 0.f; + +TGameMenu::TGameMenu() + : MenuSpeed(0) + , MenuPos(0) + , HoldToTap(false) + , MenuItemCount(1) + , SelectedGame(-1) +{ +} + + +void TGameMenu::Draw() +{ + CheckGlError("Draw TGameMenu"); + RenderUniform1i("sel", 0); + RenderUniform1f("Transparency", 1.f); + float bkgShift = MenuPos*0.1f - 100.f; + glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["main_menu_bkg_left"]); + Renderer->DrawRect(vec2(bkgShift,0.f), vec2(480.f+bkgShift,320.f)); + glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["main_menu_bkg_right"]); + Renderer->DrawRect(vec2(480.f+bkgShift,0.f), vec2(960.f+bkgShift,320.f)); + + + if (SelectedGame == 0) + { + RenderUniform1i("sel", 1); + } + else + { + RenderUniform1i("sel", 0); + } + + for (int i=0; iTexList["levelshot"+tostr(i+1)]); + Renderer->DrawRect(vec2(160.f+MenuPos+CONST_MENU_WINDOW_DISTANCE*i,80.f), vec2(160.f+240.f+MenuPos+CONST_MENU_WINDOW_DISTANCE*i, 240.f)); + } + + if (MenuItemCount == 12) + { + glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["game_end"]); + Renderer->DrawRect(vec2(160.f+MenuPos+CONST_MENU_WINDOW_DISTANCE*12,160.f - 64.f), vec2(160.f+256.f+MenuPos+CONST_MENU_WINDOW_DISTANCE*12, 160.f + 64.f)); + + } + + + + glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["select_level"]); + Renderer->DrawRect(vec2(240.f-128.f, 241.f), vec2(240.f+128.f, 305.f)); + + glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["logo_small"]); + Renderer->DrawRect(vec2(240.f-128.f+15.f, 0.f), vec2(240.f+128.f+15.f, 64.f)); + + CheckGlError("Draw TGameMenu 2"); + + +} + +void TGameMenu::Update(cardinal dt) +{ + if (HoldToTap) + return; + + float k; + + MenuPos = MenuPos + MenuSpeed*dt/1000.f; + + int menuItemToShowCount; + + if (MenuItemCount == 12) + { + menuItemToShowCount = 13; + } + else + { + menuItemToShowCount = MenuItemCount; + } + + float acc; + + if (MenuItemCount == 1) + { + k = 3; + } + else + { + k = fabs( - MenuPos - ((menuItemToShowCount-1)*CONST_MENU_WINDOW_DISTANCE*0.5f)) / ((MenuItemCount-1)*CONST_MENU_WINDOW_DISTANCE*0.5f); + } + + acc = -MenuSpeed * CONST_SPEED_NEG_ACCELERATION_K * k; + + + float xleft = (- MenuPos + CONST_SHIFT_ON_SIDE - (menuItemToShowCount-1)*CONST_MENU_WINDOW_DISTANCE); + + if (xleft < 0) + { + xleft = 0; + } + + acc += xleft*CONST_MENU_POS_K; + + float xright = (MenuPos - CONST_SHIFT_ON_SIDE); + + if (xright < 0) + { + xright = 0; + } + + acc -= xright*CONST_MENU_POS_K; + + if ((MenuSpeed + acc*dt) * MenuSpeed < 0) //Check if MenuSpeed changes direction + { + MenuSpeed = 0; + } + else + { + MenuSpeed += acc*dt; + } + + +} + +void TGameMenu::OnTapDown(vec2 pos) +{ + + if (pos.v[1]<64.f && pos.v[0]>=265.f-128.f && pos.v[0]<=265.f+128.f) + { + Application->GoFromMenuToCredits(); + return; + } + + vec2 realPos = pos - vec2(MenuPos, 0); + + if (realPos.v[1] >= 80.f && realPos.v[1] <= 240.f) + { + float x = realPos.v[0] - 160.f; + + int p = 0; + while (x >280.f) + { + x -= 280.f; + p++; + } + + if (x <= 240.f && x >= 0.f && (pGoFromMenuToGame(SelectedGame); + SelectedGame = -1; + } +} + + +void TGameMenu::OnFling(vec2 slideSpeed) +{ + HoldToTap = false; + MenuSpeed = slideSpeed.v[0]; +} + +void TGameMenu::OnScroll(vec2 shift) +{ + MenuPos = MenuPos - shift.v[0]; +} + +void TGameMenu::OpenNextLevel() +{ + if (MenuItemCount < 12) + { + MenuItemCount++; + } +} + +int TGameMenu::GetMenuItemCount() +{ + return MenuItemCount; +} + +void TGameMenu::SetMenuItemCount(int menuItemCount) +{ + MenuItemCount = menuItemCount; +} diff --git a/game/menucode.h b/game/menucode.h new file mode 100644 index 0000000..0d3d355 --- /dev/null +++ b/game/menucode.h @@ -0,0 +1,40 @@ +#ifndef MENUCODE_H_INCLUDED +#define MENUCODE_H_INCLUDED + +#include "include/Engine.h" +#include "game_area_interface.h" + +using namespace SE; + + +class TGameMenu : public TGameAreaAncestor +{ +protected: + float MenuSpeed; + float MenuPos; + + bool HoldToTap; + + int MenuItemCount; + + int SelectedGame; + + +public: + TGameMenu(); + virtual void Draw(); + virtual void Update(cardinal dt); + virtual void OnTapDown(vec2 pos); + virtual void OnTapUp(vec2 pos); + virtual void OnFling(vec2 slideSpeed); + virtual void OnScroll(vec2 shift); + + void OpenNextLevel(); + int GetMenuItemCount(); + void SetMenuItemCount(int menuItemCount); + +}; + + + +#endif diff --git a/ios/Icon.png b/ios/Icon.png old mode 100644 new mode 100755 diff --git a/ios/Splash-landscape.png b/ios/Splash-landscape.png old mode 100644 new mode 100755 diff --git a/ios/doublehitballs.xcodeproj/project.pbxproj b/ios/doublehitballs.xcodeproj/project.pbxproj old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/AppDelegate.h b/ios/doublehitballs/AppDelegate.h old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/AppDelegate.m b/ios/doublehitballs/AppDelegate.m old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/CustomGLKView.h b/ios/doublehitballs/CustomGLKView.h old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/CustomGLKView.mm b/ios/doublehitballs/CustomGLKView.mm old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/ViewController.h b/ios/doublehitballs/ViewController.h old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/ViewController.mm b/ios/doublehitballs/ViewController.mm old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/doublehitballs-Info.plist b/ios/doublehitballs/doublehitballs-Info.plist old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/doublehitballs-Prefix.pch b/ios/doublehitballs/doublehitballs-Prefix.pch old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/en.lproj/InfoPlist.strings b/ios/doublehitballs/en.lproj/InfoPlist.strings old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/en.lproj/ViewController_iPad.xib b/ios/doublehitballs/en.lproj/ViewController_iPad.xib old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/en.lproj/ViewController_iPhone.xib b/ios/doublehitballs/en.lproj/ViewController_iPhone.xib old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/ios_api.cpp b/ios/doublehitballs/ios_api.cpp old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/ios_api.h b/ios/doublehitballs/ios_api.h old mode 100644 new mode 100755 diff --git a/ios/doublehitballs/main.m b/ios/doublehitballs/main.m old mode 100644 new mode 100755 diff --git a/ios/iTunesArtwork b/ios/iTunesArtwork old mode 100644 new mode 100755 diff --git a/proj.android-studio/.gitignore b/proj.android-studio/.gitignore new file mode 100755 index 0000000..cea3ef5 --- /dev/null +++ b/proj.android-studio/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/proj.android-studio/app/.gitignore b/proj.android-studio/app/.gitignore new file mode 100755 index 0000000..796b96d --- /dev/null +++ b/proj.android-studio/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/proj.android-studio/app/CMakeLists.txt b/proj.android-studio/app/CMakeLists.txt new file mode 100755 index 0000000..8f608bb --- /dev/null +++ b/proj.android-studio/app/CMakeLists.txt @@ -0,0 +1,100 @@ +# Sets the minimum version of CMake required to build the native +# library. You should either keep the default value or only pass a +# value of 3.4.0 or lower. + +cmake_minimum_required(VERSION 3.4.1) + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds it for you. +# Gradle automatically packages shared libraries with your APK. + + +add_definitions(-DTARGET_ANDROID) + +set(BOOST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../boost_1_63_0) + +set(BOOST_GIL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/boost-gil-extension) + +set(ZIP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/julienr-libzip-android/jni) + +set(LIBPNG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libpng_1.4.1_android) + +set(LIBJPEG_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/jpeg-9") + + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../engine) + +include_directories(${BOOST_PATH}) +include_directories(${LIBPNG_PATH}) +include_directories(${LIBJPEG_PATH}) +include_directories(${ZIP_PATH}) + +include_directories(${BOOST_GIL_PATH}) + +add_library( engine + SHARED + IMPORTED ) + +set_target_properties( # Specifies the target library. + engine + + # Specifies the parameter you want to define. + PROPERTIES IMPORTED_LOCATION + + # Provides the path to the library you want to import. + ${CMAKE_CURRENT_SOURCE_DIR}/build/intermediates/exploded-aar/proj.android-studio/SalmonEngineAndroid/unspecified/jni/${ANDROID_ABI}/libengine.so ) + + + + +add_library( # Sets the name of the library. + DoubleHitBalls + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + # Associated headers in the same location as their source + # file are automatically included. + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/android_api.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/main_code.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/creditscode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/gamecode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/loadingcode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/menucode.cpp + ) + + + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because system libraries are included in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. + +find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + log ) + +find_library( # Sets the name of the path variable. + GLESv2-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + GLESv2 ) + + +# Specifies libraries CMake should link to your target library. You +# can link multiple libraries, such as libraries you define in the +# build script, prebuilt third-party libraries, or system libraries. + +target_link_libraries( # Specifies the target library. + DoubleHitBalls + + # Links the target library to the log library + # included in the NDK. + ${log-lib} ${GLESv2-lib} engine ) diff --git a/proj.android-studio/app/build.gradle b/proj.android-studio/app/build.gradle new file mode 100755 index 0000000..1cc5d3f --- /dev/null +++ b/proj.android-studio/app/build.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.1" + defaultConfig { + applicationId "fishrungames.DoubleHitBalls" + minSdkVersion 15 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags "-std=c++11 -frtti -fexceptions -fsigned-char -Wno-c++11-narrowing" + } + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } + sourceSets { + main { + assets.srcDirs = ['../../assets/'] + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:24.2.1' + testCompile 'junit:junit:4.12' + + compile project(':SalmonEngineAndroid') +} diff --git a/proj.android-studio/app/proguard-rules.pro b/proj.android-studio/app/proguard-rules.pro new file mode 100755 index 0000000..8a2f402 --- /dev/null +++ b/proj.android-studio/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/proj.android-studio/app/src/androidTest/java/fishrungames/salmonandroidtemplate/ExampleInstrumentedTest.java b/proj.android-studio/app/src/androidTest/java/fishrungames/salmonandroidtemplate/ExampleInstrumentedTest.java new file mode 100755 index 0000000..c282df4 --- /dev/null +++ b/proj.android-studio/app/src/androidTest/java/fishrungames/salmonandroidtemplate/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package fishrungames.salmonandroidtemplate; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("fishrungames.salmonandroidtemplate", appContext.getPackageName()); + } +} diff --git a/proj.android-studio/app/src/main/AndroidManifest.xml b/proj.android-studio/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f755666 --- /dev/null +++ b/proj.android-studio/app/src/main/AndroidManifest.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java new file mode 100755 index 0000000..a1558e3 --- /dev/null +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GL2JNIActivity.java @@ -0,0 +1,91 @@ +package fishrungames.doublehitballs; + +import fishrungames.salmonengineandroid.EngineWrapper; +//Deprecated +//import fishrungames.doublehitballs.R; + +import android.app.Activity; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.os.Bundle; +import android.view.GestureDetector; +import android.view.KeyEvent; +import android.view.GestureDetector.SimpleOnGestureListener; +import android.view.MotionEvent; + +//Deprecated +//import java.lang.reflect.Field; + + +public class GL2JNIActivity extends Activity +{ + + GLView mView; + + @Override + protected void onCreate(Bundle icicle) + { + + super.onCreate(icicle); + + EngineWrapper.LoadSalmonEngineLibrary(); + EngineWrapper.SetActivityInstance(this); + EngineWrapper.SetupEnviroment(); + + String apkFilePath = null; + ApplicationInfo appInfo = null; + PackageManager packMgmr = this.getPackageManager(); + try { + appInfo = packMgmr.getApplicationInfo("fishrungames.DoubleHitBalls", 0); + } catch (NameNotFoundException e) { + + e.printStackTrace(); + + throw new RuntimeException("Unable to locate assets, aborting..."); + } + apkFilePath = appInfo.sourceDir; + + EngineWrapper.SetupApkFilePath(apkFilePath); + + mView = new GLView(getApplication()); + + setContentView(mView); + + EngineWrapper.SetView(mView); + + } + + @Override + protected void onPause() + { + EngineWrapper.CallDestroy(); + super.onPause(); + mView.onPause(); + } + + @Override + protected void onResume() + { + super.onResume(); + mView.onResume(); + } + + @Override + protected void onStop() + { + super.onStop(); + } + + public boolean onTouchEvent (MotionEvent event) + { + EngineWrapper.ProcessTouchEvent(event); + return true; + } + + public boolean onKeyDown(int keyCode, KeyEvent event) + { + EngineWrapper.ProcessKeyDown(keyCode, event); + return super.onKeyDown(keyCode, event); + } +} \ No newline at end of file diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java new file mode 100755 index 0000000..ab012e3 --- /dev/null +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java @@ -0,0 +1,69 @@ +package fishrungames.doublehitballs; + + +import java.util.Calendar; + +import android.content.Context; +import android.opengl.GLSurfaceView; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import fishrungames.salmonengineandroid.GLViewAncestor; +import fishrungames.salmonengineandroid.EngineWrapper; + +class GLView extends GLViewAncestor +{ + static long lastTimeStamp; + static boolean gameIsInited = false; + + public GLView(Context context) + { + //Change this method? Don't forget to change method below! + super(context); + init(false, 0, 0); + } + + public GLView(Context context, boolean translucent, int depth, int stencil) + { + //Change this method? Don't forget to change method above! + super(context); + init(translucent, depth, stencil); + } + + public void init(boolean translucent, int depth, int stencil) + { + super.init(translucent, depth, stencil); + setRenderer(new Renderer()); + Calendar c = Calendar.getInstance(); + lastTimeStamp = c.getTimeInMillis(); + gameIsInited = true; + } + + private static class Renderer implements GLSurfaceView.Renderer + { + public void onDrawFrame(GL10 gl) + { + if (gameIsInited) + { + Calendar c = Calendar.getInstance(); + + long currentTimeStamp = c.getTimeInMillis(); + + EngineWrapper.Update(currentTimeStamp - lastTimeStamp); + + lastTimeStamp = currentTimeStamp; + } + } + + public void onSurfaceChanged(GL10 gl, int width, int height) + { + JniWrapper.Init(width,height); + } + + public void onSurfaceCreated(GL10 gl, EGLConfig config) + { + //Do nothing. + } + } +} \ No newline at end of file diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java new file mode 100755 index 0000000..8e73337 --- /dev/null +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java @@ -0,0 +1,12 @@ +package fishrungames.doublehitballs; + +public class JniWrapper +{ + static { + System.loadLibrary("DoubleHitBalls"); + } + + + public static native void Init(int width, int height); + +} \ No newline at end of file diff --git a/proj.android-studio/app/src/main/res/drawable-hdpi/ic_menu_template.png b/proj.android-studio/app/src/main/res/drawable-hdpi/ic_menu_template.png new file mode 100644 index 0000000..1e28f93 Binary files /dev/null and b/proj.android-studio/app/src/main/res/drawable-hdpi/ic_menu_template.png differ diff --git a/proj.android-studio/app/src/main/res/drawable-ldpi/ic_menu_template.png b/proj.android-studio/app/src/main/res/drawable-ldpi/ic_menu_template.png new file mode 100644 index 0000000..6a93cf2 Binary files /dev/null and b/proj.android-studio/app/src/main/res/drawable-ldpi/ic_menu_template.png differ diff --git a/proj.android-studio/app/src/main/res/drawable-mdpi/ic_menu_template.png b/proj.android-studio/app/src/main/res/drawable-mdpi/ic_menu_template.png new file mode 100644 index 0000000..7c1cab2 Binary files /dev/null and b/proj.android-studio/app/src/main/res/drawable-mdpi/ic_menu_template.png differ diff --git a/proj.android-studio/app/src/main/res/values/strings.xml b/proj.android-studio/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..e3f7331 --- /dev/null +++ b/proj.android-studio/app/src/main/res/values/strings.xml @@ -0,0 +1,29 @@ + + + + + + + + GL2JNI + + + diff --git a/proj.android-studio/app/src/test/java/fishrungames/salmonandroidtemplate/ExampleUnitTest.java b/proj.android-studio/app/src/test/java/fishrungames/salmonandroidtemplate/ExampleUnitTest.java new file mode 100755 index 0000000..49c0291 --- /dev/null +++ b/proj.android-studio/app/src/test/java/fishrungames/salmonandroidtemplate/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package fishrungames.salmonandroidtemplate; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/proj.android-studio/build.gradle b/proj.android-studio/build.gradle new file mode 100755 index 0000000..74b2ab0 --- /dev/null +++ b/proj.android-studio/build.gradle @@ -0,0 +1,23 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.3' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/proj.android-studio/gradle.properties b/proj.android-studio/gradle.properties new file mode 100755 index 0000000..aac7c9b --- /dev/null +++ b/proj.android-studio/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/proj.android-studio/gradle/wrapper/gradle-wrapper.jar b/proj.android-studio/gradle/wrapper/gradle-wrapper.jar new file mode 100755 index 0000000..13372ae Binary files /dev/null and b/proj.android-studio/gradle/wrapper/gradle-wrapper.jar differ diff --git a/proj.android-studio/gradle/wrapper/gradle-wrapper.properties b/proj.android-studio/gradle/wrapper/gradle-wrapper.properties new file mode 100755 index 0000000..04e285f --- /dev/null +++ b/proj.android-studio/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 28 10:00:20 PST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/proj.android-studio/gradlew b/proj.android-studio/gradlew new file mode 100755 index 0000000..9d82f78 --- /dev/null +++ b/proj.android-studio/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/proj.android-studio/gradlew.bat b/proj.android-studio/gradlew.bat new file mode 100755 index 0000000..8a0b282 --- /dev/null +++ b/proj.android-studio/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/proj.android-studio/settings.gradle b/proj.android-studio/settings.gradle new file mode 100755 index 0000000..f82ab8b --- /dev/null +++ b/proj.android-studio/settings.gradle @@ -0,0 +1,7 @@ +include ':SalmonEngineAndroid' +project(':SalmonEngineAndroid').projectDir =new File(settingsDir, '../../engine/SalmonEngineAndroid/app') + + +include ':app' + + diff --git a/windows/DoubleHitBalls-win/Debug/DoubleHitBalls-win.exe b/windows/DoubleHitBalls-win/Debug/DoubleHitBalls-win.exe old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/Debug/DoubleHitBalls-win.exp b/windows/DoubleHitBalls-win/Debug/DoubleHitBalls-win.exp old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/Debug/DoubleHitBalls-win.lib b/windows/DoubleHitBalls-win/Debug/DoubleHitBalls-win.lib old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/Debug/log.txt b/windows/DoubleHitBalls-win/Debug/log.txt old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win.sln b/windows/DoubleHitBalls-win/DoubleHitBalls-win.sln old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win/DoubleHitBalls-win.vcxproj b/windows/DoubleHitBalls-win/DoubleHitBalls-win/DoubleHitBalls-win.vcxproj old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win/DoubleHitBalls-win.vcxproj.filters b/windows/DoubleHitBalls-win/DoubleHitBalls-win/DoubleHitBalls-win.vcxproj.filters old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win/log.txt b/windows/DoubleHitBalls-win/DoubleHitBalls-win/log.txt old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win/main.cpp b/windows/DoubleHitBalls-win/DoubleHitBalls-win/main.cpp old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win/main.h b/windows/DoubleHitBalls-win/DoubleHitBalls-win/main.h old mode 100644 new mode 100755 diff --git a/windows/DoubleHitBalls-win/DoubleHitBalls-win/progress.txt b/windows/DoubleHitBalls-win/DoubleHitBalls-win/progress.txt old mode 100644 new mode 100755