delete files
This commit is contained in:
parent
6c76d2dc57
commit
400193f457
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding=".svn/" kind="src" path="src"/>
|
||||
<classpathentry excluding=".svn/" kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="lib" path="C:/Workplace/Projects/Android/EngineWrapper/jar/EngineWrapper.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
33
.project
33
.project
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EngineWrapper</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="fishrungames.salmonjnitemplate" android:versionCode="1" android:versionName="1.0.0">
|
||||
<application
|
||||
android:icon="@drawable/ic_menu_template" android:label="Salmon Jni Template">
|
||||
<activity android:name="fishrungames.salmonjnitemplate.MainActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:launchMode="singleTask"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:noHistory="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<uses-feature android:glEsVersion="0x00020000"/>
|
||||
<uses-sdk android:minSdkVersion="8"/>
|
||||
</manifest>
|
@ -1,77 +0,0 @@
|
||||
# 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 AND LIBS =====================
|
||||
|
||||
include $(ENGINE_PATH)/Android_Salmon_Engine.mk
|
||||
|
||||
#================= THE GAME =======================
|
||||
|
||||
|
||||
LOCAL_PATH:= $(LPATH)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_CFLAGS := -DTARGET_ANDROID -DNOSOUND -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 := SalmonJniTemplate
|
||||
LOCAL_SRC_FILES := main_code.cpp
|
||||
LOCAL_SRC_FILES += android_api.cpp
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv2
|
||||
LOCAL_LDLIBS += -llog -Wl
|
||||
|
||||
#debug
|
||||
#LOCAL_CFLAGS += -g -ggdb -O0
|
||||
#LOCAL_LDLIBS += -g -ggdb
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
@ -1,3 +0,0 @@
|
||||
APP_STL := gnustl_shared
|
||||
APP_CPPFLAGS += -fexceptions
|
||||
APP_CPPFLAGS += -frtti
|
@ -1,10 +0,0 @@
|
||||
#include "android_api.h"
|
||||
|
||||
#include "main_code.h"
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height)
|
||||
{
|
||||
JniInitApp<TMyApplication>(width, height, 480.f, 320.f);
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
#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"
|
||||
|
||||
#include "include/Engine.h"
|
||||
|
||||
using namespace SE;
|
||||
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_fishrungames_salmonjnitemplate_JniWrapper_Init(JNIEnv * env, jobject obj, jint width, jint height);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,567 +0,0 @@
|
||||
#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"
|
||||
|
||||
//Better move those to external config or something...
|
||||
const cardinal CONST_LASER_TIMER = 200;
|
||||
const int CONST_HIT_SCORE_POINTS = 100;
|
||||
const float CONST_TIME_SCALE = 0.01f;
|
||||
|
||||
const float CONST_PLAYER_ACCELERATION = 3.f;
|
||||
const float CONST_VELOCITY_FADE = 0.95f;
|
||||
const float CONST_LASER_VELOCITY = 100.f;
|
||||
|
||||
const vec2 CONST_PLAYER_HALF_SIZE(30.f, 30.f);
|
||||
const vec2 CONST_LASER_HALF_SIZE(10.f, 10.f);
|
||||
|
||||
|
||||
const vec2 CONST_AST_POS1(40, 40);
|
||||
const vec2 CONST_AST_POS2(40, 280);
|
||||
const vec2 CONST_AST_POS3(440, 160);
|
||||
|
||||
|
||||
|
||||
float HealthToScale(int health)
|
||||
{
|
||||
return 0.5f + health * 0.3f;
|
||||
}
|
||||
|
||||
float HealthToHitDistance(int health)
|
||||
{
|
||||
const float CONST_HIT_DISTANCE = 15.f;
|
||||
|
||||
return max(CONST_HIT_DISTANCE * HealthToScale(health), 10.f);
|
||||
}
|
||||
|
||||
void TMyApplication::InnerInit()
|
||||
{
|
||||
|
||||
*Console<<"Inner init go!\n";
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
ST::PathToResources = "";
|
||||
#endif
|
||||
#ifdef TARGET_WIN32
|
||||
#ifdef NDEBUG
|
||||
ST::PathToResources = "assets/";
|
||||
#else
|
||||
ST::PathToResources = "../../../assets/";
|
||||
#endif
|
||||
#endif
|
||||
#ifdef TARGET_IOS
|
||||
ST::PathToResources = "assets/";
|
||||
#endif
|
||||
|
||||
RandomGenerator.seed(static_cast<unsigned int>(std::time(0)));
|
||||
|
||||
TapIsDown = false;
|
||||
|
||||
ResourceManager->TexList.AddTexture(CONST_CONSOLE_TEX_NAME);
|
||||
|
||||
ResourceManager->ShaderManager.AddShader("DefaultShader", "gui_transparent.vertex", "gui_transparent.fragment");
|
||||
|
||||
Renderer->PushShader("DefaultShader");
|
||||
|
||||
ResourceManager->FontManager.AddFont("droid_sans14", "droid_sans14_font_bitmap.bmp32", "droid_sans14_font_charmap.txt");
|
||||
ResourceManager->FontManager.PushFont("droid_sans14");
|
||||
|
||||
ResourceManager->TexList.Serialize(*FileToPropertyTree("textures.xml"));
|
||||
|
||||
Renderer->PushProjectionMatrix(Renderer->GetScreenWidth(), Renderer->GetScreenHeight());
|
||||
|
||||
Level = 1;
|
||||
Score = 0;
|
||||
|
||||
InitLevel();
|
||||
|
||||
Player.RenderPair.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "shipTexture";
|
||||
Player.RenderPair.second.Data = MakeDataTriangleList(Player.Pos - CONST_PLAYER_HALF_SIZE, Player.Pos + CONST_PLAYER_HALF_SIZE);
|
||||
Player.RenderPair.second.RefreshBuffer();
|
||||
|
||||
BackgroundRenderPair.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "backgroundTexture";
|
||||
BackgroundRenderPair.second.Data = MakeDataTriangleList(vec2(0,0), vec2(Renderer->GetScreenWidth(), Renderer->GetScreenHeight()));
|
||||
BackgroundRenderPair.second.RefreshBuffer();
|
||||
|
||||
*Console<<"Inner init end!\n";
|
||||
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::InnerDeinit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TMyApplication::InnerDraw()
|
||||
{
|
||||
|
||||
glClearColor(0,0,0,1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//Draw background
|
||||
TRenderParamsSetter renderParamSetter(BackgroundRenderPair.first);
|
||||
|
||||
Renderer->DrawTriangleList(BackgroundRenderPair.second);
|
||||
|
||||
|
||||
//Draw asteroids
|
||||
BOOST_FOREACH(CAsteroidStruct& asteroid, Asteroids)
|
||||
{
|
||||
TRenderParamsSetter renderParamSetter(asteroid.RenderPair.first);
|
||||
|
||||
Renderer->DrawTriangleList(asteroid.RenderPair.second);
|
||||
}
|
||||
|
||||
|
||||
//Draw player
|
||||
if (GameState != GS_LOST)
|
||||
{
|
||||
TRenderParamsSetter renderParamSetter(Player.RenderPair.first);
|
||||
Renderer->DrawTriangleList(Player.RenderPair.second);
|
||||
}
|
||||
|
||||
//Draw lasers
|
||||
BOOST_FOREACH(CLaserStruct& laser, Lasers)
|
||||
{
|
||||
TRenderParamsSetter renderParamSetter(laser.RenderPair.first);
|
||||
|
||||
Renderer->DrawTriangleList(laser.RenderPair.second);
|
||||
}
|
||||
|
||||
|
||||
//Draw texts
|
||||
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList[ResourceManager->FontManager.GetCurrentFontTextureName()]);
|
||||
|
||||
Renderer->DrawTriangleList(LevelScoreText);
|
||||
Renderer->DrawTriangleList(LevelMessageText);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TMyApplication::InnerUpdate(cardinal dt)
|
||||
{
|
||||
float scaledTime = CONST_TIME_SCALE * dt;
|
||||
|
||||
//Update Asteroids
|
||||
BOOST_FOREACH(CAsteroidStruct& asteroid, Asteroids)
|
||||
{
|
||||
|
||||
float difAngle = asteroid.AngularVelocity * scaledTime;
|
||||
|
||||
asteroid.Angle += difAngle;
|
||||
|
||||
mat3 rotationMatrix = CreateZRotationMatrix(difAngle);
|
||||
|
||||
MoveDataTriangleList(asteroid.RenderPair.second.Data, -vec3(asteroid.CenterPos, 0));
|
||||
RotateDataTriangleList(asteroid.RenderPair.second.Data, rotationMatrix);
|
||||
MoveDataTriangleList(asteroid.RenderPair.second.Data, vec3(asteroid.CenterPos, 0));
|
||||
|
||||
|
||||
vec2 dif = asteroid.Velocity * scaledTime;
|
||||
|
||||
vec2 newCenterPos = NormalizePos(asteroid.CenterPos + dif);
|
||||
|
||||
dif = newCenterPos - asteroid.CenterPos;
|
||||
|
||||
asteroid.CenterPos = newCenterPos;
|
||||
|
||||
MoveDataTriangleList(asteroid.RenderPair.second.Data, vec3(dif, 0));
|
||||
|
||||
asteroid.RenderPair.second.RefreshBuffer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
UpdatePlayerPosition(scaledTime);
|
||||
|
||||
|
||||
|
||||
//Shoot laser
|
||||
LaserTimer.Update(dt);
|
||||
|
||||
if (LaserTimer.IsOver())
|
||||
{
|
||||
LaserTimer.SetTimer(CONST_LASER_TIMER);
|
||||
|
||||
if (GameState == GS_PLAY)
|
||||
{
|
||||
AddNewLaser();
|
||||
}
|
||||
}
|
||||
|
||||
//Update lasers
|
||||
BOOST_FOREACH(CLaserStruct& laser, Lasers)
|
||||
{
|
||||
vec2 dif = CONST_LASER_VELOCITY *laser.Dir * scaledTime;
|
||||
MoveDataTriangleList(laser.RenderPair.second.Data, vec3(dif, 0));
|
||||
laser.Pos += dif;
|
||||
|
||||
laser.RenderPair.second.RefreshBuffer();
|
||||
}
|
||||
|
||||
//Do all checks...
|
||||
ProcessLaserHit();
|
||||
|
||||
ProcessPlayerCollisions();
|
||||
|
||||
ClearUnusedLasers();
|
||||
|
||||
if (Asteroids.size() == 0 && GameState == GS_PLAY)
|
||||
{
|
||||
GameState = GS_WON;
|
||||
RefreshScoreText();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TMyApplication::InnerOnTapDown(vec2 p)
|
||||
{
|
||||
TapIsDown = true;
|
||||
LastTap = p;
|
||||
}
|
||||
|
||||
void TMyApplication::InnerOnTapUp(vec2 p)
|
||||
{
|
||||
TapIsDown = false;
|
||||
|
||||
|
||||
if (GameState == GS_LOST)
|
||||
{
|
||||
Level = 1;
|
||||
Score = 0;
|
||||
InitLevel();
|
||||
}
|
||||
else if (GameState == GS_WON)
|
||||
{
|
||||
Level++;
|
||||
InitLevel();
|
||||
}
|
||||
}
|
||||
|
||||
void TMyApplication::InnerOnTapUpAfterMove(vec2 p)
|
||||
{
|
||||
TapIsDown = false;
|
||||
}
|
||||
|
||||
void TMyApplication::InnerOnMove(vec2 shift)
|
||||
{
|
||||
LastTap -= shift;
|
||||
}
|
||||
|
||||
void TMyApplication::InitLevel()
|
||||
{
|
||||
GameState = GS_PLAY;
|
||||
|
||||
LaserTimer.SetTimer(CONST_LASER_TIMER);
|
||||
|
||||
Asteroids.clear();
|
||||
Lasers.clear();
|
||||
|
||||
CreateRandomAsteroid(CONST_AST_POS1, Level);
|
||||
CreateRandomAsteroid(CONST_AST_POS2, Level);
|
||||
CreateRandomAsteroid(CONST_AST_POS3, Level);
|
||||
|
||||
Player.Angle = 0;
|
||||
Player.Pos = vec2(Renderer->GetScreenWidth()/2, Renderer->GetScreenHeight()/2);
|
||||
|
||||
RefreshScoreText();
|
||||
|
||||
}
|
||||
|
||||
CAsteroidStruct TMyApplication::CreateAsteroid(vec2 pos, vec2 dir, int health)
|
||||
{
|
||||
static const float CONST_TEX_COORD_SCALE = 0.01f;
|
||||
static const float CONST_ANGULAR_VELOCITY_SCALE = 0.001f;
|
||||
|
||||
static const boost::random::uniform_int_distribution<> velocityDistribution(5, 10);
|
||||
|
||||
static const boost::random::uniform_int_distribution<> angularVelocityDistribution(0, 10);
|
||||
|
||||
static const boost::random::uniform_int_distribution<> vertexNumberDistribution(5, 10);
|
||||
static const boost::random::uniform_int_distribution<> vertexShiftDistribution(20, 30);
|
||||
|
||||
CAsteroidStruct result;
|
||||
|
||||
result.Health = health;
|
||||
|
||||
result.CenterPos = pos;
|
||||
|
||||
result.Angle = 0;
|
||||
|
||||
result.AngularVelocity = angularVelocityDistribution(RandomGenerator) * CONST_ANGULAR_VELOCITY_SCALE;
|
||||
|
||||
result.Velocity = velocityDistribution(RandomGenerator) * dir;
|
||||
|
||||
int numberOfVertices = vertexNumberDistribution(RandomGenerator);
|
||||
|
||||
std::vector<float> distArr(numberOfVertices);
|
||||
|
||||
for (int i=0; i<numberOfVertices; i++)
|
||||
{
|
||||
distArr[i] = vertexShiftDistribution(RandomGenerator) * HealthToScale(health);
|
||||
}
|
||||
|
||||
//First iteration
|
||||
vec2 prevShift = distArr[0] * vec2(1,0);
|
||||
|
||||
vec2 prevTexCoordShift = prevShift * CONST_TEX_COORD_SCALE;
|
||||
|
||||
//Other iterations
|
||||
for (int i = 1; i <= numberOfVertices; i++)
|
||||
{
|
||||
float angle = i * 2 * pi / static_cast<float>(numberOfVertices);
|
||||
|
||||
vec2 shift = distArr[i % numberOfVertices] * vec2(cosf(angle), sinf(angle));
|
||||
|
||||
vec2 texCoordShift = shift * CONST_TEX_COORD_SCALE;
|
||||
|
||||
result.RenderPair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(vec3(pos, 0));
|
||||
result.RenderPair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(vec3(pos + prevShift, 0));
|
||||
result.RenderPair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(vec3(pos + shift, 0));
|
||||
|
||||
result.RenderPair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(vec2(0.5f, 0.5f));
|
||||
result.RenderPair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(vec2(0.5f, 0.5f) + prevTexCoordShift);
|
||||
result.RenderPair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(vec2(0.5f, 0.5f) + texCoordShift);
|
||||
|
||||
prevShift = shift;
|
||||
prevTexCoordShift = texCoordShift;
|
||||
}
|
||||
|
||||
result.RenderPair.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "asteroidTexture";
|
||||
|
||||
result.RenderPair.second.RefreshBuffer();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void TMyApplication::CreateRandomAsteroid(vec2 pos, int health)
|
||||
{
|
||||
|
||||
static const boost::random::uniform_int_distribution<> angleDistribution(0, 36);
|
||||
|
||||
float randomAngle = angleDistribution(RandomGenerator) * pi / 18.f;
|
||||
|
||||
Asteroids.push_back(CreateAsteroid(pos, vec2(cosf(randomAngle), sinf(randomAngle)), health));
|
||||
}
|
||||
|
||||
void TMyApplication::CreateAsteroidParts(vec2 pos, int newHealth)
|
||||
{
|
||||
static const boost::random::uniform_int_distribution<> CreateAsteroidParts(2, 5);
|
||||
|
||||
static const boost::random::uniform_int_distribution<> angleDistribution(0, 36);
|
||||
|
||||
float randomAngle = angleDistribution(RandomGenerator) * pi / 18.f;
|
||||
|
||||
int number = CreateAsteroidParts(RandomGenerator);
|
||||
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
float partAngle = randomAngle + i * 2 * pi / static_cast<float>(number);
|
||||
Asteroids.push_back(CreateAsteroid(pos, vec2(cosf(partAngle), sinf(partAngle)), newHealth));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
vec2 TMyApplication::NormalizePos(vec2 pos)
|
||||
{
|
||||
vec2 result = pos;
|
||||
|
||||
while (result.v[0] < 0)
|
||||
{
|
||||
result.v[0] += Renderer->GetScreenWidth();
|
||||
}
|
||||
|
||||
while (result.v[1] < 0)
|
||||
{
|
||||
result.v[1] += Renderer->GetScreenHeight();
|
||||
}
|
||||
|
||||
while (result.v[0] >= Renderer->GetScreenWidth())
|
||||
{
|
||||
result.v[0] -= Renderer->GetScreenWidth();
|
||||
}
|
||||
|
||||
while (result.v[1] >= Renderer->GetScreenHeight())
|
||||
{
|
||||
result.v[1] -= Renderer->GetScreenHeight();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void TMyApplication::RefreshPlayerPos()
|
||||
{
|
||||
Replace6PointsInTriangleList(Player.RenderPair.second.Data, 0, (-1) * CONST_PLAYER_HALF_SIZE, CONST_PLAYER_HALF_SIZE);
|
||||
|
||||
mat3 rotationMatrix = CreateZRotationMatrix(Player.Angle);
|
||||
|
||||
RotateDataTriangleList(Player.RenderPair.second.Data, rotationMatrix);
|
||||
|
||||
MoveDataTriangleList(Player.RenderPair.second.Data, vec3(Player.Pos, 0));
|
||||
|
||||
Player.RenderPair.second.RefreshBuffer();
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::AddNewLaser()
|
||||
{
|
||||
CLaserStruct laser;
|
||||
|
||||
float angle = Player.Angle;
|
||||
|
||||
laser.Dir = vec2(cosf(angle), sinf(angle));
|
||||
|
||||
laser.Pos = Player.Pos;
|
||||
|
||||
laser.RenderPair.second.Data = MakeDataTriangleList((-1) * CONST_LASER_HALF_SIZE, CONST_LASER_HALF_SIZE);
|
||||
|
||||
mat3 rotationMatrix = CreateZRotationMatrix(angle);
|
||||
|
||||
RotateDataTriangleList(laser.RenderPair.second.Data, rotationMatrix);
|
||||
|
||||
MoveDataTriangleList(laser.RenderPair.second.Data, vec3(laser.Pos, 0));
|
||||
|
||||
laser.RenderPair.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "fireTexture";
|
||||
|
||||
laser.RenderPair.second.RefreshBuffer();
|
||||
|
||||
Lasers.push_back(laser);
|
||||
}
|
||||
|
||||
void TMyApplication::UpdatePlayerPosition(float scaledTime)
|
||||
{
|
||||
|
||||
if (TapIsDown)
|
||||
{
|
||||
|
||||
vec2 dir = Normalize(LastTap - Player.Pos);
|
||||
|
||||
Player.Velocity += CONST_PLAYER_ACCELERATION * scaledTime * dir;
|
||||
|
||||
Player.Angle = acosf(DotProduct(dir, vec2(1, 0)));
|
||||
|
||||
if (dir.v[1] < 0)
|
||||
{
|
||||
Player.Angle = -Player.Angle;
|
||||
}
|
||||
}
|
||||
|
||||
Player.Pos += Player.Velocity * scaledTime;
|
||||
|
||||
|
||||
Player.Velocity *= powf(CONST_VELOCITY_FADE, clamp(scaledTime, 0.f, 1.5f));
|
||||
|
||||
Player.Pos = NormalizePos(Player.Pos);
|
||||
|
||||
RefreshPlayerPos();
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::ProcessLaserHit()
|
||||
{
|
||||
|
||||
for (auto laserItr = Lasers.begin(); laserItr != Lasers.end(); )
|
||||
{
|
||||
for (auto astItr = Asteroids.begin(); astItr != Asteroids.end(); )
|
||||
{
|
||||
|
||||
float realDistance = HealthToHitDistance(astItr->Health);
|
||||
|
||||
if (fabs(laserItr->Pos.v[0] - astItr->CenterPos.v[0]) < realDistance &&
|
||||
fabs(laserItr->Pos.v[1] - astItr->CenterPos.v[1]) < realDistance)
|
||||
{
|
||||
laserItr = Lasers.erase(laserItr);
|
||||
|
||||
if (astItr->Health > 0)
|
||||
{
|
||||
CreateAsteroidParts(astItr->CenterPos, astItr->Health - 1);
|
||||
}
|
||||
|
||||
astItr = Asteroids.erase(astItr);
|
||||
|
||||
Score += CONST_HIT_SCORE_POINTS;
|
||||
RefreshScoreText();
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (astItr != Asteroids.end())
|
||||
{
|
||||
astItr++;
|
||||
}
|
||||
}
|
||||
|
||||
if (laserItr != Lasers.end())
|
||||
{
|
||||
laserItr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::ProcessPlayerCollisions()
|
||||
{
|
||||
|
||||
for (auto astItr = Asteroids.begin(); astItr != Asteroids.end(); astItr++)
|
||||
{
|
||||
float realDistance = HealthToHitDistance(astItr->Health);
|
||||
|
||||
if (fabs(astItr->CenterPos.v[0] - Player.Pos.v[0]) < realDistance && fabs(astItr->CenterPos.v[1] - Player.Pos.v[1]) < realDistance)
|
||||
{
|
||||
GameState = GS_LOST;
|
||||
RefreshScoreText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TMyApplication::ClearUnusedLasers()
|
||||
{
|
||||
for (auto itr = Lasers.begin(); itr != Lasers.end(); )
|
||||
{
|
||||
if (itr->Pos.v[0] < 0 || itr->Pos.v[1] < 0 || itr->Pos.v[0] > Renderer->GetScreenWidth() || itr->Pos.v[1] > Renderer->GetScreenHeight())
|
||||
{
|
||||
itr = Lasers.erase(itr);
|
||||
}
|
||||
|
||||
if (itr != Lasers.end())
|
||||
{
|
||||
itr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TMyApplication::RefreshScoreText()
|
||||
{
|
||||
LevelScoreText = ResourceManager->FontManager.DrawStringToVBO(vec2(10, 20), TTextBasicAreaParams(), "Score: "+ tostr(Score));
|
||||
|
||||
if (GameState == GS_PLAY)
|
||||
{
|
||||
LevelMessageText = ResourceManager->FontManager.DrawStringToVBO(vec2(10, 300), TTextBasicAreaParams(), "Now playing "+ tostr(Level) + " level");
|
||||
}
|
||||
else if (GameState == GS_WON)
|
||||
{
|
||||
LevelMessageText = ResourceManager->FontManager.DrawStringToVBO(vec2(10, 300), TTextBasicAreaParams(), "You won! Tap on screen to start next level");
|
||||
}
|
||||
else if (GameState == GS_LOST)
|
||||
{
|
||||
LevelMessageText = ResourceManager->FontManager.DrawStringToVBO(vec2(10, 300), TTextBasicAreaParams(), "You failed! Tap on screen to restart");
|
||||
}
|
||||
}
|
137
jni/main_code.h
137
jni/main_code.h
@ -1,137 +0,0 @@
|
||||
#ifndef MAIN_CODE_H_INCLUDED
|
||||
#define MAIN_CODE_H_INCLUDED
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef TARGET_ANDROID
|
||||
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#endif
|
||||
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include "boost/thread/thread.hpp"
|
||||
#include "boost/assign.hpp"
|
||||
#include "boost/bind.hpp"
|
||||
#include "boost/asio.hpp"
|
||||
#include "boost/signal.hpp"
|
||||
#include "boost/random.hpp"
|
||||
|
||||
#include "include/Engine.h"
|
||||
|
||||
using namespace SE;
|
||||
|
||||
struct CAsteroidStruct
|
||||
{
|
||||
int Health;
|
||||
float Angle;
|
||||
float AngularVelocity;
|
||||
vec2 CenterPos;
|
||||
vec2 Velocity;
|
||||
TRenderPair RenderPair;
|
||||
};
|
||||
|
||||
struct CPlayer
|
||||
{
|
||||
vec2 Pos;
|
||||
float Angle;
|
||||
vec2 Velocity;
|
||||
TRenderPair RenderPair;
|
||||
};
|
||||
|
||||
|
||||
struct CLaserStruct
|
||||
{
|
||||
vec2 Pos;
|
||||
vec2 Dir;
|
||||
TRenderPair RenderPair;
|
||||
};
|
||||
|
||||
enum CGameState
|
||||
{
|
||||
GS_PLAY,
|
||||
GS_WON,
|
||||
GS_LOST
|
||||
};
|
||||
|
||||
class TMyApplication : public TApplication
|
||||
{
|
||||
protected:
|
||||
|
||||
//Game elements
|
||||
std::list<CAsteroidStruct> Asteroids;
|
||||
std::list<CLaserStruct> Lasers;
|
||||
CPlayer Player;
|
||||
|
||||
//Minor
|
||||
boost::random::mt19937 RandomGenerator;
|
||||
bool TapIsDown;
|
||||
vec2 LastTap;
|
||||
TSimpleTimer LaserTimer;
|
||||
|
||||
//Game score and state
|
||||
CGameState GameState;
|
||||
int Level;
|
||||
int Score;
|
||||
|
||||
//Static graphics
|
||||
TTriangleList LevelScoreText;
|
||||
TTriangleList LevelMessageText;
|
||||
TRenderPair BackgroundRenderPair;
|
||||
|
||||
|
||||
CAsteroidStruct CreateAsteroid(vec2 pos, vec2 dir, int health);
|
||||
|
||||
void CreateRandomAsteroid(vec2 pos, int health);
|
||||
|
||||
void CreateAsteroidParts(vec2 pos, int newHealth);
|
||||
|
||||
vec2 NormalizePos(vec2 pos);
|
||||
|
||||
void RefreshPlayerPos();
|
||||
|
||||
void AddNewLaser();
|
||||
void UpdatePlayerPosition(float scaledTime);
|
||||
void ProcessLaserHit();
|
||||
void ProcessPlayerCollisions();
|
||||
void ClearUnusedLasers();
|
||||
|
||||
void RefreshScoreText();
|
||||
|
||||
public:
|
||||
bool Inited;
|
||||
|
||||
TMyApplication() : TApplication(), Inited(false) { }
|
||||
|
||||
|
||||
virtual void InnerInit();
|
||||
|
||||
virtual void InnerDeinit();
|
||||
|
||||
virtual void InnerDraw();
|
||||
|
||||
virtual void InnerUpdate(cardinal dt);
|
||||
|
||||
virtual void InnerOnTapDown(vec2 p);
|
||||
|
||||
virtual void InnerOnTapUp(vec2 p);
|
||||
|
||||
virtual void InnerOnTapUpAfterMove(vec2 p);
|
||||
|
||||
virtual void InnerOnMove(vec2 shift);
|
||||
|
||||
bool IsInited() { return Inited; }
|
||||
|
||||
void InitLevel();
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB |
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">AndroidJniTemplate</string>
|
||||
</resources>
|
@ -1,73 +0,0 @@
|
||||
package fishrungames.salmonjnitemplate;
|
||||
|
||||
|
||||
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.engine.GLViewAncestor;
|
||||
import fishrungames.engine.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.Destroy();
|
||||
|
||||
JniWrapper.Init(width,height);
|
||||
}
|
||||
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config)
|
||||
{
|
||||
//Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package fishrungames.salmonjnitemplate;
|
||||
|
||||
public class JniWrapper
|
||||
{
|
||||
static {
|
||||
System.loadLibrary("SalmonJniTemplate");
|
||||
}
|
||||
|
||||
|
||||
public static native void Init(int width, int height);
|
||||
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
package fishrungames.salmonjnitemplate;
|
||||
|
||||
import fishrungames.engine.EngineWrapper;
|
||||
|
||||
//Deprecated
|
||||
//import fishrungames.androidjnitemplate.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;
|
||||
|
||||
|
||||
|
||||
public class MainActivity 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.salmonjnitemplate", 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.Destroy();
|
||||
super.onPause();
|
||||
mView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
//Don't write anything here!
|
||||
super.onResume();
|
||||
mView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
//Don't write anything here!
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
EngineWrapper.ProcessKeyDown(keyCode, event);
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
EngineWrapper.ProcessTouchEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user