Changes since migrating to GitTea.
This commit is contained in:
parent
a327ea6b82
commit
6516a139cf
24
.gitignore
vendored
24
.gitignore
vendored
@ -1,12 +1,12 @@
|
||||
.gradle
|
||||
*.apk
|
||||
output.json
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/app/build
|
||||
/app/release
|
||||
*.iml
|
||||
.gradle
|
||||
*.apk
|
||||
output.json
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/app/build
|
||||
/app/release
|
||||
*.iml
|
||||
|
@ -1,44 +1,44 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:55 PM
|
||||
*
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
signingConfigs {
|
||||
}
|
||||
compileSdkVersion 26
|
||||
defaultConfig {
|
||||
applicationId 'de.frajul.endlessroll'
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 26
|
||||
versionCode 9
|
||||
versionName '1.0'
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
flavorDimensions 'releaseTargetGroup'
|
||||
productFlavors {
|
||||
flavorStoreRelease {
|
||||
dimension 'releaseTargetGroup'
|
||||
}
|
||||
flavorTest {
|
||||
dimension 'releaseTargetGroup'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:26.1.0'
|
||||
compile 'com.google.android.gms:play-services-ads:15.0.1'
|
||||
compile files('libs/simple-xml-2.7.1.jar')
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:55 PM
|
||||
*
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
signingConfigs {
|
||||
}
|
||||
compileSdkVersion 26
|
||||
defaultConfig {
|
||||
applicationId 'de.frajul.endlessroll'
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 26
|
||||
versionCode 9
|
||||
versionName '1.0'
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
flavorDimensions 'releaseTargetGroup'
|
||||
productFlavors {
|
||||
flavorStoreRelease {
|
||||
dimension 'releaseTargetGroup'
|
||||
}
|
||||
flavorTest {
|
||||
dimension 'releaseTargetGroup'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:26.1.0'
|
||||
compile 'com.google.android.gms:play-services-ads:15.0.1'
|
||||
compile files('libs/simple-xml-2.7.1.jar')
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform float texAtlasIndex;
|
||||
|
||||
const float clampBorder = 0.005;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 clampedTexCoords = pass_TexCoords;
|
||||
if(texAtlasSize.x > 1.0 || texAtlasSize.y > 1.0)
|
||||
clampedTexCoords = clamp(pass_TexCoords, clampBorder, 1.0 - clampBorder);
|
||||
|
||||
vec2 texAtlasCoords = getTexCoordsInAtlas(clampedTexCoords, texAtlasIndex);
|
||||
gl_FragColor = texture2D(texture, texAtlasCoords);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(clampedTexCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(clampedTexCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform float texAtlasIndex;
|
||||
|
||||
const float clampBorder = 0.005;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 clampedTexCoords = pass_TexCoords;
|
||||
if(texAtlasSize.x > 1.0 || texAtlasSize.y > 1.0)
|
||||
clampedTexCoords = clamp(pass_TexCoords, clampBorder, 1.0 - clampBorder);
|
||||
|
||||
vec2 texAtlasCoords = getTexCoordsInAtlas(clampedTexCoords, texAtlasIndex);
|
||||
gl_FragColor = texture2D(texture, texAtlasCoords);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(clampedTexCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(clampedTexCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
}
|
@ -1,23 +1,23 @@
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform vec2 texCoordScaling;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
vec2 scale = vec2(1.0, 1.0);
|
||||
if(texCoordScaling.x != 0.0)
|
||||
scale.x = texCoordScaling.x;
|
||||
if(texCoordScaling.y != 0.0)
|
||||
scale.y *= texCoordScaling.y;
|
||||
|
||||
vec4 transformatedPosition = transformationMatrix * position;
|
||||
gl_Position = mvpMatrix * transformatedPosition;
|
||||
pass_TexCoords = scale * texCoords;
|
||||
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform vec2 texCoordScaling;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
vec2 scale = vec2(1.0, 1.0);
|
||||
if(texCoordScaling.x != 0.0)
|
||||
scale.x = texCoordScaling.x;
|
||||
if(texCoordScaling.y != 0.0)
|
||||
scale.y *= texCoordScaling.y;
|
||||
|
||||
vec4 transformatedPosition = transformationMatrix * position;
|
||||
gl_Position = mvpMatrix * transformatedPosition;
|
||||
pass_TexCoords = scale * texCoords;
|
||||
|
||||
}
|
@ -1,27 +1,27 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec3 color;
|
||||
uniform float alpha;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a);
|
||||
|
||||
void main() {
|
||||
|
||||
float a = texture2D(texture, pass_TexCoords).a * alpha;
|
||||
vec3 black = vec3(0.0, 0.0, 0.0);
|
||||
gl_FragColor.rgb = mix(color, black, 1.0 - a);
|
||||
gl_FragColor.a = a;
|
||||
|
||||
}
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a){
|
||||
|
||||
float grayscale = (color.r * 0.299 + color.g * 0.587 + color. b * 0.114);
|
||||
float alpha = ((1.1 - a) * 0.5) * 40.0;
|
||||
|
||||
return alpha * color + (1.0 - alpha) * vec3(grayscale, grayscale, grayscale);
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec3 color;
|
||||
uniform float alpha;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a);
|
||||
|
||||
void main() {
|
||||
|
||||
float a = texture2D(texture, pass_TexCoords).a * alpha;
|
||||
vec3 black = vec3(0.0, 0.0, 0.0);
|
||||
gl_FragColor.rgb = mix(color, black, 1.0 - a);
|
||||
gl_FragColor.a = a;
|
||||
|
||||
}
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a){
|
||||
|
||||
float grayscale = (color.r * 0.299 + color.g * 0.587 + color. b * 0.114);
|
||||
float alpha = ((1.1 - a) * 0.5) * 40.0;
|
||||
|
||||
return alpha * color + (1.0 - alpha) * vec3(grayscale, grayscale, grayscale);
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = position;
|
||||
pass_TexCoords.x = texCoords.x;
|
||||
pass_TexCoords.y = -texCoords.y;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = position;
|
||||
pass_TexCoords.x = texCoords.x;
|
||||
pass_TexCoords.y = -texCoords.y;
|
||||
|
||||
}
|
34
app/proguard-rules.pro
vendored
34
app/proguard-rules.pro
vendored
@ -1,17 +1,17 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\Julian\AppData\Local\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 *;
|
||||
#}
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\Julian\AppData\Local\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 *;
|
||||
#}
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
@ -1,36 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
~ Copyright (c) 2018. All rights reserved.
|
||||
~ Last modified 7/10/18 3:54 PM
|
||||
~
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.frajul.endlessroll">
|
||||
|
||||
<uses-feature
|
||||
android:glEsVersion="0x00020000"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".main.GameActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:screenOrientation="sensorLandscape">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
~ Copyright (c) 2018. All rights reserved.
|
||||
~ Last modified 7/10/18 3:54 PM
|
||||
~
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.frajul.endlessroll">
|
||||
|
||||
<uses-feature
|
||||
android:glEsVersion="0x00020000"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".main.GameActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:screenOrientation="sensorLandscape">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,42 +1,42 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform float texAtlasIndex;
|
||||
uniform float hasColor;
|
||||
uniform vec3 color;
|
||||
|
||||
const float clampBorder = 0.005;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 clampedTexCoords = pass_TexCoords;
|
||||
if(texAtlasSize.x > 1.0 || texAtlasSize.y > 1.0)
|
||||
clampedTexCoords = clamp(pass_TexCoords, clampBorder, 1.0 - clampBorder);
|
||||
|
||||
vec2 texAtlasCoords = getTexCoordsInAtlas(clampedTexCoords, texAtlasIndex);
|
||||
gl_FragColor = texture2D(texture, texAtlasCoords);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
if(hasColor == 1.0){
|
||||
gl_FragColor.rgb = color;
|
||||
} else {
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(clampedTexCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(clampedTexCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform float texAtlasIndex;
|
||||
uniform float hasColor;
|
||||
uniform vec3 color;
|
||||
|
||||
const float clampBorder = 0.005;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 clampedTexCoords = pass_TexCoords;
|
||||
if(texAtlasSize.x > 1.0 || texAtlasSize.y > 1.0)
|
||||
clampedTexCoords = clamp(pass_TexCoords, clampBorder, 1.0 - clampBorder);
|
||||
|
||||
vec2 texAtlasCoords = getTexCoordsInAtlas(clampedTexCoords, texAtlasIndex);
|
||||
gl_FragColor = texture2D(texture, texAtlasCoords);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
if(hasColor == 1.0){
|
||||
gl_FragColor.rgb = color;
|
||||
} else {
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 clampedTexCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(clampedTexCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(clampedTexCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
}
|
@ -1,23 +1,23 @@
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform vec2 texCoordScaling;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
vec2 scale = vec2(1.0, 1.0);
|
||||
if(texCoordScaling.x != 0.0)
|
||||
scale.x = texCoordScaling.x;
|
||||
if(texCoordScaling.y != 0.0)
|
||||
scale.y *= texCoordScaling.y;
|
||||
|
||||
vec4 transformatedPosition = transformationMatrix * position;
|
||||
gl_Position = mvpMatrix * transformatedPosition;
|
||||
pass_TexCoords = scale * texCoords;
|
||||
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform vec2 texCoordScaling;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
vec2 scale = vec2(1.0, 1.0);
|
||||
if(texCoordScaling.x != 0.0)
|
||||
scale.x = texCoordScaling.x;
|
||||
if(texCoordScaling.y != 0.0)
|
||||
scale.y *= texCoordScaling.y;
|
||||
|
||||
vec4 transformatedPosition = transformationMatrix * position;
|
||||
gl_Position = mvpMatrix * transformatedPosition;
|
||||
pass_TexCoords = scale * texCoords;
|
||||
|
||||
}
|
@ -1,53 +1,53 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float useCustomColor;
|
||||
uniform vec3 color;
|
||||
uniform float alpha;
|
||||
uniform float roundValue;
|
||||
uniform float visibleAmount;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
float isInRoundedRange();
|
||||
float isInVisiblePart();
|
||||
|
||||
void main() {
|
||||
|
||||
if(isInRoundedRange() == 1.0 && isInVisiblePart() == 1.0){
|
||||
if(useCustomColor == 1.0){
|
||||
gl_FragColor.rgb = color;
|
||||
gl_FragColor.a = alpha;
|
||||
} else {
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
}
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
} else {
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float isInRoundedRange(){
|
||||
if(roundValue == 0.0)
|
||||
return 1.0;
|
||||
float relativeX = abs((pass_TexCoords.x- 0.5));
|
||||
float relativeY = abs(pass_TexCoords.y - 0.5);
|
||||
float circleX = abs(roundValue * 0.5 - 0.5);
|
||||
float circleY = abs(roundValue * 0.5 - 0.5);
|
||||
if(relativeX < circleX || relativeY < circleY)
|
||||
return 1.0;
|
||||
float radius = roundValue * 0.5;
|
||||
float distX = relativeX - circleX;
|
||||
float distY = relativeY - circleY;
|
||||
if(distX * distX + distY * distY > radius * radius)
|
||||
return 0.0;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float isInVisiblePart(){
|
||||
if(pass_TexCoords.x >= visibleAmount)
|
||||
return 1.0;
|
||||
return 0.0;
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float useCustomColor;
|
||||
uniform vec3 color;
|
||||
uniform float alpha;
|
||||
uniform float roundValue;
|
||||
uniform float visibleAmount;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
float isInRoundedRange();
|
||||
float isInVisiblePart();
|
||||
|
||||
void main() {
|
||||
|
||||
if(isInRoundedRange() == 1.0 && isInVisiblePart() == 1.0){
|
||||
if(useCustomColor == 1.0){
|
||||
gl_FragColor.rgb = color;
|
||||
gl_FragColor.a = alpha;
|
||||
} else {
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
}
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
} else {
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float isInRoundedRange(){
|
||||
if(roundValue == 0.0)
|
||||
return 1.0;
|
||||
float relativeX = abs((pass_TexCoords.x- 0.5));
|
||||
float relativeY = abs(pass_TexCoords.y - 0.5);
|
||||
float circleX = abs(roundValue * 0.5 - 0.5);
|
||||
float circleY = abs(roundValue * 0.5 - 0.5);
|
||||
if(relativeX < circleX || relativeY < circleY)
|
||||
return 1.0;
|
||||
float radius = roundValue * 0.5;
|
||||
float distX = relativeX - circleX;
|
||||
float distY = relativeY - circleY;
|
||||
if(distX * distX + distY * distY > radius * radius)
|
||||
return 0.0;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float isInVisiblePart(){
|
||||
if(pass_TexCoords.x >= visibleAmount)
|
||||
return 1.0;
|
||||
return 0.0;
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform mat4 transformationMatrix;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
vec4 transformatedPosition = transformationMatrix * position;
|
||||
gl_Position = mvpMatrix * transformatedPosition;
|
||||
pass_TexCoords = texCoords;
|
||||
|
||||
uniform mat4 mvpMatrix;
|
||||
uniform mat4 transformationMatrix;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
vec4 transformatedPosition = transformationMatrix * position;
|
||||
gl_Position = mvpMatrix * transformatedPosition;
|
||||
pass_TexCoords = texCoords;
|
||||
|
||||
}
|
@ -1,115 +1,115 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform vec2 gridSize;
|
||||
uniform float deadly;
|
||||
uniform float floating;
|
||||
uniform float bombSelected;
|
||||
uniform float bombExplosionState;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
const float clampBorder = 0.05;
|
||||
|
||||
float itermod(in float x, in float y);
|
||||
vec2 getInGridPos();
|
||||
vec2 getTexCoordsInGridSquare();
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 gridPos = getInGridPos();
|
||||
float index = 0.0;
|
||||
|
||||
bool top = gridPos.y == 0.0;
|
||||
bool bottom = gridPos.y == gridSize.y - 1.0;
|
||||
bool left = gridPos.x == 0.0;
|
||||
bool right = gridPos.x == gridSize.x - 1.0;
|
||||
|
||||
if(top){
|
||||
if(left)
|
||||
index = 5.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else if(right)
|
||||
index = 21.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else
|
||||
index = itermod(gridPos.x, 3.0);
|
||||
if(deadly == 1.0)
|
||||
index += 8.0;
|
||||
} else if(bottom){
|
||||
if(left)
|
||||
index = 37.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else if(right)
|
||||
index = 53.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else
|
||||
index = 16.0 + itermod(gridPos.x, 3.0);
|
||||
if(floating == 1.0)
|
||||
index += 8.0;
|
||||
} else if(left){
|
||||
index = 32.0 + itermod(gridPos.y, 3.0);
|
||||
} else if(gridPos.x == gridSize.x - 1.0){
|
||||
index = 40.0 + itermod(gridPos.y, 3.0);
|
||||
} else{
|
||||
index = 48.0 + itermod(gridPos.x, 2.0) + itermod(gridPos.y, 2.0);
|
||||
}
|
||||
|
||||
vec2 texCoordsInGridSquare = getTexCoordsInGridSquare();
|
||||
texCoordsInGridSquare = clamp(texCoordsInGridSquare, clampBorder, 1.0 - clampBorder);
|
||||
vec2 texCoordsInAtlas = getTexCoordsInAtlas(texCoordsInGridSquare, index);
|
||||
gl_FragColor = texture2D(texture, texCoordsInAtlas);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
if(bombSelected == 1.0 || bombExplosionState >= 0.0){
|
||||
vec3 red = vec3(1.0, 0.0, 0.0);
|
||||
float mixValue = 0.4;
|
||||
gl_FragColor.r += 0.2 * bombExplosionState;
|
||||
gl_FragColor.rgb = mix(gl_FragColor.rgb, red, mixValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float itermod(in float x, in float y){
|
||||
|
||||
while(x - y >= 0.0){
|
||||
x -= y;
|
||||
}
|
||||
return x;
|
||||
|
||||
}
|
||||
|
||||
vec2 getInGridPos(){
|
||||
|
||||
float gridX = floor(pass_TexCoords.x * gridSize.x);
|
||||
float gridY = floor(pass_TexCoords.y * gridSize.y);
|
||||
if(pass_TexCoords.y == 1.0)
|
||||
gridY -= 1.0;
|
||||
if(pass_TexCoords.x == 1.0)
|
||||
gridX -= 1.0;
|
||||
return vec2(gridX, gridY);
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInGridSquare(){
|
||||
|
||||
float x = mod(pass_TexCoords.x, 1.0 / gridSize.x) * gridSize.x;
|
||||
float y = mod(pass_TexCoords.y, 1.0 / gridSize.y) * gridSize.y;
|
||||
if(pass_TexCoords.x == 1.0)
|
||||
x = 1.0;
|
||||
if(pass_TexCoords.y == 1.0)
|
||||
y = 1.0;
|
||||
return vec2(x, y);
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(texCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(texCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform vec2 gridSize;
|
||||
uniform float deadly;
|
||||
uniform float floating;
|
||||
uniform float bombSelected;
|
||||
uniform float bombExplosionState;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
const float clampBorder = 0.05;
|
||||
|
||||
float itermod(in float x, in float y);
|
||||
vec2 getInGridPos();
|
||||
vec2 getTexCoordsInGridSquare();
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 gridPos = getInGridPos();
|
||||
float index = 0.0;
|
||||
|
||||
bool top = gridPos.y == 0.0;
|
||||
bool bottom = gridPos.y == gridSize.y - 1.0;
|
||||
bool left = gridPos.x == 0.0;
|
||||
bool right = gridPos.x == gridSize.x - 1.0;
|
||||
|
||||
if(top){
|
||||
if(left)
|
||||
index = 5.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else if(right)
|
||||
index = 21.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else
|
||||
index = itermod(gridPos.x, 3.0);
|
||||
if(deadly == 1.0)
|
||||
index += 8.0;
|
||||
} else if(bottom){
|
||||
if(left)
|
||||
index = 37.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else if(right)
|
||||
index = 53.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else
|
||||
index = 16.0 + itermod(gridPos.x, 3.0);
|
||||
if(floating == 1.0)
|
||||
index += 8.0;
|
||||
} else if(left){
|
||||
index = 32.0 + itermod(gridPos.y, 3.0);
|
||||
} else if(gridPos.x == gridSize.x - 1.0){
|
||||
index = 40.0 + itermod(gridPos.y, 3.0);
|
||||
} else{
|
||||
index = 48.0 + itermod(gridPos.x, 2.0) + itermod(gridPos.y, 2.0);
|
||||
}
|
||||
|
||||
vec2 texCoordsInGridSquare = getTexCoordsInGridSquare();
|
||||
texCoordsInGridSquare = clamp(texCoordsInGridSquare, clampBorder, 1.0 - clampBorder);
|
||||
vec2 texCoordsInAtlas = getTexCoordsInAtlas(texCoordsInGridSquare, index);
|
||||
gl_FragColor = texture2D(texture, texCoordsInAtlas);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
if(bombSelected == 1.0 || bombExplosionState >= 0.0){
|
||||
vec3 red = vec3(1.0, 0.0, 0.0);
|
||||
float mixValue = 0.4;
|
||||
gl_FragColor.r += 0.2 * bombExplosionState;
|
||||
gl_FragColor.rgb = mix(gl_FragColor.rgb, red, mixValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float itermod(in float x, in float y){
|
||||
|
||||
while(x - y >= 0.0){
|
||||
x -= y;
|
||||
}
|
||||
return x;
|
||||
|
||||
}
|
||||
|
||||
vec2 getInGridPos(){
|
||||
|
||||
float gridX = floor(pass_TexCoords.x * gridSize.x);
|
||||
float gridY = floor(pass_TexCoords.y * gridSize.y);
|
||||
if(pass_TexCoords.y == 1.0)
|
||||
gridY -= 1.0;
|
||||
if(pass_TexCoords.x == 1.0)
|
||||
gridX -= 1.0;
|
||||
return vec2(gridX, gridY);
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInGridSquare(){
|
||||
|
||||
float x = mod(pass_TexCoords.x, 1.0 / gridSize.x) * gridSize.x;
|
||||
float y = mod(pass_TexCoords.y, 1.0 / gridSize.y) * gridSize.y;
|
||||
if(pass_TexCoords.x == 1.0)
|
||||
x = 1.0;
|
||||
if(pass_TexCoords.y == 1.0)
|
||||
y = 1.0;
|
||||
return vec2(x, y);
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(texCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(texCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
}
|
@ -1,27 +1,27 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec3 color;
|
||||
uniform float alpha;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a);
|
||||
|
||||
void main() {
|
||||
|
||||
float a = texture2D(texture, pass_TexCoords).a * alpha;
|
||||
vec3 black = vec3(0.0, 0.0, 0.0);
|
||||
gl_FragColor.rgb = mix(color, black, 1.0 - a);
|
||||
gl_FragColor.a = a;
|
||||
|
||||
}
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a){
|
||||
|
||||
float grayscale = (color.r * 0.299 + color.g * 0.587 + color. b * 0.114);
|
||||
float alpha = ((1.1 - a) * 0.5) * 40.0;
|
||||
|
||||
return alpha * color + (1.0 - alpha) * vec3(grayscale, grayscale, grayscale);
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec3 color;
|
||||
uniform float alpha;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a);
|
||||
|
||||
void main() {
|
||||
|
||||
float a = texture2D(texture, pass_TexCoords).a * alpha;
|
||||
vec3 black = vec3(0.0, 0.0, 0.0);
|
||||
gl_FragColor.rgb = mix(color, black, 1.0 - a);
|
||||
gl_FragColor.a = a;
|
||||
|
||||
}
|
||||
|
||||
vec3 saturateColor(in vec3 color, in float a){
|
||||
|
||||
float grayscale = (color.r * 0.299 + color.g * 0.587 + color. b * 0.114);
|
||||
float alpha = ((1.1 - a) * 0.5) * 40.0;
|
||||
|
||||
return alpha * color + (1.0 - alpha) * vec3(grayscale, grayscale, grayscale);
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = position;
|
||||
pass_TexCoords.x = texCoords.x;
|
||||
pass_TexCoords.y = -texCoords.y;
|
||||
|
||||
attribute vec4 position;
|
||||
attribute vec2 texCoords;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = position;
|
||||
pass_TexCoords.x = texCoords.x;
|
||||
pass_TexCoords.y = -texCoords.y;
|
||||
|
||||
}
|
@ -1,46 +1,46 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float gridColumnCount;
|
||||
uniform float isEndlessTileList;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
const float texAtlasWidth = 3.0;
|
||||
|
||||
float getAtlasIndex();
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoordsInGrid, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
float atlasIndex = getAtlasIndex();
|
||||
vec2 texCoordsInGrid = pass_TexCoords;
|
||||
texCoordsInGrid.x *= gridColumnCount;
|
||||
texCoordsInGrid.x = mod(texCoordsInGrid.x, 1.0);
|
||||
vec2 texCoordsInAtlas = getTexCoordsInAtlas(texCoordsInGrid, atlasIndex);
|
||||
|
||||
gl_FragColor = texture2D(texture, texCoordsInAtlas);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
}
|
||||
|
||||
float getAtlasIndex(){
|
||||
|
||||
if(isEndlessTileList == 1.0)
|
||||
return 1.0;
|
||||
|
||||
if(pass_TexCoords.x < 1.0 / gridColumnCount)
|
||||
return 0.0;
|
||||
if(pass_TexCoords.x > 1.0 - 1.0 / gridColumnCount)
|
||||
return 2.0;
|
||||
return 1.0;
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoordsInGrid, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, texCoordsInGrid.y);
|
||||
texAtlasCoords.x = texCoordsInGrid.x / texAtlasWidth;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasWidth) / texAtlasWidth;
|
||||
return texAtlasCoords;
|
||||
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float gridColumnCount;
|
||||
uniform float isEndlessTileList;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
const float texAtlasWidth = 3.0;
|
||||
|
||||
float getAtlasIndex();
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoordsInGrid, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
float atlasIndex = getAtlasIndex();
|
||||
vec2 texCoordsInGrid = pass_TexCoords;
|
||||
texCoordsInGrid.x *= gridColumnCount;
|
||||
texCoordsInGrid.x = mod(texCoordsInGrid.x, 1.0);
|
||||
vec2 texCoordsInAtlas = getTexCoordsInAtlas(texCoordsInGrid, atlasIndex);
|
||||
|
||||
gl_FragColor = texture2D(texture, texCoordsInAtlas);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
}
|
||||
|
||||
float getAtlasIndex(){
|
||||
|
||||
if(isEndlessTileList == 1.0)
|
||||
return 1.0;
|
||||
|
||||
if(pass_TexCoords.x < 1.0 / gridColumnCount)
|
||||
return 0.0;
|
||||
if(pass_TexCoords.x > 1.0 - 1.0 / gridColumnCount)
|
||||
return 2.0;
|
||||
return 1.0;
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoordsInGrid, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, texCoordsInGrid.y);
|
||||
texAtlasCoords.x = texCoordsInGrid.x / texAtlasWidth;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasWidth) / texAtlasWidth;
|
||||
return texAtlasCoords;
|
||||
|
||||
}
|
@ -1,74 +1,74 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Color3f {
|
||||
|
||||
private float r, g, b;
|
||||
|
||||
public Color3f() {
|
||||
}
|
||||
|
||||
public Color3f(float r, float g, float b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public Color3f(Color3f other) {
|
||||
this.r = other.getR();
|
||||
this.g = other.getG();
|
||||
this.b = other.getB();
|
||||
}
|
||||
|
||||
public Color3f interpolate(float leftValue, float rightValue, Color3f color2) {
|
||||
float r = this.r + (color2.r - this.r) * leftValue;
|
||||
float g = this.g + (color2.g - this.g) * leftValue;
|
||||
float b = this.b + (color2.b - this.b) * leftValue;
|
||||
return new Color3f(r, g, b);
|
||||
}
|
||||
|
||||
private void mul(float a) {
|
||||
r *= a;
|
||||
g *= a;
|
||||
b *= a;
|
||||
}
|
||||
|
||||
private void add(Color3f other) {
|
||||
r += other.getR();
|
||||
g += other.getG();
|
||||
b += other.getB();
|
||||
}
|
||||
|
||||
public float getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public void setR(float r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public float getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(float g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
public float getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(float b) {
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Color3f {
|
||||
|
||||
private float r, g, b;
|
||||
|
||||
public Color3f() {
|
||||
}
|
||||
|
||||
public Color3f(float r, float g, float b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public Color3f(Color3f other) {
|
||||
this.r = other.getR();
|
||||
this.g = other.getG();
|
||||
this.b = other.getB();
|
||||
}
|
||||
|
||||
public Color3f interpolate(float leftValue, float rightValue, Color3f color2) {
|
||||
float r = this.r + (color2.r - this.r) * leftValue;
|
||||
float g = this.g + (color2.g - this.g) * leftValue;
|
||||
float b = this.b + (color2.b - this.b) * leftValue;
|
||||
return new Color3f(r, g, b);
|
||||
}
|
||||
|
||||
private void mul(float a) {
|
||||
r *= a;
|
||||
g *= a;
|
||||
b *= a;
|
||||
}
|
||||
|
||||
private void add(Color3f other) {
|
||||
r += other.getR();
|
||||
g += other.getG();
|
||||
b += other.getB();
|
||||
}
|
||||
|
||||
public float getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public void setR(float r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public float getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(float g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
public float getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(float b) {
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +1,65 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Color4f {
|
||||
|
||||
private float r, g, b, a;
|
||||
|
||||
public Color4f() {
|
||||
}
|
||||
|
||||
public Color4f(float r, float g, float b, float a) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public Color4f(Color4f other) {
|
||||
this.r = other.getR();
|
||||
this.g = other.getG();
|
||||
this.b = other.getB();
|
||||
this.a = other.getA();
|
||||
}
|
||||
|
||||
public float getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public void setR(float r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public float getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(float g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
public float getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(float b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public float getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(float a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Color4f {
|
||||
|
||||
private float r, g, b, a;
|
||||
|
||||
public Color4f() {
|
||||
}
|
||||
|
||||
public Color4f(float r, float g, float b, float a) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public Color4f(Color4f other) {
|
||||
this.r = other.getR();
|
||||
this.g = other.getG();
|
||||
this.b = other.getB();
|
||||
this.a = other.getA();
|
||||
}
|
||||
|
||||
public float getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public void setR(float r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public float getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(float g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
public float getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(float b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public float getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(float a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
@ -1,154 +1,154 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.11.2016.
|
||||
*/
|
||||
|
||||
public class SynchronizedArrayList<E> extends ArrayList<E> {
|
||||
|
||||
@Override
|
||||
public synchronized String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean add(E object) {
|
||||
return super.add(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(int index, E object) {
|
||||
super.add(index, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean addAll(Collection<? extends E> collection) {
|
||||
return super.addAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean addAll(int index, Collection<? extends E> collection) {
|
||||
return super.addAll(index, collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object clone() {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void ensureCapacity(int minimumCapacity) {
|
||||
super.ensureCapacity(minimumCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized E get(int index) {
|
||||
return super.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int size() {
|
||||
return super.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isEmpty() {
|
||||
return super.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean contains(Object object) {
|
||||
return super.contains(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int indexOf(Object object) {
|
||||
return super.indexOf(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int lastIndexOf(Object object) {
|
||||
return super.lastIndexOf(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized E remove(int index) {
|
||||
return super.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean remove(Object object) {
|
||||
return super.remove(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void removeRange(int fromIndex, int toIndex) {
|
||||
super.removeRange(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized E set(int index, E object) {
|
||||
return super.set(index, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object[] toArray() {
|
||||
return super.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized <T> T[] toArray(T[] contents) {
|
||||
return super.toArray(contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void trimToSize() {
|
||||
super.trimToSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<E> subList(int start, int end) {
|
||||
return super.subList(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean containsAll(Collection<?> collection) {
|
||||
return super.containsAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAll(Collection<?> collection) {
|
||||
return super.removeAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean retainAll(Collection<?> collection) {
|
||||
return super.retainAll(collection);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.11.2016.
|
||||
*/
|
||||
|
||||
public class SynchronizedArrayList<E> extends ArrayList<E> {
|
||||
|
||||
@Override
|
||||
public synchronized String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean add(E object) {
|
||||
return super.add(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(int index, E object) {
|
||||
super.add(index, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean addAll(Collection<? extends E> collection) {
|
||||
return super.addAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean addAll(int index, Collection<? extends E> collection) {
|
||||
return super.addAll(index, collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object clone() {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void ensureCapacity(int minimumCapacity) {
|
||||
super.ensureCapacity(minimumCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized E get(int index) {
|
||||
return super.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int size() {
|
||||
return super.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isEmpty() {
|
||||
return super.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean contains(Object object) {
|
||||
return super.contains(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int indexOf(Object object) {
|
||||
return super.indexOf(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int lastIndexOf(Object object) {
|
||||
return super.lastIndexOf(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized E remove(int index) {
|
||||
return super.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean remove(Object object) {
|
||||
return super.remove(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void removeRange(int fromIndex, int toIndex) {
|
||||
super.removeRange(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized E set(int index, E object) {
|
||||
return super.set(index, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object[] toArray() {
|
||||
return super.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized <T> T[] toArray(T[] contents) {
|
||||
return super.toArray(contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void trimToSize() {
|
||||
super.trimToSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<E> subList(int start, int end) {
|
||||
return super.subList(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean containsAll(Collection<?> collection) {
|
||||
return super.containsAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAll(Collection<?> collection) {
|
||||
return super.removeAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean retainAll(Collection<?> collection) {
|
||||
return super.retainAll(collection);
|
||||
}
|
||||
}
|
||||
|
@ -1,113 +1,113 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Vector {
|
||||
|
||||
public float x, y;
|
||||
|
||||
public Vector() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Vector(Vector other) {
|
||||
this(other.x, other.y);
|
||||
}
|
||||
|
||||
public Vector(float x, float y) {
|
||||
set(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector(" + x + ", " + y + ")";
|
||||
}
|
||||
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float length() {
|
||||
return (float) Math.sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
public Vector normalize() {
|
||||
float length = this.length();
|
||||
x /= length;
|
||||
y /= length;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector translate(Vector other) {
|
||||
this.x += other.x;
|
||||
this.y += other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector translate(float x, float y) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector abs() {
|
||||
this.x = Math.abs(x);
|
||||
this.y = Math.abs(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector mul(float z) {
|
||||
x *= z;
|
||||
y *= z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector mul(Vector other) {
|
||||
this.x *= other.x;
|
||||
this.y *= other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector mul(float x, float y) {
|
||||
this.x *= x;
|
||||
this.y *= y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector negate() {
|
||||
this.x *= -1;
|
||||
this.y *= -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector vectorTo(Vector other) {
|
||||
float x = other.x - this.x;
|
||||
float y = other.y - this.y;
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.data;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Vector {
|
||||
|
||||
public float x, y;
|
||||
|
||||
public Vector() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Vector(Vector other) {
|
||||
this(other.x, other.y);
|
||||
}
|
||||
|
||||
public Vector(float x, float y) {
|
||||
set(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector(" + x + ", " + y + ")";
|
||||
}
|
||||
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float length() {
|
||||
return (float) Math.sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
public Vector normalize() {
|
||||
float length = this.length();
|
||||
x /= length;
|
||||
y /= length;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector translate(Vector other) {
|
||||
this.x += other.x;
|
||||
this.y += other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector translate(float x, float y) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector abs() {
|
||||
this.x = Math.abs(x);
|
||||
this.y = Math.abs(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector mul(float z) {
|
||||
x *= z;
|
||||
y *= z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector mul(Vector other) {
|
||||
this.x *= other.x;
|
||||
this.y *= other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector mul(float x, float y) {
|
||||
this.x *= x;
|
||||
this.y *= y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector negate() {
|
||||
this.x *= -1;
|
||||
this.y *= -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector vectorTo(Vector other) {
|
||||
float x = other.x - this.x;
|
||||
float y = other.y - this.y;
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.02.2017.
|
||||
*/
|
||||
|
||||
public class AnimatedEntity extends Entity {
|
||||
|
||||
protected Animation animation;
|
||||
|
||||
public AnimatedEntity(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
animation = new Animation();
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
animation.update(timer);
|
||||
super.setTextureAtlasIndex(animation.getCurrentTexIndex());
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.02.2017.
|
||||
*/
|
||||
|
||||
public class AnimatedEntity extends Entity {
|
||||
|
||||
protected Animation animation;
|
||||
|
||||
public AnimatedEntity(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
animation = new Animation();
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
animation.update(timer);
|
||||
super.setTextureAtlasIndex(animation.getCurrentTexIndex());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 14.12.2015.
|
||||
*/
|
||||
public class Animation {
|
||||
|
||||
private int[] indexSequence = {0, 1, 2, 3};
|
||||
private boolean looping = false;
|
||||
private int requiredDelta = 110;
|
||||
|
||||
private int indexPointer = 0;
|
||||
private boolean stillRunning = true;
|
||||
private long lastSwitchTime = -1;
|
||||
|
||||
public void disable() {
|
||||
stillRunning = false;
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
if (lastSwitchTime == -1) {
|
||||
lastSwitchTime = timer.getCurrentTime();
|
||||
return;
|
||||
}
|
||||
if (stillRunning) {
|
||||
long delta = timer.getCurrentTime() - lastSwitchTime;
|
||||
if (delta >= requiredDelta) {
|
||||
lastSwitchTime = timer.getCurrentTime();
|
||||
indexPointer++;
|
||||
if (!looping && indexPointer == indexSequence.length - 1)
|
||||
stillRunning = false;
|
||||
if (looping && indexPointer == indexSequence.length)
|
||||
indexPointer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentTexIndex() {
|
||||
return indexSequence[indexPointer];
|
||||
}
|
||||
|
||||
public void setIndexSequence(int[] indexSequence) {
|
||||
this.indexSequence = indexSequence;
|
||||
}
|
||||
|
||||
public void setRequiredDelta(int requiredDelta) {
|
||||
this.requiredDelta = requiredDelta;
|
||||
}
|
||||
|
||||
public void setLooping(boolean looping) {
|
||||
this.looping = looping;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 14.12.2015.
|
||||
*/
|
||||
public class Animation {
|
||||
|
||||
private int[] indexSequence = {0, 1, 2, 3};
|
||||
private boolean looping = false;
|
||||
private int requiredDelta = 110;
|
||||
|
||||
private int indexPointer = 0;
|
||||
private boolean stillRunning = true;
|
||||
private long lastSwitchTime = -1;
|
||||
|
||||
public void disable() {
|
||||
stillRunning = false;
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
if (lastSwitchTime == -1) {
|
||||
lastSwitchTime = timer.getCurrentTime();
|
||||
return;
|
||||
}
|
||||
if (stillRunning) {
|
||||
long delta = timer.getCurrentTime() - lastSwitchTime;
|
||||
if (delta >= requiredDelta) {
|
||||
lastSwitchTime = timer.getCurrentTime();
|
||||
indexPointer++;
|
||||
if (!looping && indexPointer == indexSequence.length - 1)
|
||||
stillRunning = false;
|
||||
if (looping && indexPointer == indexSequence.length)
|
||||
indexPointer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentTexIndex() {
|
||||
return indexSequence[indexPointer];
|
||||
}
|
||||
|
||||
public void setIndexSequence(int[] indexSequence) {
|
||||
this.indexSequence = indexSequence;
|
||||
}
|
||||
|
||||
public void setRequiredDelta(int requiredDelta) {
|
||||
this.requiredDelta = requiredDelta;
|
||||
}
|
||||
|
||||
public void setLooping(boolean looping) {
|
||||
this.looping = looping;
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.07.2016.
|
||||
*/
|
||||
public class Background {
|
||||
|
||||
private List<BackgroundLayer> layers = Collections
|
||||
.synchronizedList(new ArrayList<BackgroundLayer>());
|
||||
|
||||
public Background(List<Texture> textures) {
|
||||
changeTextures(textures);
|
||||
}
|
||||
|
||||
public void changeTextures(List<Texture> textures) {
|
||||
layers.clear();
|
||||
for (int i = 0; i < textures.size(); i++) {
|
||||
Texture texture = textures.get(i);
|
||||
float speed = (float) Math.pow(0.95f, Math.pow(i + 1, Math.sqrt(i + 1)));
|
||||
layers.add(new BackgroundLayer(texture, speed));
|
||||
}
|
||||
}
|
||||
|
||||
public void move(float playerMoveX, float cameraX) {
|
||||
synchronized (layers) {
|
||||
for (BackgroundLayer layer : layers) {
|
||||
layer.move(playerMoveX, cameraX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
synchronized (layers) {
|
||||
for (BackgroundLayer layer : layers)
|
||||
layer.resetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public List<BackgroundLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.07.2016.
|
||||
*/
|
||||
public class Background {
|
||||
|
||||
private List<BackgroundLayer> layers = Collections
|
||||
.synchronizedList(new ArrayList<BackgroundLayer>());
|
||||
|
||||
public Background(List<Texture> textures) {
|
||||
changeTextures(textures);
|
||||
}
|
||||
|
||||
public void changeTextures(List<Texture> textures) {
|
||||
layers.clear();
|
||||
for (int i = 0; i < textures.size(); i++) {
|
||||
Texture texture = textures.get(i);
|
||||
float speed = (float) Math.pow(0.95f, Math.pow(i + 1, Math.sqrt(i + 1)));
|
||||
layers.add(new BackgroundLayer(texture, speed));
|
||||
}
|
||||
}
|
||||
|
||||
public void move(float playerMoveX, float cameraX) {
|
||||
synchronized (layers) {
|
||||
for (BackgroundLayer layer : layers) {
|
||||
layer.move(playerMoveX, cameraX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
synchronized (layers) {
|
||||
for (BackgroundLayer layer : layers)
|
||||
layer.resetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public List<BackgroundLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.SynchronizedArrayList;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class BackgroundLayer extends SynchronizedArrayList<Entity> {
|
||||
|
||||
private final float PART_WIDTH = 5;
|
||||
private final float HALF_PART_WIDTH = PART_WIDTH / 2f;
|
||||
private final float HEIGHT = 2.5f;
|
||||
private Texture texture;
|
||||
private float speed;
|
||||
|
||||
public BackgroundLayer(Texture texture, float speed) {
|
||||
this.texture = texture;
|
||||
this.speed = speed;
|
||||
super.add(createPart(-HALF_PART_WIDTH));
|
||||
}
|
||||
|
||||
private Entity createPart(float xLeftEdge) {
|
||||
return new Entity(texture, new Vector(xLeftEdge + HALF_PART_WIDTH, (HEIGHT - 2) / 2), PART_WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
public void move(float playerMovX, float cameraX) {
|
||||
Vector movement = new Vector(playerMovX * speed, 0);
|
||||
synchronized (this) {
|
||||
for (Entity part : this)
|
||||
part.move(movement);
|
||||
}
|
||||
if (!super.isEmpty()) {
|
||||
Entity last = super.get(super.size() - 1);
|
||||
if (last.getRightEdge() - cameraX < 3) {
|
||||
super.add(createPart(last.getRightEdge() - 0.001f));
|
||||
}
|
||||
if (super.get(0).getRightEdge() - cameraX < -3) {
|
||||
super.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
super.clear();
|
||||
super.add(createPart(-HALF_PART_WIDTH));
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.SynchronizedArrayList;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class BackgroundLayer extends SynchronizedArrayList<Entity> {
|
||||
|
||||
private final float PART_WIDTH = 5;
|
||||
private final float HALF_PART_WIDTH = PART_WIDTH / 2f;
|
||||
private final float HEIGHT = 2.5f;
|
||||
private Texture texture;
|
||||
private float speed;
|
||||
|
||||
public BackgroundLayer(Texture texture, float speed) {
|
||||
this.texture = texture;
|
||||
this.speed = speed;
|
||||
super.add(createPart(-HALF_PART_WIDTH));
|
||||
}
|
||||
|
||||
private Entity createPart(float xLeftEdge) {
|
||||
return new Entity(texture, new Vector(xLeftEdge + HALF_PART_WIDTH, (HEIGHT - 2) / 2), PART_WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
public void move(float playerMovX, float cameraX) {
|
||||
Vector movement = new Vector(playerMovX * speed, 0);
|
||||
synchronized (this) {
|
||||
for (Entity part : this)
|
||||
part.move(movement);
|
||||
}
|
||||
if (!super.isEmpty()) {
|
||||
Entity last = super.get(super.size() - 1);
|
||||
if (last.getRightEdge() - cameraX < 3) {
|
||||
super.add(createPart(last.getRightEdge() - 0.001f));
|
||||
}
|
||||
if (super.get(0).getRightEdge() - cameraX < -3) {
|
||||
super.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
super.clear();
|
||||
super.add(createPart(-HALF_PART_WIDTH));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleEffect;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.03.2016.
|
||||
*/
|
||||
public enum DestroyEffect {
|
||||
|
||||
EXPLOSION, STAR_EXPLOSION, ENERGY_COLLECT, NONE;
|
||||
|
||||
@Nullable
|
||||
public ParticleSource createEffect(ParticleSystem system, Vector position, Vector size) {
|
||||
if (this == NONE)
|
||||
return null;
|
||||
ParticleSource source = new ParticleSource(position, getEffect(system));
|
||||
source.setSpawnSize(size);
|
||||
return source;
|
||||
}
|
||||
|
||||
private ParticleEffect getEffect(ParticleSystem system) {
|
||||
switch (this) {
|
||||
case EXPLOSION:
|
||||
return system.explosion;
|
||||
case STAR_EXPLOSION:
|
||||
return system.starCollect;
|
||||
case ENERGY_COLLECT:
|
||||
return system.energyCollect;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleEffect;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.03.2016.
|
||||
*/
|
||||
public enum DestroyEffect {
|
||||
|
||||
EXPLOSION, STAR_EXPLOSION, ENERGY_COLLECT, NONE;
|
||||
|
||||
@Nullable
|
||||
public ParticleSource createEffect(ParticleSystem system, Vector position, Vector size) {
|
||||
if (this == NONE)
|
||||
return null;
|
||||
ParticleSource source = new ParticleSource(position, getEffect(system));
|
||||
source.setSpawnSize(size);
|
||||
return source;
|
||||
}
|
||||
|
||||
private ParticleEffect getEffect(ParticleSystem system) {
|
||||
switch (this) {
|
||||
case EXPLOSION:
|
||||
return system.explosion;
|
||||
case STAR_EXPLOSION:
|
||||
return system.starCollect;
|
||||
case ENERGY_COLLECT:
|
||||
return system.energyCollect;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,138 +1,138 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Quad;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.11.2015.
|
||||
*/
|
||||
public class Entity extends Quad {
|
||||
|
||||
private int textureAtlasIndex;
|
||||
private Texture texture;
|
||||
private Vector movement;
|
||||
private float rotation;
|
||||
private float alpha = 1.0f;
|
||||
private boolean destroyed;
|
||||
private DestroyEffect destroyEffect;
|
||||
private Vector maxTexSize;
|
||||
private boolean visible = true;
|
||||
private Color3f color = null;
|
||||
|
||||
public Entity(Texture texture, Vector position, float width, float height) {
|
||||
super(position, width, height);
|
||||
this.texture = texture;
|
||||
this.movement = new Vector();
|
||||
this.maxTexSize = new Vector();
|
||||
}
|
||||
|
||||
public void move(Vector movement) {
|
||||
position.translate(movement);
|
||||
}
|
||||
|
||||
public void rotate(float factor) {
|
||||
rotation += factor;
|
||||
}
|
||||
|
||||
public void setToTerrain(float terrainEdge) {
|
||||
position.y = terrainEdge + height / 2;
|
||||
}
|
||||
|
||||
public void setTopEdge(float y) {
|
||||
position.y = y - height / 2;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public Vector getMovement() {
|
||||
return movement;
|
||||
}
|
||||
|
||||
public void setMovement(Vector movement) {
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void destroy(DestroyEffect destroyEffect) {
|
||||
this.destroyed = true;
|
||||
this.destroyEffect = destroyEffect;
|
||||
}
|
||||
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
public DestroyEffect getDestroyEffect() {
|
||||
return destroyEffect;
|
||||
}
|
||||
|
||||
public void setTextureAtlasIndex(int textureAtlasIndex) {
|
||||
this.textureAtlasIndex = textureAtlasIndex;
|
||||
}
|
||||
|
||||
public int getTextureAtlasIndex() {
|
||||
return textureAtlasIndex;
|
||||
}
|
||||
|
||||
public void setMaxTexSize(Vector maxTexSize) {
|
||||
this.maxTexSize = maxTexSize;
|
||||
}
|
||||
|
||||
public Vector getMaxTexSize() {
|
||||
return maxTexSize;
|
||||
}
|
||||
|
||||
public float calcTexScaleX() {
|
||||
return getMaxTexSize().x == 0 ? 1 : getWidth() / getMaxTexSize().x;
|
||||
}
|
||||
|
||||
public float calcTexScaleY() {
|
||||
return getMaxTexSize().y == 0 ? 1 : getHeight() / getMaxTexSize().y;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setColor(Color3f color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color3f getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Quad;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.11.2015.
|
||||
*/
|
||||
public class Entity extends Quad {
|
||||
|
||||
private int textureAtlasIndex;
|
||||
private Texture texture;
|
||||
private Vector movement;
|
||||
private float rotation;
|
||||
private float alpha = 1.0f;
|
||||
private boolean destroyed;
|
||||
private DestroyEffect destroyEffect;
|
||||
private Vector maxTexSize;
|
||||
private boolean visible = true;
|
||||
private Color3f color = null;
|
||||
|
||||
public Entity(Texture texture, Vector position, float width, float height) {
|
||||
super(position, width, height);
|
||||
this.texture = texture;
|
||||
this.movement = new Vector();
|
||||
this.maxTexSize = new Vector();
|
||||
}
|
||||
|
||||
public void move(Vector movement) {
|
||||
position.translate(movement);
|
||||
}
|
||||
|
||||
public void rotate(float factor) {
|
||||
rotation += factor;
|
||||
}
|
||||
|
||||
public void setToTerrain(float terrainEdge) {
|
||||
position.y = terrainEdge + height / 2;
|
||||
}
|
||||
|
||||
public void setTopEdge(float y) {
|
||||
position.y = y - height / 2;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public Vector getMovement() {
|
||||
return movement;
|
||||
}
|
||||
|
||||
public void setMovement(Vector movement) {
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(float rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void destroy(DestroyEffect destroyEffect) {
|
||||
this.destroyed = true;
|
||||
this.destroyEffect = destroyEffect;
|
||||
}
|
||||
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
public DestroyEffect getDestroyEffect() {
|
||||
return destroyEffect;
|
||||
}
|
||||
|
||||
public void setTextureAtlasIndex(int textureAtlasIndex) {
|
||||
this.textureAtlasIndex = textureAtlasIndex;
|
||||
}
|
||||
|
||||
public int getTextureAtlasIndex() {
|
||||
return textureAtlasIndex;
|
||||
}
|
||||
|
||||
public void setMaxTexSize(Vector maxTexSize) {
|
||||
this.maxTexSize = maxTexSize;
|
||||
}
|
||||
|
||||
public Vector getMaxTexSize() {
|
||||
return maxTexSize;
|
||||
}
|
||||
|
||||
public float calcTexScaleX() {
|
||||
return getMaxTexSize().x == 0 ? 1 : getWidth() / getMaxTexSize().x;
|
||||
}
|
||||
|
||||
public float calcTexScaleY() {
|
||||
return getMaxTexSize().y == 0 ? 1 : getHeight() / getMaxTexSize().y;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setColor(Color3f color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color3f getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class Goal extends Entity {
|
||||
|
||||
public Goal(Texture texture) {
|
||||
super(texture, new Vector(), 0.1f, 3);
|
||||
super.getMaxTexSize().setY(0.2f);
|
||||
}
|
||||
|
||||
public void setGoalX(float goalX) {
|
||||
super.setPosition(new Vector(goalX - 0.05f, 0));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class Goal extends Entity {
|
||||
|
||||
public Goal(Texture texture) {
|
||||
super(texture, new Vector(), 0.1f, 3);
|
||||
super.getMaxTexSize().setY(0.2f);
|
||||
}
|
||||
|
||||
public void setGoalX(float goalX) {
|
||||
super.setPosition(new Vector(goalX - 0.05f, 0));
|
||||
}
|
||||
}
|
||||
|
@ -1,118 +1,118 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.levels.MoveComponent;
|
||||
import de.frajul.endlessroll.levels.ObstacleData;
|
||||
import de.frajul.endlessroll.levels.worlds.World;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.11.2015.
|
||||
*/
|
||||
public class Obstacle extends Entity {
|
||||
|
||||
private boolean deadly;
|
||||
private boolean floating;
|
||||
private boolean moving;
|
||||
private final float GRID_SQUARE_SIZE = 0.1f;
|
||||
private Vector gridSize;
|
||||
private MoveComponent moveComponent;
|
||||
private float movementMultiplier = 1.0f;
|
||||
|
||||
private float moveProgress;
|
||||
private float moveDirection;
|
||||
|
||||
private int bombExplosionState = -1;
|
||||
|
||||
public Obstacle(World world, ObstacleData data, float terrainEdge, Player player) {
|
||||
super(world.getObstacleTexture(), new Vector(data.getX(), data.getY()), data.getWidth(),
|
||||
data.getHeight());
|
||||
this.deadly = data.isDeadly();
|
||||
this.floating = data.isFloating();
|
||||
this.moving = data.isMoving();
|
||||
this.moveComponent = data.getMoveComponent();
|
||||
if (!floating)
|
||||
super.setToTerrain(terrainEdge);
|
||||
if (moveComponent != null && moving) {
|
||||
moveComponent.init(super.getPosition());
|
||||
moveDirection = moveComponent.getDirection();
|
||||
moveProgress = moveComponent.getStartOffset();
|
||||
//Constant player speed assumed
|
||||
float triggerX = super.getPosition().getX() - super.getWidth() / 2 - moveComponent
|
||||
.getTriggerDistance();
|
||||
float timeTillPlayerReachesTrigger = player.getSpeed() * (triggerX - player
|
||||
.getRightEdge());
|
||||
moveDirection *= -1;
|
||||
moveWithMoveComponent(timeTillPlayerReachesTrigger * 1000 * 1000, player.getSpeed());
|
||||
moveDirection *= -1;
|
||||
}
|
||||
gridSize = calcGridSize();
|
||||
}
|
||||
|
||||
private Vector calcGridSize() {
|
||||
int gridWidth = (int) (width / GRID_SQUARE_SIZE);
|
||||
int gridHeight = (int) (height / GRID_SQUARE_SIZE);
|
||||
gridWidth = Math.max(gridWidth, 2);
|
||||
gridHeight = Math.max(gridHeight, 2);
|
||||
return new Vector(gridWidth, gridHeight);
|
||||
}
|
||||
|
||||
public void slowMovementForOneFrame(float value) {
|
||||
movementMultiplier *= value;
|
||||
}
|
||||
|
||||
public void moveWithMoveComponent(float frameTime, float playerSpeed) {
|
||||
if (moveComponent.isHasPlayerXSpeed()) {
|
||||
moveComponent.calcSpeedForPlayerSpeed(playerSpeed);
|
||||
}
|
||||
float distance = frameTime * moveComponent
|
||||
.getSpeed() * moveComponent.TRANSITION_VALUE * movementMultiplier;
|
||||
float newProgress = moveDirection * distance / moveComponent.getLength();
|
||||
moveProgress += newProgress;
|
||||
if (moveProgress < 0) {
|
||||
moveProgress *= -1;
|
||||
moveDirection *= -1;
|
||||
}
|
||||
while (moveProgress > 1) {
|
||||
moveProgress -= 2;
|
||||
if (moveProgress < 0) {
|
||||
moveProgress *= -1;
|
||||
moveDirection *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
super.setPosition(moveComponent.getPositionForProgress(moveProgress));
|
||||
super.setMovement(moveComponent.getMovementVector(moveDirection));
|
||||
movementMultiplier = 1.0f;
|
||||
}
|
||||
|
||||
public boolean isMoving() {
|
||||
return moving;
|
||||
}
|
||||
|
||||
public boolean isDeadly() {
|
||||
return deadly;
|
||||
}
|
||||
|
||||
public boolean isFloating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
public Vector getGridSize() {
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
public int getBombExplosionState() {
|
||||
return bombExplosionState;
|
||||
}
|
||||
|
||||
public void setBombExplosionState(int bombExplosionState) {
|
||||
this.bombExplosionState = bombExplosionState;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.levels.MoveComponent;
|
||||
import de.frajul.endlessroll.levels.ObstacleData;
|
||||
import de.frajul.endlessroll.levels.worlds.World;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.11.2015.
|
||||
*/
|
||||
public class Obstacle extends Entity {
|
||||
|
||||
private boolean deadly;
|
||||
private boolean floating;
|
||||
private boolean moving;
|
||||
private final float GRID_SQUARE_SIZE = 0.1f;
|
||||
private Vector gridSize;
|
||||
private MoveComponent moveComponent;
|
||||
private float movementMultiplier = 1.0f;
|
||||
|
||||
private float moveProgress;
|
||||
private float moveDirection;
|
||||
|
||||
private int bombExplosionState = -1;
|
||||
|
||||
public Obstacle(World world, ObstacleData data, float terrainEdge, Player player) {
|
||||
super(world.getObstacleTexture(), new Vector(data.getX(), data.getY()), data.getWidth(),
|
||||
data.getHeight());
|
||||
this.deadly = data.isDeadly();
|
||||
this.floating = data.isFloating();
|
||||
this.moving = data.isMoving();
|
||||
this.moveComponent = data.getMoveComponent();
|
||||
if (!floating)
|
||||
super.setToTerrain(terrainEdge);
|
||||
if (moveComponent != null && moving) {
|
||||
moveComponent.init(super.getPosition());
|
||||
moveDirection = moveComponent.getDirection();
|
||||
moveProgress = moveComponent.getStartOffset();
|
||||
//Constant player speed assumed
|
||||
float triggerX = super.getPosition().getX() - super.getWidth() / 2 - moveComponent
|
||||
.getTriggerDistance();
|
||||
float timeTillPlayerReachesTrigger = player.getSpeed() * (triggerX - player
|
||||
.getRightEdge());
|
||||
moveDirection *= -1;
|
||||
moveWithMoveComponent(timeTillPlayerReachesTrigger * 1000 * 1000, player.getSpeed());
|
||||
moveDirection *= -1;
|
||||
}
|
||||
gridSize = calcGridSize();
|
||||
}
|
||||
|
||||
private Vector calcGridSize() {
|
||||
int gridWidth = (int) (width / GRID_SQUARE_SIZE);
|
||||
int gridHeight = (int) (height / GRID_SQUARE_SIZE);
|
||||
gridWidth = Math.max(gridWidth, 2);
|
||||
gridHeight = Math.max(gridHeight, 2);
|
||||
return new Vector(gridWidth, gridHeight);
|
||||
}
|
||||
|
||||
public void slowMovementForOneFrame(float value) {
|
||||
movementMultiplier *= value;
|
||||
}
|
||||
|
||||
public void moveWithMoveComponent(float frameTime, float playerSpeed) {
|
||||
if (moveComponent.isHasPlayerXSpeed()) {
|
||||
moveComponent.calcSpeedForPlayerSpeed(playerSpeed);
|
||||
}
|
||||
float distance = frameTime * moveComponent
|
||||
.getSpeed() * moveComponent.TRANSITION_VALUE * movementMultiplier;
|
||||
float newProgress = moveDirection * distance / moveComponent.getLength();
|
||||
moveProgress += newProgress;
|
||||
if (moveProgress < 0) {
|
||||
moveProgress *= -1;
|
||||
moveDirection *= -1;
|
||||
}
|
||||
while (moveProgress > 1) {
|
||||
moveProgress -= 2;
|
||||
if (moveProgress < 0) {
|
||||
moveProgress *= -1;
|
||||
moveDirection *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
super.setPosition(moveComponent.getPositionForProgress(moveProgress));
|
||||
super.setMovement(moveComponent.getMovementVector(moveDirection));
|
||||
movementMultiplier = 1.0f;
|
||||
}
|
||||
|
||||
public boolean isMoving() {
|
||||
return moving;
|
||||
}
|
||||
|
||||
public boolean isDeadly() {
|
||||
return deadly;
|
||||
}
|
||||
|
||||
public boolean isFloating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
public Vector getGridSize() {
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
public int getBombExplosionState() {
|
||||
return bombExplosionState;
|
||||
}
|
||||
|
||||
public void setBombExplosionState(int bombExplosionState) {
|
||||
this.bombExplosionState = bombExplosionState;
|
||||
}
|
||||
}
|
||||
|
@ -1,149 +1,149 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShape;
|
||||
import de.frajul.endlessroll.entities.tools.Stasis;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.11.2015.
|
||||
*/
|
||||
public class Player extends Entity {
|
||||
|
||||
public final float RADIUS = 0.1f;
|
||||
private final float START_X = -0.9f;
|
||||
private final float SPEED = 0.002f;
|
||||
|
||||
private float startSpeed, endSpeed;
|
||||
private float speed = SPEED;
|
||||
|
||||
private long currentSuperPowerDuration;
|
||||
private boolean hasSuperPower;
|
||||
private long superPowerDuration;
|
||||
private ParticleSource superPowerParticles;
|
||||
|
||||
private ParticleSystem particleSystem;
|
||||
private List<Stasis> stases = new ArrayList<>();
|
||||
private List<Float> forces = new ArrayList<>();
|
||||
private float gravityForce;
|
||||
|
||||
public Player() {
|
||||
super(PlayerShape.BALL.getTexture(), new Vector(), 0, 0);
|
||||
super.setWidth(RADIUS * 2);
|
||||
super.setHeight(RADIUS * 2);
|
||||
}
|
||||
|
||||
public void startSuperPower(long duration) {
|
||||
this.superPowerDuration = duration;
|
||||
currentSuperPowerDuration = 0;
|
||||
hasSuperPower = true;
|
||||
superPowerParticles = new ParticleSource(
|
||||
new Vector(super.getPosition().x, super.getPosition().y), particleSystem.superPower);
|
||||
superPowerParticles.start();
|
||||
}
|
||||
|
||||
public void init(PlayerShape playerShape, float terrainEdge, float startSpeed, float endSpeed, ParticleSystem particleSystem) {
|
||||
super.setTexture(playerShape.getTexture());
|
||||
super.setToTerrain(terrainEdge);
|
||||
super.getPosition().x = START_X;
|
||||
super.setMovement(new Vector(speed, 0));
|
||||
gravityForce = 0;
|
||||
hasSuperPower = false;
|
||||
forces.clear();
|
||||
this.startSpeed = startSpeed;
|
||||
this.endSpeed = endSpeed;
|
||||
setSpeedByProgress(0);
|
||||
this.particleSystem = particleSystem;
|
||||
}
|
||||
|
||||
public void setSpeedByProgress(float progress) {
|
||||
this.speed = ((endSpeed - startSpeed) * progress + startSpeed) * SPEED;
|
||||
super.getMovement().x = speed;
|
||||
}
|
||||
|
||||
public void preMoveUpdate(Timer timer) {
|
||||
if (hasSuperPower && superPowerParticles != null) {
|
||||
currentSuperPowerDuration += timer.getFrameTimeMilliseconds();
|
||||
hasSuperPower = superPowerDuration >= currentSuperPowerDuration;
|
||||
superPowerParticles.setPosition(new Vector(super.getPosition()));
|
||||
}
|
||||
if (!hasSuperPower && superPowerParticles != null)
|
||||
superPowerParticles.kill();
|
||||
|
||||
for (Stasis stasis : stases)
|
||||
stasis.influencePlayerMovementValues(this);
|
||||
|
||||
for (float force : forces)
|
||||
super.getMovement().y += force;
|
||||
super.getMovement().y += gravityForce;
|
||||
}
|
||||
|
||||
public void clearAllForces() {
|
||||
forces.clear();
|
||||
gravityForce = 0;
|
||||
}
|
||||
|
||||
public void manipulateAllForces(float factor) {
|
||||
for (int i = 0; i < forces.size(); i++)
|
||||
forces.set(i, forces.get(i) * factor);
|
||||
gravityForce *= factor * factor;
|
||||
}
|
||||
|
||||
public void postMoveUpdate() {
|
||||
stases.clear();
|
||||
forces.clear();
|
||||
}
|
||||
|
||||
public float getProgress(float goalX) {
|
||||
return (getPosition().x - START_X) / (goalX - START_X);
|
||||
}
|
||||
|
||||
public float getXFromStart(){
|
||||
return getPosition().x - START_X;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public boolean hasSuperPower() {
|
||||
return hasSuperPower;
|
||||
}
|
||||
|
||||
public void addStasis(Stasis stasis) {
|
||||
stases.add(stasis);
|
||||
}
|
||||
|
||||
public List<Stasis> getStases() {
|
||||
return stases;
|
||||
}
|
||||
|
||||
public void addForce(float force) {
|
||||
forces.add(force);
|
||||
}
|
||||
|
||||
public void setGravityForce(float gravityForce) {
|
||||
this.gravityForce = gravityForce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Vector movement) {
|
||||
super.move(movement);
|
||||
float circumference = 2 * 3.14f * RADIUS;
|
||||
float rotation = -360 * (movement.x / circumference);
|
||||
rotate(rotation);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShape;
|
||||
import de.frajul.endlessroll.entities.tools.Stasis;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.11.2015.
|
||||
*/
|
||||
public class Player extends Entity {
|
||||
|
||||
public final float RADIUS = 0.1f;
|
||||
private final float START_X = -0.9f;
|
||||
private final float SPEED = 0.002f;
|
||||
|
||||
private float startSpeed, endSpeed;
|
||||
private float speed = SPEED;
|
||||
|
||||
private long currentSuperPowerDuration;
|
||||
private boolean hasSuperPower;
|
||||
private long superPowerDuration;
|
||||
private ParticleSource superPowerParticles;
|
||||
|
||||
private ParticleSystem particleSystem;
|
||||
private List<Stasis> stases = new ArrayList<>();
|
||||
private List<Float> forces = new ArrayList<>();
|
||||
private float gravityForce;
|
||||
|
||||
public Player() {
|
||||
super(PlayerShape.BALL.getTexture(), new Vector(), 0, 0);
|
||||
super.setWidth(RADIUS * 2);
|
||||
super.setHeight(RADIUS * 2);
|
||||
}
|
||||
|
||||
public void startSuperPower(long duration) {
|
||||
this.superPowerDuration = duration;
|
||||
currentSuperPowerDuration = 0;
|
||||
hasSuperPower = true;
|
||||
superPowerParticles = new ParticleSource(
|
||||
new Vector(super.getPosition().x, super.getPosition().y), particleSystem.superPower);
|
||||
superPowerParticles.start();
|
||||
}
|
||||
|
||||
public void init(PlayerShape playerShape, float terrainEdge, float startSpeed, float endSpeed, ParticleSystem particleSystem) {
|
||||
super.setTexture(playerShape.getTexture());
|
||||
super.setToTerrain(terrainEdge);
|
||||
super.getPosition().x = START_X;
|
||||
super.setMovement(new Vector(speed, 0));
|
||||
gravityForce = 0;
|
||||
hasSuperPower = false;
|
||||
forces.clear();
|
||||
this.startSpeed = startSpeed;
|
||||
this.endSpeed = endSpeed;
|
||||
setSpeedByProgress(0);
|
||||
this.particleSystem = particleSystem;
|
||||
}
|
||||
|
||||
public void setSpeedByProgress(float progress) {
|
||||
this.speed = ((endSpeed - startSpeed) * progress + startSpeed) * SPEED;
|
||||
super.getMovement().x = speed;
|
||||
}
|
||||
|
||||
public void preMoveUpdate(Timer timer) {
|
||||
if (hasSuperPower && superPowerParticles != null) {
|
||||
currentSuperPowerDuration += timer.getFrameTimeMilliseconds();
|
||||
hasSuperPower = superPowerDuration >= currentSuperPowerDuration;
|
||||
superPowerParticles.setPosition(new Vector(super.getPosition()));
|
||||
}
|
||||
if (!hasSuperPower && superPowerParticles != null)
|
||||
superPowerParticles.kill();
|
||||
|
||||
for (Stasis stasis : stases)
|
||||
stasis.influencePlayerMovementValues(this);
|
||||
|
||||
for (float force : forces)
|
||||
super.getMovement().y += force;
|
||||
super.getMovement().y += gravityForce;
|
||||
}
|
||||
|
||||
public void clearAllForces() {
|
||||
forces.clear();
|
||||
gravityForce = 0;
|
||||
}
|
||||
|
||||
public void manipulateAllForces(float factor) {
|
||||
for (int i = 0; i < forces.size(); i++)
|
||||
forces.set(i, forces.get(i) * factor);
|
||||
gravityForce *= factor * factor;
|
||||
}
|
||||
|
||||
public void postMoveUpdate() {
|
||||
stases.clear();
|
||||
forces.clear();
|
||||
}
|
||||
|
||||
public float getProgress(float goalX) {
|
||||
return (getPosition().x - START_X) / (goalX - START_X);
|
||||
}
|
||||
|
||||
public float getXFromStart(){
|
||||
return getPosition().x - START_X;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public boolean hasSuperPower() {
|
||||
return hasSuperPower;
|
||||
}
|
||||
|
||||
public void addStasis(Stasis stasis) {
|
||||
stases.add(stasis);
|
||||
}
|
||||
|
||||
public List<Stasis> getStases() {
|
||||
return stases;
|
||||
}
|
||||
|
||||
public void addForce(float force) {
|
||||
forces.add(force);
|
||||
}
|
||||
|
||||
public void setGravityForce(float gravityForce) {
|
||||
this.gravityForce = gravityForce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Vector movement) {
|
||||
super.move(movement);
|
||||
float circumference = 2 * 3.14f * RADIUS;
|
||||
float rotation = -360 * (movement.x / circumference);
|
||||
rotate(rotation);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,51 +1,51 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.12.2016.
|
||||
*/
|
||||
|
||||
public enum Vertex {
|
||||
|
||||
UL(0, -1, 1), UR(1, 1, 1), BL(3, -1, -1), BR(2, 1, -1);
|
||||
|
||||
private int index;
|
||||
private float x, y;
|
||||
|
||||
Vertex(int index, float x, float y) {
|
||||
this.index = index;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vertex getNext(boolean clockwise) {
|
||||
int newIndex = index + 1;
|
||||
if (!clockwise)
|
||||
newIndex = index - 1;
|
||||
if (newIndex > 3)
|
||||
newIndex = 0;
|
||||
if (newIndex < 0)
|
||||
newIndex = 3;
|
||||
for (Vertex vertex : values())
|
||||
if (vertex.index == newIndex)
|
||||
return vertex;
|
||||
GameLog.e("No vertex with index " + index + " found!!!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities;
|
||||
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.12.2016.
|
||||
*/
|
||||
|
||||
public enum Vertex {
|
||||
|
||||
UL(0, -1, 1), UR(1, 1, 1), BL(3, -1, -1), BR(2, 1, -1);
|
||||
|
||||
private int index;
|
||||
private float x, y;
|
||||
|
||||
Vertex(int index, float x, float y) {
|
||||
this.index = index;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vertex getNext(boolean clockwise) {
|
||||
int newIndex = index + 1;
|
||||
if (!clockwise)
|
||||
newIndex = index - 1;
|
||||
if (newIndex > 3)
|
||||
newIndex = 0;
|
||||
if (newIndex < 0)
|
||||
newIndex = 3;
|
||||
for (Vertex vertex : values())
|
||||
if (vertex.index == newIndex)
|
||||
return vertex;
|
||||
GameLog.e("No vertex with index " + index + " found!!!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
@ -1,74 +1,74 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collectables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.SynchronizedArrayList;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.levels.Level;
|
||||
import de.frajul.endlessroll.levels.PositionData;
|
||||
|
||||
/**
|
||||
* Created by Julian on 06.09.2017.
|
||||
*/
|
||||
|
||||
public class Collectables extends SynchronizedArrayList<Entity> {
|
||||
|
||||
private List<Star> stars = Collections.synchronizedList(new ArrayList<Star>());
|
||||
private Energy energy;
|
||||
|
||||
public void init(Level level, TexturePack textures) {
|
||||
for (int i = 0; i < level.getStars().size(); i++) {
|
||||
if (level.isStarCollected(i))
|
||||
continue;
|
||||
addStar(new Star(i, textures.star, level.getStars().get(i)));
|
||||
}
|
||||
|
||||
PositionData energyData = level.getEnergyData();
|
||||
if (energyData != null && !level.isEnergyCollected()) {
|
||||
setEnergy(new Energy(textures.energy, energyData));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean remove(Object object) {
|
||||
if (object instanceof Star)
|
||||
stars.remove(object);
|
||||
else
|
||||
energy = null;
|
||||
return super.remove(object);
|
||||
}
|
||||
|
||||
private void addStar(Star star) {
|
||||
stars.add(star);
|
||||
super.add(star);
|
||||
}
|
||||
|
||||
private void setEnergy(Energy energy) {
|
||||
this.energy = energy;
|
||||
super.add(energy);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
stars.clear();
|
||||
energy = null;
|
||||
super.clear();
|
||||
}
|
||||
|
||||
public List<Star> getStars() {
|
||||
return stars;
|
||||
}
|
||||
|
||||
public Energy getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collectables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.SynchronizedArrayList;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.levels.Level;
|
||||
import de.frajul.endlessroll.levels.PositionData;
|
||||
|
||||
/**
|
||||
* Created by Julian on 06.09.2017.
|
||||
*/
|
||||
|
||||
public class Collectables extends SynchronizedArrayList<Entity> {
|
||||
|
||||
private List<Star> stars = Collections.synchronizedList(new ArrayList<Star>());
|
||||
private Energy energy;
|
||||
|
||||
public void init(Level level, TexturePack textures) {
|
||||
for (int i = 0; i < level.getStars().size(); i++) {
|
||||
if (level.isStarCollected(i))
|
||||
continue;
|
||||
addStar(new Star(i, textures.star, level.getStars().get(i)));
|
||||
}
|
||||
|
||||
PositionData energyData = level.getEnergyData();
|
||||
if (energyData != null && !level.isEnergyCollected()) {
|
||||
setEnergy(new Energy(textures.energy, energyData));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean remove(Object object) {
|
||||
if (object instanceof Star)
|
||||
stars.remove(object);
|
||||
else
|
||||
energy = null;
|
||||
return super.remove(object);
|
||||
}
|
||||
|
||||
private void addStar(Star star) {
|
||||
stars.add(star);
|
||||
super.add(star);
|
||||
}
|
||||
|
||||
private void setEnergy(Energy energy) {
|
||||
this.energy = energy;
|
||||
super.add(energy);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
stars.clear();
|
||||
energy = null;
|
||||
super.clear();
|
||||
}
|
||||
|
||||
public List<Star> getStars() {
|
||||
return stars;
|
||||
}
|
||||
|
||||
public Energy getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collectables;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.AnimatedEntity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.PositionData;
|
||||
|
||||
public class Energy extends AnimatedEntity {
|
||||
|
||||
private final static float SIZE = 0.3f;
|
||||
|
||||
public Energy(Texture texture, PositionData data) {
|
||||
super(texture, new Vector(data.getX(), data.getY()), SIZE, SIZE);
|
||||
animation.setLooping(true);
|
||||
animation.setRequiredDelta(130);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collectables;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.AnimatedEntity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.PositionData;
|
||||
|
||||
public class Energy extends AnimatedEntity {
|
||||
|
||||
private final static float SIZE = 0.3f;
|
||||
|
||||
public Energy(Texture texture, PositionData data) {
|
||||
super(texture, new Vector(data.getX(), data.getY()), SIZE, SIZE);
|
||||
animation.setLooping(true);
|
||||
animation.setRequiredDelta(130);
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collectables;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.PositionData;
|
||||
|
||||
public class Star extends Entity {
|
||||
|
||||
private final static float SIZE = 0.25f;
|
||||
private int index;
|
||||
|
||||
public Star(int index, Texture texture, PositionData data) {
|
||||
super(texture, new Vector(data.getX(), data.getY()), SIZE, SIZE);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collectables;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.PositionData;
|
||||
|
||||
public class Star extends Entity {
|
||||
|
||||
private final static float SIZE = 0.25f;
|
||||
private int index;
|
||||
|
||||
public Star(int index, Texture texture, PositionData data) {
|
||||
super(texture, new Vector(data.getX(), data.getY()), SIZE, SIZE);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +1,82 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Triangle;
|
||||
|
||||
/**
|
||||
* Created by Julian on 28.02.2016.
|
||||
*/
|
||||
public class CircleTriangleCollisionDetector {
|
||||
|
||||
public boolean isCircleTriangleCollision(Circle circle, Triangle triangle) {
|
||||
if (circleIntersectingWithTriangleVertices(circle, triangle))
|
||||
return true;
|
||||
|
||||
if (circleCenterInsideTriangle(circle, triangle))
|
||||
return true;
|
||||
|
||||
return circleIntersectingWithTriangleEdges(circle, triangle);
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleEdges(Circle circle, Triangle triangle) {
|
||||
Vector edge1 = triangle.getBottomRightVertex().vectorTo(triangle.getTopRightVertex());
|
||||
Vector edge2 = triangle.getTopRightVertex().vectorTo(triangle.getBottomLeftVertex());
|
||||
Vector edge3 = triangle.getBottomLeftVertex().vectorTo(triangle.getBottomRightVertex());
|
||||
|
||||
boolean intersectingWithEdge1 = circleIntersectingWithTriangleEdge(circle, triangle.getBottomRightVertex(), edge1);
|
||||
boolean intersectingWithEdge2 = circleIntersectingWithTriangleEdge(circle, triangle.getTopRightVertex(), edge2);
|
||||
boolean intersectingWithEdge3 = circleIntersectingWithTriangleEdge(circle, triangle.getBottomLeftVertex(), edge3);
|
||||
return intersectingWithEdge1 || intersectingWithEdge2 || intersectingWithEdge3;
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleEdge(Circle circle, Vector vertex, Vector edge) {
|
||||
Vector vertexToCenter = vertex.vectorTo(circle.getPosition());
|
||||
Vector kVector = new Vector(vertexToCenter).mul(edge);
|
||||
float k = kVector.x + kVector.y;
|
||||
|
||||
if (k > 0) {
|
||||
float length = edge.length();
|
||||
k = k / length;
|
||||
|
||||
if (k < length)
|
||||
return Math.sqrt(vertexToCenter.x * vertexToCenter.x + vertexToCenter.y * vertexToCenter.y - k * k) <= circle.getRadius();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean circleCenterInsideTriangle(Circle circle, Triangle triangle) {
|
||||
Vector vertex1To2 = triangle.getBottomRightVertex().vectorTo(triangle.getTopRightVertex());
|
||||
Vector vertex2To3 = triangle.getTopRightVertex().vectorTo(triangle.getBottomLeftVertex());
|
||||
Vector vertex3To1 = triangle.getBottomLeftVertex().vectorTo(triangle.getBottomRightVertex());
|
||||
Vector vertex1ToCenter = triangle.getBottomRightVertex().vectorTo(circle.getPosition());
|
||||
Vector vertex2ToCenter = triangle.getTopRightVertex().vectorTo(circle.getPosition());
|
||||
Vector vertex3ToCenter = triangle.getBottomLeftVertex().vectorTo(circle.getPosition());
|
||||
|
||||
boolean centerInsideV1V2 = vertex1To2.y * vertex1ToCenter.x - vertex1To2.x * vertex1ToCenter.y < 0;
|
||||
boolean centerInsideV2V3 = vertex2To3.y * vertex2ToCenter.x - vertex2To3.x * vertex2ToCenter.y < 0;
|
||||
boolean centerInsideV3V1 = vertex3To1.y * vertex3ToCenter.x - vertex3To1.x * vertex3ToCenter.y < 0;
|
||||
|
||||
return centerInsideV1V2 && centerInsideV2V3 && centerInsideV3V1;
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleVertices(Circle circle, Triangle triangle) {
|
||||
boolean intersectingWithVertex1 = circleIntersectingWithTriangleVertex(circle, triangle.getBottomRightVertex());
|
||||
boolean intersectingWithVertex2 = circleIntersectingWithTriangleVertex(circle, triangle.getTopRightVertex());
|
||||
boolean intersectingWithVertex3 = circleIntersectingWithTriangleVertex(circle, triangle.getBottomLeftVertex());
|
||||
return intersectingWithVertex1 || intersectingWithVertex2 || intersectingWithVertex3;
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleVertex(Circle circle, Vector vertex) {
|
||||
Vector centerToVertex = circle.getPosition().vectorTo(vertex);
|
||||
return centerToVertex.length() <= circle.getRadius();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Triangle;
|
||||
|
||||
/**
|
||||
* Created by Julian on 28.02.2016.
|
||||
*/
|
||||
public class CircleTriangleCollisionDetector {
|
||||
|
||||
public boolean isCircleTriangleCollision(Circle circle, Triangle triangle) {
|
||||
if (circleIntersectingWithTriangleVertices(circle, triangle))
|
||||
return true;
|
||||
|
||||
if (circleCenterInsideTriangle(circle, triangle))
|
||||
return true;
|
||||
|
||||
return circleIntersectingWithTriangleEdges(circle, triangle);
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleEdges(Circle circle, Triangle triangle) {
|
||||
Vector edge1 = triangle.getBottomRightVertex().vectorTo(triangle.getTopRightVertex());
|
||||
Vector edge2 = triangle.getTopRightVertex().vectorTo(triangle.getBottomLeftVertex());
|
||||
Vector edge3 = triangle.getBottomLeftVertex().vectorTo(triangle.getBottomRightVertex());
|
||||
|
||||
boolean intersectingWithEdge1 = circleIntersectingWithTriangleEdge(circle, triangle.getBottomRightVertex(), edge1);
|
||||
boolean intersectingWithEdge2 = circleIntersectingWithTriangleEdge(circle, triangle.getTopRightVertex(), edge2);
|
||||
boolean intersectingWithEdge3 = circleIntersectingWithTriangleEdge(circle, triangle.getBottomLeftVertex(), edge3);
|
||||
return intersectingWithEdge1 || intersectingWithEdge2 || intersectingWithEdge3;
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleEdge(Circle circle, Vector vertex, Vector edge) {
|
||||
Vector vertexToCenter = vertex.vectorTo(circle.getPosition());
|
||||
Vector kVector = new Vector(vertexToCenter).mul(edge);
|
||||
float k = kVector.x + kVector.y;
|
||||
|
||||
if (k > 0) {
|
||||
float length = edge.length();
|
||||
k = k / length;
|
||||
|
||||
if (k < length)
|
||||
return Math.sqrt(vertexToCenter.x * vertexToCenter.x + vertexToCenter.y * vertexToCenter.y - k * k) <= circle.getRadius();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean circleCenterInsideTriangle(Circle circle, Triangle triangle) {
|
||||
Vector vertex1To2 = triangle.getBottomRightVertex().vectorTo(triangle.getTopRightVertex());
|
||||
Vector vertex2To3 = triangle.getTopRightVertex().vectorTo(triangle.getBottomLeftVertex());
|
||||
Vector vertex3To1 = triangle.getBottomLeftVertex().vectorTo(triangle.getBottomRightVertex());
|
||||
Vector vertex1ToCenter = triangle.getBottomRightVertex().vectorTo(circle.getPosition());
|
||||
Vector vertex2ToCenter = triangle.getTopRightVertex().vectorTo(circle.getPosition());
|
||||
Vector vertex3ToCenter = triangle.getBottomLeftVertex().vectorTo(circle.getPosition());
|
||||
|
||||
boolean centerInsideV1V2 = vertex1To2.y * vertex1ToCenter.x - vertex1To2.x * vertex1ToCenter.y < 0;
|
||||
boolean centerInsideV2V3 = vertex2To3.y * vertex2ToCenter.x - vertex2To3.x * vertex2ToCenter.y < 0;
|
||||
boolean centerInsideV3V1 = vertex3To1.y * vertex3ToCenter.x - vertex3To1.x * vertex3ToCenter.y < 0;
|
||||
|
||||
return centerInsideV1V2 && centerInsideV2V3 && centerInsideV3V1;
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleVertices(Circle circle, Triangle triangle) {
|
||||
boolean intersectingWithVertex1 = circleIntersectingWithTriangleVertex(circle, triangle.getBottomRightVertex());
|
||||
boolean intersectingWithVertex2 = circleIntersectingWithTriangleVertex(circle, triangle.getTopRightVertex());
|
||||
boolean intersectingWithVertex3 = circleIntersectingWithTriangleVertex(circle, triangle.getBottomLeftVertex());
|
||||
return intersectingWithVertex1 || intersectingWithVertex2 || intersectingWithVertex3;
|
||||
}
|
||||
|
||||
private boolean circleIntersectingWithTriangleVertex(Circle circle, Vector vertex) {
|
||||
Vector centerToVertex = circle.getPosition().vectorTo(vertex);
|
||||
return centerToVertex.length() <= circle.getRadius();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,356 +1,356 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.EntityCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Quad;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Triangle;
|
||||
import de.frajul.endlessroll.entities.tileLists.Tile;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class CollisionDetector {
|
||||
|
||||
private CircleTriangleCollisionDetector triangleDetector;
|
||||
|
||||
public CollisionDetector() {
|
||||
triangleDetector = new CircleTriangleCollisionDetector();
|
||||
}
|
||||
|
||||
public boolean isCollision(Geometry g1, Geometry g2) {
|
||||
if (g1 instanceof Triangle) {
|
||||
if (g2 instanceof Triangle)
|
||||
return isTriangleTriangleCollision((Triangle) g1, (Triangle) g2);
|
||||
if (g2 instanceof Quad)
|
||||
return isQuadTriangleCollision((Quad) g2, (Triangle) g1);
|
||||
if (g2 instanceof Circle)
|
||||
return isCircleTriangleCollision((Circle) g2, (Triangle) g1);
|
||||
}
|
||||
if (g1 instanceof Quad) {
|
||||
if (g2 instanceof Triangle)
|
||||
return isQuadTriangleCollision((Quad) g1, (Triangle) g2);
|
||||
if (g2 instanceof Quad)
|
||||
return isQuadQuadCollision((Quad) g1, (Quad) g2);
|
||||
if (g2 instanceof Circle)
|
||||
return isCircleQuadCollision((Circle) g2, (Quad) g1);
|
||||
}
|
||||
if (g1 instanceof Circle) {
|
||||
if (g2 instanceof Triangle)
|
||||
return isCircleTriangleCollision((Circle) g1, (Triangle) g2);
|
||||
if (g2 instanceof Quad)
|
||||
return isCircleQuadCollision((Circle) g1, (Quad) g2);
|
||||
if (g2 instanceof Circle)
|
||||
return isCircleCircleCollision((Circle) g1, (Circle) g2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPointInQuad(Vector point, Quad quad) {
|
||||
if (point.getX() >= quad.getLeftEdge() && point.getX() <= quad.getRightEdge()) {
|
||||
return point.getY() >= quad.getBottomEdge() && point.getY() <= quad.getTopEdge();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCircleCircleCollision(Circle c1, Circle c2) {
|
||||
float distance = Math.abs(c1.getPosition().vectorTo(c2.getPosition()).length());
|
||||
float radiusSum = c1.getRadius() + c2.getRadius();
|
||||
return distance < radiusSum;
|
||||
}
|
||||
|
||||
public boolean isCircleQuadCollision(Circle circle, Quad quad) {
|
||||
Vector distance = circle.getPosition().vectorTo(quad.getPosition());
|
||||
distance.x = Math.abs(distance.x);
|
||||
distance.y = Math.abs(distance.y);
|
||||
|
||||
if (distance.x > circle.getRadius() + quad.getWidth() / 2)
|
||||
return false;
|
||||
if (distance.y > circle.getRadius() + quad.getHeight() / 2)
|
||||
return false;
|
||||
|
||||
if (distance.x <= quad.getWidth() / 2)
|
||||
return true;
|
||||
if (distance.y <= quad.getHeight() / 2)
|
||||
return true;
|
||||
|
||||
float cornerDistance_sq = (distance.x - quad.getWidth() / 2) * (distance.x - quad
|
||||
.getWidth() / 2) + (distance.y - quad.getHeight() / 2) * (distance.y - quad
|
||||
.getHeight() / 2);
|
||||
return cornerDistance_sq <= circle.getRadius() * circle.getRadius();
|
||||
}
|
||||
|
||||
public boolean isCircleTriangleCollision(Circle circle, Triangle triangle) {
|
||||
return triangleDetector.isCircleTriangleCollision(circle, triangle);
|
||||
}
|
||||
|
||||
public boolean isQuadQuadCollision(Quad q1, Quad q2) {
|
||||
float xDistance = Math.abs(q2.getPosition().x - q1.getPosition().x);
|
||||
float yDistance = Math.abs(q2.getPosition().y - q1.getPosition().y);
|
||||
if (xDistance >= q1.getWidth() / 2 + q2.getWidth() / 2)
|
||||
return false;
|
||||
return !(yDistance >= q1.getHeight() / 2 + q2.getHeight() / 2);
|
||||
}
|
||||
|
||||
public boolean isTriangleTriangleCollision(Triangle triangle1, Triangle triangle2) {
|
||||
boolean triangle1Vertex1InTriangle2 = isVertexInTriangle(triangle1.getBottomRightVertex(), triangle2);
|
||||
if (triangle1Vertex1InTriangle2)
|
||||
return true;
|
||||
boolean triangle1Vertex2InTriangle2 = isVertexInTriangle(triangle1.getTopRightVertex(), triangle2);
|
||||
if (triangle1Vertex2InTriangle2)
|
||||
return true;
|
||||
boolean triangle1Vertex3InTriangle2 = isVertexInTriangle(triangle1.getBottomLeftVertex(), triangle2);
|
||||
if (triangle1Vertex3InTriangle2)
|
||||
return true;
|
||||
boolean triangle2Vertex1InTriangle1 = isVertexInTriangle(triangle2.getBottomRightVertex(), triangle1);
|
||||
if (triangle2Vertex1InTriangle1)
|
||||
return true;
|
||||
boolean triangle2Vertex2InTriangle1 = isVertexInTriangle(triangle2.getTopRightVertex(), triangle1);
|
||||
if (triangle2Vertex2InTriangle1)
|
||||
return true;
|
||||
boolean triangle2Vertex3InTriangle1 = isVertexInTriangle(triangle2.getBottomLeftVertex(), triangle1);
|
||||
return triangle2Vertex3InTriangle1;
|
||||
}
|
||||
|
||||
public boolean isQuadTriangleCollision(Quad quad, Triangle triangle) {
|
||||
boolean quadVertex1InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getLeftEdge(), quad.getTopEdge()), triangle);
|
||||
if (quadVertex1InTriangle)
|
||||
return true;
|
||||
boolean quadVertex2InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getRightEdge(), quad.getTopEdge()), triangle);
|
||||
if (quadVertex2InTriangle)
|
||||
return true;
|
||||
boolean quadVertex3InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getRightEdge(), quad.getBottomEdge()), triangle);
|
||||
if (quadVertex3InTriangle)
|
||||
return true;
|
||||
boolean quadVertex4InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getLeftEdge(), quad.getBottomEdge()), triangle);
|
||||
if (quadVertex4InTriangle)
|
||||
return true;
|
||||
boolean triangleVertex1InQuad = isPointInQuad(triangle.getBottomRightVertex(), quad);
|
||||
if (triangleVertex1InQuad)
|
||||
return true;
|
||||
boolean triangleVertex2InQuad = isPointInQuad(triangle.getTopRightVertex(), quad);
|
||||
if (triangleVertex2InQuad)
|
||||
return true;
|
||||
boolean triangleVertex3InQuad = isPointInQuad(triangle.getBottomLeftVertex(), quad);
|
||||
if (triangleVertex3InQuad)
|
||||
return true;
|
||||
return triangle.getTopEdge() >= quad.getTopEdge() && triangle.getBottomEdge() <= quad.getBottomEdge() && ((triangle.getLeftEdge() <= quad.getRightEdge() && triangle.getLeftEdge() >= quad.getLeftEdge()) || (triangle.getRightEdge() <= quad.getRightEdge() && triangle.getRightEdge() >= quad.getLeftEdge()));
|
||||
}
|
||||
|
||||
private boolean isVertexInTriangle(Vector vertex, Triangle triangle) {
|
||||
if (!isPointInQuad(vertex, triangle))
|
||||
return false;
|
||||
float gradient = triangle.getGradient();
|
||||
float maxVertexY = vertex.getX() * gradient + triangle.getBottomEdge();
|
||||
return vertex.getY() <= maxVertexY;
|
||||
}
|
||||
|
||||
public EntityCollisionData playerTerrainCollision(Player player, Tile terrainTile) {
|
||||
Circle circle = new Circle(player);
|
||||
if (circle.getTopEdge() < terrainTile.getTopEdge()) {
|
||||
float xDistance = Math.abs(circle.getPosition().x - terrainTile.getPosition().x);
|
||||
if (xDistance < circle.getRadius() + terrainTile.getWidth() / 2)
|
||||
return new EntityCollisionData(terrainTile, Edge.LEFT);
|
||||
}
|
||||
|
||||
if (isCircleQuadCollision(circle, terrainTile)) {
|
||||
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), terrainTile,
|
||||
terrainTile.getMovement());
|
||||
return new EntityCollisionData(terrainTile, edge);
|
||||
}
|
||||
return new EntityCollisionData(null, null);
|
||||
}
|
||||
|
||||
public EntityCollisionData playerCeilingCollision(Player player, Tile ceilingTile) {
|
||||
Circle circle = new Circle(player);
|
||||
if (circle.getBottomEdge() > ceilingTile.getBottomEdge()) {
|
||||
float xDistance = Math.abs(circle.getPosition().x - ceilingTile.getPosition().x);
|
||||
if (xDistance < circle.getRadius() + ceilingTile.getWidth() / 2)
|
||||
return new EntityCollisionData(ceilingTile, Edge.LEFT);
|
||||
}
|
||||
|
||||
if (isCircleQuadCollision(circle, ceilingTile)) {
|
||||
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), ceilingTile,
|
||||
ceilingTile.getMovement());
|
||||
return new EntityCollisionData(ceilingTile, edge);
|
||||
}
|
||||
return new EntityCollisionData(null, null);
|
||||
}
|
||||
|
||||
public EntityCollisionData playerEntityCollision(Player player, Entity entity) {
|
||||
Circle circle = new Circle(player);
|
||||
Quad quad = entity;
|
||||
if (isCircleQuadCollision(circle, quad)) {
|
||||
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), quad,
|
||||
entity.getMovement());
|
||||
return new EntityCollisionData(entity, edge);
|
||||
}
|
||||
return new EntityCollisionData(null, null);
|
||||
}
|
||||
|
||||
private Edge circleQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||
boolean circleFullyInsideQuad = false;
|
||||
if (circle.getPosition().getX() + circle.getRadius() <= quad.getRightEdge() && circle
|
||||
.getPosition().getX() - circle.getRadius() >= quad.getLeftEdge()) {
|
||||
if (circle.getPosition().getY() + circle.getRadius() <= quad.getTopEdge() && circle
|
||||
.getPosition().getY() - circle.getRadius() >= quad.getBottomEdge()) {
|
||||
circleFullyInsideQuad = true;
|
||||
}
|
||||
}
|
||||
if (circleFullyInsideQuad)
|
||||
return circleCenterInQuadCollisionEdge(circle, circleMovement, quad, quadMovement);
|
||||
return circlePartlyOutsideQuadCollisionEdge(circle, circleMovement, quad, quadMovement);
|
||||
}
|
||||
|
||||
private Edge circlePartlyOutsideQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||
Vector relativeMovement = new Vector(circleMovement).translate(quadMovement.negate());
|
||||
|
||||
Edge edge = Edge.NONE;
|
||||
if (circle.getPosition().getY() + circle.getRadius() >= quad.getTopEdge())
|
||||
edge = Edge.TOP;
|
||||
else if (circle.getPosition().getY() - circle.getRadius() <= quad.getBottomEdge())
|
||||
edge = Edge.BOTTOM;
|
||||
if (circle.getPosition().getX() - circle.getRadius() <= quad.getLeftEdge()) {
|
||||
if (edge != Edge.NONE) {
|
||||
if (edge == Edge.TOP) {
|
||||
float m = -1;
|
||||
float t = quad.getTopEdge() - m * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() >= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.TOP;
|
||||
else
|
||||
edge = Edge.LEFT;
|
||||
} else if (edge == Edge.BOTTOM) {
|
||||
float m = 1;
|
||||
float t = quad.getBottomEdge() - m * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() <= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.BOTTOM;
|
||||
else
|
||||
edge = Edge.LEFT;
|
||||
}
|
||||
} else
|
||||
edge = Edge.LEFT;
|
||||
} else if (circle.getPosition().getX() + circle.getRadius() >= quad.getRightEdge()) {
|
||||
if (edge != Edge.NONE) {
|
||||
if (edge == Edge.TOP) {
|
||||
//This movement check is because if player falls with too much speed on topLeft Vertex, sometimes RIGHT-Edge is returned
|
||||
if (relativeMovement.getY() < 0) {
|
||||
return Edge.TOP;
|
||||
} else {
|
||||
float m = 1;
|
||||
float t = quad.getTopEdge() - m * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() >= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.TOP;
|
||||
else
|
||||
edge = Edge.RIGHT;
|
||||
}
|
||||
} else if (edge == Edge.BOTTOM) {
|
||||
float m = -1;
|
||||
float t = quad.getBottomEdge() - m * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() <= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.BOTTOM;
|
||||
else
|
||||
edge = Edge.RIGHT;
|
||||
}
|
||||
} else
|
||||
edge = Edge.RIGHT;
|
||||
}
|
||||
return edge;
|
||||
}
|
||||
|
||||
private Edge circleCenterInQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||
Vector relativeMovement = new Vector(circleMovement).translate(quadMovement.negate());
|
||||
|
||||
float m = relativeMovement.getY() / relativeMovement.getX();
|
||||
float t = circle.getPosition().getY() - m * circle.getPosition().getX();
|
||||
|
||||
float yAtLeftEdge = m * quad.getLeftEdge() + t;
|
||||
boolean touchingLeftEdge = yAtLeftEdge < quad.getTopEdge() && yAtLeftEdge > quad
|
||||
.getBottomEdge();
|
||||
float yAtRightEdge = m * quad.getRightEdge() + t;
|
||||
boolean touchingRightEdge = yAtRightEdge < quad.getTopEdge() && yAtRightEdge > quad
|
||||
.getBottomEdge();
|
||||
|
||||
float xAtTopEdge = (quad.getTopEdge() - t) / m;
|
||||
boolean touchingTopEdge = xAtTopEdge >= quad.getLeftEdge() && xAtTopEdge <= quad
|
||||
.getRightEdge();
|
||||
float xAtBottomEdge = (quad.getBottomEdge() - t) / m;
|
||||
boolean touchingBottomEdge = xAtBottomEdge >= quad.getLeftEdge() && xAtBottomEdge <= quad
|
||||
.getRightEdge();
|
||||
|
||||
if (relativeMovement.getX() == 0) {
|
||||
if (circle.getPosition().getX() - circle.getRadius() <= quad.getRightEdge() && circle
|
||||
.getPosition().getX() + circle.getRadius() >= quad.getLeftEdge()) {
|
||||
touchingTopEdge = true;
|
||||
touchingBottomEdge = true;
|
||||
}
|
||||
}
|
||||
|
||||
// CORNERS BELONGING TO TOP / BOTTOM EDGES
|
||||
if (touchingLeftEdge) {
|
||||
if (touchingRightEdge) {
|
||||
if (circle.getPosition().getX() <= quad.getPosition().getX())
|
||||
return Edge.LEFT;
|
||||
return Edge.RIGHT;
|
||||
} else if (touchingTopEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getTopEdge() - mn * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() < mn * circle.getPosition().getX() + tn)
|
||||
return Edge.LEFT;
|
||||
return Edge.TOP;
|
||||
} else if (touchingBottomEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getBottomEdge() - mn * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() > mn * circle.getPosition().getX() + tn)
|
||||
return Edge.LEFT;
|
||||
return Edge.BOTTOM;
|
||||
} else {
|
||||
return Edge.LEFT;
|
||||
}
|
||||
} else if (touchingRightEdge) {
|
||||
if (touchingTopEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getTopEdge() - mn * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() < mn * circle.getPosition().getX() + tn)
|
||||
return Edge.RIGHT;
|
||||
return Edge.TOP;
|
||||
} else if (touchingBottomEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getBottomEdge() - mn * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() > mn * circle.getPosition().getX() + tn)
|
||||
return Edge.RIGHT;
|
||||
return Edge.BOTTOM;
|
||||
} else {
|
||||
return Edge.RIGHT;
|
||||
}
|
||||
} else if (touchingTopEdge) {
|
||||
if (touchingBottomEdge) {
|
||||
if (circle.getPosition().getY() >= quad.getPosition().getY())
|
||||
return Edge.TOP;
|
||||
return Edge.BOTTOM;
|
||||
} else {
|
||||
return Edge.TOP;
|
||||
}
|
||||
} else if (touchingBottomEdge) {
|
||||
return Edge.BOTTOM;
|
||||
}
|
||||
return Edge.NONE;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.EntityCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Quad;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Triangle;
|
||||
import de.frajul.endlessroll.entities.tileLists.Tile;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class CollisionDetector {
|
||||
|
||||
private CircleTriangleCollisionDetector triangleDetector;
|
||||
|
||||
public CollisionDetector() {
|
||||
triangleDetector = new CircleTriangleCollisionDetector();
|
||||
}
|
||||
|
||||
public boolean isCollision(Geometry g1, Geometry g2) {
|
||||
if (g1 instanceof Triangle) {
|
||||
if (g2 instanceof Triangle)
|
||||
return isTriangleTriangleCollision((Triangle) g1, (Triangle) g2);
|
||||
if (g2 instanceof Quad)
|
||||
return isQuadTriangleCollision((Quad) g2, (Triangle) g1);
|
||||
if (g2 instanceof Circle)
|
||||
return isCircleTriangleCollision((Circle) g2, (Triangle) g1);
|
||||
}
|
||||
if (g1 instanceof Quad) {
|
||||
if (g2 instanceof Triangle)
|
||||
return isQuadTriangleCollision((Quad) g1, (Triangle) g2);
|
||||
if (g2 instanceof Quad)
|
||||
return isQuadQuadCollision((Quad) g1, (Quad) g2);
|
||||
if (g2 instanceof Circle)
|
||||
return isCircleQuadCollision((Circle) g2, (Quad) g1);
|
||||
}
|
||||
if (g1 instanceof Circle) {
|
||||
if (g2 instanceof Triangle)
|
||||
return isCircleTriangleCollision((Circle) g1, (Triangle) g2);
|
||||
if (g2 instanceof Quad)
|
||||
return isCircleQuadCollision((Circle) g1, (Quad) g2);
|
||||
if (g2 instanceof Circle)
|
||||
return isCircleCircleCollision((Circle) g1, (Circle) g2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPointInQuad(Vector point, Quad quad) {
|
||||
if (point.getX() >= quad.getLeftEdge() && point.getX() <= quad.getRightEdge()) {
|
||||
return point.getY() >= quad.getBottomEdge() && point.getY() <= quad.getTopEdge();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCircleCircleCollision(Circle c1, Circle c2) {
|
||||
float distance = Math.abs(c1.getPosition().vectorTo(c2.getPosition()).length());
|
||||
float radiusSum = c1.getRadius() + c2.getRadius();
|
||||
return distance < radiusSum;
|
||||
}
|
||||
|
||||
public boolean isCircleQuadCollision(Circle circle, Quad quad) {
|
||||
Vector distance = circle.getPosition().vectorTo(quad.getPosition());
|
||||
distance.x = Math.abs(distance.x);
|
||||
distance.y = Math.abs(distance.y);
|
||||
|
||||
if (distance.x > circle.getRadius() + quad.getWidth() / 2)
|
||||
return false;
|
||||
if (distance.y > circle.getRadius() + quad.getHeight() / 2)
|
||||
return false;
|
||||
|
||||
if (distance.x <= quad.getWidth() / 2)
|
||||
return true;
|
||||
if (distance.y <= quad.getHeight() / 2)
|
||||
return true;
|
||||
|
||||
float cornerDistance_sq = (distance.x - quad.getWidth() / 2) * (distance.x - quad
|
||||
.getWidth() / 2) + (distance.y - quad.getHeight() / 2) * (distance.y - quad
|
||||
.getHeight() / 2);
|
||||
return cornerDistance_sq <= circle.getRadius() * circle.getRadius();
|
||||
}
|
||||
|
||||
public boolean isCircleTriangleCollision(Circle circle, Triangle triangle) {
|
||||
return triangleDetector.isCircleTriangleCollision(circle, triangle);
|
||||
}
|
||||
|
||||
public boolean isQuadQuadCollision(Quad q1, Quad q2) {
|
||||
float xDistance = Math.abs(q2.getPosition().x - q1.getPosition().x);
|
||||
float yDistance = Math.abs(q2.getPosition().y - q1.getPosition().y);
|
||||
if (xDistance >= q1.getWidth() / 2 + q2.getWidth() / 2)
|
||||
return false;
|
||||
return !(yDistance >= q1.getHeight() / 2 + q2.getHeight() / 2);
|
||||
}
|
||||
|
||||
public boolean isTriangleTriangleCollision(Triangle triangle1, Triangle triangle2) {
|
||||
boolean triangle1Vertex1InTriangle2 = isVertexInTriangle(triangle1.getBottomRightVertex(), triangle2);
|
||||
if (triangle1Vertex1InTriangle2)
|
||||
return true;
|
||||
boolean triangle1Vertex2InTriangle2 = isVertexInTriangle(triangle1.getTopRightVertex(), triangle2);
|
||||
if (triangle1Vertex2InTriangle2)
|
||||
return true;
|
||||
boolean triangle1Vertex3InTriangle2 = isVertexInTriangle(triangle1.getBottomLeftVertex(), triangle2);
|
||||
if (triangle1Vertex3InTriangle2)
|
||||
return true;
|
||||
boolean triangle2Vertex1InTriangle1 = isVertexInTriangle(triangle2.getBottomRightVertex(), triangle1);
|
||||
if (triangle2Vertex1InTriangle1)
|
||||
return true;
|
||||
boolean triangle2Vertex2InTriangle1 = isVertexInTriangle(triangle2.getTopRightVertex(), triangle1);
|
||||
if (triangle2Vertex2InTriangle1)
|
||||
return true;
|
||||
boolean triangle2Vertex3InTriangle1 = isVertexInTriangle(triangle2.getBottomLeftVertex(), triangle1);
|
||||
return triangle2Vertex3InTriangle1;
|
||||
}
|
||||
|
||||
public boolean isQuadTriangleCollision(Quad quad, Triangle triangle) {
|
||||
boolean quadVertex1InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getLeftEdge(), quad.getTopEdge()), triangle);
|
||||
if (quadVertex1InTriangle)
|
||||
return true;
|
||||
boolean quadVertex2InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getRightEdge(), quad.getTopEdge()), triangle);
|
||||
if (quadVertex2InTriangle)
|
||||
return true;
|
||||
boolean quadVertex3InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getRightEdge(), quad.getBottomEdge()), triangle);
|
||||
if (quadVertex3InTriangle)
|
||||
return true;
|
||||
boolean quadVertex4InTriangle = isVertexInTriangle(
|
||||
new Vector(quad.getLeftEdge(), quad.getBottomEdge()), triangle);
|
||||
if (quadVertex4InTriangle)
|
||||
return true;
|
||||
boolean triangleVertex1InQuad = isPointInQuad(triangle.getBottomRightVertex(), quad);
|
||||
if (triangleVertex1InQuad)
|
||||
return true;
|
||||
boolean triangleVertex2InQuad = isPointInQuad(triangle.getTopRightVertex(), quad);
|
||||
if (triangleVertex2InQuad)
|
||||
return true;
|
||||
boolean triangleVertex3InQuad = isPointInQuad(triangle.getBottomLeftVertex(), quad);
|
||||
if (triangleVertex3InQuad)
|
||||
return true;
|
||||
return triangle.getTopEdge() >= quad.getTopEdge() && triangle.getBottomEdge() <= quad.getBottomEdge() && ((triangle.getLeftEdge() <= quad.getRightEdge() && triangle.getLeftEdge() >= quad.getLeftEdge()) || (triangle.getRightEdge() <= quad.getRightEdge() && triangle.getRightEdge() >= quad.getLeftEdge()));
|
||||
}
|
||||
|
||||
private boolean isVertexInTriangle(Vector vertex, Triangle triangle) {
|
||||
if (!isPointInQuad(vertex, triangle))
|
||||
return false;
|
||||
float gradient = triangle.getGradient();
|
||||
float maxVertexY = vertex.getX() * gradient + triangle.getBottomEdge();
|
||||
return vertex.getY() <= maxVertexY;
|
||||
}
|
||||
|
||||
public EntityCollisionData playerTerrainCollision(Player player, Tile terrainTile) {
|
||||
Circle circle = new Circle(player);
|
||||
if (circle.getTopEdge() < terrainTile.getTopEdge()) {
|
||||
float xDistance = Math.abs(circle.getPosition().x - terrainTile.getPosition().x);
|
||||
if (xDistance < circle.getRadius() + terrainTile.getWidth() / 2)
|
||||
return new EntityCollisionData(terrainTile, Edge.LEFT);
|
||||
}
|
||||
|
||||
if (isCircleQuadCollision(circle, terrainTile)) {
|
||||
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), terrainTile,
|
||||
terrainTile.getMovement());
|
||||
return new EntityCollisionData(terrainTile, edge);
|
||||
}
|
||||
return new EntityCollisionData(null, null);
|
||||
}
|
||||
|
||||
public EntityCollisionData playerCeilingCollision(Player player, Tile ceilingTile) {
|
||||
Circle circle = new Circle(player);
|
||||
if (circle.getBottomEdge() > ceilingTile.getBottomEdge()) {
|
||||
float xDistance = Math.abs(circle.getPosition().x - ceilingTile.getPosition().x);
|
||||
if (xDistance < circle.getRadius() + ceilingTile.getWidth() / 2)
|
||||
return new EntityCollisionData(ceilingTile, Edge.LEFT);
|
||||
}
|
||||
|
||||
if (isCircleQuadCollision(circle, ceilingTile)) {
|
||||
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), ceilingTile,
|
||||
ceilingTile.getMovement());
|
||||
return new EntityCollisionData(ceilingTile, edge);
|
||||
}
|
||||
return new EntityCollisionData(null, null);
|
||||
}
|
||||
|
||||
public EntityCollisionData playerEntityCollision(Player player, Entity entity) {
|
||||
Circle circle = new Circle(player);
|
||||
Quad quad = entity;
|
||||
if (isCircleQuadCollision(circle, quad)) {
|
||||
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), quad,
|
||||
entity.getMovement());
|
||||
return new EntityCollisionData(entity, edge);
|
||||
}
|
||||
return new EntityCollisionData(null, null);
|
||||
}
|
||||
|
||||
private Edge circleQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||
boolean circleFullyInsideQuad = false;
|
||||
if (circle.getPosition().getX() + circle.getRadius() <= quad.getRightEdge() && circle
|
||||
.getPosition().getX() - circle.getRadius() >= quad.getLeftEdge()) {
|
||||
if (circle.getPosition().getY() + circle.getRadius() <= quad.getTopEdge() && circle
|
||||
.getPosition().getY() - circle.getRadius() >= quad.getBottomEdge()) {
|
||||
circleFullyInsideQuad = true;
|
||||
}
|
||||
}
|
||||
if (circleFullyInsideQuad)
|
||||
return circleCenterInQuadCollisionEdge(circle, circleMovement, quad, quadMovement);
|
||||
return circlePartlyOutsideQuadCollisionEdge(circle, circleMovement, quad, quadMovement);
|
||||
}
|
||||
|
||||
private Edge circlePartlyOutsideQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||
Vector relativeMovement = new Vector(circleMovement).translate(quadMovement.negate());
|
||||
|
||||
Edge edge = Edge.NONE;
|
||||
if (circle.getPosition().getY() + circle.getRadius() >= quad.getTopEdge())
|
||||
edge = Edge.TOP;
|
||||
else if (circle.getPosition().getY() - circle.getRadius() <= quad.getBottomEdge())
|
||||
edge = Edge.BOTTOM;
|
||||
if (circle.getPosition().getX() - circle.getRadius() <= quad.getLeftEdge()) {
|
||||
if (edge != Edge.NONE) {
|
||||
if (edge == Edge.TOP) {
|
||||
float m = -1;
|
||||
float t = quad.getTopEdge() - m * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() >= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.TOP;
|
||||
else
|
||||
edge = Edge.LEFT;
|
||||
} else if (edge == Edge.BOTTOM) {
|
||||
float m = 1;
|
||||
float t = quad.getBottomEdge() - m * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() <= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.BOTTOM;
|
||||
else
|
||||
edge = Edge.LEFT;
|
||||
}
|
||||
} else
|
||||
edge = Edge.LEFT;
|
||||
} else if (circle.getPosition().getX() + circle.getRadius() >= quad.getRightEdge()) {
|
||||
if (edge != Edge.NONE) {
|
||||
if (edge == Edge.TOP) {
|
||||
//This movement check is because if player falls with too much speed on topLeft Vertex, sometimes RIGHT-Edge is returned
|
||||
if (relativeMovement.getY() < 0) {
|
||||
return Edge.TOP;
|
||||
} else {
|
||||
float m = 1;
|
||||
float t = quad.getTopEdge() - m * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() >= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.TOP;
|
||||
else
|
||||
edge = Edge.RIGHT;
|
||||
}
|
||||
} else if (edge == Edge.BOTTOM) {
|
||||
float m = -1;
|
||||
float t = quad.getBottomEdge() - m * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() <= m * circle.getPosition().getX() + t)
|
||||
edge = Edge.BOTTOM;
|
||||
else
|
||||
edge = Edge.RIGHT;
|
||||
}
|
||||
} else
|
||||
edge = Edge.RIGHT;
|
||||
}
|
||||
return edge;
|
||||
}
|
||||
|
||||
private Edge circleCenterInQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||
Vector relativeMovement = new Vector(circleMovement).translate(quadMovement.negate());
|
||||
|
||||
float m = relativeMovement.getY() / relativeMovement.getX();
|
||||
float t = circle.getPosition().getY() - m * circle.getPosition().getX();
|
||||
|
||||
float yAtLeftEdge = m * quad.getLeftEdge() + t;
|
||||
boolean touchingLeftEdge = yAtLeftEdge < quad.getTopEdge() && yAtLeftEdge > quad
|
||||
.getBottomEdge();
|
||||
float yAtRightEdge = m * quad.getRightEdge() + t;
|
||||
boolean touchingRightEdge = yAtRightEdge < quad.getTopEdge() && yAtRightEdge > quad
|
||||
.getBottomEdge();
|
||||
|
||||
float xAtTopEdge = (quad.getTopEdge() - t) / m;
|
||||
boolean touchingTopEdge = xAtTopEdge >= quad.getLeftEdge() && xAtTopEdge <= quad
|
||||
.getRightEdge();
|
||||
float xAtBottomEdge = (quad.getBottomEdge() - t) / m;
|
||||
boolean touchingBottomEdge = xAtBottomEdge >= quad.getLeftEdge() && xAtBottomEdge <= quad
|
||||
.getRightEdge();
|
||||
|
||||
if (relativeMovement.getX() == 0) {
|
||||
if (circle.getPosition().getX() - circle.getRadius() <= quad.getRightEdge() && circle
|
||||
.getPosition().getX() + circle.getRadius() >= quad.getLeftEdge()) {
|
||||
touchingTopEdge = true;
|
||||
touchingBottomEdge = true;
|
||||
}
|
||||
}
|
||||
|
||||
// CORNERS BELONGING TO TOP / BOTTOM EDGES
|
||||
if (touchingLeftEdge) {
|
||||
if (touchingRightEdge) {
|
||||
if (circle.getPosition().getX() <= quad.getPosition().getX())
|
||||
return Edge.LEFT;
|
||||
return Edge.RIGHT;
|
||||
} else if (touchingTopEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getTopEdge() - mn * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() < mn * circle.getPosition().getX() + tn)
|
||||
return Edge.LEFT;
|
||||
return Edge.TOP;
|
||||
} else if (touchingBottomEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getBottomEdge() - mn * quad.getLeftEdge();
|
||||
if (circle.getPosition().getY() > mn * circle.getPosition().getX() + tn)
|
||||
return Edge.LEFT;
|
||||
return Edge.BOTTOM;
|
||||
} else {
|
||||
return Edge.LEFT;
|
||||
}
|
||||
} else if (touchingRightEdge) {
|
||||
if (touchingTopEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getTopEdge() - mn * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() < mn * circle.getPosition().getX() + tn)
|
||||
return Edge.RIGHT;
|
||||
return Edge.TOP;
|
||||
} else if (touchingBottomEdge) {
|
||||
// Normale through vertex
|
||||
float mn = -1 / m;
|
||||
float tn = quad.getBottomEdge() - mn * quad.getRightEdge();
|
||||
if (circle.getPosition().getY() > mn * circle.getPosition().getX() + tn)
|
||||
return Edge.RIGHT;
|
||||
return Edge.BOTTOM;
|
||||
} else {
|
||||
return Edge.RIGHT;
|
||||
}
|
||||
} else if (touchingTopEdge) {
|
||||
if (touchingBottomEdge) {
|
||||
if (circle.getPosition().getY() >= quad.getPosition().getY())
|
||||
return Edge.TOP;
|
||||
return Edge.BOTTOM;
|
||||
} else {
|
||||
return Edge.TOP;
|
||||
}
|
||||
} else if (touchingBottomEdge) {
|
||||
return Edge.BOTTOM;
|
||||
}
|
||||
return Edge.NONE;
|
||||
}
|
||||
}
|
||||
|
@ -1,109 +1,109 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Obstacle;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collectables.Energy;
|
||||
import de.frajul.endlessroll.entities.collectables.Star;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.EntityCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.ObstacleCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.PlayerCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.ToolCollisionData;
|
||||
import de.frajul.endlessroll.entities.tools.Tool;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.main.game.GameScene;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.main.physics.Physics;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.01.2016.
|
||||
*/
|
||||
public class CollisionManager {
|
||||
|
||||
private Game game;
|
||||
private Player player;
|
||||
private Timer timer;
|
||||
|
||||
public CollisionManager(Game game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
//Check Obstacle always before tool, because at tool, player could be moved etc.
|
||||
public void update(Physics physics, GameScene scene, Timer timer) {
|
||||
physics.checkToolCollision(scene);
|
||||
|
||||
this.player = scene.getPlayer();
|
||||
this.timer = timer;
|
||||
PlayerCollisionData data = physics.getPlayerCollisionData(scene);
|
||||
if (data.isTerrainCollision())
|
||||
checkTerrainCollision(data.getTerrainCollisionData());
|
||||
if (data.isCeilingCollision())
|
||||
checkCeilingCollision(data.getCeilingCollisionData());
|
||||
if (data.isObstacleCollision())
|
||||
checkObstacleCollision(data.getObstacleCollisionData(), player.hasSuperPower());
|
||||
if (data.isToolCollision())
|
||||
checkToolCollision(data.getToolCollisionData());
|
||||
if (data.isStarCollision())
|
||||
game.onStarCollision((Star) data.getStarCollisionData().getEntity());
|
||||
if (data.isEnergyCollision())
|
||||
game.onEnergyCollision((Energy) data.getEnergyCollisionData().getEntity());
|
||||
}
|
||||
|
||||
private void checkTerrainCollision(EntityCollisionData data) {
|
||||
checkEntityCollision(data);
|
||||
if (data.getEdge() != Edge.TOP)
|
||||
game.onGameOver(true);
|
||||
}
|
||||
|
||||
private void checkCeilingCollision(EntityCollisionData data) {
|
||||
checkEntityCollision(data);
|
||||
if (data.getEdge() != Edge.BOTTOM)
|
||||
game.onGameOver(true);
|
||||
}
|
||||
|
||||
private void checkToolCollision(ToolCollisionData data) {
|
||||
for (Tool tool : data.getTools())
|
||||
tool.onPlayerCollision(player, timer);
|
||||
}
|
||||
|
||||
private void checkObstacleCollision(ObstacleCollisionData data, boolean playerHasSuperpower) {
|
||||
for (EntityCollisionData entityData : data.getCollisions()) {
|
||||
if (playerHasSuperpower) {
|
||||
entityData.getEntity().destroy(DestroyEffect.EXPLOSION);
|
||||
} else {
|
||||
if (entityData.getEdge() != Edge.TOP || ((Obstacle) entityData.getEntity())
|
||||
.isDeadly())
|
||||
game.onGameOver(true);
|
||||
else
|
||||
checkEntityCollision(entityData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEntityCollision(EntityCollisionData data) {
|
||||
switch (data.getEdge()) {
|
||||
case TOP:
|
||||
player.getMovement().y = 0;
|
||||
player.setToTerrain(data.getEntity().getTopEdge());
|
||||
break;
|
||||
case BOTTOM:
|
||||
player.getMovement().y = 0;
|
||||
player.setTopEdge(data.getEntity().getBottomEdge());
|
||||
break;
|
||||
case LEFT:
|
||||
player.getPosition().x = data.getEntity().getLeftEdge() - player.RADIUS;
|
||||
break;
|
||||
case RIGHT:
|
||||
player.getPosition().x = data.getEntity().getRightEdge() + player.RADIUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Obstacle;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collectables.Energy;
|
||||
import de.frajul.endlessroll.entities.collectables.Star;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.EntityCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.ObstacleCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.PlayerCollisionData;
|
||||
import de.frajul.endlessroll.entities.collision.collisionData.ToolCollisionData;
|
||||
import de.frajul.endlessroll.entities.tools.Tool;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.main.game.GameScene;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.main.physics.Physics;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.01.2016.
|
||||
*/
|
||||
public class CollisionManager {
|
||||
|
||||
private Game game;
|
||||
private Player player;
|
||||
private Timer timer;
|
||||
|
||||
public CollisionManager(Game game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
//Check Obstacle always before tool, because at tool, player could be moved etc.
|
||||
public void update(Physics physics, GameScene scene, Timer timer) {
|
||||
physics.checkToolCollision(scene);
|
||||
|
||||
this.player = scene.getPlayer();
|
||||
this.timer = timer;
|
||||
PlayerCollisionData data = physics.getPlayerCollisionData(scene);
|
||||
if (data.isTerrainCollision())
|
||||
checkTerrainCollision(data.getTerrainCollisionData());
|
||||
if (data.isCeilingCollision())
|
||||
checkCeilingCollision(data.getCeilingCollisionData());
|
||||
if (data.isObstacleCollision())
|
||||
checkObstacleCollision(data.getObstacleCollisionData(), player.hasSuperPower());
|
||||
if (data.isToolCollision())
|
||||
checkToolCollision(data.getToolCollisionData());
|
||||
if (data.isStarCollision())
|
||||
game.onStarCollision((Star) data.getStarCollisionData().getEntity());
|
||||
if (data.isEnergyCollision())
|
||||
game.onEnergyCollision((Energy) data.getEnergyCollisionData().getEntity());
|
||||
}
|
||||
|
||||
private void checkTerrainCollision(EntityCollisionData data) {
|
||||
checkEntityCollision(data);
|
||||
if (data.getEdge() != Edge.TOP)
|
||||
game.onGameOver(true);
|
||||
}
|
||||
|
||||
private void checkCeilingCollision(EntityCollisionData data) {
|
||||
checkEntityCollision(data);
|
||||
if (data.getEdge() != Edge.BOTTOM)
|
||||
game.onGameOver(true);
|
||||
}
|
||||
|
||||
private void checkToolCollision(ToolCollisionData data) {
|
||||
for (Tool tool : data.getTools())
|
||||
tool.onPlayerCollision(player, timer);
|
||||
}
|
||||
|
||||
private void checkObstacleCollision(ObstacleCollisionData data, boolean playerHasSuperpower) {
|
||||
for (EntityCollisionData entityData : data.getCollisions()) {
|
||||
if (playerHasSuperpower) {
|
||||
entityData.getEntity().destroy(DestroyEffect.EXPLOSION);
|
||||
} else {
|
||||
if (entityData.getEdge() != Edge.TOP || ((Obstacle) entityData.getEntity())
|
||||
.isDeadly())
|
||||
game.onGameOver(true);
|
||||
else
|
||||
checkEntityCollision(entityData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEntityCollision(EntityCollisionData data) {
|
||||
switch (data.getEdge()) {
|
||||
case TOP:
|
||||
player.getMovement().y = 0;
|
||||
player.setToTerrain(data.getEntity().getTopEdge());
|
||||
break;
|
||||
case BOTTOM:
|
||||
player.getMovement().y = 0;
|
||||
player.setTopEdge(data.getEntity().getBottomEdge());
|
||||
break;
|
||||
case LEFT:
|
||||
player.getPosition().x = data.getEntity().getLeftEdge() - player.RADIUS;
|
||||
break;
|
||||
case RIGHT:
|
||||
player.getPosition().x = data.getEntity().getRightEdge() + player.RADIUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
public enum Edge {
|
||||
LEFT, RIGHT, TOP, BOTTOM, NONE
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision;
|
||||
|
||||
public enum Edge {
|
||||
LEFT, RIGHT, TOP, BOTTOM, NONE
|
||||
}
|
@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.collision.Edge;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.01.2016.
|
||||
*/
|
||||
public class EntityCollisionData {
|
||||
|
||||
private Entity entity;
|
||||
private Edge edge;
|
||||
|
||||
public EntityCollisionData(Entity entity, Edge edge) {
|
||||
this.entity = entity;
|
||||
this.edge = edge;
|
||||
}
|
||||
|
||||
public boolean isCollision() {
|
||||
return entity != null && edge != null;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Edge getEdge() {
|
||||
return edge;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.collision.Edge;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.01.2016.
|
||||
*/
|
||||
public class EntityCollisionData {
|
||||
|
||||
private Entity entity;
|
||||
private Edge edge;
|
||||
|
||||
public EntityCollisionData(Entity entity, Edge edge) {
|
||||
this.entity = entity;
|
||||
this.edge = edge;
|
||||
}
|
||||
|
||||
public boolean isCollision() {
|
||||
return entity != null && edge != null;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Edge getEdge() {
|
||||
return edge;
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,30 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Julian on 04.01.2016.
|
||||
*/
|
||||
public class ObstacleCollisionData {
|
||||
|
||||
private List<EntityCollisionData> collisions;
|
||||
|
||||
public ObstacleCollisionData(List<EntityCollisionData> collisions) {
|
||||
this.collisions = collisions;
|
||||
}
|
||||
|
||||
public boolean isCollision() {
|
||||
return collisions.size() > 0;
|
||||
}
|
||||
|
||||
public List<EntityCollisionData> getCollisions() {
|
||||
return collisions;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Julian on 04.01.2016.
|
||||
*/
|
||||
public class ObstacleCollisionData {
|
||||
|
||||
private List<EntityCollisionData> collisions;
|
||||
|
||||
public ObstacleCollisionData(List<EntityCollisionData> collisions) {
|
||||
this.collisions = collisions;
|
||||
}
|
||||
|
||||
public boolean isCollision() {
|
||||
return collisions.size() > 0;
|
||||
}
|
||||
|
||||
public List<EntityCollisionData> getCollisions() {
|
||||
return collisions;
|
||||
}
|
||||
}
|
||||
|
@ -1,78 +1,78 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
/**
|
||||
* Created by Julian on 05.12.2015.
|
||||
*/
|
||||
public class PlayerCollisionData {
|
||||
|
||||
private EntityCollisionData terrainCollision;
|
||||
private EntityCollisionData ceilingCollision;
|
||||
private ObstacleCollisionData obstacleCollision;
|
||||
private ToolCollisionData toolCollision;
|
||||
private EntityCollisionData starCollision;
|
||||
private EntityCollisionData energyCollision;
|
||||
|
||||
public PlayerCollisionData(EntityCollisionData terrainCollision, EntityCollisionData ceilingCollision, ObstacleCollisionData obstacleCollision, ToolCollisionData toolCollision, EntityCollisionData starCollision, EntityCollisionData energyCollision) {
|
||||
this.terrainCollision = terrainCollision;
|
||||
this.ceilingCollision = ceilingCollision;
|
||||
this.obstacleCollision = obstacleCollision;
|
||||
this.toolCollision = toolCollision;
|
||||
this.starCollision = starCollision;
|
||||
this.energyCollision = energyCollision;
|
||||
}
|
||||
|
||||
public boolean isTerrainCollision() {
|
||||
return terrainCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getTerrainCollisionData() {
|
||||
return terrainCollision;
|
||||
}
|
||||
|
||||
public boolean isCeilingCollision() {
|
||||
return ceilingCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getCeilingCollisionData() {
|
||||
return ceilingCollision;
|
||||
}
|
||||
|
||||
public boolean isObstacleCollision() {
|
||||
return obstacleCollision.isCollision();
|
||||
}
|
||||
|
||||
public ObstacleCollisionData getObstacleCollisionData() {
|
||||
return obstacleCollision;
|
||||
}
|
||||
|
||||
public boolean isToolCollision() {
|
||||
return toolCollision.isCollision();
|
||||
}
|
||||
|
||||
public ToolCollisionData getToolCollisionData() {
|
||||
return toolCollision;
|
||||
}
|
||||
|
||||
public boolean isStarCollision() {
|
||||
return starCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getStarCollisionData() {
|
||||
return starCollision;
|
||||
}
|
||||
|
||||
public boolean isEnergyCollision() {
|
||||
return energyCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getEnergyCollisionData() {
|
||||
return energyCollision;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
/**
|
||||
* Created by Julian on 05.12.2015.
|
||||
*/
|
||||
public class PlayerCollisionData {
|
||||
|
||||
private EntityCollisionData terrainCollision;
|
||||
private EntityCollisionData ceilingCollision;
|
||||
private ObstacleCollisionData obstacleCollision;
|
||||
private ToolCollisionData toolCollision;
|
||||
private EntityCollisionData starCollision;
|
||||
private EntityCollisionData energyCollision;
|
||||
|
||||
public PlayerCollisionData(EntityCollisionData terrainCollision, EntityCollisionData ceilingCollision, ObstacleCollisionData obstacleCollision, ToolCollisionData toolCollision, EntityCollisionData starCollision, EntityCollisionData energyCollision) {
|
||||
this.terrainCollision = terrainCollision;
|
||||
this.ceilingCollision = ceilingCollision;
|
||||
this.obstacleCollision = obstacleCollision;
|
||||
this.toolCollision = toolCollision;
|
||||
this.starCollision = starCollision;
|
||||
this.energyCollision = energyCollision;
|
||||
}
|
||||
|
||||
public boolean isTerrainCollision() {
|
||||
return terrainCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getTerrainCollisionData() {
|
||||
return terrainCollision;
|
||||
}
|
||||
|
||||
public boolean isCeilingCollision() {
|
||||
return ceilingCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getCeilingCollisionData() {
|
||||
return ceilingCollision;
|
||||
}
|
||||
|
||||
public boolean isObstacleCollision() {
|
||||
return obstacleCollision.isCollision();
|
||||
}
|
||||
|
||||
public ObstacleCollisionData getObstacleCollisionData() {
|
||||
return obstacleCollision;
|
||||
}
|
||||
|
||||
public boolean isToolCollision() {
|
||||
return toolCollision.isCollision();
|
||||
}
|
||||
|
||||
public ToolCollisionData getToolCollisionData() {
|
||||
return toolCollision;
|
||||
}
|
||||
|
||||
public boolean isStarCollision() {
|
||||
return starCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getStarCollisionData() {
|
||||
return starCollision;
|
||||
}
|
||||
|
||||
public boolean isEnergyCollision() {
|
||||
return energyCollision.isCollision();
|
||||
}
|
||||
|
||||
public EntityCollisionData getEnergyCollisionData() {
|
||||
return energyCollision;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.tools.Tool;
|
||||
|
||||
/**
|
||||
* Created by Julian on 21.02.2016.
|
||||
*/
|
||||
public class ToolCollisionData {
|
||||
|
||||
private List<Tool> tools;
|
||||
|
||||
public ToolCollisionData(List<Tool> tools) {
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
public boolean isCollision() {
|
||||
return tools.size() > 0;
|
||||
}
|
||||
|
||||
public List<Tool> getTools() {
|
||||
return tools;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.collisionData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.tools.Tool;
|
||||
|
||||
/**
|
||||
* Created by Julian on 21.02.2016.
|
||||
*/
|
||||
public class ToolCollisionData {
|
||||
|
||||
private List<Tool> tools;
|
||||
|
||||
public ToolCollisionData(List<Tool> tools) {
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
public boolean isCollision() {
|
||||
return tools.size() > 0;
|
||||
}
|
||||
|
||||
public List<Tool> getTools() {
|
||||
return tools;
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Circle extends Geometry {
|
||||
|
||||
private Vector center;
|
||||
private float radius;
|
||||
|
||||
public Circle(Player ball) {
|
||||
this(new Vector(ball.getPosition()), ball.getWidth() / 2);
|
||||
}
|
||||
|
||||
public Circle(Vector center, float radius) {
|
||||
this.center = center;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRightEdge() {
|
||||
return center.x + radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLeftEdge() {
|
||||
return center.x - radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTopEdge() {
|
||||
return center.y + radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBottomEdge() {
|
||||
return center.y - radius;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return center;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Circle extends Geometry {
|
||||
|
||||
private Vector center;
|
||||
private float radius;
|
||||
|
||||
public Circle(Player ball) {
|
||||
this(new Vector(ball.getPosition()), ball.getWidth() / 2);
|
||||
}
|
||||
|
||||
public Circle(Vector center, float radius) {
|
||||
this.center = center;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRightEdge() {
|
||||
return center.x + radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLeftEdge() {
|
||||
return center.x - radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTopEdge() {
|
||||
return center.y + radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBottomEdge() {
|
||||
return center.y - radius;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return center;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
/**
|
||||
* Created by Julian on 28.02.2016.
|
||||
*/
|
||||
public abstract class Geometry {
|
||||
|
||||
public abstract float getTopEdge();
|
||||
|
||||
public abstract float getBottomEdge();
|
||||
|
||||
public abstract float getRightEdge();
|
||||
|
||||
public abstract float getLeftEdge();
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
/**
|
||||
* Created by Julian on 28.02.2016.
|
||||
*/
|
||||
public abstract class Geometry {
|
||||
|
||||
public abstract float getTopEdge();
|
||||
|
||||
public abstract float getBottomEdge();
|
||||
|
||||
public abstract float getRightEdge();
|
||||
|
||||
public abstract float getLeftEdge();
|
||||
|
||||
}
|
||||
|
@ -1,70 +1,70 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Quad extends Geometry {
|
||||
|
||||
protected Vector position;
|
||||
protected float width, height;
|
||||
|
||||
public Quad(Vector position, float width, float height) {
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRightEdge() {
|
||||
return position.x + width / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLeftEdge() {
|
||||
return position.x - width / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTopEdge() {
|
||||
return position.y + height / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBottomEdge() {
|
||||
return position.y - height / 2;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Quad extends Geometry {
|
||||
|
||||
protected Vector position;
|
||||
protected float width, height;
|
||||
|
||||
public Quad(Vector position, float width, float height) {
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRightEdge() {
|
||||
return position.x + width / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLeftEdge() {
|
||||
return position.x - width / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTopEdge() {
|
||||
return position.y + height / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBottomEdge() {
|
||||
return position.y - height / 2;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.tools.Ramp;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Triangle extends Quad {
|
||||
|
||||
public Triangle(Ramp ramp) {
|
||||
super(ramp.getPosition(), ramp.getWidth(), ramp.getHeight());
|
||||
}
|
||||
|
||||
public float getGradient() {
|
||||
return super.getHeight() / super.getWidth();
|
||||
}
|
||||
|
||||
public Vector getBottomRightVertex() {
|
||||
return new Vector(getRightEdge(), getBottomEdge());
|
||||
}
|
||||
|
||||
public Vector getBottomLeftVertex() {
|
||||
return new Vector(getLeftEdge(), getBottomEdge());
|
||||
}
|
||||
|
||||
public Vector getTopRightVertex() {
|
||||
return new Vector(getRightEdge(), getTopEdge());
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.collision.geometry;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.tools.Ramp;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.12.2015.
|
||||
*/
|
||||
public class Triangle extends Quad {
|
||||
|
||||
public Triangle(Ramp ramp) {
|
||||
super(ramp.getPosition(), ramp.getWidth(), ramp.getHeight());
|
||||
}
|
||||
|
||||
public float getGradient() {
|
||||
return super.getHeight() / super.getWidth();
|
||||
}
|
||||
|
||||
public Vector getBottomRightVertex() {
|
||||
return new Vector(getRightEdge(), getBottomEdge());
|
||||
}
|
||||
|
||||
public Vector getBottomLeftVertex() {
|
||||
return new Vector(getLeftEdge(), getBottomEdge());
|
||||
}
|
||||
|
||||
public Vector getTopRightVertex() {
|
||||
return new Vector(getRightEdge(), getTopEdge());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,101 +1,101 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 31.07.2016.
|
||||
*/
|
||||
public class Countdown extends Gui {
|
||||
|
||||
private Game game;
|
||||
private SoundManager soundManager;
|
||||
private SoundStream soundStream;
|
||||
private Texture texture3;
|
||||
private Texture texture2;
|
||||
private Texture texture1;
|
||||
|
||||
private AtomicBoolean running;
|
||||
private int currentSeconds = 0;
|
||||
private float time = 0;
|
||||
|
||||
public Countdown(Game game, SoundManager soundManager, TexturePack texturePack) {
|
||||
super(texturePack.countdown3, new Vector(), 0.8f, 0.8f);
|
||||
this.game = game;
|
||||
this.soundManager = soundManager;
|
||||
this.texture3 = texturePack.countdown1;
|
||||
this.texture2 = texturePack.countdown2;
|
||||
this.texture1 = texturePack.countdown3;
|
||||
running = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
public void update(float delta) {
|
||||
if (running.get()) {
|
||||
time += delta;
|
||||
if (time >= 1000 && currentSeconds == 0) {
|
||||
currentSeconds = 1;
|
||||
onNextSecondThread(currentSeconds, true);
|
||||
|
||||
}
|
||||
if (time >= 2000 && currentSeconds == 1) {
|
||||
currentSeconds = 2;
|
||||
onNextSecondThread(currentSeconds, true);
|
||||
}
|
||||
if (time >= 3000 && currentSeconds == 2) {
|
||||
currentSeconds = 3;
|
||||
running.set(false);
|
||||
game.countdownFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reset();
|
||||
running.set(true);
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundSingle);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running.set(false);
|
||||
if (soundStream != null)
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
time = 0;
|
||||
currentSeconds = 0;
|
||||
onNextSecondThread(0, false);
|
||||
}
|
||||
|
||||
private void onNextSecondThread(final int second, final boolean playSound) {
|
||||
if (playSound) {
|
||||
if (second == 2)
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundLast);
|
||||
else
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundSingle);
|
||||
}
|
||||
super.setTexture(texture1);
|
||||
if (second == 1)
|
||||
super.setTexture(texture2);
|
||||
else if (second == 2)
|
||||
super.setTexture(texture3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return running.get();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 31.07.2016.
|
||||
*/
|
||||
public class Countdown extends Gui {
|
||||
|
||||
private Game game;
|
||||
private SoundManager soundManager;
|
||||
private SoundStream soundStream;
|
||||
private Texture texture3;
|
||||
private Texture texture2;
|
||||
private Texture texture1;
|
||||
|
||||
private AtomicBoolean running;
|
||||
private int currentSeconds = 0;
|
||||
private float time = 0;
|
||||
|
||||
public Countdown(Game game, SoundManager soundManager, TexturePack texturePack) {
|
||||
super(texturePack.countdown3, new Vector(), 0.8f, 0.8f);
|
||||
this.game = game;
|
||||
this.soundManager = soundManager;
|
||||
this.texture3 = texturePack.countdown1;
|
||||
this.texture2 = texturePack.countdown2;
|
||||
this.texture1 = texturePack.countdown3;
|
||||
running = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
public void update(float delta) {
|
||||
if (running.get()) {
|
||||
time += delta;
|
||||
if (time >= 1000 && currentSeconds == 0) {
|
||||
currentSeconds = 1;
|
||||
onNextSecondThread(currentSeconds, true);
|
||||
|
||||
}
|
||||
if (time >= 2000 && currentSeconds == 1) {
|
||||
currentSeconds = 2;
|
||||
onNextSecondThread(currentSeconds, true);
|
||||
}
|
||||
if (time >= 3000 && currentSeconds == 2) {
|
||||
currentSeconds = 3;
|
||||
running.set(false);
|
||||
game.countdownFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reset();
|
||||
running.set(true);
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundSingle);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running.set(false);
|
||||
if (soundStream != null)
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
time = 0;
|
||||
currentSeconds = 0;
|
||||
onNextSecondThread(0, false);
|
||||
}
|
||||
|
||||
private void onNextSecondThread(final int second, final boolean playSound) {
|
||||
if (playSound) {
|
||||
if (second == 2)
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundLast);
|
||||
else
|
||||
soundStream = soundManager.playSound(soundManager.countdownSoundSingle);
|
||||
}
|
||||
super.setTexture(texture1);
|
||||
if (second == 1)
|
||||
super.setTexture(texture2);
|
||||
else if (second == 2)
|
||||
super.setTexture(texture3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return running.get();
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Color4f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class Gui extends Entity {
|
||||
|
||||
protected float roundValue = 0;
|
||||
|
||||
public Gui(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
}
|
||||
|
||||
public float getRoundValue() {
|
||||
return roundValue;
|
||||
}
|
||||
|
||||
public void setRoundValue(float roundValue) {
|
||||
this.roundValue = roundValue;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Color4f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class Gui extends Entity {
|
||||
|
||||
protected float roundValue = 0;
|
||||
|
||||
public Gui(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
}
|
||||
|
||||
public float getRoundValue() {
|
||||
return roundValue;
|
||||
}
|
||||
|
||||
public void setRoundValue(float roundValue) {
|
||||
this.roundValue = roundValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,48 +1,48 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class Progressbar extends Gui {
|
||||
|
||||
private float maxTime;
|
||||
private float progress;
|
||||
|
||||
public Progressbar(Texture texture, Vector position, float width, float height, float maxTime) {
|
||||
super(texture, position, width, height);
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
progress += frameTime / maxTime;
|
||||
if (progress >= 1f)
|
||||
progress = 1f;
|
||||
}
|
||||
|
||||
public boolean hasFinished() {
|
||||
return progress == 1;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public float getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
public void setMaxTime(float maxTime) {
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class Progressbar extends Gui {
|
||||
|
||||
private float maxTime;
|
||||
private float progress;
|
||||
|
||||
public Progressbar(Texture texture, Vector position, float width, float height, float maxTime) {
|
||||
super(texture, position, width, height);
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
progress += frameTime / maxTime;
|
||||
if (progress >= 1f)
|
||||
progress = 1f;
|
||||
}
|
||||
|
||||
public boolean hasFinished() {
|
||||
return progress == 1;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public float getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
public void setMaxTime(float maxTime) {
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
}
|
||||
|
@ -1,157 +1,157 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
import de.frajul.endlessroll.data.Color4f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.entities.tools.ToolSlot;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.entities.tools.ToolUpgradeType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
|
||||
public class ToolButton {
|
||||
|
||||
private final Color3f LOCKED = new Color3f(0.29f, 0.29f, 0.29f);
|
||||
private final Color3f ACTIVE_READY = new Color3f(0.25f, 0.89f, 0.17f);
|
||||
private final Color3f ACTIVE_NOT_READY = new Color3f(0.86f, 0.08f, 0.13f);
|
||||
private final Color3f INACTIVE_READY = new Color3f(1.0f, 0.95f, 0.0f);
|
||||
private final Color3f INACTIVE_NOT_READY = new Color3f(0.57f, 0.11f, 0.06f);
|
||||
|
||||
private Gui border;
|
||||
private Gui background;
|
||||
private Progressbar progressbar;
|
||||
private ToolButtonAnimationLayer animationLayer;
|
||||
|
||||
private Game game;
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
private AtomicBoolean active;
|
||||
private Texture toolButtonLockedTexture;
|
||||
private Texture toolButtonEmptyTexture;
|
||||
|
||||
public ToolButton(Vector position, float width, float height, TexturePack texturePack, Game game) {
|
||||
this.game = game;
|
||||
active = new AtomicBoolean(false);
|
||||
toolButtonLockedTexture = texturePack.toolButtonLocked;
|
||||
toolButtonEmptyTexture = texturePack.toolButtonEmpty;
|
||||
|
||||
border = new Gui(texturePack.white, position, width, height);
|
||||
border.setRoundValue(0.3f);
|
||||
border.setAlpha(0.9f);
|
||||
background = new Gui(null, position, height, height);
|
||||
progressbar = new Progressbar(texturePack.white, position, height, height, 0);
|
||||
progressbar.setColor(new Color3f(0.4f, 0.4f, 0.4f));
|
||||
progressbar.setAlpha(0.6f);
|
||||
progressbar.setRoundValue(1);
|
||||
progressbar.setProgress(0.6f);
|
||||
animationLayer = new ToolButtonAnimationLayer(toolButtonLockedTexture, position, height,
|
||||
height);
|
||||
}
|
||||
|
||||
public void setToolSlot(ToolSlot toolSlot) {
|
||||
this.toolType = toolSlot.getToolType();
|
||||
this.locked = toolSlot.isLocked();
|
||||
|
||||
if (locked) {
|
||||
background.setTexture(toolButtonLockedTexture);
|
||||
} else if (toolType == null) {
|
||||
background.setTexture(toolButtonEmptyTexture);
|
||||
} else {
|
||||
background.setTexture(toolType.getToolButtonTexture());
|
||||
animationLayer.setTexture(toolType.getToolButtonTexture());
|
||||
}
|
||||
if (toolType != null)
|
||||
progressbar.setMaxTime(toolType.getCurrentUpgradeValue(ToolUpgradeType.COOLDOWN));
|
||||
|
||||
if (locked || toolType == null)
|
||||
border.setColor(LOCKED);
|
||||
else
|
||||
border.setColor(INACTIVE_NOT_READY);
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
progressbar.setProgress(progress);
|
||||
updateBorderColor();
|
||||
}
|
||||
|
||||
public boolean hasFinishedLoading() {
|
||||
return progressbar.hasFinished();
|
||||
}
|
||||
|
||||
public void update(float frameTime, boolean gameRunning) {
|
||||
if (gameRunning) {
|
||||
if (!progressbar.hasFinished()) {
|
||||
progressbar.update(frameTime);
|
||||
if (progressbar.hasFinished()) {
|
||||
animationLayer.startAnimation();
|
||||
if (active.get())
|
||||
game.onToolButtonFinishedLoading(toolType);
|
||||
}
|
||||
}
|
||||
updateBorderColor();
|
||||
}
|
||||
|
||||
animationLayer.update(frameTime);
|
||||
}
|
||||
|
||||
public synchronized void updateBorderColor() {
|
||||
if (!locked && toolType != null) {
|
||||
if (active.get()) {
|
||||
if (progressbar.hasFinished())
|
||||
border.setColor(ACTIVE_READY);
|
||||
else
|
||||
border.setColor(ACTIVE_NOT_READY);
|
||||
} else {
|
||||
if (progressbar.hasFinished())
|
||||
border.setColor(INACTIVE_READY);
|
||||
else
|
||||
border.setColor(INACTIVE_NOT_READY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible){
|
||||
border.setVisible(visible);
|
||||
background.setVisible(visible);
|
||||
progressbar.setVisible(visible);
|
||||
animationLayer.setVisible(visible);
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active.set(active);
|
||||
}
|
||||
|
||||
public AtomicBoolean getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public Gui getBorder() {
|
||||
return border;
|
||||
}
|
||||
|
||||
public Gui getBackground() {
|
||||
return background;
|
||||
}
|
||||
|
||||
public Progressbar getProgressbar() {
|
||||
return progressbar;
|
||||
}
|
||||
|
||||
public ToolButtonAnimationLayer getAnimationLayer() {
|
||||
return animationLayer;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
import de.frajul.endlessroll.data.Color4f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.entities.tools.ToolSlot;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.entities.tools.ToolUpgradeType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
|
||||
public class ToolButton {
|
||||
|
||||
private final Color3f LOCKED = new Color3f(0.29f, 0.29f, 0.29f);
|
||||
private final Color3f ACTIVE_READY = new Color3f(0.25f, 0.89f, 0.17f);
|
||||
private final Color3f ACTIVE_NOT_READY = new Color3f(0.86f, 0.08f, 0.13f);
|
||||
private final Color3f INACTIVE_READY = new Color3f(1.0f, 0.95f, 0.0f);
|
||||
private final Color3f INACTIVE_NOT_READY = new Color3f(0.57f, 0.11f, 0.06f);
|
||||
|
||||
private Gui border;
|
||||
private Gui background;
|
||||
private Progressbar progressbar;
|
||||
private ToolButtonAnimationLayer animationLayer;
|
||||
|
||||
private Game game;
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
private AtomicBoolean active;
|
||||
private Texture toolButtonLockedTexture;
|
||||
private Texture toolButtonEmptyTexture;
|
||||
|
||||
public ToolButton(Vector position, float width, float height, TexturePack texturePack, Game game) {
|
||||
this.game = game;
|
||||
active = new AtomicBoolean(false);
|
||||
toolButtonLockedTexture = texturePack.toolButtonLocked;
|
||||
toolButtonEmptyTexture = texturePack.toolButtonEmpty;
|
||||
|
||||
border = new Gui(texturePack.white, position, width, height);
|
||||
border.setRoundValue(0.3f);
|
||||
border.setAlpha(0.9f);
|
||||
background = new Gui(null, position, height, height);
|
||||
progressbar = new Progressbar(texturePack.white, position, height, height, 0);
|
||||
progressbar.setColor(new Color3f(0.4f, 0.4f, 0.4f));
|
||||
progressbar.setAlpha(0.6f);
|
||||
progressbar.setRoundValue(1);
|
||||
progressbar.setProgress(0.6f);
|
||||
animationLayer = new ToolButtonAnimationLayer(toolButtonLockedTexture, position, height,
|
||||
height);
|
||||
}
|
||||
|
||||
public void setToolSlot(ToolSlot toolSlot) {
|
||||
this.toolType = toolSlot.getToolType();
|
||||
this.locked = toolSlot.isLocked();
|
||||
|
||||
if (locked) {
|
||||
background.setTexture(toolButtonLockedTexture);
|
||||
} else if (toolType == null) {
|
||||
background.setTexture(toolButtonEmptyTexture);
|
||||
} else {
|
||||
background.setTexture(toolType.getToolButtonTexture());
|
||||
animationLayer.setTexture(toolType.getToolButtonTexture());
|
||||
}
|
||||
if (toolType != null)
|
||||
progressbar.setMaxTime(toolType.getCurrentUpgradeValue(ToolUpgradeType.COOLDOWN));
|
||||
|
||||
if (locked || toolType == null)
|
||||
border.setColor(LOCKED);
|
||||
else
|
||||
border.setColor(INACTIVE_NOT_READY);
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
progressbar.setProgress(progress);
|
||||
updateBorderColor();
|
||||
}
|
||||
|
||||
public boolean hasFinishedLoading() {
|
||||
return progressbar.hasFinished();
|
||||
}
|
||||
|
||||
public void update(float frameTime, boolean gameRunning) {
|
||||
if (gameRunning) {
|
||||
if (!progressbar.hasFinished()) {
|
||||
progressbar.update(frameTime);
|
||||
if (progressbar.hasFinished()) {
|
||||
animationLayer.startAnimation();
|
||||
if (active.get())
|
||||
game.onToolButtonFinishedLoading(toolType);
|
||||
}
|
||||
}
|
||||
updateBorderColor();
|
||||
}
|
||||
|
||||
animationLayer.update(frameTime);
|
||||
}
|
||||
|
||||
public synchronized void updateBorderColor() {
|
||||
if (!locked && toolType != null) {
|
||||
if (active.get()) {
|
||||
if (progressbar.hasFinished())
|
||||
border.setColor(ACTIVE_READY);
|
||||
else
|
||||
border.setColor(ACTIVE_NOT_READY);
|
||||
} else {
|
||||
if (progressbar.hasFinished())
|
||||
border.setColor(INACTIVE_READY);
|
||||
else
|
||||
border.setColor(INACTIVE_NOT_READY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible){
|
||||
border.setVisible(visible);
|
||||
background.setVisible(visible);
|
||||
progressbar.setVisible(visible);
|
||||
animationLayer.setVisible(visible);
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active.set(active);
|
||||
}
|
||||
|
||||
public AtomicBoolean getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public Gui getBorder() {
|
||||
return border;
|
||||
}
|
||||
|
||||
public Gui getBackground() {
|
||||
return background;
|
||||
}
|
||||
|
||||
public Progressbar getProgressbar() {
|
||||
return progressbar;
|
||||
}
|
||||
|
||||
public ToolButtonAnimationLayer getAnimationLayer() {
|
||||
return animationLayer;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +1,58 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class ToolButtonAnimationLayer extends Gui {
|
||||
|
||||
private final float ANIMATION_TIME = 500;
|
||||
|
||||
private float startWidth;
|
||||
private float startHeight;
|
||||
private boolean animationRunning = false;
|
||||
private float elapsedTime = 0;
|
||||
|
||||
public ToolButtonAnimationLayer(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
super.setVisible(false);
|
||||
this.startWidth = width;
|
||||
this.startHeight = height;
|
||||
}
|
||||
|
||||
public void startAnimation() {
|
||||
reset();
|
||||
super.setVisible(true);
|
||||
animationRunning = true;
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
if (animationRunning) {
|
||||
elapsedTime += frameTime;
|
||||
if (elapsedTime >= ANIMATION_TIME) {
|
||||
reset();
|
||||
}
|
||||
float progress = elapsedTime / ANIMATION_TIME;
|
||||
super.setAlpha(0.5f - 0.5f * progress);
|
||||
float scaleFactor = 1 + 2 * progress;
|
||||
super.setWidth(scaleFactor * startWidth);
|
||||
super.setHeight(scaleFactor * startHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
animationRunning = false;
|
||||
elapsedTime = 0;
|
||||
super.setVisible(false);
|
||||
super.setAlpha(0.5f);
|
||||
super.setWidth(startWidth);
|
||||
super.setHeight(startHeight);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class ToolButtonAnimationLayer extends Gui {
|
||||
|
||||
private final float ANIMATION_TIME = 500;
|
||||
|
||||
private float startWidth;
|
||||
private float startHeight;
|
||||
private boolean animationRunning = false;
|
||||
private float elapsedTime = 0;
|
||||
|
||||
public ToolButtonAnimationLayer(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
super.setVisible(false);
|
||||
this.startWidth = width;
|
||||
this.startHeight = height;
|
||||
}
|
||||
|
||||
public void startAnimation() {
|
||||
reset();
|
||||
super.setVisible(true);
|
||||
animationRunning = true;
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
if (animationRunning) {
|
||||
elapsedTime += frameTime;
|
||||
if (elapsedTime >= ANIMATION_TIME) {
|
||||
reset();
|
||||
}
|
||||
float progress = elapsedTime / ANIMATION_TIME;
|
||||
super.setAlpha(0.5f - 0.5f * progress);
|
||||
float scaleFactor = 1 + 2 * progress;
|
||||
super.setWidth(scaleFactor * startWidth);
|
||||
super.setHeight(scaleFactor * startHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
animationRunning = false;
|
||||
elapsedTime = 0;
|
||||
super.setVisible(false);
|
||||
super.setAlpha(0.5f);
|
||||
super.setWidth(startWidth);
|
||||
super.setHeight(startHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,101 +1,101 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.user.ToolSlotSettings;
|
||||
|
||||
public class ToolButtonBar {
|
||||
|
||||
private final int BUTTON_COUNT = 4;
|
||||
private final float BUTTON_HEIGHT = 0.34f;
|
||||
private final float BUTTON_WIDTH = BUTTON_HEIGHT * 1.17f;
|
||||
private final float BUTTON_MARGIN = 0.012f;
|
||||
|
||||
private List<ToolButton> toolButtons = new ArrayList<>();
|
||||
|
||||
public ToolButtonBar(TexturePack texturePack, Game game, ToolSlotSettings toolSlotSettings) {
|
||||
float buttonWidth = BUTTON_WIDTH + 2 * BUTTON_MARGIN;
|
||||
float totalWidth = BUTTON_COUNT * buttonWidth;
|
||||
|
||||
for (int i = 0; i < BUTTON_COUNT; i++) {
|
||||
Vector position = new Vector(-totalWidth / 2 + (i + 0.5f) * buttonWidth,
|
||||
1 - (0.5f * BUTTON_HEIGHT + BUTTON_MARGIN * 2));
|
||||
ToolButton toolButton = new ToolButton(position, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
texturePack, game);
|
||||
toolButton.setToolSlot(toolSlotSettings.get(i));
|
||||
toolButtons.add(toolButton);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(float frameTime, boolean gameRunning) {
|
||||
for (ToolButton button : toolButtons)
|
||||
button.update(frameTime, gameRunning);
|
||||
}
|
||||
|
||||
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
toolButtons.get(i).setToolSlot(toolSlotSettings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(ToolSlotSettings toolSlotSettings) {
|
||||
changeToolButtonTypes(toolSlotSettings);
|
||||
|
||||
boolean activeButtonAlreadySet = false;
|
||||
for (ToolButton toolButton : toolButtons) {
|
||||
if (!activeButtonAlreadySet && toolButton.getToolType() != null) {
|
||||
toolButton.setActive(true);
|
||||
activeButtonAlreadySet = true;
|
||||
} else
|
||||
toolButton.setActive(false);
|
||||
toolButton.updateBorderColor();
|
||||
toolButton.setProgress(1);
|
||||
toolButton.getAnimationLayer().reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void setActive(ToolType activeType) {
|
||||
for (ToolButton button : toolButtons)
|
||||
button.setActive(button.getToolType() == activeType);
|
||||
}
|
||||
|
||||
public ToolButton getActiveButton() {
|
||||
for (ToolButton button : toolButtons)
|
||||
if (button.getActive().get())
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Gui> toGuiList() {
|
||||
List<Gui> list = new ArrayList<>();
|
||||
for (ToolButton button : toolButtons) {
|
||||
list.add(button.getBorder());
|
||||
list.add(button.getBackground());
|
||||
list.add(button.getProgressbar());
|
||||
list.add(button.getAnimationLayer());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
for (ToolButton button : toolButtons) {
|
||||
button.setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ToolButton> getToolButtons() {
|
||||
return toolButtons;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.user.ToolSlotSettings;
|
||||
|
||||
public class ToolButtonBar {
|
||||
|
||||
private final int BUTTON_COUNT = 4;
|
||||
private final float BUTTON_HEIGHT = 0.34f;
|
||||
private final float BUTTON_WIDTH = BUTTON_HEIGHT * 1.17f;
|
||||
private final float BUTTON_MARGIN = 0.012f;
|
||||
|
||||
private List<ToolButton> toolButtons = new ArrayList<>();
|
||||
|
||||
public ToolButtonBar(TexturePack texturePack, Game game, ToolSlotSettings toolSlotSettings) {
|
||||
float buttonWidth = BUTTON_WIDTH + 2 * BUTTON_MARGIN;
|
||||
float totalWidth = BUTTON_COUNT * buttonWidth;
|
||||
|
||||
for (int i = 0; i < BUTTON_COUNT; i++) {
|
||||
Vector position = new Vector(-totalWidth / 2 + (i + 0.5f) * buttonWidth,
|
||||
1 - (0.5f * BUTTON_HEIGHT + BUTTON_MARGIN * 2));
|
||||
ToolButton toolButton = new ToolButton(position, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
texturePack, game);
|
||||
toolButton.setToolSlot(toolSlotSettings.get(i));
|
||||
toolButtons.add(toolButton);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(float frameTime, boolean gameRunning) {
|
||||
for (ToolButton button : toolButtons)
|
||||
button.update(frameTime, gameRunning);
|
||||
}
|
||||
|
||||
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
toolButtons.get(i).setToolSlot(toolSlotSettings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(ToolSlotSettings toolSlotSettings) {
|
||||
changeToolButtonTypes(toolSlotSettings);
|
||||
|
||||
boolean activeButtonAlreadySet = false;
|
||||
for (ToolButton toolButton : toolButtons) {
|
||||
if (!activeButtonAlreadySet && toolButton.getToolType() != null) {
|
||||
toolButton.setActive(true);
|
||||
activeButtonAlreadySet = true;
|
||||
} else
|
||||
toolButton.setActive(false);
|
||||
toolButton.updateBorderColor();
|
||||
toolButton.setProgress(1);
|
||||
toolButton.getAnimationLayer().reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void setActive(ToolType activeType) {
|
||||
for (ToolButton button : toolButtons)
|
||||
button.setActive(button.getToolType() == activeType);
|
||||
}
|
||||
|
||||
public ToolButton getActiveButton() {
|
||||
for (ToolButton button : toolButtons)
|
||||
if (button.getActive().get())
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Gui> toGuiList() {
|
||||
List<Gui> list = new ArrayList<>();
|
||||
for (ToolButton button : toolButtons) {
|
||||
list.add(button.getBorder());
|
||||
list.add(button.getBackground());
|
||||
list.add(button.getProgressbar());
|
||||
list.add(button.getAnimationLayer());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
for (ToolButton button : toolButtons) {
|
||||
button.setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ToolButton> getToolButtons() {
|
||||
return toolButtons;
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.main.game.Camera;
|
||||
|
||||
/**
|
||||
* Created by Julian on 15.07.2017.
|
||||
*/
|
||||
|
||||
public class Firework {
|
||||
|
||||
private ParticleEffect effect;
|
||||
private Camera camera;
|
||||
private Random random;
|
||||
|
||||
public Firework(ParticleEffect effect, Camera camera) {
|
||||
this.effect = effect;
|
||||
this.camera = camera;
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
randomExplosion(0);
|
||||
randomExplosion(100);
|
||||
randomExplosion(300);
|
||||
}
|
||||
|
||||
private void randomExplosion(float delay) {
|
||||
ParticleSource explosion = new ParticleSource(randomPosition(), effect);
|
||||
explosion.setDelayMS(delay);
|
||||
explosion.start();
|
||||
}
|
||||
|
||||
private Vector randomPosition() {
|
||||
float x = camera.getX() + (random.nextFloat() - 0.5f) * 2.5f;
|
||||
float y = camera.getY() + (random.nextFloat() * 0.5f) - 1f;
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.main.game.Camera;
|
||||
|
||||
/**
|
||||
* Created by Julian on 15.07.2017.
|
||||
*/
|
||||
|
||||
public class Firework {
|
||||
|
||||
private ParticleEffect effect;
|
||||
private Camera camera;
|
||||
private Random random;
|
||||
|
||||
public Firework(ParticleEffect effect, Camera camera) {
|
||||
this.effect = effect;
|
||||
this.camera = camera;
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
randomExplosion(0);
|
||||
randomExplosion(100);
|
||||
randomExplosion(300);
|
||||
}
|
||||
|
||||
private void randomExplosion(float delay) {
|
||||
ParticleSource explosion = new ParticleSource(randomPosition(), effect);
|
||||
explosion.setDelayMS(delay);
|
||||
explosion.start();
|
||||
}
|
||||
|
||||
private Vector randomPosition() {
|
||||
float x = camera.getX() + (random.nextFloat() - 0.5f) * 2.5f;
|
||||
float y = camera.getY() + (random.nextFloat() * 0.5f) - 1f;
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,118 +1,118 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Particle extends Entity {
|
||||
|
||||
private Color3f color;
|
||||
private Random random;
|
||||
private boolean active;
|
||||
private float maxLife;
|
||||
private float passedLifetime;
|
||||
|
||||
private Timeline scaleTimeline;
|
||||
private Range scale;
|
||||
private Timeline velocityTimeline;
|
||||
private Range velocity;
|
||||
private Timeline angleTimeline;
|
||||
private Range angle;
|
||||
private Timeline rotationTimeline;
|
||||
private Range rotation;
|
||||
private Timeline transparencyTimeline;
|
||||
private TintTimeline tintTimeline;
|
||||
private Timeline windTimeline;
|
||||
private Range wind;
|
||||
private Timeline gravityTimeline;
|
||||
private Range gravity;
|
||||
|
||||
public Particle(Random random) {
|
||||
super(null, new Vector(), 1, 1);
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public void activate(Vector position, float liveValue, ParticleData particleData) {
|
||||
active = true;
|
||||
passedLifetime = 0;
|
||||
super.setPosition(position);
|
||||
maxLife = particleData.getLife().createValue(random, liveValue);
|
||||
scaleTimeline = particleData.getScaleTR().getTimeline();
|
||||
scale = particleData.getScaleTR().getRange().createNormalizedInstance(random);
|
||||
velocityTimeline = particleData.getVelocityTR().getTimeline();
|
||||
velocity = particleData.getVelocityTR().getRange().createNormalizedInstance(random);
|
||||
angleTimeline = particleData.getAngleTR().getTimeline();
|
||||
angle = particleData.getAngleTR().getRange().createNormalizedInstance(random);
|
||||
rotationTimeline = particleData.getRotationTR().getTimeline();
|
||||
rotation = particleData.getRotationTR().getRange().createNormalizedInstance(random);
|
||||
transparencyTimeline = particleData.getTransparencyT();
|
||||
tintTimeline = particleData.getTint();
|
||||
windTimeline = particleData.getWindTR().getTimeline();
|
||||
wind = particleData.getWindTR().getRange().createNormalizedInstance(random);
|
||||
gravityTimeline = particleData.getGravityTR().getTimeline();
|
||||
gravity = particleData.getGravityTR().getRange().createNormalizedInstance(random);
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
if (active) {
|
||||
passedLifetime += timer.getFrameTimeMilliseconds();
|
||||
if (passedLifetime >= maxLife)
|
||||
active = false;
|
||||
float lifetimePercent = passedLifetime / maxLife;
|
||||
setScale(scale.createValue(random, scaleTimeline.getValueAtTime(lifetimePercent)));
|
||||
setMovement(
|
||||
velocity.createValue(random, velocityTimeline.getValueAtTime(lifetimePercent)),
|
||||
angle.createValue(random, angleTimeline.getValueAtTime(lifetimePercent)),
|
||||
wind.createValue(random, windTimeline.getValueAtTime(lifetimePercent)),
|
||||
gravity.createValue(random, gravityTimeline.getValueAtTime(lifetimePercent)));
|
||||
super.setRotation(-rotation
|
||||
.createValue(random, rotationTimeline.getValueAtTime(lifetimePercent)));
|
||||
super.setAlpha(transparencyTimeline.getValueAtTime(lifetimePercent));
|
||||
setColor(tintTimeline.getValueAtTime(lifetimePercent));
|
||||
}
|
||||
}
|
||||
|
||||
private void setScale(float scale) {
|
||||
super.setWidth(scale * ParticleSystem.TRANSFER_VALUE);
|
||||
super.setHeight(scale * ParticleSystem.TRANSFER_VALUE);
|
||||
}
|
||||
|
||||
private void setMovement(float velocity, float angle, float windStrength, float gravityStrength) {
|
||||
float radians = (float) Math.toRadians(angle);
|
||||
Vector normalMovement = new Vector();
|
||||
normalMovement.setX((float) Math.cos(radians));
|
||||
normalMovement.setY((float) Math.sin(radians));
|
||||
normalMovement.mul(velocity * ParticleSystem.TRANSFER_VALUE);
|
||||
normalMovement.translate(windStrength * ParticleSystem.TRANSFER_VALUE,
|
||||
gravityStrength * ParticleSystem.TRANSFER_VALUE);
|
||||
super.setMovement(normalMovement);
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setColor(Color3f color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color3f getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Particle extends Entity {
|
||||
|
||||
private Color3f color;
|
||||
private Random random;
|
||||
private boolean active;
|
||||
private float maxLife;
|
||||
private float passedLifetime;
|
||||
|
||||
private Timeline scaleTimeline;
|
||||
private Range scale;
|
||||
private Timeline velocityTimeline;
|
||||
private Range velocity;
|
||||
private Timeline angleTimeline;
|
||||
private Range angle;
|
||||
private Timeline rotationTimeline;
|
||||
private Range rotation;
|
||||
private Timeline transparencyTimeline;
|
||||
private TintTimeline tintTimeline;
|
||||
private Timeline windTimeline;
|
||||
private Range wind;
|
||||
private Timeline gravityTimeline;
|
||||
private Range gravity;
|
||||
|
||||
public Particle(Random random) {
|
||||
super(null, new Vector(), 1, 1);
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public void activate(Vector position, float liveValue, ParticleData particleData) {
|
||||
active = true;
|
||||
passedLifetime = 0;
|
||||
super.setPosition(position);
|
||||
maxLife = particleData.getLife().createValue(random, liveValue);
|
||||
scaleTimeline = particleData.getScaleTR().getTimeline();
|
||||
scale = particleData.getScaleTR().getRange().createNormalizedInstance(random);
|
||||
velocityTimeline = particleData.getVelocityTR().getTimeline();
|
||||
velocity = particleData.getVelocityTR().getRange().createNormalizedInstance(random);
|
||||
angleTimeline = particleData.getAngleTR().getTimeline();
|
||||
angle = particleData.getAngleTR().getRange().createNormalizedInstance(random);
|
||||
rotationTimeline = particleData.getRotationTR().getTimeline();
|
||||
rotation = particleData.getRotationTR().getRange().createNormalizedInstance(random);
|
||||
transparencyTimeline = particleData.getTransparencyT();
|
||||
tintTimeline = particleData.getTint();
|
||||
windTimeline = particleData.getWindTR().getTimeline();
|
||||
wind = particleData.getWindTR().getRange().createNormalizedInstance(random);
|
||||
gravityTimeline = particleData.getGravityTR().getTimeline();
|
||||
gravity = particleData.getGravityTR().getRange().createNormalizedInstance(random);
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
if (active) {
|
||||
passedLifetime += timer.getFrameTimeMilliseconds();
|
||||
if (passedLifetime >= maxLife)
|
||||
active = false;
|
||||
float lifetimePercent = passedLifetime / maxLife;
|
||||
setScale(scale.createValue(random, scaleTimeline.getValueAtTime(lifetimePercent)));
|
||||
setMovement(
|
||||
velocity.createValue(random, velocityTimeline.getValueAtTime(lifetimePercent)),
|
||||
angle.createValue(random, angleTimeline.getValueAtTime(lifetimePercent)),
|
||||
wind.createValue(random, windTimeline.getValueAtTime(lifetimePercent)),
|
||||
gravity.createValue(random, gravityTimeline.getValueAtTime(lifetimePercent)));
|
||||
super.setRotation(-rotation
|
||||
.createValue(random, rotationTimeline.getValueAtTime(lifetimePercent)));
|
||||
super.setAlpha(transparencyTimeline.getValueAtTime(lifetimePercent));
|
||||
setColor(tintTimeline.getValueAtTime(lifetimePercent));
|
||||
}
|
||||
}
|
||||
|
||||
private void setScale(float scale) {
|
||||
super.setWidth(scale * ParticleSystem.TRANSFER_VALUE);
|
||||
super.setHeight(scale * ParticleSystem.TRANSFER_VALUE);
|
||||
}
|
||||
|
||||
private void setMovement(float velocity, float angle, float windStrength, float gravityStrength) {
|
||||
float radians = (float) Math.toRadians(angle);
|
||||
Vector normalMovement = new Vector();
|
||||
normalMovement.setX((float) Math.cos(radians));
|
||||
normalMovement.setY((float) Math.sin(radians));
|
||||
normalMovement.mul(velocity * ParticleSystem.TRANSFER_VALUE);
|
||||
normalMovement.translate(windStrength * ParticleSystem.TRANSFER_VALUE,
|
||||
gravityStrength * ParticleSystem.TRANSFER_VALUE);
|
||||
super.setMovement(normalMovement);
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setColor(Color3f color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color3f getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +1,77 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
|
||||
/**
|
||||
* Created by Julian on 03.08.2016.
|
||||
*/
|
||||
public class ParticleData {
|
||||
|
||||
private Range life;
|
||||
private TimelineRange scaleTR;
|
||||
private TimelineRange velocityTR;
|
||||
private TimelineRange angleTR;
|
||||
private TimelineRange rotationTR;
|
||||
private Timeline transparencyT;
|
||||
private TintTimeline tint;
|
||||
private TimelineRange windTR;
|
||||
private TimelineRange gravityTR;
|
||||
|
||||
public ParticleData(Range life, TimelineRange scaleTR, TimelineRange velocityTR, TimelineRange angleTR, TimelineRange rotationTR, Timeline transparencyT, TintTimeline tint, TimelineRange windTR, TimelineRange gravityTR) {
|
||||
this.life = life;
|
||||
this.scaleTR = scaleTR;
|
||||
this.velocityTR = velocityTR;
|
||||
this.angleTR = angleTR;
|
||||
this.rotationTR = rotationTR;
|
||||
this.transparencyT = transparencyT;
|
||||
this.tint = tint;
|
||||
this.windTR = windTR;
|
||||
this.gravityTR = gravityTR;
|
||||
}
|
||||
|
||||
public Range getLife() {
|
||||
return life;
|
||||
}
|
||||
|
||||
public TimelineRange getScaleTR() {
|
||||
return scaleTR;
|
||||
}
|
||||
|
||||
public TimelineRange getVelocityTR() {
|
||||
return velocityTR;
|
||||
}
|
||||
|
||||
public TimelineRange getAngleTR() {
|
||||
return angleTR;
|
||||
}
|
||||
|
||||
public TimelineRange getRotationTR() {
|
||||
return rotationTR;
|
||||
}
|
||||
|
||||
public Timeline getTransparencyT() {
|
||||
return transparencyT;
|
||||
}
|
||||
|
||||
public TintTimeline getTint() {
|
||||
return tint;
|
||||
}
|
||||
|
||||
public TimelineRange getWindTR() {
|
||||
return windTR;
|
||||
}
|
||||
|
||||
public TimelineRange getGravityTR() {
|
||||
return gravityTR;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
|
||||
/**
|
||||
* Created by Julian on 03.08.2016.
|
||||
*/
|
||||
public class ParticleData {
|
||||
|
||||
private Range life;
|
||||
private TimelineRange scaleTR;
|
||||
private TimelineRange velocityTR;
|
||||
private TimelineRange angleTR;
|
||||
private TimelineRange rotationTR;
|
||||
private Timeline transparencyT;
|
||||
private TintTimeline tint;
|
||||
private TimelineRange windTR;
|
||||
private TimelineRange gravityTR;
|
||||
|
||||
public ParticleData(Range life, TimelineRange scaleTR, TimelineRange velocityTR, TimelineRange angleTR, TimelineRange rotationTR, Timeline transparencyT, TintTimeline tint, TimelineRange windTR, TimelineRange gravityTR) {
|
||||
this.life = life;
|
||||
this.scaleTR = scaleTR;
|
||||
this.velocityTR = velocityTR;
|
||||
this.angleTR = angleTR;
|
||||
this.rotationTR = rotationTR;
|
||||
this.transparencyT = transparencyT;
|
||||
this.tint = tint;
|
||||
this.windTR = windTR;
|
||||
this.gravityTR = gravityTR;
|
||||
}
|
||||
|
||||
public Range getLife() {
|
||||
return life;
|
||||
}
|
||||
|
||||
public TimelineRange getScaleTR() {
|
||||
return scaleTR;
|
||||
}
|
||||
|
||||
public TimelineRange getVelocityTR() {
|
||||
return velocityTR;
|
||||
}
|
||||
|
||||
public TimelineRange getAngleTR() {
|
||||
return angleTR;
|
||||
}
|
||||
|
||||
public TimelineRange getRotationTR() {
|
||||
return rotationTR;
|
||||
}
|
||||
|
||||
public Timeline getTransparencyT() {
|
||||
return transparencyT;
|
||||
}
|
||||
|
||||
public TintTimeline getTint() {
|
||||
return tint;
|
||||
}
|
||||
|
||||
public TimelineRange getWindTR() {
|
||||
return windTR;
|
||||
}
|
||||
|
||||
public TimelineRange getGravityTR() {
|
||||
return gravityTR;
|
||||
}
|
||||
}
|
||||
|
@ -1,236 +1,236 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Options;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 05.08.2016.
|
||||
*/
|
||||
public class ParticleEffect {
|
||||
|
||||
private TimelineRange life;
|
||||
//Particle Timeline
|
||||
private TimelineRange scale;
|
||||
private TimelineRange velocity;
|
||||
private TimelineRange angle;
|
||||
private TimelineRange rotation;
|
||||
private Timeline transparency;
|
||||
private TintTimeline tint;
|
||||
private TimelineRange wind;
|
||||
private TimelineRange gravity;
|
||||
|
||||
//Source Timeline
|
||||
private Range delay;
|
||||
private Range duration;
|
||||
private TimelineRange emission;
|
||||
private Range xOffset;
|
||||
private Range yOffset;
|
||||
private SpawnShape.Shape spawnShape;
|
||||
private TimelineRange spawnWidth;
|
||||
private TimelineRange spawnHeight;
|
||||
|
||||
private Options options;
|
||||
private Texture texture;
|
||||
private String textureName;
|
||||
|
||||
private Random random;
|
||||
private List<ParticleSource> sources = Collections.synchronizedList(new ArrayList<ParticleSource>());
|
||||
|
||||
public ParticleEffect() {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
synchronized (sources) {
|
||||
for (ParticleSource source : sources)
|
||||
source.update(timer);
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleData createParticleData() {
|
||||
return new ParticleData(life.getRange(), scale, velocity, angle, rotation, transparency, tint, wind, gravity);
|
||||
}
|
||||
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
public void addSource(ParticleSource source) {
|
||||
sources.add(source);
|
||||
}
|
||||
|
||||
public void setDelay(Range delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public void setDuration(Range duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public void setEmission(TimelineRange emission) {
|
||||
this.emission = emission;
|
||||
}
|
||||
|
||||
public void setLife(TimelineRange life) {
|
||||
this.life = life;
|
||||
}
|
||||
|
||||
public void setxOffset(Range xOffset) {
|
||||
this.xOffset = xOffset;
|
||||
}
|
||||
|
||||
public void setyOffset(Range yOffset) {
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public void setSpawnShape(SpawnShape.Shape spawnShape) {
|
||||
this.spawnShape = spawnShape;
|
||||
}
|
||||
|
||||
public void setSpawnWidth(TimelineRange spawnWidth) {
|
||||
this.spawnWidth = spawnWidth;
|
||||
}
|
||||
|
||||
public void setSpawnHeight(TimelineRange spawnHeight) {
|
||||
this.spawnHeight = spawnHeight;
|
||||
}
|
||||
|
||||
public void setScale(TimelineRange scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void setVelocity(TimelineRange velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public void setAngle(TimelineRange angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
public void setRotation(TimelineRange rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void setWind(TimelineRange wind) {
|
||||
this.wind = wind;
|
||||
}
|
||||
|
||||
public void setGravity(TimelineRange gravity) {
|
||||
this.gravity = gravity;
|
||||
}
|
||||
|
||||
public void setTint(TintTimeline tint) {
|
||||
this.tint = tint;
|
||||
}
|
||||
|
||||
public void setTransparency(Timeline transparency) {
|
||||
this.transparency = transparency;
|
||||
}
|
||||
|
||||
public Timeline getTransparency() {
|
||||
return transparency;
|
||||
}
|
||||
|
||||
public TintTimeline getTint() {
|
||||
return tint;
|
||||
}
|
||||
|
||||
public void setOptions(Options options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setTextureName(String textureName) {
|
||||
this.textureName = textureName;
|
||||
}
|
||||
|
||||
public String getTextureName() {
|
||||
return textureName;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public Range getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public Range getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public TimelineRange getEmission() {
|
||||
return emission;
|
||||
}
|
||||
|
||||
public Options getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public TimelineRange getWind() {
|
||||
return wind;
|
||||
}
|
||||
|
||||
public TimelineRange getGravity() {
|
||||
return gravity;
|
||||
}
|
||||
|
||||
public Range getxOffset() {
|
||||
return xOffset;
|
||||
}
|
||||
|
||||
public Range getyOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
public synchronized List<ParticleSource> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
public TimelineRange getLife() {
|
||||
return life;
|
||||
}
|
||||
|
||||
public SpawnShape.Shape getSpawnShape() {
|
||||
return spawnShape;
|
||||
}
|
||||
|
||||
public TimelineRange getSpawnHeight() {
|
||||
return spawnHeight;
|
||||
}
|
||||
|
||||
public void deleteSources() {
|
||||
synchronized (sources) {
|
||||
for (ParticleSource source : sources)
|
||||
source.kill();
|
||||
sources.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public TimelineRange getSpawnWidth() {
|
||||
return spawnWidth;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Options;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 05.08.2016.
|
||||
*/
|
||||
public class ParticleEffect {
|
||||
|
||||
private TimelineRange life;
|
||||
//Particle Timeline
|
||||
private TimelineRange scale;
|
||||
private TimelineRange velocity;
|
||||
private TimelineRange angle;
|
||||
private TimelineRange rotation;
|
||||
private Timeline transparency;
|
||||
private TintTimeline tint;
|
||||
private TimelineRange wind;
|
||||
private TimelineRange gravity;
|
||||
|
||||
//Source Timeline
|
||||
private Range delay;
|
||||
private Range duration;
|
||||
private TimelineRange emission;
|
||||
private Range xOffset;
|
||||
private Range yOffset;
|
||||
private SpawnShape.Shape spawnShape;
|
||||
private TimelineRange spawnWidth;
|
||||
private TimelineRange spawnHeight;
|
||||
|
||||
private Options options;
|
||||
private Texture texture;
|
||||
private String textureName;
|
||||
|
||||
private Random random;
|
||||
private List<ParticleSource> sources = Collections.synchronizedList(new ArrayList<ParticleSource>());
|
||||
|
||||
public ParticleEffect() {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
synchronized (sources) {
|
||||
for (ParticleSource source : sources)
|
||||
source.update(timer);
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleData createParticleData() {
|
||||
return new ParticleData(life.getRange(), scale, velocity, angle, rotation, transparency, tint, wind, gravity);
|
||||
}
|
||||
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
public void addSource(ParticleSource source) {
|
||||
sources.add(source);
|
||||
}
|
||||
|
||||
public void setDelay(Range delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public void setDuration(Range duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public void setEmission(TimelineRange emission) {
|
||||
this.emission = emission;
|
||||
}
|
||||
|
||||
public void setLife(TimelineRange life) {
|
||||
this.life = life;
|
||||
}
|
||||
|
||||
public void setxOffset(Range xOffset) {
|
||||
this.xOffset = xOffset;
|
||||
}
|
||||
|
||||
public void setyOffset(Range yOffset) {
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public void setSpawnShape(SpawnShape.Shape spawnShape) {
|
||||
this.spawnShape = spawnShape;
|
||||
}
|
||||
|
||||
public void setSpawnWidth(TimelineRange spawnWidth) {
|
||||
this.spawnWidth = spawnWidth;
|
||||
}
|
||||
|
||||
public void setSpawnHeight(TimelineRange spawnHeight) {
|
||||
this.spawnHeight = spawnHeight;
|
||||
}
|
||||
|
||||
public void setScale(TimelineRange scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void setVelocity(TimelineRange velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public void setAngle(TimelineRange angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
public void setRotation(TimelineRange rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void setWind(TimelineRange wind) {
|
||||
this.wind = wind;
|
||||
}
|
||||
|
||||
public void setGravity(TimelineRange gravity) {
|
||||
this.gravity = gravity;
|
||||
}
|
||||
|
||||
public void setTint(TintTimeline tint) {
|
||||
this.tint = tint;
|
||||
}
|
||||
|
||||
public void setTransparency(Timeline transparency) {
|
||||
this.transparency = transparency;
|
||||
}
|
||||
|
||||
public Timeline getTransparency() {
|
||||
return transparency;
|
||||
}
|
||||
|
||||
public TintTimeline getTint() {
|
||||
return tint;
|
||||
}
|
||||
|
||||
public void setOptions(Options options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setTextureName(String textureName) {
|
||||
this.textureName = textureName;
|
||||
}
|
||||
|
||||
public String getTextureName() {
|
||||
return textureName;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public Range getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public Range getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public TimelineRange getEmission() {
|
||||
return emission;
|
||||
}
|
||||
|
||||
public Options getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public TimelineRange getWind() {
|
||||
return wind;
|
||||
}
|
||||
|
||||
public TimelineRange getGravity() {
|
||||
return gravity;
|
||||
}
|
||||
|
||||
public Range getxOffset() {
|
||||
return xOffset;
|
||||
}
|
||||
|
||||
public Range getyOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
public synchronized List<ParticleSource> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
public TimelineRange getLife() {
|
||||
return life;
|
||||
}
|
||||
|
||||
public SpawnShape.Shape getSpawnShape() {
|
||||
return spawnShape;
|
||||
}
|
||||
|
||||
public TimelineRange getSpawnHeight() {
|
||||
return spawnHeight;
|
||||
}
|
||||
|
||||
public void deleteSources() {
|
||||
synchronized (sources) {
|
||||
for (ParticleSource source : sources)
|
||||
source.kill();
|
||||
sources.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public TimelineRange getSpawnWidth() {
|
||||
return spawnWidth;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,170 +1,170 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.Attribute;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.AttributeValueReader;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.ParticleAttributeType;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ImagePath;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Options;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ParticleReader {
|
||||
|
||||
private Context context;
|
||||
private AttributeValueReader attributeValueReader;
|
||||
|
||||
private List<Attribute> attributes;
|
||||
private Attribute currentAttribute;
|
||||
|
||||
public ParticleReader(Context context) {
|
||||
this.context = context;
|
||||
attributeValueReader = new AttributeValueReader();
|
||||
}
|
||||
|
||||
/**
|
||||
* reads ParticleEffect from *.pe files
|
||||
* !Ignores COUNT, LIFE_OFFSET!
|
||||
*/
|
||||
public ParticleEffect read(String filename) throws Exception {
|
||||
try {
|
||||
attributes = new ArrayList<>();
|
||||
currentAttribute = null;
|
||||
InputStream is = context.getAssets().open(filename);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
handleLine(line);
|
||||
}
|
||||
reader.close();
|
||||
return createParticleEffect();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Could not read particleFile: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLine(String line) throws Exception {
|
||||
if (line.startsWith("- ")) {
|
||||
Attribute attrib = ParticleAttributeType.getByInFileTitle(line).createInstance();
|
||||
attributes.add(attrib);
|
||||
currentAttribute = attrib;
|
||||
} else if (currentAttribute != null)
|
||||
attributeValueReader.addValueForAttribute(currentAttribute, line);
|
||||
}
|
||||
|
||||
private ParticleEffect createParticleEffect() throws Exception {
|
||||
ParticleEffect effect = new ParticleEffect();
|
||||
Timeline timeline = null;
|
||||
Range range = null;
|
||||
for (Attribute attribute : attributes) {
|
||||
switch (attribute.getType()) {
|
||||
case DELAY:
|
||||
effect.setDelay((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case DURATION:
|
||||
effect.setDuration((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case COUNT:
|
||||
break;
|
||||
case EMISSION:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setEmission(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case LIFE:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setLife(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case LIFE_OFFSET:
|
||||
break;
|
||||
case X_OFFSET:
|
||||
effect.setxOffset((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case Y_OFFSET:
|
||||
effect.setyOffset((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case SPAWN_SHAPE:
|
||||
effect.setSpawnShape(((SpawnShape) attribute.get(ParticleAttributeValueType.SPAWN_SHAPE)).getShape());
|
||||
break;
|
||||
case SPAWN_WIDTH:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setSpawnWidth(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case SPAWN_HEIGHT:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setSpawnHeight(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case SCALE:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setScale(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case VELOCITY:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setVelocity(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case ANGLE:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setAngle(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case ROTATION:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setRotation(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case WIND:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setWind(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case GRAVITY:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setGravity(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case TINT:
|
||||
effect.setTint((TintTimeline) attribute.get(ParticleAttributeValueType.TINT_TIMELINE));
|
||||
break;
|
||||
case TRANSPARENCY:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
effect.setTransparency(timeline);
|
||||
break;
|
||||
case OPTIONS:
|
||||
effect.setOptions((Options) attribute.get(ParticleAttributeValueType.OPTIONS));
|
||||
break;
|
||||
case IMAGE_PATH:
|
||||
String path = ((ImagePath) attribute.get(ParticleAttributeValueType.IMAGE_PATH)).getImagePath();
|
||||
effect.setTextureName(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.Attribute;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.AttributeValueReader;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.ParticleAttributeType;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ImagePath;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Options;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ParticleReader {
|
||||
|
||||
private Context context;
|
||||
private AttributeValueReader attributeValueReader;
|
||||
|
||||
private List<Attribute> attributes;
|
||||
private Attribute currentAttribute;
|
||||
|
||||
public ParticleReader(Context context) {
|
||||
this.context = context;
|
||||
attributeValueReader = new AttributeValueReader();
|
||||
}
|
||||
|
||||
/**
|
||||
* reads ParticleEffect from *.pe files
|
||||
* !Ignores COUNT, LIFE_OFFSET!
|
||||
*/
|
||||
public ParticleEffect read(String filename) throws Exception {
|
||||
try {
|
||||
attributes = new ArrayList<>();
|
||||
currentAttribute = null;
|
||||
InputStream is = context.getAssets().open(filename);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
handleLine(line);
|
||||
}
|
||||
reader.close();
|
||||
return createParticleEffect();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Could not read particleFile: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLine(String line) throws Exception {
|
||||
if (line.startsWith("- ")) {
|
||||
Attribute attrib = ParticleAttributeType.getByInFileTitle(line).createInstance();
|
||||
attributes.add(attrib);
|
||||
currentAttribute = attrib;
|
||||
} else if (currentAttribute != null)
|
||||
attributeValueReader.addValueForAttribute(currentAttribute, line);
|
||||
}
|
||||
|
||||
private ParticleEffect createParticleEffect() throws Exception {
|
||||
ParticleEffect effect = new ParticleEffect();
|
||||
Timeline timeline = null;
|
||||
Range range = null;
|
||||
for (Attribute attribute : attributes) {
|
||||
switch (attribute.getType()) {
|
||||
case DELAY:
|
||||
effect.setDelay((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case DURATION:
|
||||
effect.setDuration((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case COUNT:
|
||||
break;
|
||||
case EMISSION:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setEmission(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case LIFE:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setLife(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case LIFE_OFFSET:
|
||||
break;
|
||||
case X_OFFSET:
|
||||
effect.setxOffset((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case Y_OFFSET:
|
||||
effect.setyOffset((Range) attribute.get(ParticleAttributeValueType.RANGE));
|
||||
break;
|
||||
case SPAWN_SHAPE:
|
||||
effect.setSpawnShape(((SpawnShape) attribute.get(ParticleAttributeValueType.SPAWN_SHAPE)).getShape());
|
||||
break;
|
||||
case SPAWN_WIDTH:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setSpawnWidth(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case SPAWN_HEIGHT:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setSpawnHeight(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case SCALE:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setScale(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case VELOCITY:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setVelocity(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case ANGLE:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setAngle(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case ROTATION:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setRotation(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case WIND:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setWind(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case GRAVITY:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
range = (Range) attribute.get(ParticleAttributeValueType.RANGE);
|
||||
effect.setGravity(new TimelineRange(timeline, range));
|
||||
break;
|
||||
case TINT:
|
||||
effect.setTint((TintTimeline) attribute.get(ParticleAttributeValueType.TINT_TIMELINE));
|
||||
break;
|
||||
case TRANSPARENCY:
|
||||
timeline = (Timeline) attribute.get(ParticleAttributeValueType.TIMELINE);
|
||||
effect.setTransparency(timeline);
|
||||
break;
|
||||
case OPTIONS:
|
||||
effect.setOptions((Options) attribute.get(ParticleAttributeValueType.OPTIONS));
|
||||
break;
|
||||
case IMAGE_PATH:
|
||||
String path = ((ImagePath) attribute.get(ParticleAttributeValueType.IMAGE_PATH)).getImagePath();
|
||||
effect.setTextureName(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
@ -1,183 +1,183 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.rendering.Lock;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ParticleSource {
|
||||
|
||||
private Vector position;
|
||||
private ParticleEffect effect;
|
||||
private Random random;
|
||||
|
||||
private boolean delayManuallySet = false;
|
||||
|
||||
private boolean alife;
|
||||
private float currentDelay;
|
||||
private float lifePercent;
|
||||
private float maxTime = -1;
|
||||
private float passedTime;
|
||||
private float emittPause;
|
||||
private float passedEmittPause;
|
||||
private float passedSecond;
|
||||
|
||||
private Vector spawnSize = null;
|
||||
private ParticleData particleData;
|
||||
private List<Particle> activeParticles = new ArrayList<>();
|
||||
private List<Particle> inactiveParticles = new ArrayList<>();
|
||||
private Lock activeParticleLock = new Lock();
|
||||
|
||||
public ParticleSource(Vector position, ParticleEffect effect) {
|
||||
this.position = position;
|
||||
this.effect = effect;
|
||||
random = effect.getRandom();
|
||||
effect.addSource(this);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
alife = true;
|
||||
if (!delayManuallySet)
|
||||
currentDelay = effect.getDelay().createValue(random, 0);
|
||||
maxTime = effect.getDuration().createValue(random, 0) + currentDelay;
|
||||
passedTime = 0;
|
||||
emittPause = calcEmittPause();
|
||||
passedEmittPause = 0;
|
||||
passedSecond = 0;
|
||||
lifePercent = 0;
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
if (alife) {
|
||||
passedTime += timer.getFrameTimeMilliseconds();
|
||||
lifePercent = passedTime / maxTime;
|
||||
|
||||
if (passedTime >= currentDelay) {
|
||||
passedEmittPause += timer.getFrameTimeMilliseconds();
|
||||
while (passedEmittPause >= emittPause) {
|
||||
passedEmittPause -= emittPause;
|
||||
emitt();
|
||||
}
|
||||
|
||||
passedSecond += timer.getFrameTimeMilliseconds();
|
||||
if (passedSecond >= 1000) {
|
||||
passedSecond -= 1000;
|
||||
calcEmittPause();
|
||||
}
|
||||
}
|
||||
if (passedTime >= maxTime)
|
||||
die();
|
||||
}
|
||||
updateParticles(timer);
|
||||
}
|
||||
|
||||
private void updateParticles(Timer timer) {
|
||||
activeParticleLock.lock();
|
||||
Iterator<Particle> iter = activeParticles.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Particle particle = iter.next();
|
||||
particle.update(timer);
|
||||
if (!particle.isActive()) {
|
||||
inactiveParticles.add(particle);
|
||||
iter.remove();
|
||||
} else {
|
||||
particle.move(
|
||||
new Vector(particle.getMovement()).mul(timer.getFrameTimeMilliseconds() / 1000));
|
||||
}
|
||||
}
|
||||
activeParticleLock.unlock();
|
||||
}
|
||||
|
||||
private void die() {
|
||||
alife = false;
|
||||
if (effect.getOptions().isContinuous())
|
||||
start();
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
alife = false;
|
||||
}
|
||||
|
||||
public void emitt() {
|
||||
if (particleData == null)
|
||||
particleData = effect.createParticleData();
|
||||
float xOff = effect.getxOffset().createValue(random, 0) * ParticleSystem.TRANSFER_VALUE;
|
||||
float yOff = effect.getyOffset().createValue(random, 0) * ParticleSystem.TRANSFER_VALUE;
|
||||
if (effect.getSpawnShape() == SpawnShape.Shape.SQUARE || effect.getSpawnShape() == SpawnShape.Shape.LINE) {
|
||||
float width, height;
|
||||
if (spawnSize == null) {
|
||||
width = effect.getSpawnWidth().getRange().createValue(random,
|
||||
effect.getSpawnWidth().getTimeline().getValueAtTime(lifePercent));
|
||||
height = effect.getSpawnHeight().getRange().createValue(random,
|
||||
effect.getSpawnHeight().getTimeline().getValueAtTime(lifePercent));
|
||||
} else {
|
||||
width = spawnSize.getX() / ParticleSystem.TRANSFER_VALUE;
|
||||
height = spawnSize.getY() / ParticleSystem.TRANSFER_VALUE;
|
||||
}
|
||||
xOff += (random.nextFloat() * width - width * 0.5f) * ParticleSystem.TRANSFER_VALUE;
|
||||
yOff += (random.nextFloat() * height - height * 0.5f) * ParticleSystem.TRANSFER_VALUE;
|
||||
}
|
||||
setUpParticle(new Vector(position).translate(xOff, yOff));
|
||||
}
|
||||
|
||||
private void setUpParticle(Vector position) {
|
||||
Particle particle;
|
||||
if (inactiveParticles.size() > 0)
|
||||
particle = inactiveParticles.remove(0);
|
||||
else
|
||||
particle = new Particle(random);
|
||||
|
||||
particle.activate(position, effect.getLife().getTimeline().getValueAtTime(lifePercent),
|
||||
particleData);
|
||||
activeParticleLock.lock();
|
||||
activeParticles.add(particle);
|
||||
activeParticleLock.unlock();
|
||||
}
|
||||
|
||||
private float calcEmittPause() {
|
||||
float emittedPerSecond = effect.getEmission().getRange().createValue(random,
|
||||
effect.getEmission().getTimeline().getValueAtTime(passedTime / maxTime));
|
||||
return 1000 / emittedPerSecond;
|
||||
}
|
||||
|
||||
public Lock getActiveParticleLock() {
|
||||
return activeParticleLock;
|
||||
}
|
||||
|
||||
public List<Particle> getActiveParticles() {
|
||||
return activeParticles;
|
||||
}
|
||||
|
||||
public void setSpawnSize(Vector spawnSize) {
|
||||
this.spawnSize = spawnSize;
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setDelayMS(float delay) {
|
||||
currentDelay = delay;
|
||||
delayManuallySet = true;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.rendering.Lock;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ParticleSource {
|
||||
|
||||
private Vector position;
|
||||
private ParticleEffect effect;
|
||||
private Random random;
|
||||
|
||||
private boolean delayManuallySet = false;
|
||||
|
||||
private boolean alife;
|
||||
private float currentDelay;
|
||||
private float lifePercent;
|
||||
private float maxTime = -1;
|
||||
private float passedTime;
|
||||
private float emittPause;
|
||||
private float passedEmittPause;
|
||||
private float passedSecond;
|
||||
|
||||
private Vector spawnSize = null;
|
||||
private ParticleData particleData;
|
||||
private List<Particle> activeParticles = new ArrayList<>();
|
||||
private List<Particle> inactiveParticles = new ArrayList<>();
|
||||
private Lock activeParticleLock = new Lock();
|
||||
|
||||
public ParticleSource(Vector position, ParticleEffect effect) {
|
||||
this.position = position;
|
||||
this.effect = effect;
|
||||
random = effect.getRandom();
|
||||
effect.addSource(this);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
alife = true;
|
||||
if (!delayManuallySet)
|
||||
currentDelay = effect.getDelay().createValue(random, 0);
|
||||
maxTime = effect.getDuration().createValue(random, 0) + currentDelay;
|
||||
passedTime = 0;
|
||||
emittPause = calcEmittPause();
|
||||
passedEmittPause = 0;
|
||||
passedSecond = 0;
|
||||
lifePercent = 0;
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
if (alife) {
|
||||
passedTime += timer.getFrameTimeMilliseconds();
|
||||
lifePercent = passedTime / maxTime;
|
||||
|
||||
if (passedTime >= currentDelay) {
|
||||
passedEmittPause += timer.getFrameTimeMilliseconds();
|
||||
while (passedEmittPause >= emittPause) {
|
||||
passedEmittPause -= emittPause;
|
||||
emitt();
|
||||
}
|
||||
|
||||
passedSecond += timer.getFrameTimeMilliseconds();
|
||||
if (passedSecond >= 1000) {
|
||||
passedSecond -= 1000;
|
||||
calcEmittPause();
|
||||
}
|
||||
}
|
||||
if (passedTime >= maxTime)
|
||||
die();
|
||||
}
|
||||
updateParticles(timer);
|
||||
}
|
||||
|
||||
private void updateParticles(Timer timer) {
|
||||
activeParticleLock.lock();
|
||||
Iterator<Particle> iter = activeParticles.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Particle particle = iter.next();
|
||||
particle.update(timer);
|
||||
if (!particle.isActive()) {
|
||||
inactiveParticles.add(particle);
|
||||
iter.remove();
|
||||
} else {
|
||||
particle.move(
|
||||
new Vector(particle.getMovement()).mul(timer.getFrameTimeMilliseconds() / 1000));
|
||||
}
|
||||
}
|
||||
activeParticleLock.unlock();
|
||||
}
|
||||
|
||||
private void die() {
|
||||
alife = false;
|
||||
if (effect.getOptions().isContinuous())
|
||||
start();
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
alife = false;
|
||||
}
|
||||
|
||||
public void emitt() {
|
||||
if (particleData == null)
|
||||
particleData = effect.createParticleData();
|
||||
float xOff = effect.getxOffset().createValue(random, 0) * ParticleSystem.TRANSFER_VALUE;
|
||||
float yOff = effect.getyOffset().createValue(random, 0) * ParticleSystem.TRANSFER_VALUE;
|
||||
if (effect.getSpawnShape() == SpawnShape.Shape.SQUARE || effect.getSpawnShape() == SpawnShape.Shape.LINE) {
|
||||
float width, height;
|
||||
if (spawnSize == null) {
|
||||
width = effect.getSpawnWidth().getRange().createValue(random,
|
||||
effect.getSpawnWidth().getTimeline().getValueAtTime(lifePercent));
|
||||
height = effect.getSpawnHeight().getRange().createValue(random,
|
||||
effect.getSpawnHeight().getTimeline().getValueAtTime(lifePercent));
|
||||
} else {
|
||||
width = spawnSize.getX() / ParticleSystem.TRANSFER_VALUE;
|
||||
height = spawnSize.getY() / ParticleSystem.TRANSFER_VALUE;
|
||||
}
|
||||
xOff += (random.nextFloat() * width - width * 0.5f) * ParticleSystem.TRANSFER_VALUE;
|
||||
yOff += (random.nextFloat() * height - height * 0.5f) * ParticleSystem.TRANSFER_VALUE;
|
||||
}
|
||||
setUpParticle(new Vector(position).translate(xOff, yOff));
|
||||
}
|
||||
|
||||
private void setUpParticle(Vector position) {
|
||||
Particle particle;
|
||||
if (inactiveParticles.size() > 0)
|
||||
particle = inactiveParticles.remove(0);
|
||||
else
|
||||
particle = new Particle(random);
|
||||
|
||||
particle.activate(position, effect.getLife().getTimeline().getValueAtTime(lifePercent),
|
||||
particleData);
|
||||
activeParticleLock.lock();
|
||||
activeParticles.add(particle);
|
||||
activeParticleLock.unlock();
|
||||
}
|
||||
|
||||
private float calcEmittPause() {
|
||||
float emittedPerSecond = effect.getEmission().getRange().createValue(random,
|
||||
effect.getEmission().getTimeline().getValueAtTime(passedTime / maxTime));
|
||||
return 1000 / emittedPerSecond;
|
||||
}
|
||||
|
||||
public Lock getActiveParticleLock() {
|
||||
return activeParticleLock;
|
||||
}
|
||||
|
||||
public List<Particle> getActiveParticles() {
|
||||
return activeParticles;
|
||||
}
|
||||
|
||||
public void setSpawnSize(Vector spawnSize) {
|
||||
this.spawnSize = spawnSize;
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setDelayMS(float delay) {
|
||||
currentDelay = delay;
|
||||
delayManuallySet = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,78 +1,78 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.TextureLoader;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ParticleSystem {
|
||||
|
||||
public static final float TRANSFER_VALUE = 0.002f;
|
||||
public final ParticleEffect stasis;
|
||||
public final ParticleEffect testFire;
|
||||
public final ParticleEffect colorChange;
|
||||
public final ParticleEffect explosion;
|
||||
public final ParticleEffect magnet;
|
||||
public final ParticleEffect starCollect;
|
||||
public final ParticleEffect energyCollect;
|
||||
public final ParticleEffect firework;
|
||||
public final ParticleEffect superPower;
|
||||
public final ParticleEffect snow;
|
||||
private ParticleEffect[] effects;
|
||||
|
||||
private TextureLoader textureLoader;
|
||||
|
||||
public ParticleSystem(Context context) throws Exception {
|
||||
this.textureLoader = new TextureLoader(context);
|
||||
ParticleReader reader = new ParticleReader(context);
|
||||
stasis = reader.read("particleEffects/stasis.pe");
|
||||
testFire = reader.read("particleEffects/test_fire.pe");
|
||||
colorChange = reader.read("particleEffects/colorChange.pe");
|
||||
explosion = reader.read("particleEffects/explosion.pe");
|
||||
magnet = reader.read("particleEffects/magnet.pe");
|
||||
starCollect = reader.read("particleEffects/collectStar.pe");
|
||||
energyCollect = reader.read("particleEffects/collectEnergy.pe");
|
||||
firework = reader.read("particleEffects/firework.pe");
|
||||
superPower = reader.read("particleEffects/superPower.pe");
|
||||
snow = reader.read("particleEffects/snow.pe");
|
||||
|
||||
effects = new ParticleEffect[]{stasis, testFire, colorChange, explosion, magnet, starCollect, energyCollect, firework, superPower, snow};
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
synchronized (effects) {
|
||||
for (ParticleEffect effect : effects)
|
||||
effect.update(timer);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTextures() throws Exception {
|
||||
synchronized (effects) {
|
||||
for (ParticleEffect effect : effects)
|
||||
effect.setTexture(
|
||||
textureLoader.loadTexture("particleEffects/" + effect.getTextureName()));
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAllSources() {
|
||||
synchronized (effects) {
|
||||
for (ParticleEffect effect : effects) {
|
||||
effect.deleteSources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized ParticleEffect[] getEffects() {
|
||||
return effects;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.TextureLoader;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ParticleSystem {
|
||||
|
||||
public static final float TRANSFER_VALUE = 0.002f;
|
||||
public final ParticleEffect stasis;
|
||||
public final ParticleEffect testFire;
|
||||
public final ParticleEffect colorChange;
|
||||
public final ParticleEffect explosion;
|
||||
public final ParticleEffect magnet;
|
||||
public final ParticleEffect starCollect;
|
||||
public final ParticleEffect energyCollect;
|
||||
public final ParticleEffect firework;
|
||||
public final ParticleEffect superPower;
|
||||
public final ParticleEffect snow;
|
||||
private ParticleEffect[] effects;
|
||||
|
||||
private TextureLoader textureLoader;
|
||||
|
||||
public ParticleSystem(Context context) throws Exception {
|
||||
this.textureLoader = new TextureLoader(context);
|
||||
ParticleReader reader = new ParticleReader(context);
|
||||
stasis = reader.read("particleEffects/stasis.pe");
|
||||
testFire = reader.read("particleEffects/test_fire.pe");
|
||||
colorChange = reader.read("particleEffects/colorChange.pe");
|
||||
explosion = reader.read("particleEffects/explosion.pe");
|
||||
magnet = reader.read("particleEffects/magnet.pe");
|
||||
starCollect = reader.read("particleEffects/collectStar.pe");
|
||||
energyCollect = reader.read("particleEffects/collectEnergy.pe");
|
||||
firework = reader.read("particleEffects/firework.pe");
|
||||
superPower = reader.read("particleEffects/superPower.pe");
|
||||
snow = reader.read("particleEffects/snow.pe");
|
||||
|
||||
effects = new ParticleEffect[]{stasis, testFire, colorChange, explosion, magnet, starCollect, energyCollect, firework, superPower, snow};
|
||||
}
|
||||
|
||||
public void update(Timer timer) {
|
||||
synchronized (effects) {
|
||||
for (ParticleEffect effect : effects)
|
||||
effect.update(timer);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTextures() throws Exception {
|
||||
synchronized (effects) {
|
||||
for (ParticleEffect effect : effects)
|
||||
effect.setTexture(
|
||||
textureLoader.loadTexture("particleEffects/" + effect.getTextureName()));
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAllSources() {
|
||||
synchronized (effects) {
|
||||
for (ParticleEffect effect : effects) {
|
||||
effect.deleteSources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized ParticleEffect[] getEffects() {
|
||||
return effects;
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValue;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Attribute {
|
||||
|
||||
private ParticleAttributeType type;
|
||||
private List<ParticleAttributeValue> values = new ArrayList<>();
|
||||
|
||||
public Attribute(ParticleAttributeType type, ParticleAttributeValueType... valueTypes) {
|
||||
this.type = type;
|
||||
for (ParticleAttributeValueType valueType : valueTypes)
|
||||
values.add(valueType.createInstance());
|
||||
}
|
||||
|
||||
public ParticleAttributeValue get(ParticleAttributeValueType valueType) throws Exception {
|
||||
for (ParticleAttributeValue v : values)
|
||||
if (v.getType() == valueType)
|
||||
return v;
|
||||
throw new Exception("ParticleAttributeValue with type: " + valueType + " does not exist in Attribute " + type);
|
||||
}
|
||||
|
||||
public ParticleAttributeType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValue;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Attribute {
|
||||
|
||||
private ParticleAttributeType type;
|
||||
private List<ParticleAttributeValue> values = new ArrayList<>();
|
||||
|
||||
public Attribute(ParticleAttributeType type, ParticleAttributeValueType... valueTypes) {
|
||||
this.type = type;
|
||||
for (ParticleAttributeValueType valueType : valueTypes)
|
||||
values.add(valueType.createInstance());
|
||||
}
|
||||
|
||||
public ParticleAttributeValue get(ParticleAttributeValueType valueType) throws Exception {
|
||||
for (ParticleAttributeValue v : values)
|
||||
if (v.getType() == valueType)
|
||||
return v;
|
||||
throw new Exception("ParticleAttributeValue with type: " + valueType + " does not exist in Attribute " + type);
|
||||
}
|
||||
|
||||
public ParticleAttributeType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +1,84 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ImagePath;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Options;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class AttributeValueReader {
|
||||
|
||||
public void addValueForAttribute(Attribute attribute, String line) throws Exception {
|
||||
//RANGE
|
||||
if (line.startsWith("lowMin:") || line.startsWith("min:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setLowMin(parseFloat(line));
|
||||
else if (line.startsWith("lowMax:") || line.startsWith("max:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setLowMax(parseFloat(line));
|
||||
else if (line.startsWith("highMin:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setHighMin(parseFloat(line));
|
||||
else if (line.startsWith("highMax:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setHighMax(parseFloat(line));
|
||||
//TIMELINE
|
||||
else if (!line.startsWith("scalingCount") && line.startsWith("scaling"))
|
||||
((Timeline) attribute.get(ParticleAttributeValueType.TIMELINE)).setValueOfPoint(parseTimeLineIndex("scaling", line), parseFloat(line));
|
||||
else if (!line.startsWith("timelineCount") && line.startsWith("timeline") && attribute.getType() != ParticleAttributeType.TINT)
|
||||
((Timeline) attribute.get(ParticleAttributeValueType.TIMELINE)).setTimeOfPoint(parseTimeLineIndex("timeline", line), parseFloat(line));
|
||||
//TINT_TIMELINE
|
||||
else if (!line.startsWith("colorsCount") && line.startsWith("colors")) {
|
||||
int index = parseTimeLineIndex("colors", line);
|
||||
((TintTimeline) attribute.get(ParticleAttributeValueType.TINT_TIMELINE)).setValueOfPoint((int) (index / 3f), index % 3, parseFloat(line));
|
||||
} else if (!line.startsWith("timelineCount") && line.startsWith("timeline") && attribute.getType() == ParticleAttributeType.TINT)
|
||||
((TintTimeline) attribute.get(ParticleAttributeValueType.TINT_TIMELINE)).setTimeOfPoint(parseTimeLineIndex("timeline", line), parseFloat(line));
|
||||
//SPAWN_SHAPE
|
||||
else if (line.startsWith("shape:"))
|
||||
((SpawnShape) attribute.get(ParticleAttributeValueType.SPAWN_SHAPE)).setShape(SpawnShape.Shape.byName(parseString(line)));
|
||||
//OPTIONS
|
||||
else if (line.startsWith("attached:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setAttached(parseBoolean(line));
|
||||
else if (line.startsWith("continuous:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setContinuous(parseBoolean(line));
|
||||
else if (line.startsWith("aligned:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setAligned(parseBoolean(line));
|
||||
else if (line.startsWith("additive:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setAdditive(parseBoolean(line));
|
||||
else if (line.startsWith("behind:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setBehind(parseBoolean(line));
|
||||
else if (line.startsWith("premultipliedAlpha:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setPremultipliedAlpha(parseBoolean(line));
|
||||
//IMAGE PATH
|
||||
else if (attribute.getType() == ParticleAttributeType.IMAGE_PATH)
|
||||
((ImagePath) attribute.get(ParticleAttributeValueType.IMAGE_PATH)).setImagePath(line);
|
||||
}
|
||||
|
||||
private int parseTimeLineIndex(String start, String line) {
|
||||
String asString = line.split(start)[1].split(":")[0];
|
||||
return Integer.parseInt(asString);
|
||||
}
|
||||
|
||||
private float parseFloat(String line) {
|
||||
String asString = line.split(" ")[1];
|
||||
return Float.parseFloat(asString);
|
||||
}
|
||||
|
||||
private String parseString(String line) {
|
||||
return line.split(" ")[1];
|
||||
}
|
||||
|
||||
private boolean parseBoolean(String line) {
|
||||
String asString = line.split(" ")[1];
|
||||
return Boolean.parseBoolean(asString);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ImagePath;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Options;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Range;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.Timeline;
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class AttributeValueReader {
|
||||
|
||||
public void addValueForAttribute(Attribute attribute, String line) throws Exception {
|
||||
//RANGE
|
||||
if (line.startsWith("lowMin:") || line.startsWith("min:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setLowMin(parseFloat(line));
|
||||
else if (line.startsWith("lowMax:") || line.startsWith("max:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setLowMax(parseFloat(line));
|
||||
else if (line.startsWith("highMin:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setHighMin(parseFloat(line));
|
||||
else if (line.startsWith("highMax:"))
|
||||
((Range) attribute.get(ParticleAttributeValueType.RANGE)).setHighMax(parseFloat(line));
|
||||
//TIMELINE
|
||||
else if (!line.startsWith("scalingCount") && line.startsWith("scaling"))
|
||||
((Timeline) attribute.get(ParticleAttributeValueType.TIMELINE)).setValueOfPoint(parseTimeLineIndex("scaling", line), parseFloat(line));
|
||||
else if (!line.startsWith("timelineCount") && line.startsWith("timeline") && attribute.getType() != ParticleAttributeType.TINT)
|
||||
((Timeline) attribute.get(ParticleAttributeValueType.TIMELINE)).setTimeOfPoint(parseTimeLineIndex("timeline", line), parseFloat(line));
|
||||
//TINT_TIMELINE
|
||||
else if (!line.startsWith("colorsCount") && line.startsWith("colors")) {
|
||||
int index = parseTimeLineIndex("colors", line);
|
||||
((TintTimeline) attribute.get(ParticleAttributeValueType.TINT_TIMELINE)).setValueOfPoint((int) (index / 3f), index % 3, parseFloat(line));
|
||||
} else if (!line.startsWith("timelineCount") && line.startsWith("timeline") && attribute.getType() == ParticleAttributeType.TINT)
|
||||
((TintTimeline) attribute.get(ParticleAttributeValueType.TINT_TIMELINE)).setTimeOfPoint(parseTimeLineIndex("timeline", line), parseFloat(line));
|
||||
//SPAWN_SHAPE
|
||||
else if (line.startsWith("shape:"))
|
||||
((SpawnShape) attribute.get(ParticleAttributeValueType.SPAWN_SHAPE)).setShape(SpawnShape.Shape.byName(parseString(line)));
|
||||
//OPTIONS
|
||||
else if (line.startsWith("attached:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setAttached(parseBoolean(line));
|
||||
else if (line.startsWith("continuous:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setContinuous(parseBoolean(line));
|
||||
else if (line.startsWith("aligned:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setAligned(parseBoolean(line));
|
||||
else if (line.startsWith("additive:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setAdditive(parseBoolean(line));
|
||||
else if (line.startsWith("behind:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setBehind(parseBoolean(line));
|
||||
else if (line.startsWith("premultipliedAlpha:"))
|
||||
((Options) attribute.get(ParticleAttributeValueType.OPTIONS)).setPremultipliedAlpha(parseBoolean(line));
|
||||
//IMAGE PATH
|
||||
else if (attribute.getType() == ParticleAttributeType.IMAGE_PATH)
|
||||
((ImagePath) attribute.get(ParticleAttributeValueType.IMAGE_PATH)).setImagePath(line);
|
||||
}
|
||||
|
||||
private int parseTimeLineIndex(String start, String line) {
|
||||
String asString = line.split(start)[1].split(":")[0];
|
||||
return Integer.parseInt(asString);
|
||||
}
|
||||
|
||||
private float parseFloat(String line) {
|
||||
String asString = line.split(" ")[1];
|
||||
return Float.parseFloat(asString);
|
||||
}
|
||||
|
||||
private String parseString(String line) {
|
||||
return line.split(" ")[1];
|
||||
}
|
||||
|
||||
private boolean parseBoolean(String line) {
|
||||
String asString = line.split(" ")[1];
|
||||
return Boolean.parseBoolean(asString);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
|
||||
public enum ParticleAttributeType {
|
||||
NONE(""),
|
||||
DELAY("Delay", ParticleAttributeValueType.RANGE),
|
||||
DURATION("Duration", ParticleAttributeValueType.RANGE),
|
||||
COUNT("Count", ParticleAttributeValueType.RANGE),
|
||||
EMISSION("Emission", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
LIFE("Life", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
LIFE_OFFSET("Life Offset", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
X_OFFSET("X Offset", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
Y_OFFSET("Y Offset", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
SPAWN_SHAPE("Spawn Shape", ParticleAttributeValueType.SPAWN_SHAPE),
|
||||
SPAWN_WIDTH("Spawn Width", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
SPAWN_HEIGHT("Spawn Height", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
SCALE("Scale", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
VELOCITY("Velocity", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
ANGLE("Angle", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
ROTATION("Rotation", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
WIND("Wind", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
GRAVITY("Gravity", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
TINT("Tint", ParticleAttributeValueType.TINT_TIMELINE),
|
||||
TRANSPARENCY("Transparency", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
OPTIONS("Options", ParticleAttributeValueType.OPTIONS),
|
||||
IMAGE_PATH("Image Path", ParticleAttributeValueType.IMAGE_PATH);
|
||||
|
||||
private String name;
|
||||
private ParticleAttributeValueType[] valueTypes;
|
||||
|
||||
ParticleAttributeType(String name, ParticleAttributeValueType... valueTypes) {
|
||||
this.name = name;
|
||||
this.valueTypes = valueTypes;
|
||||
}
|
||||
|
||||
private String getInFileTitle() {
|
||||
return "- " + name + " -";
|
||||
}
|
||||
|
||||
public static ParticleAttributeType getByInFileTitle(String title) throws Exception {
|
||||
for (ParticleAttributeType setting : values()) {
|
||||
if (setting != NONE && setting.getInFileTitle().equals(title))
|
||||
return setting;
|
||||
}
|
||||
throw new Exception("Could not find ParticleAttributeType by title: " + title);
|
||||
}
|
||||
|
||||
public Attribute createInstance() throws Exception {
|
||||
if (this == NONE)
|
||||
throw new Exception("Cannot create Instance from Attribute NONE");
|
||||
return new Attribute(this, valueTypes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes;
|
||||
|
||||
import de.frajul.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
|
||||
|
||||
public enum ParticleAttributeType {
|
||||
NONE(""),
|
||||
DELAY("Delay", ParticleAttributeValueType.RANGE),
|
||||
DURATION("Duration", ParticleAttributeValueType.RANGE),
|
||||
COUNT("Count", ParticleAttributeValueType.RANGE),
|
||||
EMISSION("Emission", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
LIFE("Life", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
LIFE_OFFSET("Life Offset", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
X_OFFSET("X Offset", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
Y_OFFSET("Y Offset", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
SPAWN_SHAPE("Spawn Shape", ParticleAttributeValueType.SPAWN_SHAPE),
|
||||
SPAWN_WIDTH("Spawn Width", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
SPAWN_HEIGHT("Spawn Height", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
SCALE("Scale", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
VELOCITY("Velocity", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
ANGLE("Angle", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
ROTATION("Rotation", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
WIND("Wind", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
GRAVITY("Gravity", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
TINT("Tint", ParticleAttributeValueType.TINT_TIMELINE),
|
||||
TRANSPARENCY("Transparency", ParticleAttributeValueType.RANGE, ParticleAttributeValueType.TIMELINE),
|
||||
OPTIONS("Options", ParticleAttributeValueType.OPTIONS),
|
||||
IMAGE_PATH("Image Path", ParticleAttributeValueType.IMAGE_PATH);
|
||||
|
||||
private String name;
|
||||
private ParticleAttributeValueType[] valueTypes;
|
||||
|
||||
ParticleAttributeType(String name, ParticleAttributeValueType... valueTypes) {
|
||||
this.name = name;
|
||||
this.valueTypes = valueTypes;
|
||||
}
|
||||
|
||||
private String getInFileTitle() {
|
||||
return "- " + name + " -";
|
||||
}
|
||||
|
||||
public static ParticleAttributeType getByInFileTitle(String title) throws Exception {
|
||||
for (ParticleAttributeType setting : values()) {
|
||||
if (setting != NONE && setting.getInFileTitle().equals(title))
|
||||
return setting;
|
||||
}
|
||||
throw new Exception("Could not find ParticleAttributeType by title: " + title);
|
||||
}
|
||||
|
||||
public Attribute createInstance() throws Exception {
|
||||
if (this == NONE)
|
||||
throw new Exception("Cannot create Instance from Attribute NONE");
|
||||
return new Attribute(this, valueTypes);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ImagePath extends ParticleAttributeValue {
|
||||
|
||||
private String imagePath;
|
||||
|
||||
public ImagePath() {
|
||||
super(ParticleAttributeValueType.IMAGE_PATH);
|
||||
}
|
||||
|
||||
public String getImagePath() {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
public void setImagePath(String imagePath) {
|
||||
this.imagePath = imagePath;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class ImagePath extends ParticleAttributeValue {
|
||||
|
||||
private String imagePath;
|
||||
|
||||
public ImagePath() {
|
||||
super(ParticleAttributeValueType.IMAGE_PATH);
|
||||
}
|
||||
|
||||
public String getImagePath() {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
public void setImagePath(String imagePath) {
|
||||
this.imagePath = imagePath;
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,73 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Options extends ParticleAttributeValue {
|
||||
|
||||
private boolean attached;
|
||||
private boolean continuous;
|
||||
private boolean aligned;
|
||||
private boolean additive;
|
||||
private boolean behind;
|
||||
private boolean premultipliedAlpha;
|
||||
|
||||
public Options() {
|
||||
super(ParticleAttributeValueType.OPTIONS);
|
||||
}
|
||||
|
||||
public boolean isAttached() {
|
||||
return attached;
|
||||
}
|
||||
|
||||
public void setAttached(boolean attached) {
|
||||
this.attached = attached;
|
||||
}
|
||||
|
||||
public boolean isContinuous() {
|
||||
return continuous;
|
||||
}
|
||||
|
||||
public void setContinuous(boolean continuous) {
|
||||
this.continuous = continuous;
|
||||
}
|
||||
|
||||
public boolean isAligned() {
|
||||
return aligned;
|
||||
}
|
||||
|
||||
public void setAligned(boolean aligned) {
|
||||
this.aligned = aligned;
|
||||
}
|
||||
|
||||
public boolean isAdditive() {
|
||||
return additive;
|
||||
}
|
||||
|
||||
public void setAdditive(boolean additive) {
|
||||
this.additive = additive;
|
||||
}
|
||||
|
||||
public boolean isBehind() {
|
||||
return behind;
|
||||
}
|
||||
|
||||
public void setBehind(boolean behind) {
|
||||
this.behind = behind;
|
||||
}
|
||||
|
||||
public boolean isPremultipliedAlpha() {
|
||||
return premultipliedAlpha;
|
||||
}
|
||||
|
||||
public void setPremultipliedAlpha(boolean premultipliedAlpha) {
|
||||
this.premultipliedAlpha = premultipliedAlpha;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Options extends ParticleAttributeValue {
|
||||
|
||||
private boolean attached;
|
||||
private boolean continuous;
|
||||
private boolean aligned;
|
||||
private boolean additive;
|
||||
private boolean behind;
|
||||
private boolean premultipliedAlpha;
|
||||
|
||||
public Options() {
|
||||
super(ParticleAttributeValueType.OPTIONS);
|
||||
}
|
||||
|
||||
public boolean isAttached() {
|
||||
return attached;
|
||||
}
|
||||
|
||||
public void setAttached(boolean attached) {
|
||||
this.attached = attached;
|
||||
}
|
||||
|
||||
public boolean isContinuous() {
|
||||
return continuous;
|
||||
}
|
||||
|
||||
public void setContinuous(boolean continuous) {
|
||||
this.continuous = continuous;
|
||||
}
|
||||
|
||||
public boolean isAligned() {
|
||||
return aligned;
|
||||
}
|
||||
|
||||
public void setAligned(boolean aligned) {
|
||||
this.aligned = aligned;
|
||||
}
|
||||
|
||||
public boolean isAdditive() {
|
||||
return additive;
|
||||
}
|
||||
|
||||
public void setAdditive(boolean additive) {
|
||||
this.additive = additive;
|
||||
}
|
||||
|
||||
public boolean isBehind() {
|
||||
return behind;
|
||||
}
|
||||
|
||||
public void setBehind(boolean behind) {
|
||||
this.behind = behind;
|
||||
}
|
||||
|
||||
public boolean isPremultipliedAlpha() {
|
||||
return premultipliedAlpha;
|
||||
}
|
||||
|
||||
public void setPremultipliedAlpha(boolean premultipliedAlpha) {
|
||||
this.premultipliedAlpha = premultipliedAlpha;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public abstract class ParticleAttributeValue {
|
||||
|
||||
private ParticleAttributeValueType type;
|
||||
|
||||
public ParticleAttributeValue(ParticleAttributeValueType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ParticleAttributeValueType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public abstract class ParticleAttributeValue {
|
||||
|
||||
private ParticleAttributeValueType type;
|
||||
|
||||
public ParticleAttributeValue(ParticleAttributeValueType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ParticleAttributeValueType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public enum ParticleAttributeValueType {
|
||||
|
||||
RANGE, TIMELINE, TINT_TIMELINE, SPAWN_SHAPE, OPTIONS, IMAGE_PATH;
|
||||
|
||||
public ParticleAttributeValue createInstance() {
|
||||
switch (this) {
|
||||
case RANGE:
|
||||
return new Range();
|
||||
case TIMELINE:
|
||||
return new Timeline();
|
||||
case TINT_TIMELINE:
|
||||
return new TintTimeline();
|
||||
case SPAWN_SHAPE:
|
||||
return new SpawnShape();
|
||||
case OPTIONS:
|
||||
return new Options();
|
||||
case IMAGE_PATH:
|
||||
return new ImagePath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public enum ParticleAttributeValueType {
|
||||
|
||||
RANGE, TIMELINE, TINT_TIMELINE, SPAWN_SHAPE, OPTIONS, IMAGE_PATH;
|
||||
|
||||
public ParticleAttributeValue createInstance() {
|
||||
switch (this) {
|
||||
case RANGE:
|
||||
return new Range();
|
||||
case TIMELINE:
|
||||
return new Timeline();
|
||||
case TINT_TIMELINE:
|
||||
return new TintTimeline();
|
||||
case SPAWN_SHAPE:
|
||||
return new SpawnShape();
|
||||
case OPTIONS:
|
||||
return new Options();
|
||||
case IMAGE_PATH:
|
||||
return new ImagePath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,89 +1,89 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Range extends ParticleAttributeValue {
|
||||
|
||||
private float lowMin;
|
||||
private float lowMax;
|
||||
private float highMin;
|
||||
private float highMax;
|
||||
|
||||
public Range() {
|
||||
super(ParticleAttributeValueType.RANGE);
|
||||
}
|
||||
|
||||
public Range createNormalizedInstance(Random random) {
|
||||
Range range = new Range();
|
||||
float high = createHighValue(random);
|
||||
range.setHighMax(high);
|
||||
range.setHighMin(high);
|
||||
float low = createLowValue(random);
|
||||
range.setLowMax(low);
|
||||
range.setLowMin(low);
|
||||
return range;
|
||||
}
|
||||
|
||||
public float createValue(Random random, float mix) {
|
||||
if (mix == 1)
|
||||
return createHighValue(random);
|
||||
else if (mix == 0)
|
||||
return createLowValue(random);
|
||||
else {
|
||||
float highValue = createHighValue(random);
|
||||
float lowValue = createLowValue(random);
|
||||
return mix * (highValue - lowValue) + lowValue;
|
||||
}
|
||||
}
|
||||
|
||||
private float createHighValue(Random random) {
|
||||
float min = highMin;
|
||||
float max = highMax;
|
||||
if (min == max)
|
||||
return min;
|
||||
return random.nextFloat() * (max - min) + min;
|
||||
}
|
||||
|
||||
private float createLowValue(Random random) {
|
||||
float min = lowMin;
|
||||
float max = lowMax;
|
||||
if (min == max)
|
||||
return min;
|
||||
return random.nextFloat() * (max - min) + min;
|
||||
}
|
||||
|
||||
public void setLowMin(float lowMin) {
|
||||
this.lowMin = lowMin;
|
||||
}
|
||||
|
||||
public void setLowMax(float lowMax) {
|
||||
this.lowMax = lowMax;
|
||||
}
|
||||
|
||||
public void setHighMin(float highMin) {
|
||||
this.highMin = highMin;
|
||||
}
|
||||
|
||||
public void setHighMax(float highMax) {
|
||||
this.highMax = highMax;
|
||||
}
|
||||
|
||||
private boolean isLowDifference() {
|
||||
return lowMin - lowMax != 0;
|
||||
}
|
||||
|
||||
private boolean isHighDifference() {
|
||||
return highMin - highMax != 0;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Range extends ParticleAttributeValue {
|
||||
|
||||
private float lowMin;
|
||||
private float lowMax;
|
||||
private float highMin;
|
||||
private float highMax;
|
||||
|
||||
public Range() {
|
||||
super(ParticleAttributeValueType.RANGE);
|
||||
}
|
||||
|
||||
public Range createNormalizedInstance(Random random) {
|
||||
Range range = new Range();
|
||||
float high = createHighValue(random);
|
||||
range.setHighMax(high);
|
||||
range.setHighMin(high);
|
||||
float low = createLowValue(random);
|
||||
range.setLowMax(low);
|
||||
range.setLowMin(low);
|
||||
return range;
|
||||
}
|
||||
|
||||
public float createValue(Random random, float mix) {
|
||||
if (mix == 1)
|
||||
return createHighValue(random);
|
||||
else if (mix == 0)
|
||||
return createLowValue(random);
|
||||
else {
|
||||
float highValue = createHighValue(random);
|
||||
float lowValue = createLowValue(random);
|
||||
return mix * (highValue - lowValue) + lowValue;
|
||||
}
|
||||
}
|
||||
|
||||
private float createHighValue(Random random) {
|
||||
float min = highMin;
|
||||
float max = highMax;
|
||||
if (min == max)
|
||||
return min;
|
||||
return random.nextFloat() * (max - min) + min;
|
||||
}
|
||||
|
||||
private float createLowValue(Random random) {
|
||||
float min = lowMin;
|
||||
float max = lowMax;
|
||||
if (min == max)
|
||||
return min;
|
||||
return random.nextFloat() * (max - min) + min;
|
||||
}
|
||||
|
||||
public void setLowMin(float lowMin) {
|
||||
this.lowMin = lowMin;
|
||||
}
|
||||
|
||||
public void setLowMax(float lowMax) {
|
||||
this.lowMax = lowMax;
|
||||
}
|
||||
|
||||
public void setHighMin(float highMin) {
|
||||
this.highMin = highMin;
|
||||
}
|
||||
|
||||
public void setHighMax(float highMax) {
|
||||
this.highMax = highMax;
|
||||
}
|
||||
|
||||
private boolean isLowDifference() {
|
||||
return lowMin - lowMax != 0;
|
||||
}
|
||||
|
||||
private boolean isHighDifference() {
|
||||
return highMin - highMax != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,45 +1,45 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class SpawnShape extends ParticleAttributeValue {
|
||||
|
||||
public enum Shape {
|
||||
POINT("point"), SQUARE("square"), LINE("line");
|
||||
|
||||
private String name;
|
||||
|
||||
Shape(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Shape byName(String text) throws Exception {
|
||||
for (Shape shape : values())
|
||||
if (shape.name.equals(text))
|
||||
return shape;
|
||||
throw new Exception("spawnShape with name \"" + text + "\" does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private Shape shape;
|
||||
|
||||
public SpawnShape() {
|
||||
super(ParticleAttributeValueType.SPAWN_SHAPE);
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class SpawnShape extends ParticleAttributeValue {
|
||||
|
||||
public enum Shape {
|
||||
POINT("point"), SQUARE("square"), LINE("line");
|
||||
|
||||
private String name;
|
||||
|
||||
Shape(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Shape byName(String text) throws Exception {
|
||||
for (Shape shape : values())
|
||||
if (shape.name.equals(text))
|
||||
return shape;
|
||||
throw new Exception("spawnShape with name \"" + text + "\" does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private Shape shape;
|
||||
|
||||
public SpawnShape() {
|
||||
super(ParticleAttributeValueType.SPAWN_SHAPE);
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +1,61 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Timeline extends ParticleAttributeValue {
|
||||
|
||||
private List<TimelinePoint> points = new ArrayList<>();
|
||||
|
||||
public Timeline() {
|
||||
super(ParticleAttributeValueType.TIMELINE);
|
||||
}
|
||||
|
||||
public void setValueOfPoint(int index, float value) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TimelinePoint());
|
||||
}
|
||||
points.get(index).setValue(value);
|
||||
}
|
||||
|
||||
public void setTimeOfPoint(int index, float time) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TimelinePoint());
|
||||
}
|
||||
points.get(index).setTime(time);
|
||||
}
|
||||
|
||||
public float getValueAtTime(float time) {
|
||||
TimelinePoint left = null, right = null;
|
||||
for (TimelinePoint point : points) {
|
||||
if (point.getTime() <= time) {
|
||||
if (left == null || left.getTime() < point.getTime())
|
||||
left = point;
|
||||
} else if (right == null || right.getTime() > point.getTime())
|
||||
right = point;
|
||||
}
|
||||
if (left != null) {
|
||||
if (right != null) {
|
||||
float leftDist = Math.abs(left.getTime() - time);
|
||||
float rightDist = Math.abs(right.getTime() - time);
|
||||
float totalDist = leftDist + rightDist;
|
||||
float leftMultiplier = 1 - (leftDist / totalDist);
|
||||
float rightMultiplier = 1 - (rightDist / totalDist);
|
||||
return left.getValue() * leftMultiplier + right.getValue() * rightMultiplier;
|
||||
}
|
||||
return left.getValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class Timeline extends ParticleAttributeValue {
|
||||
|
||||
private List<TimelinePoint> points = new ArrayList<>();
|
||||
|
||||
public Timeline() {
|
||||
super(ParticleAttributeValueType.TIMELINE);
|
||||
}
|
||||
|
||||
public void setValueOfPoint(int index, float value) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TimelinePoint());
|
||||
}
|
||||
points.get(index).setValue(value);
|
||||
}
|
||||
|
||||
public void setTimeOfPoint(int index, float time) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TimelinePoint());
|
||||
}
|
||||
points.get(index).setTime(time);
|
||||
}
|
||||
|
||||
public float getValueAtTime(float time) {
|
||||
TimelinePoint left = null, right = null;
|
||||
for (TimelinePoint point : points) {
|
||||
if (point.getTime() <= time) {
|
||||
if (left == null || left.getTime() < point.getTime())
|
||||
left = point;
|
||||
} else if (right == null || right.getTime() > point.getTime())
|
||||
right = point;
|
||||
}
|
||||
if (left != null) {
|
||||
if (right != null) {
|
||||
float leftDist = Math.abs(left.getTime() - time);
|
||||
float rightDist = Math.abs(right.getTime() - time);
|
||||
float totalDist = leftDist + rightDist;
|
||||
float leftMultiplier = 1 - (leftDist / totalDist);
|
||||
float rightMultiplier = 1 - (rightDist / totalDist);
|
||||
return left.getValue() * leftMultiplier + right.getValue() * rightMultiplier;
|
||||
}
|
||||
return left.getValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +1,30 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
public class TimelinePoint {
|
||||
|
||||
private float time, value;
|
||||
|
||||
public float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(float time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
public class TimelinePoint {
|
||||
|
||||
private float time, value;
|
||||
|
||||
public float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(float time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class TimelineRange {
|
||||
|
||||
private Timeline timeline;
|
||||
private Range range;
|
||||
|
||||
public TimelineRange(Timeline timeline, Range range) {
|
||||
this.timeline = timeline;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public Timeline getTimeline() {
|
||||
return timeline;
|
||||
}
|
||||
|
||||
public void setTimeline(Timeline timeline) {
|
||||
this.timeline = timeline;
|
||||
}
|
||||
|
||||
public Range getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
public void setRange(Range range) {
|
||||
this.range = range;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class TimelineRange {
|
||||
|
||||
private Timeline timeline;
|
||||
private Range range;
|
||||
|
||||
public TimelineRange(Timeline timeline, Range range) {
|
||||
this.timeline = timeline;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public Timeline getTimeline() {
|
||||
return timeline;
|
||||
}
|
||||
|
||||
public void setTimeline(Timeline timeline) {
|
||||
this.timeline = timeline;
|
||||
}
|
||||
|
||||
public Range getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
public void setRange(Range range) {
|
||||
this.range = range;
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,64 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class TintTimeline extends ParticleAttributeValue {
|
||||
|
||||
private List<TintTimelinePoint> points = new ArrayList<>();
|
||||
|
||||
public TintTimeline() {
|
||||
super(ParticleAttributeValueType.TINT_TIMELINE);
|
||||
}
|
||||
|
||||
public void setValueOfPoint(int index, int colorIndex, float value) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TintTimelinePoint());
|
||||
}
|
||||
points.get(index).setValue(colorIndex, value);
|
||||
}
|
||||
|
||||
public void setTimeOfPoint(int index, float time) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TintTimelinePoint());
|
||||
}
|
||||
points.get(index).setTime(time);
|
||||
}
|
||||
|
||||
public Color3f getValueAtTime(float time) {
|
||||
TintTimelinePoint left = null, right = null;
|
||||
for (TintTimelinePoint point : points) {
|
||||
if (point.getTime() <= time) {
|
||||
if (left == null || left.getTime() < point.getTime())
|
||||
left = point;
|
||||
} else if (right == null || right.getTime() > point.getTime())
|
||||
right = point;
|
||||
}
|
||||
if (left != null) {
|
||||
if (right != null) {
|
||||
float leftDist = Math.abs(left.getTime() - time);
|
||||
float rightDist = Math.abs(right.getTime() - time);
|
||||
float totalDist = leftDist + rightDist;
|
||||
float leftMultiplier = leftDist / totalDist;
|
||||
float rightMultiplier = rightDist / totalDist;
|
||||
|
||||
return left.getColor().interpolate(leftMultiplier, rightMultiplier, right.getColor());
|
||||
}
|
||||
return left.getColor();
|
||||
}
|
||||
return new Color3f();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.08.2016.
|
||||
*/
|
||||
public class TintTimeline extends ParticleAttributeValue {
|
||||
|
||||
private List<TintTimelinePoint> points = new ArrayList<>();
|
||||
|
||||
public TintTimeline() {
|
||||
super(ParticleAttributeValueType.TINT_TIMELINE);
|
||||
}
|
||||
|
||||
public void setValueOfPoint(int index, int colorIndex, float value) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TintTimelinePoint());
|
||||
}
|
||||
points.get(index).setValue(colorIndex, value);
|
||||
}
|
||||
|
||||
public void setTimeOfPoint(int index, float time) {
|
||||
if (points.size() <= index) {
|
||||
points.add(new TintTimelinePoint());
|
||||
}
|
||||
points.get(index).setTime(time);
|
||||
}
|
||||
|
||||
public Color3f getValueAtTime(float time) {
|
||||
TintTimelinePoint left = null, right = null;
|
||||
for (TintTimelinePoint point : points) {
|
||||
if (point.getTime() <= time) {
|
||||
if (left == null || left.getTime() < point.getTime())
|
||||
left = point;
|
||||
} else if (right == null || right.getTime() > point.getTime())
|
||||
right = point;
|
||||
}
|
||||
if (left != null) {
|
||||
if (right != null) {
|
||||
float leftDist = Math.abs(left.getTime() - time);
|
||||
float rightDist = Math.abs(right.getTime() - time);
|
||||
float totalDist = leftDist + rightDist;
|
||||
float leftMultiplier = leftDist / totalDist;
|
||||
float rightMultiplier = rightDist / totalDist;
|
||||
|
||||
return left.getColor().interpolate(leftMultiplier, rightMultiplier, right.getColor());
|
||||
}
|
||||
return left.getColor();
|
||||
}
|
||||
return new Color3f();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
|
||||
public class TintTimelinePoint {
|
||||
|
||||
private float time;
|
||||
private Color3f color;
|
||||
|
||||
public float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(float time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Color3f getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setValue(int colorIndex, float value) {
|
||||
if (color == null)
|
||||
color = new Color3f();
|
||||
if (colorIndex == 0)
|
||||
color.setR(value);
|
||||
else if (colorIndex == 1)
|
||||
color.setG(value);
|
||||
else if (colorIndex == 2)
|
||||
color.setB(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.particles.attributes.attributeValues;
|
||||
|
||||
import de.frajul.endlessroll.data.Color3f;
|
||||
|
||||
public class TintTimelinePoint {
|
||||
|
||||
private float time;
|
||||
private Color3f color;
|
||||
|
||||
public float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(float time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Color3f getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setValue(int colorIndex, float value) {
|
||||
if (color == null)
|
||||
color = new Color3f();
|
||||
if (colorIndex == 0)
|
||||
color.setR(value);
|
||||
else if (colorIndex == 1)
|
||||
color.setG(value);
|
||||
else if (colorIndex == 2)
|
||||
color.setB(value);
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class CollectEnergyTask extends Task {
|
||||
|
||||
public CollectEnergyTask(int condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return levelManager.getTotalCollectedEnergyCount() >= condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
if (conditionFulfilled) {
|
||||
return context.getString(R.string.task_collect_energy_format_d, condition);
|
||||
}
|
||||
return context.getString(R.string.task_collect_energy_progress_format_ddd, condition,
|
||||
levelManager.getTotalCollectedEnergyCount(), condition);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class CollectEnergyTask extends Task {
|
||||
|
||||
public CollectEnergyTask(int condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return levelManager.getTotalCollectedEnergyCount() >= condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
if (conditionFulfilled) {
|
||||
return context.getString(R.string.task_collect_energy_format_d, condition);
|
||||
}
|
||||
return context.getString(R.string.task_collect_energy_progress_format_ddd, condition,
|
||||
levelManager.getTotalCollectedEnergyCount(), condition);
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class CollectStarTask extends Task {
|
||||
|
||||
public CollectStarTask(int condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return levelManager.getTotalCollectedStarCount() >= condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
if (conditionFulfilled) {
|
||||
return context.getString(R.string.task_collect_stars_format_d, condition);
|
||||
}
|
||||
return context.getString(R.string.task_collect_stars_progress_format_ddd, condition,
|
||||
levelManager.getTotalCollectedStarCount(), condition);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class CollectStarTask extends Task {
|
||||
|
||||
public CollectStarTask(int condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return levelManager.getTotalCollectedStarCount() >= condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
if (conditionFulfilled) {
|
||||
return context.getString(R.string.task_collect_stars_format_d, condition);
|
||||
}
|
||||
return context.getString(R.string.task_collect_stars_progress_format_ddd, condition,
|
||||
levelManager.getTotalCollectedStarCount(), condition);
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,34 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class CompleteWorldTask extends Task {
|
||||
|
||||
public CompleteWorldTask(int condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return levelManager.getPackWithId(condition).isAllLevelsFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
return context.getString(R.string.task_complete_world_format_d, condition);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class CompleteWorldTask extends Task {
|
||||
|
||||
public CompleteWorldTask(int condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return levelManager.getPackWithId(condition).isAllLevelsFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
return context.getString(R.string.task_complete_world_format_d, condition);
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,34 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class EmptyTask extends Task {
|
||||
|
||||
public EmptyTask() {
|
||||
super(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
return context.getString(R.string.task_empty);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 30.10.2017.
|
||||
*/
|
||||
|
||||
public class EmptyTask extends Task {
|
||||
|
||||
public EmptyTask() {
|
||||
super(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkConditionFulfilled(LevelManager levelManager) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Context context, LevelManager levelManager) {
|
||||
return context.getString(R.string.task_empty);
|
||||
}
|
||||
}
|
||||
|
@ -1,99 +1,99 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public enum PlayerShape {
|
||||
BALL(R.string.playershape_name_ball, R.string.playershape_description_ball,
|
||||
R.drawable.playershapes_ball, true, new EmptyTask()),
|
||||
CLOCK(R.string.playershape_name_clock, R.string.playershape_description_clock,
|
||||
R.drawable.playershapes_clock, true, new CollectStarTask(15)),
|
||||
SMILEY(R.string.playershape_name_smiley, R.string.playershape_description_smiley,
|
||||
R.drawable.playershapes_smiley, true, new CollectStarTask(50)),
|
||||
WHEEL(R.string.playershape_name_wheel, R.string.playershape_description_wheel,
|
||||
R.drawable.playershapes_wheel, true, new CollectStarTask(80)),
|
||||
|
||||
PACMAN(R.string.playershape_name_pacman, R.string.playershape_description_pacman,
|
||||
R.drawable.playershapes_pacman, false, new CompleteWorldTask(1)),
|
||||
SOCCER(R.string.playershape_name_soccer, R.string.playershape_description_soccer, R.drawable.playershapes_soccer, false, new CompleteWorldTask(2)),
|
||||
HYPNO_SPIRAL(R.string.playershape_name_hypno_spiral,
|
||||
R.string.playershape_description_hypno_spiral, R.drawable.playershapes_hypno_spiral, false,
|
||||
new CollectEnergyTask(5)),
|
||||
BLUE(R.string.playershape_name_blue, R.string.playershape_description_blue,
|
||||
R.drawable.playershapes_blue, false, new CollectEnergyTask(20)),
|
||||
SUN(R.string.playershape_name_sun, R.string.playershape_description_sun,
|
||||
R.drawable.playershapes_sun, false, new CollectEnergyTask(30)),
|
||||
RAINBOW(R.string.playershape_name_rainbow, R.string.playershape_description_rainbow, R.drawable.playershapes_rainbow, true, new EmptyTask());
|
||||
|
||||
@StringRes
|
||||
private int nameId;
|
||||
@StringRes
|
||||
private int descriptionId;
|
||||
@DrawableRes
|
||||
private int drawableId;
|
||||
private boolean inTopRow;
|
||||
private Task unlockTask;
|
||||
|
||||
private Texture texture;
|
||||
|
||||
PlayerShape(@StringRes int nameId, @StringRes int descriptionId, @DrawableRes int drawableId, boolean inTopRow, Task unlockTask) {
|
||||
this.nameId = nameId;
|
||||
this.descriptionId = descriptionId;
|
||||
this.drawableId = drawableId;
|
||||
this.inTopRow = inTopRow;
|
||||
this.unlockTask = unlockTask;
|
||||
}
|
||||
|
||||
public static void loadAllTextures(TexturePack texturePack) {
|
||||
for (PlayerShape playerShape : values())
|
||||
playerShape.loadTexture(texturePack);
|
||||
}
|
||||
|
||||
private void loadTexture(TexturePack texturePack) {
|
||||
if (drawableId == -1)
|
||||
return;
|
||||
texture = texturePack.loadTexture(drawableId);
|
||||
}
|
||||
|
||||
public Task getUnlockTask() {
|
||||
return unlockTask;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getNameId() {
|
||||
return nameId;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getDescriptionId() {
|
||||
return descriptionId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getDrawableId() {
|
||||
return drawableId;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public boolean isInTopRow() {
|
||||
return inTopRow;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public enum PlayerShape {
|
||||
BALL(R.string.playershape_name_ball, R.string.playershape_description_ball,
|
||||
R.drawable.playershapes_ball, true, new EmptyTask()),
|
||||
CLOCK(R.string.playershape_name_clock, R.string.playershape_description_clock,
|
||||
R.drawable.playershapes_clock, true, new CollectStarTask(15)),
|
||||
SMILEY(R.string.playershape_name_smiley, R.string.playershape_description_smiley,
|
||||
R.drawable.playershapes_smiley, true, new CollectStarTask(50)),
|
||||
WHEEL(R.string.playershape_name_wheel, R.string.playershape_description_wheel,
|
||||
R.drawable.playershapes_wheel, true, new CollectStarTask(80)),
|
||||
|
||||
PACMAN(R.string.playershape_name_pacman, R.string.playershape_description_pacman,
|
||||
R.drawable.playershapes_pacman, false, new CompleteWorldTask(1)),
|
||||
SOCCER(R.string.playershape_name_soccer, R.string.playershape_description_soccer, R.drawable.playershapes_soccer, false, new CompleteWorldTask(2)),
|
||||
HYPNO_SPIRAL(R.string.playershape_name_hypno_spiral,
|
||||
R.string.playershape_description_hypno_spiral, R.drawable.playershapes_hypno_spiral, false,
|
||||
new CollectEnergyTask(5)),
|
||||
BLUE(R.string.playershape_name_blue, R.string.playershape_description_blue,
|
||||
R.drawable.playershapes_blue, false, new CollectEnergyTask(20)),
|
||||
SUN(R.string.playershape_name_sun, R.string.playershape_description_sun,
|
||||
R.drawable.playershapes_sun, false, new CollectEnergyTask(30)),
|
||||
RAINBOW(R.string.playershape_name_rainbow, R.string.playershape_description_rainbow, R.drawable.playershapes_rainbow, true, new EmptyTask());
|
||||
|
||||
@StringRes
|
||||
private int nameId;
|
||||
@StringRes
|
||||
private int descriptionId;
|
||||
@DrawableRes
|
||||
private int drawableId;
|
||||
private boolean inTopRow;
|
||||
private Task unlockTask;
|
||||
|
||||
private Texture texture;
|
||||
|
||||
PlayerShape(@StringRes int nameId, @StringRes int descriptionId, @DrawableRes int drawableId, boolean inTopRow, Task unlockTask) {
|
||||
this.nameId = nameId;
|
||||
this.descriptionId = descriptionId;
|
||||
this.drawableId = drawableId;
|
||||
this.inTopRow = inTopRow;
|
||||
this.unlockTask = unlockTask;
|
||||
}
|
||||
|
||||
public static void loadAllTextures(TexturePack texturePack) {
|
||||
for (PlayerShape playerShape : values())
|
||||
playerShape.loadTexture(texturePack);
|
||||
}
|
||||
|
||||
private void loadTexture(TexturePack texturePack) {
|
||||
if (drawableId == -1)
|
||||
return;
|
||||
texture = texturePack.loadTexture(drawableId);
|
||||
}
|
||||
|
||||
public Task getUnlockTask() {
|
||||
return unlockTask;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getNameId() {
|
||||
return nameId;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getDescriptionId() {
|
||||
return descriptionId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getDrawableId() {
|
||||
return drawableId;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public boolean isInTopRow() {
|
||||
return inTopRow;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import de.frajul.endlessroll.views.PlayerShapeButton;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public interface PlayerShapeButtonOnClickListener {
|
||||
|
||||
void onClick(PlayerShapeButton button);
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import de.frajul.endlessroll.views.PlayerShapeButton;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public interface PlayerShapeButtonOnClickListener {
|
||||
|
||||
void onClick(PlayerShapeButton button);
|
||||
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 29.10.2017.
|
||||
*/
|
||||
|
||||
public abstract class Task {
|
||||
|
||||
protected int condition;
|
||||
protected boolean conditionFulfilled;
|
||||
|
||||
public Task(int condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public void update(LevelManager levelManager) {
|
||||
conditionFulfilled = checkConditionFulfilled(levelManager);
|
||||
}
|
||||
|
||||
protected abstract boolean checkConditionFulfilled(LevelManager levelManager);
|
||||
|
||||
public abstract String toString(Context context, LevelManager levelManager);
|
||||
|
||||
public boolean isConditionFulfilled() {
|
||||
return conditionFulfilled;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.frajul.endlessroll.levels.LevelManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 29.10.2017.
|
||||
*/
|
||||
|
||||
public abstract class Task {
|
||||
|
||||
protected int condition;
|
||||
protected boolean conditionFulfilled;
|
||||
|
||||
public Task(int condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public void update(LevelManager levelManager) {
|
||||
conditionFulfilled = checkConditionFulfilled(levelManager);
|
||||
}
|
||||
|
||||
protected abstract boolean checkConditionFulfilled(LevelManager levelManager);
|
||||
|
||||
public abstract String toString(Context context, LevelManager levelManager);
|
||||
|
||||
public boolean isConditionFulfilled() {
|
||||
return conditionFulfilled;
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.textures;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.12.2015.
|
||||
*/
|
||||
public class Texture {
|
||||
|
||||
private int id;
|
||||
private int atlasWidth;
|
||||
private int atlasHeight;
|
||||
|
||||
public Texture(int id, int atlasWidth, int atlasHeight) {
|
||||
this.id = id;
|
||||
this.atlasWidth = atlasWidth;
|
||||
this.atlasHeight = atlasHeight;
|
||||
}
|
||||
|
||||
public Texture(Texture other) {
|
||||
this.id = other.getId();
|
||||
this.atlasWidth = other.getAtlasWidth();
|
||||
this.atlasHeight = other.getAtlasHeight();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getAtlasWidth() {
|
||||
return atlasWidth;
|
||||
}
|
||||
|
||||
public int getAtlasHeight() {
|
||||
return atlasHeight;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.textures;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.12.2015.
|
||||
*/
|
||||
public class Texture {
|
||||
|
||||
private int id;
|
||||
private int atlasWidth;
|
||||
private int atlasHeight;
|
||||
|
||||
public Texture(int id, int atlasWidth, int atlasHeight) {
|
||||
this.id = id;
|
||||
this.atlasWidth = atlasWidth;
|
||||
this.atlasHeight = atlasHeight;
|
||||
}
|
||||
|
||||
public Texture(Texture other) {
|
||||
this.id = other.getId();
|
||||
this.atlasWidth = other.getAtlasWidth();
|
||||
this.atlasHeight = other.getAtlasHeight();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getAtlasWidth() {
|
||||
return atlasWidth;
|
||||
}
|
||||
|
||||
public int getAtlasHeight() {
|
||||
return atlasHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,66 +1,66 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.textures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
/**
|
||||
* Created by Julian on 26.11.2015.
|
||||
*/
|
||||
public class TextureLoader {
|
||||
|
||||
private Context context;
|
||||
|
||||
public TextureLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public int loadTextureId(int texture, boolean isAtlas) {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), texture);
|
||||
return loadTextureId(bitmap, isAtlas);
|
||||
}
|
||||
|
||||
public Texture loadTexture(String inAssetsLocation) throws Exception {
|
||||
InputStream is = context.getAssets().open(inAssetsLocation);
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inScaled = false;
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
|
||||
return new Texture(loadTextureId(bitmap, false), 1, 1);
|
||||
}
|
||||
|
||||
private int loadTextureId(Bitmap bitmap, boolean isAtlas) {
|
||||
int id = genTexture();
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, id);
|
||||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
|
||||
GLES20.GL_NEAREST);
|
||||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
|
||||
GLES20.GL_NEAREST);
|
||||
|
||||
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
|
||||
|
||||
bitmap.recycle();
|
||||
GameLog.d("Texture " + id + " successfully loaded");
|
||||
return id;
|
||||
}
|
||||
|
||||
private int genTexture() {
|
||||
int[] idField = new int[1];
|
||||
GLES20.glGenTextures(1, idField, 0);
|
||||
return idField[0];
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.textures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
/**
|
||||
* Created by Julian on 26.11.2015.
|
||||
*/
|
||||
public class TextureLoader {
|
||||
|
||||
private Context context;
|
||||
|
||||
public TextureLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public int loadTextureId(int texture, boolean isAtlas) {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), texture);
|
||||
return loadTextureId(bitmap, isAtlas);
|
||||
}
|
||||
|
||||
public Texture loadTexture(String inAssetsLocation) throws Exception {
|
||||
InputStream is = context.getAssets().open(inAssetsLocation);
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inScaled = false;
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
|
||||
return new Texture(loadTextureId(bitmap, false), 1, 1);
|
||||
}
|
||||
|
||||
private int loadTextureId(Bitmap bitmap, boolean isAtlas) {
|
||||
int id = genTexture();
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, id);
|
||||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
|
||||
GLES20.GL_NEAREST);
|
||||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
|
||||
GLES20.GL_NEAREST);
|
||||
|
||||
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
|
||||
|
||||
bitmap.recycle();
|
||||
GameLog.d("Texture " + id + " successfully loaded");
|
||||
return id;
|
||||
}
|
||||
|
||||
private int genTexture() {
|
||||
int[] idField = new int[1];
|
||||
GLES20.glGenTextures(1, idField, 0);
|
||||
return idField[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,63 +1,63 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.textures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.DrawableRes;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShape;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.levels.worlds.World;
|
||||
|
||||
/**
|
||||
* Created by Julian on 05.12.2015.
|
||||
*/
|
||||
public class TexturePack {
|
||||
|
||||
private TextureLoader loader;
|
||||
|
||||
public final Texture white;
|
||||
public final Texture goal;
|
||||
public final Texture playerArrow;
|
||||
public final Texture star;
|
||||
public final Texture energy;
|
||||
public final Texture countdown3, countdown2, countdown1;
|
||||
public final Texture toolButtonLocked;
|
||||
public final Texture toolButtonEmpty;
|
||||
|
||||
public TexturePack(Context context) {
|
||||
loader = new TextureLoader(context);
|
||||
white = loadTexture(R.drawable.white);
|
||||
goal = loadTexture(R.drawable.guis_goal);
|
||||
playerArrow = loadTexture(R.drawable.guis_playerarrow);
|
||||
|
||||
star = loadTexture(R.drawable.currency_star);
|
||||
energy = loadAtlas(R.drawable.currency_energy_atlas, 2, 2);
|
||||
|
||||
countdown3 = loadTexture(R.drawable.guis_countdown_3);
|
||||
countdown2 = loadTexture(R.drawable.guis_countdown_2);
|
||||
countdown1 = loadTexture(R.drawable.guis_countdown_1);
|
||||
toolButtonLocked = loadTexture(R.drawable.tools_button_locked);
|
||||
toolButtonEmpty = loadTexture(R.drawable.tools_button_empty);
|
||||
|
||||
PlayerShape.loadAllTextures(this);
|
||||
ToolType.loadAllToolTextures(this);
|
||||
World.loadAllSpecificTextures(this);
|
||||
}
|
||||
|
||||
public Texture loadTexture(@DrawableRes int id) {
|
||||
int texId = loader.loadTextureId(id, false);
|
||||
return new Texture(texId, 1, 1);
|
||||
}
|
||||
|
||||
public Texture loadAtlas(@DrawableRes int id, int atlasWidth, int atlasHeight) {
|
||||
int texId = loader.loadTextureId(id, true);
|
||||
return new Texture(texId, atlasWidth, atlasHeight);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.textures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.DrawableRes;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShape;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.levels.worlds.World;
|
||||
|
||||
/**
|
||||
* Created by Julian on 05.12.2015.
|
||||
*/
|
||||
public class TexturePack {
|
||||
|
||||
private TextureLoader loader;
|
||||
|
||||
public final Texture white;
|
||||
public final Texture goal;
|
||||
public final Texture playerArrow;
|
||||
public final Texture star;
|
||||
public final Texture energy;
|
||||
public final Texture countdown3, countdown2, countdown1;
|
||||
public final Texture toolButtonLocked;
|
||||
public final Texture toolButtonEmpty;
|
||||
|
||||
public TexturePack(Context context) {
|
||||
loader = new TextureLoader(context);
|
||||
white = loadTexture(R.drawable.white);
|
||||
goal = loadTexture(R.drawable.guis_goal);
|
||||
playerArrow = loadTexture(R.drawable.guis_playerarrow);
|
||||
|
||||
star = loadTexture(R.drawable.currency_star);
|
||||
energy = loadAtlas(R.drawable.currency_energy_atlas, 2, 2);
|
||||
|
||||
countdown3 = loadTexture(R.drawable.guis_countdown_3);
|
||||
countdown2 = loadTexture(R.drawable.guis_countdown_2);
|
||||
countdown1 = loadTexture(R.drawable.guis_countdown_1);
|
||||
toolButtonLocked = loadTexture(R.drawable.tools_button_locked);
|
||||
toolButtonEmpty = loadTexture(R.drawable.tools_button_empty);
|
||||
|
||||
PlayerShape.loadAllTextures(this);
|
||||
ToolType.loadAllToolTextures(this);
|
||||
World.loadAllSpecificTextures(this);
|
||||
}
|
||||
|
||||
public Texture loadTexture(@DrawableRes int id) {
|
||||
int texId = loader.loadTextureId(id, false);
|
||||
return new Texture(texId, 1, 1);
|
||||
}
|
||||
|
||||
public Texture loadAtlas(@DrawableRes int id, int atlasWidth, int atlasHeight) {
|
||||
int texId = loader.loadTextureId(id, true);
|
||||
return new Texture(texId, atlasWidth, atlasHeight);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Ceiling extends TileList {
|
||||
|
||||
public Ceiling(Texture texture) {
|
||||
super(Type.CEILING, texture);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Ceiling extends TileList {
|
||||
|
||||
public Ceiling(Texture texture) {
|
||||
super(Type.CEILING, texture);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Terrain extends TileList {
|
||||
|
||||
public Terrain(Texture texture) {
|
||||
super(TileList.Type.TERRAIN, texture);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Terrain extends TileList {
|
||||
|
||||
public Terrain(Texture texture) {
|
||||
super(TileList.Type.TERRAIN, texture);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.TileData;
|
||||
|
||||
/**
|
||||
* Created by Julian on 18.12.2015.
|
||||
*/
|
||||
|
||||
public class Tile extends Entity {
|
||||
|
||||
private int gridColumnCount;
|
||||
|
||||
public Tile(TileList.Type type, Texture texture, float edge, TileData data) {
|
||||
this(type, texture, edge, data.getX(), data.getWidth());
|
||||
}
|
||||
|
||||
public Tile(TileList.Type type, Texture texture, float edge, float x, float width) {
|
||||
super(texture, new Vector(), width, 0);
|
||||
super.height = type.calculateTileHeightFromEdge(edge);
|
||||
super.position.x = x;
|
||||
switch (type) {
|
||||
case TERRAIN:
|
||||
super.position.y = edge - super.height / 2;
|
||||
break;
|
||||
case CEILING:
|
||||
super.position.y = edge + super.height / 2;
|
||||
break;
|
||||
}
|
||||
gridColumnCount = (int) (width / height);
|
||||
gridColumnCount = Math.max(gridColumnCount, 3);
|
||||
}
|
||||
|
||||
public int getGridColumnCount() {
|
||||
return gridColumnCount;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Entity;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.TileData;
|
||||
|
||||
/**
|
||||
* Created by Julian on 18.12.2015.
|
||||
*/
|
||||
|
||||
public class Tile extends Entity {
|
||||
|
||||
private int gridColumnCount;
|
||||
|
||||
public Tile(TileList.Type type, Texture texture, float edge, TileData data) {
|
||||
this(type, texture, edge, data.getX(), data.getWidth());
|
||||
}
|
||||
|
||||
public Tile(TileList.Type type, Texture texture, float edge, float x, float width) {
|
||||
super(texture, new Vector(), width, 0);
|
||||
super.height = type.calculateTileHeightFromEdge(edge);
|
||||
super.position.x = x;
|
||||
switch (type) {
|
||||
case TERRAIN:
|
||||
super.position.y = edge - super.height / 2;
|
||||
break;
|
||||
case CEILING:
|
||||
super.position.y = edge + super.height / 2;
|
||||
break;
|
||||
}
|
||||
gridColumnCount = (int) (width / height);
|
||||
gridColumnCount = Math.max(gridColumnCount, 3);
|
||||
}
|
||||
|
||||
public int getGridColumnCount() {
|
||||
return gridColumnCount;
|
||||
}
|
||||
}
|
||||
|
@ -1,106 +1,106 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.SynchronizedArrayList;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.TileData;
|
||||
import de.frajul.endlessroll.levels.worlds.World;
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class TileList extends SynchronizedArrayList<Tile> {
|
||||
|
||||
public enum Type {
|
||||
TERRAIN,
|
||||
CEILING;
|
||||
|
||||
public float calculateTileHeightFromEdge(float edge) {
|
||||
switch (this) {
|
||||
case TERRAIN:
|
||||
if (edge <= -0.6f)
|
||||
return 0.4f;
|
||||
return 1 + edge;
|
||||
case CEILING:
|
||||
if (edge >= 0.6f)
|
||||
return 0.4f;
|
||||
return 1 - edge;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Type type;
|
||||
private Texture texture;
|
||||
private float edge;
|
||||
private boolean endless;
|
||||
|
||||
public TileList(Type type, Texture texture) {
|
||||
this.type = type;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void loadData(World world, float edge, List<TileData> tileData) {
|
||||
this.texture = world.getTerrainTexture();
|
||||
if (type == Type.CEILING)
|
||||
this.texture = world.getCeilingTexture();
|
||||
this.endless = false;
|
||||
super.clear();
|
||||
float lastRightEdge = -10;
|
||||
for (TileData data : tileData) {
|
||||
float leftEdge = data.getX() - data.getWidth() / 2;
|
||||
float rightEdge = data.getX() + data.getWidth() / 2;
|
||||
if (Math.abs(lastRightEdge - leftEdge) < 0.1f)
|
||||
GameLog.i("!!! Too small gap found !!! " + toMeters(lastRightEdge) + "m; " + lastRightEdge + "-" + leftEdge + "; iRight=" + tileData.indexOf(data));
|
||||
lastRightEdge = rightEdge;
|
||||
super.add(new Tile(type, texture, edge, data));
|
||||
}
|
||||
this.edge = edge;
|
||||
if (edge >= 1 || edge <= -1)
|
||||
super.clear();
|
||||
}
|
||||
|
||||
private float toMeters(float value) {
|
||||
return ((int) (value * 20)) / 10f;
|
||||
}
|
||||
|
||||
public void createEndless(World world, float edge) {
|
||||
loadData(world, edge, new ArrayList<TileData>());
|
||||
super.add(createEndlessTile(0));
|
||||
this.endless = true;
|
||||
}
|
||||
|
||||
public void update(float cameraX) {
|
||||
if (!super.isEmpty()) {
|
||||
if (endless) {
|
||||
Tile last = super.get(super.size() - 1);
|
||||
if (last.getRightEdge() - cameraX < 3)
|
||||
super.add(createEndlessTile(last.getRightEdge() + 2.5f));
|
||||
}
|
||||
if (super.get(0).getRightEdge() - cameraX < -3) {
|
||||
super.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Tile createEndlessTile(float x) {
|
||||
return new Tile(type, texture, edge, x, 5);
|
||||
}
|
||||
|
||||
public float getEdge() {
|
||||
return edge;
|
||||
}
|
||||
|
||||
public boolean isEndless() {
|
||||
return endless;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tileLists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.SynchronizedArrayList;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.levels.TileData;
|
||||
import de.frajul.endlessroll.levels.worlds.World;
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class TileList extends SynchronizedArrayList<Tile> {
|
||||
|
||||
public enum Type {
|
||||
TERRAIN,
|
||||
CEILING;
|
||||
|
||||
public float calculateTileHeightFromEdge(float edge) {
|
||||
switch (this) {
|
||||
case TERRAIN:
|
||||
if (edge <= -0.6f)
|
||||
return 0.4f;
|
||||
return 1 + edge;
|
||||
case CEILING:
|
||||
if (edge >= 0.6f)
|
||||
return 0.4f;
|
||||
return 1 - edge;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Type type;
|
||||
private Texture texture;
|
||||
private float edge;
|
||||
private boolean endless;
|
||||
|
||||
public TileList(Type type, Texture texture) {
|
||||
this.type = type;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void loadData(World world, float edge, List<TileData> tileData) {
|
||||
this.texture = world.getTerrainTexture();
|
||||
if (type == Type.CEILING)
|
||||
this.texture = world.getCeilingTexture();
|
||||
this.endless = false;
|
||||
super.clear();
|
||||
float lastRightEdge = -10;
|
||||
for (TileData data : tileData) {
|
||||
float leftEdge = data.getX() - data.getWidth() / 2;
|
||||
float rightEdge = data.getX() + data.getWidth() / 2;
|
||||
if (Math.abs(lastRightEdge - leftEdge) < 0.1f)
|
||||
GameLog.i("!!! Too small gap found !!! " + toMeters(lastRightEdge) + "m; " + lastRightEdge + "-" + leftEdge + "; iRight=" + tileData.indexOf(data));
|
||||
lastRightEdge = rightEdge;
|
||||
super.add(new Tile(type, texture, edge, data));
|
||||
}
|
||||
this.edge = edge;
|
||||
if (edge >= 1 || edge <= -1)
|
||||
super.clear();
|
||||
}
|
||||
|
||||
private float toMeters(float value) {
|
||||
return ((int) (value * 20)) / 10f;
|
||||
}
|
||||
|
||||
public void createEndless(World world, float edge) {
|
||||
loadData(world, edge, new ArrayList<TileData>());
|
||||
super.add(createEndlessTile(0));
|
||||
this.endless = true;
|
||||
}
|
||||
|
||||
public void update(float cameraX) {
|
||||
if (!super.isEmpty()) {
|
||||
if (endless) {
|
||||
Tile last = super.get(super.size() - 1);
|
||||
if (last.getRightEdge() - cameraX < 3)
|
||||
super.add(createEndlessTile(last.getRightEdge() + 2.5f));
|
||||
}
|
||||
if (super.get(0).getRightEdge() - cameraX < -3) {
|
||||
super.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Tile createEndlessTile(float x) {
|
||||
return new Tile(type, texture, edge, x, 5);
|
||||
}
|
||||
|
||||
public float getEdge() {
|
||||
return edge;
|
||||
}
|
||||
|
||||
public boolean isEndless() {
|
||||
return endless;
|
||||
}
|
||||
}
|
||||
|
@ -1,80 +1,80 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Obstacle;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.02.2016.
|
||||
*/
|
||||
public class Bomb extends Tool {
|
||||
|
||||
private float delta;
|
||||
private boolean exploding = false;
|
||||
private Obstacle attachedObstacle;
|
||||
private Vector offsetToObstaclePosition = new Vector();
|
||||
|
||||
public Bomb(Vector position) {
|
||||
super(ToolType.BOMB, position, .25f, .25f, false, false);
|
||||
animation.setIndexSequence(new int[]{0, 1, 2});
|
||||
animation.setLooping(false);
|
||||
animation.setRequiredDelta(
|
||||
(int) (ToolType.BOMB.getCurrentUpgradeValue(ToolUpgradeType.DURATION) / 3f));
|
||||
super.setFloating(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Timer timer) {
|
||||
super.update(timer);
|
||||
float explosionDuration = ToolType.BOMB.getCurrentUpgradeValue(ToolUpgradeType.DURATION);
|
||||
delta += timer.getFrameTimeMilliseconds();
|
||||
int currentExplosionState = Math.min((int) (delta / (explosionDuration / 3f)), 3);
|
||||
if (attachedObstacle != null) {
|
||||
if (attachedObstacle.isMoving())
|
||||
super.setPosition(new Vector(attachedObstacle.getPosition()).translate(offsetToObstaclePosition));
|
||||
attachedObstacle.setBombExplosionState(currentExplosionState);
|
||||
}
|
||||
if (delta >= explosionDuration)
|
||||
exploding = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAttachedObstacle(Obstacle attachedObstacle) {
|
||||
this.attachedObstacle = attachedObstacle;
|
||||
offsetToObstaclePosition = attachedObstacle.getPosition().vectorTo(super.getPosition());
|
||||
attachedObstacle.setBombExplosionState(0);
|
||||
}
|
||||
|
||||
public boolean isExploding() {
|
||||
return exploding;
|
||||
}
|
||||
|
||||
public void explode() {
|
||||
if (attachedObstacle != null)
|
||||
attachedObstacle.destroy(DestroyEffect.EXPLOSION);
|
||||
super.destroy(DestroyEffect.EXPLOSION);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Obstacle;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 20.02.2016.
|
||||
*/
|
||||
public class Bomb extends Tool {
|
||||
|
||||
private float delta;
|
||||
private boolean exploding = false;
|
||||
private Obstacle attachedObstacle;
|
||||
private Vector offsetToObstaclePosition = new Vector();
|
||||
|
||||
public Bomb(Vector position) {
|
||||
super(ToolType.BOMB, position, .25f, .25f, false, false);
|
||||
animation.setIndexSequence(new int[]{0, 1, 2});
|
||||
animation.setLooping(false);
|
||||
animation.setRequiredDelta(
|
||||
(int) (ToolType.BOMB.getCurrentUpgradeValue(ToolUpgradeType.DURATION) / 3f));
|
||||
super.setFloating(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Timer timer) {
|
||||
super.update(timer);
|
||||
float explosionDuration = ToolType.BOMB.getCurrentUpgradeValue(ToolUpgradeType.DURATION);
|
||||
delta += timer.getFrameTimeMilliseconds();
|
||||
int currentExplosionState = Math.min((int) (delta / (explosionDuration / 3f)), 3);
|
||||
if (attachedObstacle != null) {
|
||||
if (attachedObstacle.isMoving())
|
||||
super.setPosition(new Vector(attachedObstacle.getPosition()).translate(offsetToObstaclePosition));
|
||||
attachedObstacle.setBombExplosionState(currentExplosionState);
|
||||
}
|
||||
if (delta >= explosionDuration)
|
||||
exploding = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAttachedObstacle(Obstacle attachedObstacle) {
|
||||
this.attachedObstacle = attachedObstacle;
|
||||
offsetToObstaclePosition = attachedObstacle.getPosition().vectorTo(super.getPosition());
|
||||
attachedObstacle.setBombExplosionState(0);
|
||||
}
|
||||
|
||||
public boolean isExploding() {
|
||||
return exploding;
|
||||
}
|
||||
|
||||
public void explode() {
|
||||
if (attachedObstacle != null)
|
||||
attachedObstacle.destroy(DestroyEffect.EXPLOSION);
|
||||
super.destroy(DestroyEffect.EXPLOSION);
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +1,84 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.02.2016.
|
||||
*/
|
||||
public class Magnet extends Tool {
|
||||
|
||||
private SoundManager soundManager;
|
||||
private ParticleSource particleSource;
|
||||
private SoundStream soundStream;
|
||||
|
||||
public Magnet(Vector position, ParticleSystem particleSystem, SoundManager soundManager) {
|
||||
super(ToolType.MAGNET, position, .24f, .24f, false, false);
|
||||
this.soundManager = soundManager;
|
||||
animation.setRequiredDelta(300);
|
||||
animation.setIndexSequence(new int[]{1, 1, 0});
|
||||
animation.setLooping(true);
|
||||
super.setFloating(true);
|
||||
particleSource = new ParticleSource(new Vector(position), particleSystem.magnet);
|
||||
particleSource.start();
|
||||
soundStream = soundManager.playSound(soundManager.magnetSound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(DestroyEffect destroyEffect) {
|
||||
super.destroy(destroyEffect);
|
||||
particleSource.kill();
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
public void updateSoundVolume(Player player) {
|
||||
float distanceToPlayer = super.getPosition().vectorTo(player.getPosition()).length();
|
||||
float factor = 1.0f / distanceToPlayer;
|
||||
if (distanceToPlayer > 3 && player.getPosition().getX() > super.getPosition().getX()) {
|
||||
soundManager.stopSound(soundStream);
|
||||
return;
|
||||
}
|
||||
soundStream.setCurrentVolumeModifier(factor);
|
||||
soundManager.onStreamVolumeChanged(soundStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
float fromPlayerDistance = player.getPosition().vectorTo(super.getPosition()).length();
|
||||
float fromPlayerDistanceGreaterFour = Math.max(fromPlayerDistance, 0.4f);
|
||||
float fromPlayerYDistance = super.getPosition().y - player.getPosition().y;
|
||||
float force = 0.0000012f / (fromPlayerDistanceGreaterFour * fromPlayerDistanceGreaterFour);
|
||||
force *= ToolType.MAGNET.getCurrentUpgradeValue(ToolUpgradeType.FORCE) / 100;
|
||||
force *= timer.getFrameTimeMilliseconds();
|
||||
|
||||
if (fromPlayerYDistance < 0) {
|
||||
force = -force;
|
||||
}
|
||||
player.addForce(force);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return new Circle(super.getPosition(), 2);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.02.2016.
|
||||
*/
|
||||
public class Magnet extends Tool {
|
||||
|
||||
private SoundManager soundManager;
|
||||
private ParticleSource particleSource;
|
||||
private SoundStream soundStream;
|
||||
|
||||
public Magnet(Vector position, ParticleSystem particleSystem, SoundManager soundManager) {
|
||||
super(ToolType.MAGNET, position, .24f, .24f, false, false);
|
||||
this.soundManager = soundManager;
|
||||
animation.setRequiredDelta(300);
|
||||
animation.setIndexSequence(new int[]{1, 1, 0});
|
||||
animation.setLooping(true);
|
||||
super.setFloating(true);
|
||||
particleSource = new ParticleSource(new Vector(position), particleSystem.magnet);
|
||||
particleSource.start();
|
||||
soundStream = soundManager.playSound(soundManager.magnetSound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(DestroyEffect destroyEffect) {
|
||||
super.destroy(destroyEffect);
|
||||
particleSource.kill();
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
public void updateSoundVolume(Player player) {
|
||||
float distanceToPlayer = super.getPosition().vectorTo(player.getPosition()).length();
|
||||
float factor = 1.0f / distanceToPlayer;
|
||||
if (distanceToPlayer > 3 && player.getPosition().getX() > super.getPosition().getX()) {
|
||||
soundManager.stopSound(soundStream);
|
||||
return;
|
||||
}
|
||||
soundStream.setCurrentVolumeModifier(factor);
|
||||
soundManager.onStreamVolumeChanged(soundStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
float fromPlayerDistance = player.getPosition().vectorTo(super.getPosition()).length();
|
||||
float fromPlayerDistanceGreaterFour = Math.max(fromPlayerDistance, 0.4f);
|
||||
float fromPlayerYDistance = super.getPosition().y - player.getPosition().y;
|
||||
float force = 0.0000012f / (fromPlayerDistanceGreaterFour * fromPlayerDistanceGreaterFour);
|
||||
force *= ToolType.MAGNET.getCurrentUpgradeValue(ToolUpgradeType.FORCE) / 100;
|
||||
force *= timer.getFrameTimeMilliseconds();
|
||||
|
||||
if (fromPlayerYDistance < 0) {
|
||||
force = -force;
|
||||
}
|
||||
player.addForce(force);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return new Circle(super.getPosition(), 2);
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.10.2017.
|
||||
*/
|
||||
|
||||
public class PowerMushroom extends Tool {
|
||||
|
||||
private SoundManager soundManager;
|
||||
|
||||
public PowerMushroom(Vector position, SoundManager soundManager) {
|
||||
super(ToolType.POWER_MUSHROOM, position, .35f, .3f, true, true);
|
||||
animation.disable();
|
||||
this.soundManager = soundManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
player.startSuperPower((long) ToolType.POWER_MUSHROOM.getCurrentUpgradeValue(ToolUpgradeType.DURATION));
|
||||
soundManager.playSound(soundManager.mushroomSound);
|
||||
super.destroy(DestroyEffect.ENERGY_COLLECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 02.10.2017.
|
||||
*/
|
||||
|
||||
public class PowerMushroom extends Tool {
|
||||
|
||||
private SoundManager soundManager;
|
||||
|
||||
public PowerMushroom(Vector position, SoundManager soundManager) {
|
||||
super(ToolType.POWER_MUSHROOM, position, .35f, .3f, true, true);
|
||||
animation.disable();
|
||||
this.soundManager = soundManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
player.startSuperPower((long) ToolType.POWER_MUSHROOM.getCurrentUpgradeValue(ToolUpgradeType.DURATION));
|
||||
soundManager.playSound(soundManager.mushroomSound);
|
||||
super.destroy(DestroyEffect.ENERGY_COLLECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,71 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Triangle;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 29.11.2015.
|
||||
*/
|
||||
public class Ramp extends Tool {
|
||||
|
||||
public Ramp(Vector position) {
|
||||
super(ToolType.RAMP, position, .4f, .35f, true, true);
|
||||
animation.setLooping(true);
|
||||
}
|
||||
|
||||
public float getGradient() {
|
||||
return super.getHeight() / super.getWidth();
|
||||
}
|
||||
|
||||
public float getHeightAt(float x, boolean clamp) {
|
||||
float ratio = (x - getLeftEdge()) / super.getWidth();
|
||||
if (clamp) {
|
||||
if (ratio < 0)
|
||||
return getBottomEdge();
|
||||
if (ratio > 1)
|
||||
return getTopEdge();
|
||||
}
|
||||
return getBottomEdge() + super.getHeight() * ratio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
float necessaryY = calcNecessaryPlayerY(player);
|
||||
player.getPosition().y = necessaryY;
|
||||
float acceleration = player.getMovement().x * getGradient();
|
||||
|
||||
player.setGravityForce(0);
|
||||
player.getMovement().setY(0);
|
||||
player.addForce(acceleration);
|
||||
}
|
||||
|
||||
private float calcNecessaryPlayerY(Player player) {
|
||||
float normalM = -1 / getGradient();
|
||||
Vector normalToCircleCenter = new Vector(-1, -normalM).normalize();
|
||||
normalToCircleCenter.mul(player.RADIUS);
|
||||
float normalX = player.getPosition().x - normalToCircleCenter.x;
|
||||
float normalY = getHeightAt(normalX, false);
|
||||
return normalY + normalToCircleCenter.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return new Triangle(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return new Triangle(this);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Triangle;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 29.11.2015.
|
||||
*/
|
||||
public class Ramp extends Tool {
|
||||
|
||||
public Ramp(Vector position) {
|
||||
super(ToolType.RAMP, position, .4f, .35f, true, true);
|
||||
animation.setLooping(true);
|
||||
}
|
||||
|
||||
public float getGradient() {
|
||||
return super.getHeight() / super.getWidth();
|
||||
}
|
||||
|
||||
public float getHeightAt(float x, boolean clamp) {
|
||||
float ratio = (x - getLeftEdge()) / super.getWidth();
|
||||
if (clamp) {
|
||||
if (ratio < 0)
|
||||
return getBottomEdge();
|
||||
if (ratio > 1)
|
||||
return getTopEdge();
|
||||
}
|
||||
return getBottomEdge() + super.getHeight() * ratio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
float necessaryY = calcNecessaryPlayerY(player);
|
||||
player.getPosition().y = necessaryY;
|
||||
float acceleration = player.getMovement().x * getGradient();
|
||||
|
||||
player.setGravityForce(0);
|
||||
player.getMovement().setY(0);
|
||||
player.addForce(acceleration);
|
||||
}
|
||||
|
||||
private float calcNecessaryPlayerY(Player player) {
|
||||
float normalM = -1 / getGradient();
|
||||
Vector normalToCircleCenter = new Vector(-1, -normalM).normalize();
|
||||
normalToCircleCenter.mul(player.RADIUS);
|
||||
float normalX = player.getPosition().x - normalToCircleCenter.x;
|
||||
float normalY = getHeightAt(normalX, false);
|
||||
return normalY + normalToCircleCenter.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return new Triangle(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return new Triangle(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,59 +1,59 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Quad;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 04.01.2016.
|
||||
*/
|
||||
public class Spring extends Tool {
|
||||
|
||||
private boolean hasYetCollided = false;
|
||||
private SoundManager soundManager;
|
||||
|
||||
public Spring(Vector position, SoundManager soundManager) {
|
||||
super(ToolType.SPRING, position, .3f, .35f, true, true);
|
||||
animation.setIndexSequence(new int[]{1, 3, 3, 1});
|
||||
animation.setRequiredDelta(80);
|
||||
this.soundManager = soundManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Timer timer) {
|
||||
if (hasYetCollided)
|
||||
super.update(timer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
if (!hasYetCollided) {
|
||||
hasYetCollided = true;
|
||||
soundManager.playSound(soundManager.springSound);
|
||||
|
||||
player.clearAllForces();
|
||||
player.getMovement().setY(0);
|
||||
player.addForce(.0022f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return new Quad(super.getPosition(), .2f, .1f);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Quad;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
|
||||
/**
|
||||
* Created by Julian on 04.01.2016.
|
||||
*/
|
||||
public class Spring extends Tool {
|
||||
|
||||
private boolean hasYetCollided = false;
|
||||
private SoundManager soundManager;
|
||||
|
||||
public Spring(Vector position, SoundManager soundManager) {
|
||||
super(ToolType.SPRING, position, .3f, .35f, true, true);
|
||||
animation.setIndexSequence(new int[]{1, 3, 3, 1});
|
||||
animation.setRequiredDelta(80);
|
||||
this.soundManager = soundManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Timer timer) {
|
||||
if (hasYetCollided)
|
||||
super.update(timer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
if (!hasYetCollided) {
|
||||
hasYetCollided = true;
|
||||
soundManager.playSound(soundManager.springSound);
|
||||
|
||||
player.clearAllForces();
|
||||
player.getMovement().setY(0);
|
||||
player.addForce(.0022f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return new Quad(super.getPosition(), .2f, .1f);
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +1,103 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.02.2016.
|
||||
*/
|
||||
public class Stasis extends Tool {
|
||||
|
||||
private SoundManager soundManager;
|
||||
private ParticleSource particleSource;
|
||||
private boolean firstCollision = true;
|
||||
private final static float Y_SLOW_FACTOR = .4f; //Final .2f
|
||||
private final static float X_SLOW_FACTOR = .9f; //Final .8f
|
||||
private float forceValue;
|
||||
|
||||
private SoundStream soundStream;
|
||||
|
||||
public Stasis(Vector position, ParticleSystem particleSystem, SoundManager soundManager) {
|
||||
super(ToolType.STASIS, position,
|
||||
.7f * ToolType.STASIS.getCurrentUpgradeValue(ToolUpgradeType.SIZE) / 100,
|
||||
.7f * ToolType.STASIS.getCurrentUpgradeValue(ToolUpgradeType.SIZE) / 100, false,
|
||||
false);
|
||||
this.soundManager = soundManager;
|
||||
animation.setLooping(true);
|
||||
animation.setRequiredDelta(300);
|
||||
animation.setIndexSequence(new int[]{1, 1, 2, 3, 2, 4, 4, 3, 2, 2, 3, 3});
|
||||
super.setFloating(true);
|
||||
particleSource = new ParticleSource(new Vector(position), particleSystem.stasis);
|
||||
particleSource.setSpawnSize(new Vector(super.width, super.height));
|
||||
particleSource.start();
|
||||
forceValue = ToolType.STASIS.getCurrentUpgradeValue(ToolUpgradeType.FORCE);
|
||||
soundStream = soundManager.playSound(soundManager.stasisSound);
|
||||
}
|
||||
|
||||
public void updateSoundVolume(Player player) {
|
||||
float distanceToPlayer = super.getPosition().getX() - player.getPosition().getX();
|
||||
boolean playerInXRange = (player.getRightEdge() >= super.getLeftEdge() && player
|
||||
.getRightEdge() <= super.getRightEdge()) || (player.getLeftEdge() >= super
|
||||
.getLeftEdge() && player.getLeftEdge() <= super.getRightEdge());
|
||||
float factor = 1.0f;
|
||||
if (!playerInXRange) {
|
||||
factor = 1.0f / (distanceToPlayer * distanceToPlayer);
|
||||
if (distanceToPlayer < -2) {
|
||||
soundManager.stopSound(soundStream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
soundStream.setCurrentVolumeModifier(factor);
|
||||
soundManager.onStreamVolumeChanged(soundStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(DestroyEffect destroyEffect) {
|
||||
super.destroy(destroyEffect);
|
||||
particleSource.kill();
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
player.addStasis(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void influencePlayerMovementValues(Player player) {
|
||||
float finalXSlow = getCurrentXSlowFactor();
|
||||
player.manipulateAllForces(Y_SLOW_FACTOR / forceValue);
|
||||
player.getMovement().setX(player.getMovement().getX() * finalXSlow);
|
||||
if (firstCollision) {
|
||||
player.getMovement().y *= Y_SLOW_FACTOR / forceValue;
|
||||
firstCollision = false;
|
||||
}
|
||||
}
|
||||
|
||||
public float getCurrentXSlowFactor() {
|
||||
return X_SLOW_FACTOR - forceValue / 20f;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.DestroyEffect;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSource;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
import de.frajul.endlessroll.sounds.SoundStream;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.02.2016.
|
||||
*/
|
||||
public class Stasis extends Tool {
|
||||
|
||||
private SoundManager soundManager;
|
||||
private ParticleSource particleSource;
|
||||
private boolean firstCollision = true;
|
||||
private final static float Y_SLOW_FACTOR = .4f; //Final .2f
|
||||
private final static float X_SLOW_FACTOR = .9f; //Final .8f
|
||||
private float forceValue;
|
||||
|
||||
private SoundStream soundStream;
|
||||
|
||||
public Stasis(Vector position, ParticleSystem particleSystem, SoundManager soundManager) {
|
||||
super(ToolType.STASIS, position,
|
||||
.7f * ToolType.STASIS.getCurrentUpgradeValue(ToolUpgradeType.SIZE) / 100,
|
||||
.7f * ToolType.STASIS.getCurrentUpgradeValue(ToolUpgradeType.SIZE) / 100, false,
|
||||
false);
|
||||
this.soundManager = soundManager;
|
||||
animation.setLooping(true);
|
||||
animation.setRequiredDelta(300);
|
||||
animation.setIndexSequence(new int[]{1, 1, 2, 3, 2, 4, 4, 3, 2, 2, 3, 3});
|
||||
super.setFloating(true);
|
||||
particleSource = new ParticleSource(new Vector(position), particleSystem.stasis);
|
||||
particleSource.setSpawnSize(new Vector(super.width, super.height));
|
||||
particleSource.start();
|
||||
forceValue = ToolType.STASIS.getCurrentUpgradeValue(ToolUpgradeType.FORCE);
|
||||
soundStream = soundManager.playSound(soundManager.stasisSound);
|
||||
}
|
||||
|
||||
public void updateSoundVolume(Player player) {
|
||||
float distanceToPlayer = super.getPosition().getX() - player.getPosition().getX();
|
||||
boolean playerInXRange = (player.getRightEdge() >= super.getLeftEdge() && player
|
||||
.getRightEdge() <= super.getRightEdge()) || (player.getLeftEdge() >= super
|
||||
.getLeftEdge() && player.getLeftEdge() <= super.getRightEdge());
|
||||
float factor = 1.0f;
|
||||
if (!playerInXRange) {
|
||||
factor = 1.0f / (distanceToPlayer * distanceToPlayer);
|
||||
if (distanceToPlayer < -2) {
|
||||
soundManager.stopSound(soundStream);
|
||||
return;
|
||||
}
|
||||
}
|
||||
soundStream.setCurrentVolumeModifier(factor);
|
||||
soundManager.onStreamVolumeChanged(soundStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(DestroyEffect destroyEffect) {
|
||||
super.destroy(destroyEffect);
|
||||
particleSource.kill();
|
||||
soundManager.stopSound(soundStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCollision(Player player, Timer timer) {
|
||||
player.addStasis(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createWorldCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Geometry createPlayerCollisionBounds() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void influencePlayerMovementValues(Player player) {
|
||||
float finalXSlow = getCurrentXSlowFactor();
|
||||
player.manipulateAllForces(Y_SLOW_FACTOR / forceValue);
|
||||
player.getMovement().setX(player.getMovement().getX() * finalXSlow);
|
||||
if (firstCollision) {
|
||||
player.getMovement().y *= Y_SLOW_FACTOR / forceValue;
|
||||
firstCollision = false;
|
||||
}
|
||||
}
|
||||
|
||||
public float getCurrentXSlowFactor() {
|
||||
return X_SLOW_FACTOR - forceValue / 20f;
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,64 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.AnimatedEntity;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 04.01.2016.
|
||||
*/
|
||||
public abstract class Tool extends AnimatedEntity {
|
||||
|
||||
private boolean placedByRightEdge;
|
||||
private boolean updateBounds;
|
||||
private Geometry worldCollisionBounds;
|
||||
private Geometry playerCollisionBounds;
|
||||
private boolean floating = false;
|
||||
|
||||
public Tool(ToolType type, Vector position, float width, float height, boolean updateBounds, boolean placedByRightEdge) {
|
||||
super(type.getToolTexture(), position, width, height);
|
||||
this.updateBounds = updateBounds;
|
||||
this.placedByRightEdge = placedByRightEdge;
|
||||
worldCollisionBounds = createWorldCollisionBounds();
|
||||
playerCollisionBounds = createPlayerCollisionBounds();
|
||||
}
|
||||
|
||||
public abstract void onPlayerCollision(Player player, Timer timer);
|
||||
|
||||
protected abstract Geometry createWorldCollisionBounds();
|
||||
|
||||
protected abstract Geometry createPlayerCollisionBounds();
|
||||
|
||||
public Geometry getWorldCollisionBounds() {
|
||||
if (updateBounds)
|
||||
return createWorldCollisionBounds();
|
||||
return worldCollisionBounds;
|
||||
}
|
||||
|
||||
public Geometry getPlayerCollisionBounds() {
|
||||
if (updateBounds)
|
||||
return createPlayerCollisionBounds();
|
||||
return playerCollisionBounds;
|
||||
}
|
||||
|
||||
public void setFloating(boolean floating) {
|
||||
this.floating = floating;
|
||||
}
|
||||
|
||||
public boolean isFloating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
public boolean isPlacedByRightEdge() {
|
||||
return placedByRightEdge;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.AnimatedEntity;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collision.geometry.Geometry;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
|
||||
/**
|
||||
* Created by Julian on 04.01.2016.
|
||||
*/
|
||||
public abstract class Tool extends AnimatedEntity {
|
||||
|
||||
private boolean placedByRightEdge;
|
||||
private boolean updateBounds;
|
||||
private Geometry worldCollisionBounds;
|
||||
private Geometry playerCollisionBounds;
|
||||
private boolean floating = false;
|
||||
|
||||
public Tool(ToolType type, Vector position, float width, float height, boolean updateBounds, boolean placedByRightEdge) {
|
||||
super(type.getToolTexture(), position, width, height);
|
||||
this.updateBounds = updateBounds;
|
||||
this.placedByRightEdge = placedByRightEdge;
|
||||
worldCollisionBounds = createWorldCollisionBounds();
|
||||
playerCollisionBounds = createPlayerCollisionBounds();
|
||||
}
|
||||
|
||||
public abstract void onPlayerCollision(Player player, Timer timer);
|
||||
|
||||
protected abstract Geometry createWorldCollisionBounds();
|
||||
|
||||
protected abstract Geometry createPlayerCollisionBounds();
|
||||
|
||||
public Geometry getWorldCollisionBounds() {
|
||||
if (updateBounds)
|
||||
return createWorldCollisionBounds();
|
||||
return worldCollisionBounds;
|
||||
}
|
||||
|
||||
public Geometry getPlayerCollisionBounds() {
|
||||
if (updateBounds)
|
||||
return createPlayerCollisionBounds();
|
||||
return playerCollisionBounds;
|
||||
}
|
||||
|
||||
public void setFloating(boolean floating) {
|
||||
this.floating = floating;
|
||||
}
|
||||
|
||||
public boolean isFloating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
public boolean isPlacedByRightEdge() {
|
||||
return placedByRightEdge;
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.07.2016.
|
||||
*/
|
||||
public class ToolSlot {
|
||||
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
|
||||
public ToolSlot(ToolType toolType, boolean locked) {
|
||||
this.toolType = toolType;
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
|
||||
public int getDrawable() {
|
||||
if (locked)
|
||||
return R.drawable.tools_button_locked;
|
||||
else if (toolType != null)
|
||||
return toolType.getButtonDrawable();
|
||||
else
|
||||
return R.drawable.tools_button_empty;
|
||||
}
|
||||
|
||||
public void setToolType(ToolType toolType) {
|
||||
this.toolType = toolType;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.07.2016.
|
||||
*/
|
||||
public class ToolSlot {
|
||||
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
|
||||
public ToolSlot(ToolType toolType, boolean locked) {
|
||||
this.toolType = toolType;
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
|
||||
public int getDrawable() {
|
||||
if (locked)
|
||||
return R.drawable.tools_button_locked;
|
||||
else if (toolType != null)
|
||||
return toolType.getButtonDrawable();
|
||||
else
|
||||
return R.drawable.tools_button_empty;
|
||||
}
|
||||
|
||||
public void setToolType(ToolType toolType) {
|
||||
this.toolType = toolType;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
}
|
||||
|
@ -1,195 +1,195 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
|
||||
public enum ToolType {
|
||||
|
||||
//Check newInstance when new Tool is added!
|
||||
RAMP(R.string.tool_name_ramp, R.string.tool_description_ramp, R.drawable.tools_ramp,
|
||||
R.drawable.tools_ramp_button, 0, 1, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 3000, 1000)),
|
||||
SPRING(R.string.tool_name_spring, R.string.tool_description_spring, R.drawable.tools_spring,
|
||||
R.drawable.tools_spring_button, 5, 2, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 4000, 2000)),
|
||||
BOMB(R.string.tool_name_bomb, R.string.tool_description_bomb, R.drawable.tools_bomb,
|
||||
R.drawable.tools_bomb_button, 25, 4, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 5000, 2000),
|
||||
new ToolUpgrade(ToolUpgradeType.DURATION, 1200, 500)),
|
||||
MAGNET(R.string.tool_name_magnet, R.string.tool_description_magnet, R.drawable.tools_magnet,
|
||||
R.drawable.tools_magnet_button, 22, 2, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 5000, 3000),
|
||||
new ToolUpgrade(ToolUpgradeType.FORCE, 100, 500)),
|
||||
STASIS(R.string.tool_name_stasis, R.string.tool_description_stasis, R.drawable.tools_stasis,
|
||||
R.drawable.tools_stasis_button, 27, 4, 6,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 6000, 4000),
|
||||
new ToolUpgrade(ToolUpgradeType.FORCE, 1, 2),
|
||||
new ToolUpgrade(ToolUpgradeType.SIZE, 100, 200)),
|
||||
POWER_MUSHROOM(R.string.tool_name_power_mushroom, R.string.tool_description_power_mushroom,
|
||||
R.drawable.tools_power_mushroom, R.drawable.tools_power_mushroom_button, 50,
|
||||
5, 7, new ToolUpgrade(ToolUpgradeType.COOLDOWN, 15000, 11000),
|
||||
new ToolUpgrade(ToolUpgradeType.DURATION, 5000, 10000));
|
||||
|
||||
@StringRes
|
||||
private final int name;
|
||||
@StringRes
|
||||
private final int description;
|
||||
private final int toolTextureId;
|
||||
private final int buttonDrawable;
|
||||
private final int buyPrice;
|
||||
private final int upgradePrice;
|
||||
private final int maxUpgradeLevel;
|
||||
private final List<ToolUpgrade> upgrades;
|
||||
|
||||
private Texture toolTexture = null;
|
||||
private Texture toolButtonTexture = null;
|
||||
private boolean bought;
|
||||
private int currentUpgradeLevel = 1;
|
||||
|
||||
ToolType(@StringRes int name, @StringRes int description, int toolTextureId, int buttonDrawable, int buyPrice, int upgradePrice, int maxUpgradeLevel, ToolUpgrade... upgrades) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.toolTextureId = toolTextureId;
|
||||
this.buttonDrawable = buttonDrawable;
|
||||
this.buyPrice = buyPrice;
|
||||
this.upgradePrice = upgradePrice;
|
||||
this.maxUpgradeLevel = maxUpgradeLevel;
|
||||
this.upgrades = Arrays.asList(upgrades);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Tool newInstance(Vector position, ParticleSystem particleSystem, SoundManager soundManager) {
|
||||
Tool tool = null;
|
||||
switch (this) {
|
||||
case RAMP:
|
||||
tool = new Ramp(position);
|
||||
break;
|
||||
case SPRING:
|
||||
tool = new Spring(position, soundManager);
|
||||
break;
|
||||
case MAGNET:
|
||||
tool = new Magnet(position, particleSystem, soundManager);
|
||||
break;
|
||||
case BOMB:
|
||||
tool = new Bomb(position);
|
||||
break;
|
||||
case POWER_MUSHROOM:
|
||||
tool = new PowerMushroom(position, soundManager);
|
||||
break;
|
||||
case STASIS:
|
||||
tool = new Stasis(position, particleSystem, soundManager);
|
||||
break;
|
||||
}
|
||||
if (tool != null && tool.isPlacedByRightEdge())
|
||||
tool.move(new Vector(-tool.getWidth() / 2, 0));
|
||||
return tool;
|
||||
}
|
||||
|
||||
public static void loadAllToolTextures(TexturePack texturePack) {
|
||||
for (ToolType type : values()) {
|
||||
type.loadToolTexture(texturePack);
|
||||
type.loadToolButtonTexture(texturePack);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadToolTexture(TexturePack texturePack) {
|
||||
if (toolTextureId == -1)
|
||||
return;
|
||||
if (this != POWER_MUSHROOM)
|
||||
toolTexture = texturePack.loadAtlas(toolTextureId, 2, 2);
|
||||
else
|
||||
toolTexture = texturePack.loadTexture(toolTextureId);
|
||||
}
|
||||
|
||||
private void loadToolButtonTexture(TexturePack texturePack) {
|
||||
if (buttonDrawable == -1)
|
||||
return;
|
||||
toolButtonTexture = texturePack.loadTexture(buttonDrawable);
|
||||
}
|
||||
|
||||
public Texture getToolTexture() {
|
||||
return toolTexture;
|
||||
}
|
||||
|
||||
public Texture getToolButtonTexture() {
|
||||
return toolButtonTexture;
|
||||
}
|
||||
|
||||
public int getButtonDrawable() {
|
||||
return buttonDrawable;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setBought(boolean bought) {
|
||||
this.bought = bought;
|
||||
}
|
||||
|
||||
public boolean isBought() {
|
||||
if (this == RAMP)
|
||||
bought = true;
|
||||
return bought;
|
||||
}
|
||||
|
||||
public void upgrade() {
|
||||
currentUpgradeLevel++;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setBought(false);
|
||||
currentUpgradeLevel = 1;
|
||||
}
|
||||
|
||||
public int getBuyPrice() {
|
||||
return buyPrice;
|
||||
}
|
||||
|
||||
public int getUpgradePrice() {
|
||||
return upgradePrice + currentUpgradeLevel - 1;
|
||||
}
|
||||
|
||||
public int getCurrentUpgradeLevel() {
|
||||
return currentUpgradeLevel;
|
||||
}
|
||||
|
||||
public void setCurrentUpgradeLevel(int currentUpgradeLevel) {
|
||||
this.currentUpgradeLevel = currentUpgradeLevel;
|
||||
}
|
||||
|
||||
public float getCurrentUpgradeValue(ToolUpgradeType type) {
|
||||
for (ToolUpgrade upgrade : upgrades)
|
||||
if (upgrade.getType().equals(type))
|
||||
return upgrade.getValueAtLevel(currentUpgradeLevel, maxUpgradeLevel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean isAtMaxUpgradeLevel() {
|
||||
return currentUpgradeLevel == maxUpgradeLevel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.particles.ParticleSystem;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.sounds.SoundManager;
|
||||
|
||||
public enum ToolType {
|
||||
|
||||
//Check newInstance when new Tool is added!
|
||||
RAMP(R.string.tool_name_ramp, R.string.tool_description_ramp, R.drawable.tools_ramp,
|
||||
R.drawable.tools_ramp_button, 0, 1, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 3000, 1000)),
|
||||
SPRING(R.string.tool_name_spring, R.string.tool_description_spring, R.drawable.tools_spring,
|
||||
R.drawable.tools_spring_button, 5, 2, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 4000, 2000)),
|
||||
BOMB(R.string.tool_name_bomb, R.string.tool_description_bomb, R.drawable.tools_bomb,
|
||||
R.drawable.tools_bomb_button, 25, 4, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 5000, 2000),
|
||||
new ToolUpgrade(ToolUpgradeType.DURATION, 1200, 500)),
|
||||
MAGNET(R.string.tool_name_magnet, R.string.tool_description_magnet, R.drawable.tools_magnet,
|
||||
R.drawable.tools_magnet_button, 22, 2, 5,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 5000, 3000),
|
||||
new ToolUpgrade(ToolUpgradeType.FORCE, 100, 500)),
|
||||
STASIS(R.string.tool_name_stasis, R.string.tool_description_stasis, R.drawable.tools_stasis,
|
||||
R.drawable.tools_stasis_button, 27, 4, 6,
|
||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 6000, 4000),
|
||||
new ToolUpgrade(ToolUpgradeType.FORCE, 1, 2),
|
||||
new ToolUpgrade(ToolUpgradeType.SIZE, 100, 200)),
|
||||
POWER_MUSHROOM(R.string.tool_name_power_mushroom, R.string.tool_description_power_mushroom,
|
||||
R.drawable.tools_power_mushroom, R.drawable.tools_power_mushroom_button, 50,
|
||||
5, 7, new ToolUpgrade(ToolUpgradeType.COOLDOWN, 15000, 11000),
|
||||
new ToolUpgrade(ToolUpgradeType.DURATION, 5000, 10000));
|
||||
|
||||
@StringRes
|
||||
private final int name;
|
||||
@StringRes
|
||||
private final int description;
|
||||
private final int toolTextureId;
|
||||
private final int buttonDrawable;
|
||||
private final int buyPrice;
|
||||
private final int upgradePrice;
|
||||
private final int maxUpgradeLevel;
|
||||
private final List<ToolUpgrade> upgrades;
|
||||
|
||||
private Texture toolTexture = null;
|
||||
private Texture toolButtonTexture = null;
|
||||
private boolean bought;
|
||||
private int currentUpgradeLevel = 1;
|
||||
|
||||
ToolType(@StringRes int name, @StringRes int description, int toolTextureId, int buttonDrawable, int buyPrice, int upgradePrice, int maxUpgradeLevel, ToolUpgrade... upgrades) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.toolTextureId = toolTextureId;
|
||||
this.buttonDrawable = buttonDrawable;
|
||||
this.buyPrice = buyPrice;
|
||||
this.upgradePrice = upgradePrice;
|
||||
this.maxUpgradeLevel = maxUpgradeLevel;
|
||||
this.upgrades = Arrays.asList(upgrades);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Tool newInstance(Vector position, ParticleSystem particleSystem, SoundManager soundManager) {
|
||||
Tool tool = null;
|
||||
switch (this) {
|
||||
case RAMP:
|
||||
tool = new Ramp(position);
|
||||
break;
|
||||
case SPRING:
|
||||
tool = new Spring(position, soundManager);
|
||||
break;
|
||||
case MAGNET:
|
||||
tool = new Magnet(position, particleSystem, soundManager);
|
||||
break;
|
||||
case BOMB:
|
||||
tool = new Bomb(position);
|
||||
break;
|
||||
case POWER_MUSHROOM:
|
||||
tool = new PowerMushroom(position, soundManager);
|
||||
break;
|
||||
case STASIS:
|
||||
tool = new Stasis(position, particleSystem, soundManager);
|
||||
break;
|
||||
}
|
||||
if (tool != null && tool.isPlacedByRightEdge())
|
||||
tool.move(new Vector(-tool.getWidth() / 2, 0));
|
||||
return tool;
|
||||
}
|
||||
|
||||
public static void loadAllToolTextures(TexturePack texturePack) {
|
||||
for (ToolType type : values()) {
|
||||
type.loadToolTexture(texturePack);
|
||||
type.loadToolButtonTexture(texturePack);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadToolTexture(TexturePack texturePack) {
|
||||
if (toolTextureId == -1)
|
||||
return;
|
||||
if (this != POWER_MUSHROOM)
|
||||
toolTexture = texturePack.loadAtlas(toolTextureId, 2, 2);
|
||||
else
|
||||
toolTexture = texturePack.loadTexture(toolTextureId);
|
||||
}
|
||||
|
||||
private void loadToolButtonTexture(TexturePack texturePack) {
|
||||
if (buttonDrawable == -1)
|
||||
return;
|
||||
toolButtonTexture = texturePack.loadTexture(buttonDrawable);
|
||||
}
|
||||
|
||||
public Texture getToolTexture() {
|
||||
return toolTexture;
|
||||
}
|
||||
|
||||
public Texture getToolButtonTexture() {
|
||||
return toolButtonTexture;
|
||||
}
|
||||
|
||||
public int getButtonDrawable() {
|
||||
return buttonDrawable;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setBought(boolean bought) {
|
||||
this.bought = bought;
|
||||
}
|
||||
|
||||
public boolean isBought() {
|
||||
if (this == RAMP)
|
||||
bought = true;
|
||||
return bought;
|
||||
}
|
||||
|
||||
public void upgrade() {
|
||||
currentUpgradeLevel++;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setBought(false);
|
||||
currentUpgradeLevel = 1;
|
||||
}
|
||||
|
||||
public int getBuyPrice() {
|
||||
return buyPrice;
|
||||
}
|
||||
|
||||
public int getUpgradePrice() {
|
||||
return upgradePrice + currentUpgradeLevel - 1;
|
||||
}
|
||||
|
||||
public int getCurrentUpgradeLevel() {
|
||||
return currentUpgradeLevel;
|
||||
}
|
||||
|
||||
public void setCurrentUpgradeLevel(int currentUpgradeLevel) {
|
||||
this.currentUpgradeLevel = currentUpgradeLevel;
|
||||
}
|
||||
|
||||
public float getCurrentUpgradeValue(ToolUpgradeType type) {
|
||||
for (ToolUpgrade upgrade : upgrades)
|
||||
if (upgrade.getType().equals(type))
|
||||
return upgrade.getValueAtLevel(currentUpgradeLevel, maxUpgradeLevel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean isAtMaxUpgradeLevel() {
|
||||
return currentUpgradeLevel == maxUpgradeLevel;
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +1,34 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
/**
|
||||
* Created by Julian on 09.06.2017.
|
||||
*/
|
||||
|
||||
public class ToolUpgrade {
|
||||
|
||||
private ToolUpgradeType type;
|
||||
private float first, last;
|
||||
|
||||
public ToolUpgrade(ToolUpgradeType type, float first, float last) {
|
||||
this.type = type;
|
||||
this.first = first;
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public ToolUpgradeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public float getValueAtLevel(int level, int maxLevel) {
|
||||
float step = (last - first) / ((float) maxLevel - 1);
|
||||
return first + (level - 1) * step;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
/**
|
||||
* Created by Julian on 09.06.2017.
|
||||
*/
|
||||
|
||||
public class ToolUpgrade {
|
||||
|
||||
private ToolUpgradeType type;
|
||||
private float first, last;
|
||||
|
||||
public ToolUpgrade(ToolUpgradeType type, float first, float last) {
|
||||
this.type = type;
|
||||
this.first = first;
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public ToolUpgradeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public float getValueAtLevel(int level, int maxLevel) {
|
||||
float step = (last - first) / ((float) maxLevel - 1);
|
||||
return first + (level - 1) * step;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
/**
|
||||
* Created by Julian on 28.10.2017.
|
||||
*/
|
||||
|
||||
public enum ToolUpgradeType {
|
||||
|
||||
COOLDOWN, DURATION, FORCE, SIZE
|
||||
|
||||
}
|
||||
/*
|
||||
* Created by Julian Mutter on 7/10/18 3:58 PM
|
||||
* Copyright (c) 2018. All rights reserved.
|
||||
* Last modified 7/10/18 3:54 PM
|
||||
*
|
||||
*/
|
||||
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
/**
|
||||
* Created by Julian on 28.10.2017.
|
||||
*/
|
||||
|
||||
public enum ToolUpgradeType {
|
||||
|
||||
COOLDOWN, DURATION, FORCE, SIZE
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user