first blood

This commit is contained in:
vladislav.khorev committed 2013-01-19 22:25:53 +00:00
1 parent 23c5e8c4bf
commit b4c58abee4
62 files changed
+3023

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
# 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
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_PATH = $(SalmonEnginePath)
#BOOST_PATH = $(LibsPath)/boost_1_47_0
#OGG_PATH = $(LibsPath)/libogg-1.3.0
#VORBIS_PATH = $(LibsPath)/libvorbis-1.3.2
#SQUIRREL_PATH = $(LibsPath)/sqplus
#LIBPNG_PATH = $(LibsPath)/libpng_1.4.1_android
#ZIP_PATH = $(LibsPath)/julienr-libzip-android/jni
#====== ENGINE AND LIBS =====================
include $(ENGINE_PATH)/Android_Engine.mk
#================= THE GAME =======================
LOCAL_PATH:= $(LPATH)
include $(CLEAR_VARS)
#LOCAL_CFLAGS := -DTARGET_ANDROID -DTARGET_HALIBUT -g -ggdb -O0
LOCAL_CFLAGS := -DTARGET_ANDROID -DTARGET_HALIBUT
LOCAL_STATIC_LIBRARIES := boost
LOCAL_STATIC_LIBRARIES += squirrel
LOCAL_STATIC_LIBRARIES += png_lib
LOCAL_STATIC_LIBRARIES += zip
LOCAL_SHARED_LIBRARIES := HalibutEngine
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 := CrystalOfRhylilLib
LOCAL_SRC_FILES := main_code.cpp
LOCAL_SRC_FILES += android_api.cpp
LOCAL_SRC_FILES += match3/match3field.cpp
LOCAL_LDLIBS := -lGLESv2
#LOCAL_LDLIBS += -llog -Wl -g -ggdb -lz
LOCAL_LDLIBS += -llog -Wl -lz
include $(BUILD_SHARED_LIBRARY)
+11
View File
@@ -0,0 +1,11 @@
#APP_PLATFORM := android-9
#APP_STL := gnustl_static
#APP_STL := stlport_static
APP_STL := gnustl_shared
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -frtti
APP_OPTIM := debug
#APP_ABI := armeabi-v7a
+150
View File
@@ -0,0 +1,150 @@
#include "android_api.h"
#include "main_code.h"
//#include "boost/shared_ptr.h"
const float CONST_MAXRIX_WIDTH = 800.f;
const float CONST_MAXRIX_HEIGHT = 480.f;
boost::mutex RenderMutex;
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height)
{
try
{
if (App->Inited)
{
App->OuterDeinit(); //Clean up what is left at previous launch (if applicable)
}
App->OuterInit(width, height, CONST_MAXRIX_WIDTH, CONST_MAXRIX_HEIGHT);
App->Inited = true;
}
catch (ErrorCommon e)
{
throw;
}
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_StopSounds(JNIEnv * env, jobject obj)
{
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_Update(JNIEnv * env, jobject obj, long dt)
{
RenderMutex.lock();
try
{
if (App->Inited)
{
App->OuterDraw();
App->OuterUpdate(dt);
}
}
catch (...)
{
throw;
}
RenderMutex.unlock();
}
JNIEXPORT int JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_IsInited(JNIEnv * env, jobject obj)
{
if (App->Inited)
{
return 1;
}
else
{
return 0;
}
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_Destroy(JNIEnv * env, jobject obj)
{
RenderMutex.lock();
try
{
if (App->Inited)
{
App->Inited = false;
App->OuterDeinit();
}
}
catch (ErrorCommon e)
{
throw;
}
RenderMutex.unlock();
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, float x, float y, long time)
{
try
{
App->OuterOnTapDown(vec2(x*CONST_MAXRIX_WIDTH/HalibutRender->GetScreenWidth(), y*CONST_MAXRIX_HEIGHT/HalibutRender->GetScreenHeight()));
}
catch (ErrorCommon e)
{
throw;
}
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnTapUp(JNIEnv * env, jobject obj, float x, float y, long time)
{
try
{
App->OuterOnTapUp(vec2(x*CONST_MAXRIX_WIDTH/HalibutRender->GetScreenWidth(), y*CONST_MAXRIX_HEIGHT/HalibutRender->GetScreenHeight()));
}
catch (ErrorCommon e)
{
throw;
}
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, float x, float y, long time)
{
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time)
{
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time)
{
try
{
App->OuterOnMove(vec2(distanceX*CONST_MAXRIX_WIDTH/HalibutRender->GetScreenWidth(), distanceY*CONST_MAXRIX_HEIGHT/HalibutRender->GetScreenHeight()));
}
catch (ErrorCommon e)
{
throw;
}
}
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnKeyPress(JNIEnv * env, jobject obj, jint keyCode)
{
try
{
App->OnKeyPress(keyCode);
}
catch (ErrorCommon e)
{
throw;
}
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef ANDROID_API_H_INCLUDED
#define ANDROID_API_H_INCLUDED
#include <jni.h>
#include <android/log.h>
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "boost/shared_ptr.hpp"
#include "main_code.h"
extern "C" {
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_StopSounds(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_Update(JNIEnv * env, jobject obj, long dt);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_Destroy(JNIEnv * env, jobject obj);
JNIEXPORT int JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_IsInited(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnTapDown(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnTapUp(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnTapMove(JNIEnv * env, jobject obj, jfloat x, jfloat y, long time);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnFling(JNIEnv * env, jobject obj, jfloat velocityX, jfloat velocityY, long time);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnScroll(JNIEnv * env, jobject obj, jfloat distanceX, jfloat distanceY, long time);
JNIEXPORT void JNICALL Java_fishrungames_crystalofrhylil_JniWrapper_OnKeyPress(JNIEnv * env, jobject obj, jint keyCode);
};
#endif
+141
View File
@@ -0,0 +1,141 @@
#include "main_code.h"
#ifdef TARGET_ANDROID
#include "android_api.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "include/Engine.h"
#include "main_code.h"
#ifndef TARGET_IOS
boost::shared_ptr<TMyApplication> App(new TMyApplication);
#endif
bool animPaused = false;
struct TOnClickTest
{
void operator()()
{
//ResourceManager->ScriptManager.RunScript("5+5;");
if (animPaused)
{
//animPaused = false;
//ResourceManager->HalibutAnimationManager.StartAnimation("test_anim");
//ResourceManager->HalibutAnimationManager.ShowAnimation("test_anim");
//ResourceManager->SoundManager.PlayMusic("finalogg.ogg");
//App->Match3Controller.Match3Field->StartAnimateChip(4,1);
//App->Match3Controller.Match3Field->HighlightMatch3();
}
else
{
//animPaused = true;
//ResourceManager->HalibutAnimationManager.StopAnimation("test_anim");
//ResourceManager->HalibutAnimationManager.HideAnimation("test_anim");
//ResourceManager->SoundManager.StopMusic("finalogg.ogg");
//App->Match3Controller.Match3Field->StopAnimateChip(4,1);
//App->Match3Controller.Match3Field->HighlightMatch3();
}
}
};
//What to do on init
void TMyApplication::InnerInit()
{
#ifdef TARGET_ANDROID
ResourceManager->PathToResources = "";
#endif
#ifdef TARGET_WIN32
#ifdef DEBUG
ResourceManager->PathToResources = "../../assets/";
#else
ResourceManager->PathToResources = "res/";
#endif
#endif
#ifdef TARGET_IOS
ResourceManager->PathToResources = "assets/";
#endif
boost::shared_ptr<boost::property_tree::ptree> px = FileToPropertyTree("function_info_list.xml");
ResourceManager->ScriptManager.Serialize(*px);
px = FileToPropertyTree("shaders.xml");
ResourceManager->ShaderManager.Serialize(*px);
HalibutRender->PushShader("DefaultShader");
px = FileToPropertyTree("textures.xml");
ResourceManager->TexList.Serialize(*px);
px = FileToPropertyTree("fonts.xml");
ResourceManager->FontManager.Serialize(*px);
ResourceManager->FontManager.PushFont("droid_sans14");
ResourceManager->GUIManager.AddWidgetAndFill(boost::shared_ptr<TInstancingWidgetAncestor>(new TSquareButton),
"ololo", "group1",
boost::shared_ptr<TTriangleListFillerAncestor>(new TSquareButtonTriangleListFiller(vec2(100, 100), vec2(200, 200), "button_normal", "button_pressed")));
ResourceManager->GUIManager.AddWidgetAndFill(boost::shared_ptr<TInstancingWidgetAncestor>(new TSquareStatic),
"Background", "group1",
boost::shared_ptr<TSquareStaticTriangleListFiller>(new TSquareStaticTriangleListFiller(vec2(0, 0), vec2(800, 480), "cave_hd")));
ResourceManager->GUIManager.AddWidget(boost::shared_ptr<TInstancingWidgetAncestor>(new TMatch3Field(Match3Controller)),
"match3", "group1");
ResourceManager->GUIManager.MoveWidget("ololo", vec2(-100, 0));
TOnClickTest OnClickTest;
//ResourceManager->GUIManager.GetOnClickSignal("ololo").connect(OnClickTest);
//testAnimObject.Serialize(FileToPropertyTree("test_animation_xml.xml"));
//ResourceManager->HalibutAnimationManager.AddAnimationObject("test_anim", testAnimObject);
//ResourceManager->HalibutAnimationManager.StartAnimation("test_anim");
//ResourceManager->ShaderManager.AddShader("DefaultShader", "shader_vertex.txt", "shader_fragment.txt");
/*HalibutRender->PushShader("DefaultShader");
ResourceManager->TexList.AddTexture(CONST_CONSOLE_TEX_NAME);
ResourceManager->FontManager.AddFont("droid_sans14", "droid_sans14_font_bitmap.bmp32", "droid_sans14_font_charmap.txt");
ResourceManager->FontManager.PushFont("droid_sans14");*/
}
//What to do on deinit
void TMyApplication::InnerDeinit()
{
Inited = false;
}
//What to do on draw
void TMyApplication::InnerDraw()
{
}
//What to do on update. timer means how many ms passed since last update
void TMyApplication::InnerUpdate(cardinal timer)
{
}
+64
View File
@@ -0,0 +1,64 @@
#ifndef GL_CODE_H_INCLUDED
#define GL_CODE_H_INCLUDED
#ifdef TARGET_ANDROID
//#include "android_api.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "boost/shared_ptr.hpp"
/*#include "boost/thread/thread.hpp"
#include "boost/signal.hpp"
#include "boost/assign.hpp"
#include "boost/bind.hpp"
*/
#include "include/Engine.h"
#include "match3/match3field.h"
class TMatch3Controller
{
public:
TMatch3Field* Match3Field;
TMatch3Controller()
: Match3Field(NULL)
{
}
};
//Application class
class TMyApplication : public TApplication
{
public:
bool Inited;
TMatch3Controller Match3Controller;
TMyApplication() : Inited(false) { }
virtual void InnerInit();
//What to do on init
virtual void InnerDeinit();
//What to do on deinit
virtual void InnerDraw();
//What to do on draw
virtual void InnerUpdate(cardinal timer);
//What to do on update. timer means how many ms passed since last update
};
#ifndef TARGET_IOS
extern boost::shared_ptr<TMyApplication> App;
#endif
#endif
File diff suppressed because it is too large. Load diff
+276
View File
@@ -0,0 +1,276 @@
#ifndef MATCH3FIELD_H_INCLUDED
#define MATCH3FIELD_H_INCLUDED
#include "include/Engine.h"
const cardinal CONST_MAX_FIELD_WIDTH = 11;
const cardinal CONST_MAX_FIELD_HEIGHT = 11;
const float CONST_MATCH3_CELL_WIDTH = 42.f;
const float CONST_MATCH3_CELL_HEIGHT = 42.f;
const float CONST_CHIP_LOWEST_SPEED = -0.5f;
const float CONST_CHIP_ACCELERATION = -0.0014f;
/*
const float CONST_MATCH3_CELL_WIDTH = 32.f;
const float CONST_MATCH3_CELL_HEIGHT = 32.f;
const float CONST_CHIP_LOWEST_SPEED = -0.3f;
const float CONST_CHIP_ACCELERATION = -0.001f;
*/
const cardinal CONST_MATCH_TIME = 150;
const float CONST_CHIP_POSITION_EPSILON = 1.f;
const float CONST_CHIP_VELOCITY_EPSILON = 0.3f;
const float CONST_CHIP_K = 0.4f;
const cardinal CONST_CHIP_TYPE_COUNT = 4;
struct TChipTemplateParams : public TSerializeInterface
{
THalibutExternalAnimObject SelectedTemplateAnimObject;
THalibutExternalAnimObject FinishingTemplateAnimObject;
TRenderParams SelectedRenderParams;
TRenderParams FinishingRenderParams;
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TMatch3FieldParams : public TSerializeInterface
{
cardinal FieldWidth;
cardinal FieldHeight;
float CellWidth;
float CellHeight;
float ChipLowestSpeed;
float ChipAcceleration;
float ChipPositionEpsilon;
float ChipVelocityEpsilon;
float ChipK;
cardinal ChipMatchTime;
cardinal ChipTypeCount;
std::vector<TChipTemplateParams> ChipTemplateParamsArr;
TMatch3FieldParams()
: FieldWidth(CONST_MAX_FIELD_WIDTH)
, FieldHeight(CONST_MAX_FIELD_HEIGHT)
, CellWidth(CONST_MATCH3_CELL_WIDTH)
, CellHeight(CONST_MATCH3_CELL_HEIGHT)
, ChipLowestSpeed(CONST_CHIP_LOWEST_SPEED)
, ChipAcceleration(CONST_CHIP_ACCELERATION)
, ChipPositionEpsilon(CONST_CHIP_POSITION_EPSILON)
, ChipVelocityEpsilon(CONST_CHIP_VELOCITY_EPSILON)
, ChipK(CONST_CHIP_K)
, ChipMatchTime(CONST_MATCH_TIME)
, ChipTypeCount(CONST_CHIP_TYPE_COUNT)
{
}
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TChip
{
int ChipType; // -1 means empty field
std::string AnimName; //Generated automatically
TRenderPairList::iterator RenderPair;
cardinal VertexListShift;
float Velocity;
enum TChipState
{
CS_STANDBY,
CS_SWAPPING,
CS_FALLING,
CS_LOCKED,
CS_FINISHING,
CS_X,
} ChipState;
TChip(int chipType, TRenderPairList::iterator renderPair, cardinal vertexListShift, TChipState chipState = CS_FALLING);
~TChip();
vec2 GetLeftBottomPos();
void SetLeftBottomPos(vec2 newPos);
void MoveLeftBottomPos(vec2 shift);
static int StaticAnimationIndex;
};
struct TChipSwappingPair
{
float T;
ivec2 Chip1;
ivec2 Chip2;
vec2 Chip1RealPosFrom;
vec2 Chip2RealPosFrom;
bool IsReturning;
TChipSwappingPair(ivec2 chip1, ivec2 chip2, vec2 chip1PosFrom, vec2 chip2PosFrom)
: Chip1(chip1)
, Chip2(chip2)
, T(0)
, Chip1RealPosFrom(chip1PosFrom)
, Chip2RealPosFrom(chip2PosFrom)
, IsReturning(false)
{
}
};
struct TChipDeletingData
{
float T;
ivec2 Chip;
vec2 Pos;
TChipDeletingData(ivec2 chip, vec2 pos)
: T(0.f)
, Chip(chip)
, Pos(pos)
{
}
};
class TMatch3Logic
{
protected:
cardinal ChipTypeCount;
std::vector<std::vector<TChip> > ChipMatrix;
std::vector<TChipSwappingPair> ChipSwappingPairVector;
std::vector<TChipDeletingData> ChipDeletingVector;
std::vector<TRenderPairList::iterator> RenderPairIteratorVector;
ivec2 selectedChip;
vec2 LeftBottomPosField;
TMatch3FieldParams Match3FieldParams;
void FillRandomChipMatrix(std::vector<TRenderPairList::iterator> renderPairIteratorVector, vec2 leftBottomPos);
vec2 GetExpectedLeftBottomPos(cardinal x, cardinal y);
void StartAnimateChip(cardinal x, cardinal y);
void StopAnimateChip(cardinal x, cardinal y);
bool ChipIsLocked(ivec2 chip);
bool ChipIsFinishing(ivec2 chip);
bool ChipIsStable(ivec2 chip);
bool ChipCanBeSelected(ivec2 chip);
bool ChipsCanBeSwapped(ivec2 p1, ivec2 p2);
bool ChipCanBeMatchedUp(ivec2 chip);
bool ChipCanBeMatchedDown(ivec2 chip);
bool ChipCanBeMatchedLeft(ivec2 chip);
bool ChipCanBeMatchedRight(ivec2 chip);
void UnmatchChips(std::vector<ivec2> chipList);
void UpdateChipPosition(cardinal dt);
void RemoveBubbles();
void ReplaceAnimation(ivec2 p);
void MoveVertexListShiftBack(TRenderPairList::iterator renderPairItr, cardinal moveFrom);
void MoveVertexCoordDown(TRenderPairList::iterator renderPairItr, cardinal moveFrom, float value);
void AddChipToUp(cardinal colNum, int chipType, vec2 spawnPos, TChip::TChipState chipState = TChip::CS_FALLING);
void InsertEmptyChip(cardinal colNum, cardinal rowNum, int chipType);
void UpdateChipSwapping(cardinal dt);
void TryMatchAllChips();
void DestroyChip(ivec2 p);
void ChangeChipType(ivec2 p);
public:
TMatch3Logic();
virtual ~TMatch3Logic();
void SelectChip(ivec2 pos);
void UnselectChip();
ivec2 GetSelectedChip();
std::vector<ivec2> GetAvailableMatchingChips();
void SwapChips(ivec2 p1, ivec2 p2, bool isReturning = false);
void ResetChipPos(ivec2 p);
void UpdateLogic(cardinal dt);
void HitFieldWithPattern(ivec2 pos, std::vector<std::vector<char> > pattern, std::vector<std::vector<char> > jumpingPattern);
};
class TMatch3Controller;
class TMatch3Field : public TMatch3Logic, public TInstancingWidgetAncestor
{
protected:
void FillBasicChipMatrixAndTriangleList();
//TMatch3Controller& Match3Controller;
vec2 LastTappedPos;
vec2 LastMovePos;
ivec2 PosToChip(vec2 pos);
public:
TMatch3Field();
TMatch3Field(const TMatch3Field& m);
TMatch3Field& operator=(const TMatch3Field& m);
TMatch3Field(TMatch3Controller& match3Controller);
~TMatch3Field();
virtual void Update(cardinal dt);
virtual void OnTapDown(vec2 pos);
virtual void OnTapUp(vec2 pos);
virtual void OnMove(vec2 shift);
virtual bool CheckClick(vec2 mousePos);
void HighlightMatch3();
};
#endif