Changed path to de.frajul

This commit is contained in:
= 2017-05-25 13:51:15 +02:00
parent bf848cd46c
commit beb0a6e747
187 changed files with 12 additions and 18100 deletions

View File

@ -6,7 +6,7 @@ android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.julian.endlessroll"
applicationId 'de.frajul.endlessroll'
minSdkVersion 12
targetSdkVersion 23
versionCode 1

View File

@ -1,13 +0,0 @@
/**
* Automatically generated file. DO NOT MODIFY
*/
package com.example.julian.endlessroll.test;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.example.julian.endlessroll.test";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}

View File

@ -1,13 +0,0 @@
/**
* Automatically generated file. DO NOT MODIFY
*/
package com.example.julian.endlessroll;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.example.julian.endlessroll";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.julian.endlessroll.test">
package="de.frajul.endlessroll.test">
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="23" />
@ -9,8 +9,8 @@
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.julian.endlessroll"
android:targetPackage="de.frajul.endlessroll"
android:handleProfiling="false"
android:functionalTest="false"
android:label="Tests for com.example.julian.endlessroll"/>
android:label="Tests for de.frajul.endlessroll"/>
</manifest>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.julian.endlessroll"
package="de.frajul.endlessroll"
android:versionCode="1"
android:versionName="1.0" >
@ -19,7 +19,7 @@
android:supportsRtl="true" >
android:theme="@style/AppTheme">
<activity
android:name="com.example.julian.endlessroll.main.GameActivity"
android:name="de.frajul.endlessroll.main.GameActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="landscape" >
<intent-filter>

View File

@ -2,7 +2,7 @@
manifest
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:2:1-28:12
package
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:3:5-45
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:3:5-36
INJECTED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml
INJECTED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml
android:versionName
@ -31,7 +31,7 @@ MERGED from [com.android.support:support-v4:23.1.1] C:\Users\Julian\.android\bui
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:10:9-35
android:icon
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:11:9-43
activity#com.example.julian.endlessroll.main.GameActivity
activity#de.frajul.endlessroll.main.GameActivity
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:16:9-25:20
android:screenOrientation
ADDED from C:\Users\Julian\AndroidStudioProjects\EndlessRoll\app\src\main\AndroidManifest.xml:19:13-50

View File

@ -1,13 +0,0 @@
package com.example.julian.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);
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.julian.endlessroll">
package="de.frajul.endlessroll">
<uses-feature
android:glEsVersion="0x00020000"

View File

@ -1,69 +0,0 @@
package com.example.julian.endlessroll.data;
/**
* Created by Julian on 02.08.2016.
*/
public class Color {
private float r, g, b;
public Color() {
}
public Color(float r, float g, float b) {
this.r = r;
this.g = g;
this.b = b;
}
public Color(Color other) {
this.r = other.getR();
this.g = other.getG();
this.b = other.getB();
}
public Color mix(float leftValue, float rightValue, Color color2) {
Color mySelf = new Color(this);
Color second = new Color(color2);
mySelf.mul(leftValue);
second.mul(rightValue);
mySelf.add(second);
return mySelf;
}
private void mul(float a) {
r *= a;
g *= a;
b *= a;
}
private void add(Color 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;
}
}

View File

@ -1,147 +0,0 @@
package com.example.julian.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);
}
}

View File

@ -1,101 +0,0 @@
package com.example.julian.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 Vector set(float x, float y) {
this.x = x;
this.y = y;
return this;
}
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 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;
}
}

View File

@ -1,25 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.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());
}
}

View File

@ -1,51 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.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 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;
}
}

View File

@ -1,56 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.SynchronizedArrayList;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.textures.Texture;
/**
* Created by Julian on 20.07.2016.
*/
public class Background extends SynchronizedArrayList<Entity> {
private final float PART_WIDTH = 5;
private final float HALF_PART_WIDTH = PART_WIDTH / 2;
private final float HEIGHT = 2.5f;
private Texture texture;
public Background(Texture texture) {
this.texture = texture;
super.add(createPart(-HALF_PART_WIDTH));
}
public void changeTexture(Texture texture) {
this.texture = texture;
synchronized (this) {
for (Entity entity : this)
entity.setTexture(texture);
}
}
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 x, float cameraX) {
Vector movement = new Vector(x, 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));
}
}

View File

@ -1,39 +0,0 @@
package com.example.julian.endlessroll.entities;
import android.support.annotation.Nullable;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.particles.ParticleEffect;
import com.example.julian.endlessroll.entities.particles.ParticleSource;
import com.example.julian.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;
}
}
}

View File

@ -1,16 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.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);
}
}

View File

@ -1,104 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.collision.geometry.Quad;
import com.example.julian.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;
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;
}
}

View File

@ -1,16 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.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));
}
}

View File

@ -1,93 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.levels.MoveComponent;
import com.example.julian.endlessroll.levels.ObstacleData;
import com.example.julian.endlessroll.levels.worlds.World;
import java.util.Random;
/**
* Created by Julian on 20.11.2015.
*/
public class Obstacle extends Entity {
private boolean deadly;
private boolean floating;
private boolean moving;
private MoveComponent moveComponent;
private Vertex zeroPoint;
private boolean clockwise;
private float totalMoveDistance;
private float moveProgress;
public Obstacle(World world, ObstacleData data, float terrainEdge) {
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 (moveComponent != null)
moveComponent.shrink(new Vector(super.getWidth(), super.getHeight()));
if (!floating)
super.setToTerrain(terrainEdge);
setTextureAtlasIndex();
if (moving)
randomMovementData();
}
public void moveWithMoveComponent(float value) {
float distance = value * moveComponent.getSpeed() * 0.001f;
moveProgress += distance / totalMoveDistance;
moveProgress %= 1.0f;
setPositionForMoveProgress();
}
private void setPositionForMoveProgress() {
float distance = 0;
Vertex lastVertex = zeroPoint;
while (true) {
Vertex nextVertex = lastVertex.getNext(clockwise);
float nextDistance = distance + (Math.abs(lastVertex.getX() - nextVertex.getX()) * 0.5f * moveComponent.getWidth()) + (Math.abs(lastVertex.getY() - nextVertex.getY()) * 0.5f * moveComponent.getHeight());
if (nextDistance >= moveProgress * totalMoveDistance) {
float distanceLeft = moveProgress * totalMoveDistance - distance;
Vector direction = new Vector(nextVertex.getX(), nextVertex.getY()).translate(new Vector(lastVertex.getX(), lastVertex.getY()).negate());
direction = direction.mul(0.5f * distanceLeft);
super.setPosition(moveComponent.getPositionOfVertex(lastVertex).translate(direction));
return;
}
distance = nextDistance;
lastVertex = nextVertex;
}
}
private void randomMovementData() {
Random random = new Random();
int index = random.nextInt(4);
zeroPoint = Vertex.values()[index];
clockwise = random.nextBoolean();
totalMoveDistance = moveComponent.getWidth() * 2 + moveComponent.getHeight() * 2;
}
private void setTextureAtlasIndex() {
if (deadly)
super.setTextureAtlasIndex(2);
if (floating)
super.setTextureAtlasIndex(0);
if (deadly && floating)
super.setTextureAtlasIndex(1);
if (!deadly && !floating)
super.setTextureAtlasIndex(3);
}
public boolean isMoving() {
return moving;
}
public boolean isDeadly() {
return deadly;
}
}

View File

@ -1,54 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.endlessroll.main.GameLog;
/**
* Created by Julian on 20.11.2015.
*/
public class Player extends Entity {
private final float ROTATION_SPEED = -400;
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;
public Player(Texture texture) {
super(texture, new Vector(), 0, 0);
super.setWidth(RADIUS * 2);
super.setHeight(RADIUS * 2);
}
public void init(float terrainEdge, float startSpeed, float endSpeed) {
GameLog.i("init: " + startSpeed + "; " + endSpeed);
super.setToTerrain(terrainEdge);
super.getPosition().x = START_X;
super.setMovement(new Vector(speed, 0));
this.startSpeed = startSpeed;
this.endSpeed = endSpeed;
setSpeedByProgress(0);
}
public void setSpeedByProgress(float progress) {
this.speed = ((endSpeed - startSpeed) * progress + startSpeed) * SPEED;
super.getMovement().x = speed;
}
public float getProgress() {
return getPosition().x - START_X;
}
public float getSpeed() {
return speed;
}
@Override
public void move(Vector movement) {
super.move(movement);
rotate(movement.x * ROTATION_SPEED);
}
}

View File

@ -1,20 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.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;
}
}

View File

@ -1,44 +0,0 @@
package com.example.julian.endlessroll.entities;
import com.example.julian.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;
}
}

View File

@ -1,78 +0,0 @@
package com.example.julian.endlessroll.entities.collision;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.collision.geometry.Circle;
import com.example.julian.endlessroll.entities.collision.geometry.Triangle;
/**
* Created by Julian on 28.02.2016.
*/
public class CircleTriangleCollisionDetector {
public boolean circleTriangleCollision(Circle circle, Triangle triangle) {
if (circleIntersectingWithTriangleVertices(circle, triangle))
return true;
if (circleCenterInsideTriangle(circle, triangle))
return true;
if (circleIntersectingWithTriangleEdges(circle, triangle))
return true;
return false;
}
private boolean circleIntersectingWithTriangleEdges(Circle circle, Triangle triangle) {
Vector edge1 = triangle.getVertex1().vectorTo(triangle.getVertex2());
Vector edge2 = triangle.getVertex2().vectorTo(triangle.getVertex3());
Vector edge3 = triangle.getVertex3().vectorTo(triangle.getVertex1());
boolean intersectingWithEdge1 = circleIntersectingWithTriangleEdge(circle, triangle.getVertex1(), edge1);
boolean intersectingWithEdge2 = circleIntersectingWithTriangleEdge(circle, triangle.getVertex2(), edge2);
boolean intersectingWithEdge3 = circleIntersectingWithTriangleEdge(circle, triangle.getVertex3(), edge3);
return intersectingWithEdge1 || intersectingWithEdge2 || intersectingWithEdge3;
}
private boolean circleIntersectingWithTriangleEdge(Circle circle, Vector vertex, Vector edge) {
Vector vertexToCenter = vertex.vectorTo(circle.getCenter());
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)
if (Math.sqrt(vertexToCenter.x * vertexToCenter.x + vertexToCenter.y * vertexToCenter.y - k * k) <= circle.getRadius())
return true;
}
return false;
}
private boolean circleCenterInsideTriangle(Circle circle, Triangle triangle) {
Vector vertex1To2 = triangle.getVertex1().vectorTo(triangle.getVertex2());
Vector vertex2To3 = triangle.getVertex2().vectorTo(triangle.getVertex3());
Vector vertex3To1 = triangle.getVertex3().vectorTo(triangle.getVertex1());
Vector vertex1ToCenter = triangle.getVertex1().vectorTo(circle.getCenter());
Vector vertex2ToCenter = triangle.getVertex2().vectorTo(circle.getCenter());
Vector vertex3ToCenter = triangle.getVertex3().vectorTo(circle.getCenter());
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.getVertex1());
boolean intersectingWithVertex2 = circleIntersectingWithTriangleVertex(circle, triangle.getVertex2());
boolean intersectingWithVertex3 = circleIntersectingWithTriangleVertex(circle, triangle.getVertex3());
return intersectingWithVertex1 || intersectingWithVertex2 || intersectingWithVertex3;
}
private boolean circleIntersectingWithTriangleVertex(Circle circle, Vector vertex) {
Vector centerToVertex = circle.getCenter().vectorTo(vertex);
return centerToVertex.length() <= circle.getRadius();
}
}

View File

@ -1,126 +0,0 @@
package com.example.julian.endlessroll.entities.collision;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.collision.collisionData.EntityCollisionData;
import com.example.julian.endlessroll.entities.collision.geometry.Circle;
import com.example.julian.endlessroll.entities.collision.geometry.Geometry;
import com.example.julian.endlessroll.entities.collision.geometry.Quad;
import com.example.julian.endlessroll.entities.collision.geometry.Triangle;
/**
* Created by Julian on 01.12.2015.
*/
public class CollisionDetector {
private CircleTriangleCollisionDetector triangleDetector;
public CollisionDetector() {
triangleDetector = new CircleTriangleCollisionDetector();
}
public boolean quadQuadCollision(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;
if (yDistance >= q1.getHeight() / 2 + q2.getHeight() / 2)
return false;
return true;
}
public EntityCollisionData playerEntityCollision(Player player, Entity entity) {
Circle circle = new Circle(player);
Quad quad = entity;
if (circleQuadCollision(circle, quad)) {
Edge edge = circleQuadCollisionEdge(circle, player.getMovement(), quad, entity.getMovement());
return new EntityCollisionData(entity, edge);
}
return new EntityCollisionData(null, null);
}
public boolean circleToolCollision(Circle circle, Geometry bounds) {
if (bounds instanceof Circle)
return circleCircleCollision(circle, (Circle) bounds);
else if (bounds instanceof Quad)
return circleQuadCollision(circle, (Quad) bounds);
else if (bounds instanceof Triangle)
return triangleDetector.circleTriangleCollision(circle, (Triangle) bounds);
return false;
}
private boolean circleCircleCollision(Circle c1, Circle c2) {
float distance = Math.abs(c1.getCenter().vectorTo(c2.getCenter()).length());
float radiusSum = c1.getRadius() + c2.getRadius();
return distance < radiusSum;
}
private boolean circleQuadCollision(Circle circle, Quad quad) {
Vector distance = circle.getCenter().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();
}
private Edge circleQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
Vector relativeMovement = circleMovement.translate(quadMovement);
//LEFT || TOP || BOTTOM
if (relativeMovement.x > 0) {
//LEFT || BOTTOM
if (relativeMovement.y > 0) {
float toLeftDistance = quad.getLeftEdge() - circle.getCenter().x;
float actualY = toLeftDistance * (relativeMovement.y / relativeMovement.x) + circle.getCenter().y;
if (actualY < quad.getBottomEdge())
return Edge.BOTTOM;
else
return Edge.LEFT;
}
//LEFT || TOP
else if (relativeMovement.y < 0) {
float toLeftDistance = quad.getLeftEdge() - circle.getCenter().x;
float actualY = toLeftDistance * (relativeMovement.y / relativeMovement.x) + circle.getCenter().y;
if (actualY < quad.getTopEdge())
return Edge.LEFT;
else
return Edge.TOP;
} else return Edge.LEFT;
}
//RIGHT || TOP || BOTTOM
else if (relativeMovement.x < 0) {
//RIGHT || BOTTOM
if (relativeMovement.y > 0) {
float toRightDistance = quad.getRightEdge() - circle.getCenter().x;
float actualY = toRightDistance * (relativeMovement.y / relativeMovement.x) + circle.getCenter().y;
if (actualY < quad.getBottomEdge())
return Edge.BOTTOM;
else
return Edge.RIGHT;
}
//RIGHT || TOP
else if (relativeMovement.y < 0) {
float toRightDistance = quad.getRightEdge() - circle.getCenter().x;
float actualY = toRightDistance * (relativeMovement.y / relativeMovement.x) + circle.getCenter().y;
if (actualY < quad.getTopEdge())
return Edge.RIGHT;
else
return Edge.TOP;
} else return Edge.RIGHT;
} else {
if (relativeMovement.y > 0)
return Edge.BOTTOM;
else if (relativeMovement.y < 0)
return Edge.TOP;
}
return Edge.NONE;
}
}

View File

@ -1,92 +0,0 @@
package com.example.julian.endlessroll.entities.collision;
import com.example.julian.endlessroll.entities.Energy;
import com.example.julian.endlessroll.entities.Obstacle;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.Star;
import com.example.julian.endlessroll.entities.collision.collisionData.EntityCollisionData;
import com.example.julian.endlessroll.entities.collision.collisionData.ObstacleCollisionData;
import com.example.julian.endlessroll.entities.collision.collisionData.PlayerCollisionData;
import com.example.julian.endlessroll.entities.collision.collisionData.ToolCollisionData;
import com.example.julian.endlessroll.entities.tools.Tool;
import com.example.julian.endlessroll.main.game.Game;
import com.example.julian.endlessroll.main.game.GameScene;
import com.example.julian.endlessroll.main.game.Physics;
/**
* Created by Julian on 02.01.2016.
*/
public class CollisionManager {
private Game game;
private Player player;
public CollisionManager(Game game) {
this.game = game;
}
//Check Obstacle always before tool
public void update(Physics physics, GameScene scene) {
this.player = scene.getPlayer();
PlayerCollisionData data = physics.getPlayerCollisionData(scene);
if (data.isTerrainCollision())
checkTerrainCollision(data.getTerrainCollisionData());
if (data.isCeilingCollision())
checkCeilingCollision(data.getCeilingCollisionData());
if (data.isObstacleCollision())
checkObstacleCollision(data.getObstacleCollisionData());
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, -0.01f);
if (data.getEdge() != Edge.TOP)
game.onGameOver(true);
}
private void checkCeilingCollision(EntityCollisionData data) {
checkEntityCollision(data, -0.01f);
if (data.getEdge() == Edge.RIGHT || data.getEdge() == Edge.LEFT)
game.onGameOver(true);
}
private void checkToolCollision(ToolCollisionData data) {
for (Tool tool : data.getTools())
tool.onPlayerCollision(player);
}
private void checkObstacleCollision(ObstacleCollisionData data) {
for (EntityCollisionData entityData : data.getCollisions()) {
checkEntityCollision(entityData, 0);
if (entityData.getEdge() != Edge.TOP || ((Obstacle) entityData.getEntity()).isDeadly())
game.onGameOver(true);
}
}
private void checkEntityCollision(EntityCollisionData data, float xBounceFactor) {
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.getMovement().x *= xBounceFactor;
player.getPosition().x = data.getEntity().getLeftEdge() - player.RADIUS;
break;
case RIGHT:
player.getMovement().x *= xBounceFactor;
player.getPosition().x = data.getEntity().getRightEdge() + player.RADIUS;
break;
}
}
}

View File

@ -1,5 +0,0 @@
package com.example.julian.endlessroll.entities.collision;
public enum Edge {
LEFT, RIGHT, TOP, BOTTOM, NONE;
}

View File

@ -1,30 +0,0 @@
package com.example.julian.endlessroll.entities.collision.collisionData;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.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;
}
}

View File

@ -1,23 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,71 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,25 +0,0 @@
package com.example.julian.endlessroll.entities.collision.collisionData;
import com.example.julian.endlessroll.entities.tools.Tool;
import java.util.List;
/**
* 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;
}
}

View File

@ -1,38 +0,0 @@
package com.example.julian.endlessroll.entities.collision.geometry;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Player;
/**
* Created by Julian on 01.12.2015.
*/
public class Circle implements 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;
}
public Vector getCenter() {
return center;
}
public void setCenter(Vector center) {
this.center = center;
}
public float getRadius() {
return radius;
}
public void setRadius(float radius) {
this.radius = radius;
}
}

View File

@ -1,7 +0,0 @@
package com.example.julian.endlessroll.entities.collision.geometry;
/**
* Created by Julian on 28.02.2016.
*/
public interface Geometry {
}

View File

@ -1,74 +0,0 @@
package com.example.julian.endlessroll.entities.collision.geometry;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.collision.Edge;
/**
* Created by Julian on 01.12.2015.
*/
public class Quad implements 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;
}
public float getRightEdge() {
return position.x + width / 2;
}
public float getLeftEdge() {
return position.x - width / 2;
}
public float getTopEdge() {
return position.y + height / 2;
}
public float getBottomEdge() {
return position.y - height / 2;
}
public float getEdge(Edge edge) {
switch (edge) {
case LEFT:
return getLeftEdge();
case RIGHT:
return getRightEdge();
case TOP:
return getTopEdge();
case BOTTOM:
return getBottomEdge();
}
return -1;
}
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;
}
}

View File

@ -1,51 +0,0 @@
package com.example.julian.endlessroll.entities.collision.geometry;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.tools.Ramp;
/**
* Created by Julian on 01.12.2015.
*/
public class Triangle implements Geometry {
private Vector vertex1, vertex2, vertex3;
public Triangle(Ramp ramp) {
Vector vertex1 = new Vector(ramp.getRightEdge(), ramp.getBottomEdge());
Vector vertex2 = new Vector(ramp.getRightEdge(), ramp.getTopEdge());
Vector vertex3 = new Vector(ramp.getLeftEdge(), ramp.getBottomEdge());
setVertex1(vertex1);
setVertex2(vertex2);
setVertex3(vertex3);
}
public Triangle(Vector vertex1, Vector vertex2, Vector vertex3) {
this.vertex1 = vertex1;
this.vertex2 = vertex2;
this.vertex3 = vertex3;
}
public Vector getVertex1() {
return vertex1;
}
public void setVertex1(Vector vertex1) {
this.vertex1 = vertex1;
}
public Vector getVertex2() {
return vertex2;
}
public void setVertex2(Vector vertex2) {
this.vertex2 = vertex2;
}
public Vector getVertex3() {
return vertex3;
}
public void setVertex3(Vector vertex3) {
this.vertex3 = vertex3;
}
}

View File

@ -1,98 +0,0 @@
package com.example.julian.endlessroll.entities.particles;
import com.example.julian.endlessroll.data.Color;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Range;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Timeline;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
import com.example.julian.endlessroll.main.game.Timer;
import java.util.Random;
/**
* Created by Julian on 02.08.2016.
*/
public class Particle extends Entity {
private Color 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;
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();
}
public void update(Timer timer, float windStrength, float gravityStrength) {
if (active) {
passedLifetime += timer.getFrameTimeSeconds();
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)), windStrength, gravityStrength);
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(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
}

View File

@ -1,58 +0,0 @@
package com.example.julian.endlessroll.entities.particles;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Range;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Timeline;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
import com.example.julian.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;
public ParticleData(Range life, TimelineRange scaleTR, TimelineRange velocityTR, TimelineRange angleTR, TimelineRange rotationTR, Timeline transparencyT, TintTimeline tint) {
this.life = life;
this.scaleTR = scaleTR;
this.velocityTR = velocityTR;
this.angleTR = angleTR;
this.rotationTR = rotationTR;
this.transparencyT = transparencyT;
this.tint = tint;
}
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;
}
}

View File

@ -1,229 +0,0 @@
package com.example.julian.endlessroll.entities.particles;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Options;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Range;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Timeline;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.endlessroll.main.game.Timer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* 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;
//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 TimelineRange wind;
private TimelineRange gravity;
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);
}
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;
}
}

View File

@ -1,163 +0,0 @@
package com.example.julian.endlessroll.entities.particles;
import android.content.Context;
import com.example.julian.endlessroll.entities.particles.attributes.Attribute;
import com.example.julian.endlessroll.entities.particles.attributes.AttributeValueReader;
import com.example.julian.endlessroll.entities.particles.attributes.ParticleAttributeType;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.ImagePath;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Options;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Range;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Timeline;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.TimelineRange;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.TintTimeline;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* 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;
}
}

View File

@ -1,163 +0,0 @@
package com.example.julian.endlessroll.entities.particles;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
import com.example.julian.endlessroll.main.game.Timer;
import com.example.julian.endlessroll.rendering.Lock;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
/**
* Created by Julian on 02.08.2016.
*/
public class ParticleSource {
private Vector position;
private ParticleEffect effect;
private Random random;
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 float windStrength;
private float gravityStrength;
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;
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.getFrameTimeSeconds();
lifePercent = passedTime / maxTime;
if (passedTime >= currentDelay) {
passedEmittPause += timer.getFrameTimeSeconds();
calcWindAndGravity();
while (passedEmittPause >= emittPause) {
passedEmittPause -= emittPause;
emitt();
}
passedSecond += timer.getFrameTimeSeconds();
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, windStrength, gravityStrength);
if (!particle.isActive()) {
inactiveParticles.add(particle);
iter.remove();
} else {
particle.move(new Vector(particle.getMovement()).mul(timer.getFrameTimeSeconds() / 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) {
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 Particle 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();
return particle;
}
private void calcWindAndGravity() {
windStrength = effect.getWind().getRange().createValue(random, effect.getWind().getTimeline().getValueAtTime(lifePercent));
gravityStrength = effect.getGravity().getRange().createValue(random, effect.getGravity().getTimeline().getValueAtTime(lifePercent));
}
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;
}
}

View File

@ -1,58 +0,0 @@
package com.example.julian.endlessroll.entities.particles;
import android.content.Context;
import com.example.julian.endlessroll.entities.textures.TextureLoader;
import com.example.julian.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 explosion;
public final ParticleEffect magnet;
public final ParticleEffect starCollect;
public final ParticleEffect energyCollect;
private ParticleEffect[] effects;
private TextureLoader textureLoader;
public ParticleSystem(Context context) throws Exception {
this.textureLoader = new TextureLoader(context);
ParticleReader reader = new ParticleReader(context);
explosion = reader.read("particleEffects/explosion.pe");
magnet = reader.read("particleEffects/magnet.pe");
starCollect = reader.read("particleEffects/collectStar.pe");
energyCollect = reader.read("particleEffects/collectEnergy.pe");
effects = new ParticleEffect[]{explosion, magnet, starCollect, energyCollect};
}
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;
}
}

View File

@ -1,33 +0,0 @@
package com.example.julian.endlessroll.entities.particles.attributes;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValue;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
import java.util.ArrayList;
import java.util.List;
/**
* 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;
}
}

View File

@ -1,77 +0,0 @@
package com.example.julian.endlessroll.entities.particles.attributes;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.ImagePath;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Options;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.ParticleAttributeValueType;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Range;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.SpawnShape;
import com.example.julian.endlessroll.entities.particles.attributes.attributeValues.Timeline;
import com.example.julian.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) throws Exception {
String asString = line.split(start)[1].split(":")[0];
return Integer.parseInt(asString);
}
private float parseFloat(String line) throws Exception {
String asString = line.split(" ")[1];
return Float.parseFloat(asString);
}
private String parseString(String line) throws Exception {
return line.split(" ")[1];
}
private boolean parseBoolean(String line) throws Exception {
String asString = line.split(" ")[1];
return Boolean.parseBoolean(asString);
}
}

View File

@ -1,55 +0,0 @@
package com.example.julian.endlessroll.entities.particles.attributes;
import com.example.julian.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);
}
}

View File

@ -1,21 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,66 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,17 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,28 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,82 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,38 +0,0 @@
package com.example.julian.endlessroll.entities.particles.attributes.attributeValues;
/**
* Created by Julian on 02.08.2016.
*/
public class SpawnShape extends ParticleAttributeValue {
public enum Shape {
POINT("point"), SQUARE("square");
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("Shape 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;
}
}

View File

@ -1,52 +0,0 @@
package com.example.julian.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 = 1 - Math.abs(left.getTime() - time);
float rightDist = 1 - Math.abs(right.getTime() - time);
float totalDist = leftDist + rightDist;
return left.getValue() * (leftDist / totalDist) + right.getValue() * (rightDist / totalDist);
}
return left.getValue();
}
return 0;
}
}

View File

@ -1,23 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,31 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,54 +0,0 @@
package com.example.julian.endlessroll.entities.particles.attributes.attributeValues;
import com.example.julian.endlessroll.data.Color;
import java.util.ArrayList;
import java.util.List;
/**
* 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 Color 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 = 1 - Math.abs(left.getTime() - time);
float rightDist = 1 - Math.abs(right.getTime() - time);
float totalDist = leftDist + rightDist;
return left.getColor().mix((leftDist / totalDist), (rightDist / totalDist), right.getColor());
}
return left.getColor();
}
return new Color();
}
}

View File

@ -1,33 +0,0 @@
package com.example.julian.endlessroll.entities.particles.attributes.attributeValues;
import com.example.julian.endlessroll.data.Color;
public class TintTimelinePoint {
private float time;
private Color color;
public float getTime() {
return time;
}
public void setTime(float time) {
this.time = time;
}
public Color getColor() {
return color;
}
public void setValue(int colorIndex, float value) {
if (color == null)
color = new Color();
if (colorIndex == 0)
color.setR(value);
else if (colorIndex == 1)
color.setG(value);
else if (colorIndex == 2)
color.setB(value);
}
}

View File

@ -1,36 +0,0 @@
package com.example.julian.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;
}
}

View File

@ -1,62 +0,0 @@
package com.example.julian.endlessroll.entities.textures;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLES20;
import android.opengl.GLUtils;
import com.example.julian.endlessroll.main.GameLog;
import java.io.InputStream;
/**
* 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);
if (!isAtlas) {
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_LINEAR);
} else {
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_LINEAR);
}
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];
}
}

View File

@ -1,45 +0,0 @@
package com.example.julian.endlessroll.entities.textures;
import android.content.Context;
import android.support.annotation.DrawableRes;
import com.example.julian.endlessroll.R;
import com.example.julian.endlessroll.entities.tools.ToolType;
import com.example.julian.endlessroll.levels.worlds.World;
/**
* Created by Julian on 05.12.2015.
*/
public class TexturePack {
private TextureLoader loader;
public final Texture goal;
public final Texture playerArrow;
public final Texture player;
public final Texture star;
public final Texture energy;
public TexturePack(Context context) {
loader = new TextureLoader(context);
goal = loadTexture(R.drawable.goal);
player = loadTexture(R.drawable.playershapes_ball);
playerArrow = loadTexture(R.drawable.guis_playerarrow);
star = loadTexture(R.drawable.currency_star);
energy = loadAtlas(R.drawable.currency_energy_atlas, 2, 2);
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);
}
}

View File

@ -1,12 +0,0 @@
package com.example.julian.endlessroll.entities.tileLists;
import com.example.julian.endlessroll.entities.textures.Texture;
@SuppressWarnings("serial")
public class Ceiling extends TileList {
public Ceiling(Texture texture) {
super(Type.CEILING, texture);
}
}

View File

@ -1,12 +0,0 @@
package com.example.julian.endlessroll.entities.tileLists;
import com.example.julian.endlessroll.entities.textures.Texture;
@SuppressWarnings("serial")
public class Terrain extends TileList {
public Terrain(Texture texture) {
super(TileList.Type.TERRAIN, texture);
}
}

View File

@ -1,32 +0,0 @@
package com.example.julian.endlessroll.entities.tileLists;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.endlessroll.levels.TileData;
/**
* Created by Julian on 18.12.2015.
*/
public class Tile extends Entity {
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;
}
}
}

View File

@ -1,79 +0,0 @@
package com.example.julian.endlessroll.entities.tileLists;
import com.example.julian.endlessroll.data.SynchronizedArrayList;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.endlessroll.levels.TileData;
import com.example.julian.endlessroll.levels.worlds.World;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("serial")
public class TileList extends SynchronizedArrayList<Tile> {
public enum Type {
TERRAIN, CEILING;
public float calculateTileHeightFromEdge(float edge) {
switch (this) {
case TERRAIN:
return 1 + edge;
case CEILING:
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();
for (TileData data : tileData)
super.add(new Tile(type, texture, edge, data));
this.edge = edge;
if (edge >= 1 || edge <= -1)
super.clear();
}
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;
}
}

View File

@ -1,60 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.DestroyEffect;
import com.example.julian.endlessroll.entities.Obstacle;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.collision.CollisionDetector;
import com.example.julian.endlessroll.entities.collision.geometry.Geometry;
import com.example.julian.endlessroll.entities.collision.geometry.Quad;
import com.example.julian.endlessroll.main.game.Timer;
import java.util.List;
/**
* Created by Julian on 20.02.2016.
*/
public class Bomb extends Tool {
public final float RANGE = 1;
private float delta;
private boolean exploding = false;
public Bomb(Vector position) {
super(ToolType.BOMB, position, .29f, .29f, false, false);
animation.setIndexSequence(new int[]{0, 1, 2});
animation.setLooping(false);
animation.setRequiredDelta(300);
}
@Override
public void update(Timer timer) {
super.update(timer);
delta += timer.getFrameTimeSeconds();
if (delta >= 1000)
exploding = true;
}
@Override
public void onPlayerCollision(Player player) {
}
@Override
protected Geometry createCollisionBounds() {
return this;
}
public boolean isExploding() {
return exploding;
}
public void explode(List<Obstacle> obstacles, CollisionDetector detector) {
Quad explotionRange = new Quad(new Vector(super.getPosition()), RANGE, RANGE);
for (Obstacle obstacle : obstacles) {
if (detector.quadQuadCollision(obstacle, explotionRange))
obstacle.destroy(DestroyEffect.EXPLOSION);
}
super.destroy(DestroyEffect.EXPLOSION);
}
}

View File

@ -1,52 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.DestroyEffect;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.collision.geometry.Circle;
import com.example.julian.endlessroll.entities.collision.geometry.Geometry;
import com.example.julian.endlessroll.entities.particles.ParticleSource;
import com.example.julian.endlessroll.entities.particles.ParticleSystem;
import com.example.julian.endlessroll.main.game.Timer;
/**
* Created by Julian on 11.02.2016.
*/
public class Magnet extends Tool {
private ParticleSource particleSource;
public Magnet(Vector position, ParticleSystem particleSystem) {
super(ToolType.MAGNET, position, .24f, .24f, false, false);
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();
}
@Override
public void destroy(DestroyEffect destroyEffect) {
super.destroy(destroyEffect);
particleSource.kill();
}
@Override
public void onPlayerCollision(Player player) {
float fromPlayerDistance = player.getPosition().vectorTo(super.getPosition()).length();
float fromPlayerYDistance = super.getPosition().y - player.getPosition().y;
float t = Math.min(2f, 1 / fromPlayerDistance);
float influenz = .00004f * t * t;
if (fromPlayerYDistance < 0) {
player.getMovement().y -= influenz;
} else if (fromPlayerYDistance > 0) {
player.getMovement().y += influenz;
}
}
@Override
protected Geometry createCollisionBounds() {
return new Circle(super.getPosition(), 2);
}
}

View File

@ -1,56 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.collision.geometry.Geometry;
import com.example.julian.endlessroll.entities.collision.geometry.Triangle;
import com.example.julian.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) {
float necessaryY = calcNecessaryPlayerY(player);
player.getPosition().y = necessaryY;
float acceleration = player.getMovement().x * getGradient();
player.getMovement().y = 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 createCollisionBounds() {
return new Triangle(this);
}
}

View File

@ -1,40 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.collision.geometry.Geometry;
import com.example.julian.endlessroll.entities.collision.geometry.Quad;
import com.example.julian.endlessroll.main.game.Timer;
/**
* Created by Julian on 04.01.2016.
*/
public class Spring extends Tool {
private boolean hasYetCollided = false;
public Spring(Vector position) {
super(ToolType.SPRING, position, .3f, .35f, true, true);
animation.setIndexSequence(new int[]{1, 0, 0, 3, 3, 3, 1});
animation.setRequiredDelta(80);
}
@Override
public void update(Timer timer) {
if (hasYetCollided)
super.update(timer);
}
@Override
public void onPlayerCollision(Player player) {
if (!hasYetCollided) {
hasYetCollided = true;
player.getMovement().y = .0022f;
}
}
@Override
protected Geometry createCollisionBounds() {
return new Quad(super.getPosition(), .2f, .2f);
}
}

View File

@ -1,49 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.AnimatedEntity;
import com.example.julian.endlessroll.entities.Animation;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.collision.geometry.Geometry;
import com.example.julian.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 collisionBounds;
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;
collisionBounds = createCollisionBounds();
}
public abstract void onPlayerCollision(Player player);
protected abstract Geometry createCollisionBounds();
public Geometry getCollisionBounds() {
if (updateBounds)
return createCollisionBounds();
return collisionBounds;
}
public void setFloating(boolean floating) {
this.floating = floating;
}
public boolean isFloating() {
return floating;
}
public boolean isPlacedByRightEdge() {
return placedByRightEdge;
}
}

View File

@ -1,40 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import com.example.julian.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_lockedbutton;
else
return toolType.getButtonDrawable();
}
public void setToolType(ToolType toolType) {
this.toolType = toolType;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
}

View File

@ -1,117 +0,0 @@
package com.example.julian.endlessroll.entities.tools;
import android.support.annotation.Nullable;
import com.example.julian.endlessroll.R;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.particles.ParticleSystem;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.endlessroll.entities.textures.TexturePack;
import com.example.julian.endlessroll.sounds.SoundManager;
public enum ToolType {
//Check newInstance when new Tool is added!
RAMP("Ramp", R.drawable.ramp, R.drawable.rampbutton, R.raw.ramp, 3f, 0),
SPRING("Spring", R.drawable.tools_spring, R.drawable.tools_springbutton, R.raw.ramp, 4f, 5),
MAGNET("Magnet", R.drawable.tools_magnet, R.drawable.tools_magnetbutton, R.raw.ramp, 6f, 10),
BOMB("Bomb", R.drawable.tools_bomb, R.drawable.tools_bombbutton, R.raw.ramp, 6f, 12),
NONE("None", -1, R.drawable.tools_emptybutton, -1, 0, 0);
private String name;
private int toolTextureId;
private Texture toolTexture = null;
private int buttonDrawable;
private int placingSoundId;
private int placingSound = -1;
private float regenerationTime;
private int costs;
private boolean bought = false;
ToolType(String name, int toolTextureId, int buttonDrawable, int placingSoundId, float regenerationTime, int costs) {
this.name = name;
this.toolTextureId = toolTextureId;
this.buttonDrawable = buttonDrawable;
this.placingSoundId = placingSoundId;
this.regenerationTime = regenerationTime;
this.costs = costs;
}
@Nullable
public Tool newInstance(Vector position, ParticleSystem particleSystem) {
Tool tool = null;
switch (this) {
case RAMP:
tool = new Ramp(position);
break;
case SPRING:
tool = new Spring(position);
break;
case MAGNET:
tool = new Magnet(position, particleSystem);
break;
case BOMB:
tool = new Bomb(position);
break;
case NONE:
break;
}
if (tool != null && tool.isPlacedByRightEdge())
tool.move(new Vector(-tool.getWidth() / 2, 0));
return tool;
}
public void loadAllPlacingSounds(SoundManager soundManager) {
for (ToolType type : values())
type.loadPlacingSound(soundManager);
}
public static void loadAllToolTextures(TexturePack texturePack) {
for (ToolType type : values())
type.loadToolTexture(texturePack);
}
private void loadPlacingSound(SoundManager soundManager) {
if (placingSoundId == -1)
return;
placingSound = soundManager.loadSound(placingSoundId);
}
private void loadToolTexture(TexturePack texturePack) {
if (toolTextureId == -1)
return;
toolTexture = texturePack.loadAtlas(toolTextureId, 2, 2);
}
public Texture getToolTexture() {
return toolTexture;
}
public int getButtonDrawable() {
return buttonDrawable;
}
public int getPlacingSound() {
return placingSound;
}
public String getName() {
return name;
}
public void setBought(boolean bought) {
this.bought = bought;
}
public boolean isBought() {
return bought;
}
public int getCosts() {
return costs;
}
public float getRegenerationTime() {
return regenerationTime;
}
}

View File

@ -1,22 +0,0 @@
package com.example.julian.endlessroll.levels;
import org.simpleframework.xml.Attribute;
/**
* Created by Julian on 27.11.2015.
*/
public class Gap {
@Attribute
private float leftEdge;
@Attribute
private float rightEdge;
public float getLeftEdge() {
return leftEdge;
}
public float getRightEdge() {
return rightEdge;
}
}

View File

@ -1,147 +0,0 @@
package com.example.julian.endlessroll.levels;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import java.util.List;
/**
* Created by Julian on 07.12.2015.
*/
public class Level {
@Attribute
private int packId;
@Attribute
private int id;
@Attribute
private float goalX;
@Attribute
private float startSpeed;
@Attribute
private float endSpeed;
@Attribute
private float terrainEdge;
@Attribute
private float ceilingEdge;
@ElementList
private List<TileData> terrainTiles;
@ElementList
private List<TileData> ceilingTiles;
@ElementList
private List<ObstacleData> obstacles;
@ElementList
private List<PositionData> stars;
@Element(required = false)
private PositionData energy;
private boolean finished = false;
private boolean locked = true;
private boolean[] collectedStars = {false, false, false};
private boolean energyCollected = false;
public int getPackId() {
return packId;
}
public int getId() {
return id;
}
public float getGoalX() {
return goalX;
}
public float getStartSpeed() {
return startSpeed;
}
public float getEndSpeed() {
return endSpeed;
}
public float getTerrainEdge() {
return terrainEdge;
}
public float getCeilingEdge() {
return ceilingEdge;
}
public List<TileData> getTerrainTiles() {
return terrainTiles;
}
public List<TileData> getCeilingTiles() {
return ceilingTiles;
}
public List<ObstacleData> getObstacles() {
return obstacles;
}
public List<PositionData> getStars() {
return stars;
}
public PositionData getEnergyData() {
return energy;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public boolean isFinished() {
return finished;
}
public void setFinished(boolean finished) {
this.finished = finished;
}
public boolean isStarCollected(int index) {
return collectedStars[index];
}
public void setStarCollected(int index, boolean collected) {
collectedStars[index] = collected;
}
public String getCollectedStarCodeForSQL() {
String code = "";
for (int i = 0; i < 3; i++)
code += collectedStars[i] ? (i + 1) + "" : "";
return code;
}
public void setCollectedStarsFromSQL(String code) {
for (int i = 0; i < 3; i++)
collectedStars[i] = code.contains((i + 1) + "");
}
public boolean[] getCollectedStars() {
return collectedStars;
}
public boolean isEnergyCollected() {
return energyCollected;
}
public void setEnergyCollected(boolean collected) {
this.energyCollected = collected;
}
public void reset() {
finished = false;
locked = true;
collectedStars = new boolean[]{false, false, false};
energyCollected = false;
}
}

View File

@ -1,88 +0,0 @@
package com.example.julian.endlessroll.levels;
import android.content.Context;
import com.example.julian.endlessroll.main.DataStorageHandler;
import com.example.julian.endlessroll.main.GameLog;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class LevelManager extends ArrayList<LevelPack> {
public LevelManager(Context context, DataStorageHandler dataStorageHandler) throws Exception {
String[] assets = context.getAssets().list("levelpacks");
for (String asset : assets) {
try {
LevelPack pack = loadLevelPack(context, "levelpacks/" + asset);
pack.setName(asset.split(".xml")[0]);
dataStorageHandler.readLevelProgress(pack);
dataStorageHandler.readLevelPackLocked(pack);
pack.tryToUnlockFirstLevel();
if (pack.getId() == 1)
pack.setLocked(false);
super.add(pack);
} catch (Exception e) {
GameLog.e(e);
}
}
sortPacks();
}
private void sortPacks(){
Collections.sort(this, packComparator);
}
private LevelPack loadLevelPack(Context context, String name) throws Exception {
try {
InputStream source = context.getAssets().open(name);
Serializer serializer = new Persister();
return serializer.read(LevelPack.class, source);
} catch (Exception e) {
throw new Exception("Could not load levelPack \"" + name + "\"", e);
}
}
public LevelPack getNextLevelPack(LevelPack currentPack) {
int searchedId = currentPack.getId() + 1;
for (LevelPack pack : this) {
if (pack.getId() == searchedId)
return pack;
}
return null;
}
public void reset() {
for (LevelPack pack : this) {
pack.reset();
if (pack.getId() == 1)
pack.setLocked(false);
}
}
private Comparator<LevelPack> packComparator = new Comparator<LevelPack>() {
@Override
public int compare(LevelPack lhs, LevelPack rhs) {
return lhs.getId() - rhs.getId();
}
};
//CHEAT
public void unlockAllPacks() {
for (LevelPack levelPack : this)
levelPack.setLocked(false);
}
public void unlockAllLevels() {
for (LevelPack levelPack : this) {
for (Level level : levelPack.getLevels())
level.setLocked(false);
}
}
}

View File

@ -1,113 +0,0 @@
package com.example.julian.endlessroll.levels;
import com.example.julian.endlessroll.levels.worlds.World;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.util.List;
/**
* Created by Julian on 07.12.2015.
*/
@Root
public class LevelPack {
@Attribute
private int id;
@Element
private World world;
@ElementList
private List<Level> levels;
private String name;
private boolean locked = true;
public int getId() {
return id;
}
public List<Level> getLevels() {
return levels;
}
public World getWorld() {
return world;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public int getFinishedLevelCount() {
int count = 0;
for (Level level : levels)
if (level.isFinished())
count++;
return count;
}
public int getCollectedStarCount() {
int count = 0;
for (Level level : levels)
count += level.getCollectedStarCodeForSQL().length();
return count;
}
public int getAvailableStars() {
return levels.size() * 3;
}
public int getCollectedEnergyCount(){
int count = 0;
for(Level level : levels)
count += level.isEnergyCollected() ? 1 : 0;
return count;
}
public int getAvailableEnergy(){
return levels.size();
}
public void tryToUnlockFirstLevel() {
Level firstLevel = getLevel(1);
if (firstLevel != null)
firstLevel.setLocked(false);
}
public Level getLevel(int id) {
for (Level level : levels)
if (level.getId() == id)
return level;
return null;
}
public Level getNextLevel(Level currentLevel) {
return getLevel(currentLevel.getId() + 1);
}
public boolean isLastLevel(Level level) {
return getNextLevel(level) == null;
}
public void reset() {
for (Level level : levels)
level.reset();
setLocked(true);
tryToUnlockFirstLevel();
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public boolean isLocked() {
return locked;
}
}

View File

@ -1,56 +0,0 @@
package com.example.julian.endlessroll.levels;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.Vertex;
import org.simpleframework.xml.Attribute;
public class MoveComponent {
@Attribute
private float width;
@Attribute
private float height;
@Attribute
private float x;
@Attribute
private float y;
@Attribute
private float speed;
public float getWidth() {
return width;
}
public float getHeight() {
return height;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
public float getSpeed() {
return speed;
}
public Vector getPositionOfVertex(Vertex vertex) {
float x = this.x + (width / 2f) * vertex.getX();
float y = this.y + (height / 2f) * vertex.getY();
return new Vector(x, y);
}
public void shrink(Vector value) {
this.width -= value.getX();
this.height -= value.getY();
if (width < 0)
width = 0;
if (height < 0)
height = 0;
}
}

View File

@ -1,59 +0,0 @@
package com.example.julian.endlessroll.levels;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
/**
* Created by Julian on 07.12.2015.
*/
public class ObstacleData {
@Attribute
private boolean floating;
@Attribute
private boolean moving;
@Attribute
private boolean deadly;
@Attribute
private float leftEdge;
@Attribute
private float rightEdge;
@Attribute
private float height;
@Attribute
private float y;
@Element(required = false)
private MoveComponent moveComponent;
public boolean isFloating() {
return floating;
}
public boolean isMoving() {
return moving;
}
public boolean isDeadly() {
return deadly;
}
public float getX() {
return leftEdge + getWidth() / 2;
}
public float getWidth() {
return rightEdge - leftEdge;
}
public float getHeight() {
return height;
}
public float getY() {
return y;
}
public MoveComponent getMoveComponent() {
return moveComponent;
}
}

View File

@ -1,23 +0,0 @@
package com.example.julian.endlessroll.levels;
import org.simpleframework.xml.Attribute;
/**
* Created by Julian on 27.01.2017.
*/
public class PositionData {
@Attribute
private float x;
@Attribute
private float y;
public float getX() {
return x;
}
public float getY() {
return y;
}
}

View File

@ -1,19 +0,0 @@
package com.example.julian.endlessroll.levels;
import org.simpleframework.xml.Attribute;
public class TileData {
@Attribute
private float x;
@Attribute
private float width;
public float getX() {
return x;
}
public float getWidth() {
return width;
}
}

View File

@ -1,80 +0,0 @@
package com.example.julian.endlessroll.levels.worlds;
import android.support.annotation.DrawableRes;
import com.example.julian.endlessroll.R;
import com.example.julian.endlessroll.entities.textures.Texture;
import com.example.julian.endlessroll.entities.textures.TexturePack;
/**
* Created by Julian on 14.11.2016.
*/
public enum World {
GRASSLANDS("Grasslands", R.drawable.previews_grass, R.drawable.backgrounds_game_grass, R.drawable.terrain_t_grass, R.drawable.terrain_c_grass, R.drawable.obstacles_grass),
TESTCAVE("Testcave", R.drawable.previews_grass, R.drawable.backgrounds_game_cave, R.drawable.terrain_t_grass, R.drawable.terrain_c_grass, R.drawable.obstacles_cave),
ICY_MOUNTAINS("Icy Mountains", R.drawable.previews_grass, R.drawable.backgrounds_game_mountains, R.drawable.terrain_t_grass, R.drawable.terrain_c_grass, R.drawable.obstacles_mountains);
private String name;
@DrawableRes
private int previewId;
@DrawableRes
private int backgroundId;
@DrawableRes
private int terrainId;
@DrawableRes
private int ceilingId;
@DrawableRes
private int obstacleId;
private Texture background;
private Texture terrain;
private Texture ceiling;
private Texture obstacle;
World(String name, @DrawableRes int previewId, @DrawableRes int backgroundId, @DrawableRes int terrainId, @DrawableRes int ceilingId, @DrawableRes int obstacleId) {
this.name = name;
this.previewId = previewId;
this.backgroundId = backgroundId;
this.terrainId = terrainId;
this.ceilingId = ceilingId;
this.obstacleId = obstacleId;
}
public static void loadAllSpecificTextures(TexturePack texturePack) {
for (World world : values())
world.loadSpecificTextures(texturePack);
}
private void loadSpecificTextures(TexturePack texturePack) {
background = texturePack.loadTexture(backgroundId);
terrain = texturePack.loadTexture(terrainId);
ceiling = texturePack.loadTexture(ceilingId);
obstacle = texturePack.loadAtlas(obstacleId, 2, 2);
}
public String getName() {
return name;
}
public int getPreviewId() {
return previewId;
}
public Texture getBackgroundTexture() {
return background;
}
public Texture getTerrainTexture() {
return terrain;
}
public Texture getCeilingTexture() {
return ceiling;
}
public Texture getObstacleTexture() {
return obstacle;
}
}

View File

@ -1,12 +0,0 @@
package com.example.julian.endlessroll.main;
import com.example.julian.endlessroll.user.User;
/**
* Created by Julian on 15.07.2016.
*/
public class DataSafer {
private User user;
}

View File

@ -1,126 +0,0 @@
package com.example.julian.endlessroll.main;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import com.example.julian.endlessroll.user.ToolSlotSettings;
import com.example.julian.endlessroll.entities.tools.ToolType;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.levels.LevelPack;
import com.example.julian.endlessroll.user.User;
import com.example.julian.endlessroll.sqlDatabase.MyDatabase;
/**
* Created by Julian on 25.04.2016.
*/
public class DataStorageHandler {
private final String PREFERENCES_NAME = "GamePreferences";
private final String SOUND_ON = "Sound";
private final String USER_EP = "EP";
private final String USER_LEVEL = "Level";
private final String USER_STARS = "Stars";
private final String USER_ENERGY = "Energy";
private final String USER_TOOL_1 = "Tool1";
private final String USER_TOOL_2 = "Tool2";
private final String USER_TOOL_3 = "Tool3";
private final String USER_TOOL_4 = "Tool4";
private final String USER_TOOLS_LOCKED = "ToolsLocked";
private SharedPreferences preferences;
private MyDatabase database;
public DataStorageHandler(Activity activity) {
preferences = activity.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
database = new MyDatabase(activity);
}
public boolean readIsSoundOn() {
return preferences.getBoolean(SOUND_ON, true);
}
public void writeSoundOn(boolean soundOn) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(SOUND_ON, soundOn);
editor.apply();
}
public User readUserData(User.LvUpListener lvUpListener) throws Exception {
int ep = preferences.getInt(USER_EP, 0);
int level = preferences.getInt(USER_LEVEL, 1);
int stars = preferences.getInt(USER_STARS, 0);
int energy = preferences.getInt(USER_ENERGY, 0);
int toolsLocked = preferences.getInt(USER_TOOLS_LOCKED, 3);
String tool1 = preferences.getString(USER_TOOL_1, ToolType.RAMP.name());
String tool2 = preferences.getString(USER_TOOL_2, ToolType.NONE.name());
String tool3 = preferences.getString(USER_TOOL_3, ToolType.NONE.name());
String tool4 = preferences.getString(USER_TOOL_4, ToolType.NONE.name());
ToolSlotSettings toolSlotSettings = new ToolSlotSettings(tool1, tool2, tool3, tool4, toolsLocked);
return new User(lvUpListener, ep, level, stars, energy, toolSlotSettings);
}
public void writeUserData(User user) {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(USER_EP, user.getEp());
editor.putInt(USER_LEVEL, user.getLevel());
editor.putInt(USER_STARS, user.getStarCount());
editor.putInt(USER_ENERGY, user.getEnergyCount());
editor.putString(USER_TOOL_1, user.getToolSlotSettings().get(0).getToolType().name());
editor.putString(USER_TOOL_2, user.getToolSlotSettings().get(1).getToolType().name());
editor.putString(USER_TOOL_3, user.getToolSlotSettings().get(2).getToolType().name());
editor.putString(USER_TOOL_4, user.getToolSlotSettings().get(3).getToolType().name());
editor.putInt(USER_TOOLS_LOCKED, user.getToolSlotSettings().getLockedSlotCount());
editor.apply();
}
public void writeLevelProgress(Level level) {
database.open();
database.writeLevelProgress(level);
database.close();
}
public void writeLevelPackLocked(LevelPack levelPack) {
database.open();
database.writeLevelPackLocked(levelPack);
database.close();
}
public void readLevelPackLocked(LevelPack levelPack) {
database.open();
database.readLevelPackLocked(levelPack);
database.close();
}
public void clearLevelPackLocked() {
database.open();
database.clearLevelPackLocked();
database.close();
}
public void readLevelProgress(LevelPack levelPack) {
database.open();
for (Level level : levelPack.getLevels())
database.readLevelProgress(level);
database.close();
}
public void clearLevelProgess() {
database.open();
database.clearLevelProgess();
database.close();
}
public void readBoughtTools() {
database.open();
database.readBoughtTools();
database.close();
}
public void writeBoughtTools() {
database.open();
database.writeBoughtTools();
database.close();
}
}

View File

@ -1,10 +0,0 @@
package com.example.julian.endlessroll.main;
/**
* Created by Julian on 06.02.2016.
*/
public interface ExceptionHandler {
void onException(Exception e);
}

View File

@ -1,216 +0,0 @@
package com.example.julian.endlessroll.main;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.levels.LevelManager;
import com.example.julian.endlessroll.levels.LevelPack;
import com.example.julian.endlessroll.main.screens.GameScreen;
import com.example.julian.endlessroll.main.screens.LevelsScreen;
import com.example.julian.endlessroll.main.screens.Screen;
import com.example.julian.endlessroll.main.screens.ScreenFlipper;
import com.example.julian.endlessroll.main.screens.StartScreen;
import com.example.julian.endlessroll.main.screens.ToolShopScreen;
import com.example.julian.endlessroll.main.screens.WorldsScreen;
import com.example.julian.endlessroll.main.tutorial.BreakPoint;
import com.example.julian.endlessroll.main.tutorial.Tutorial;
import com.example.julian.endlessroll.main.tutorial.TutorialView;
import com.example.julian.endlessroll.rendering.renderer.GameRenderer;
import com.example.julian.endlessroll.sounds.SoundManager;
import com.example.julian.endlessroll.user.User;
import com.example.julian.endlessroll.views.LevelupMessage;
import com.example.julian.endlessroll.views.TopBarData;
import java.util.List;
/**
* Created by Julian on 06.02.2016.
*/
public class GameActivity extends Activity implements ExceptionHandler, User.LvUpListener {
private DataStorageHandler dataStorageHandler;
private LevelManager levelManager;
private SoundManager soundManager;
private User user;
private MyGlSurfaceView glSurfaceView;
private ScreenFlipper flipper;
private StartScreen startScreen;
private WorldsScreen worldsScreen;
private LevelsScreen levelsScreen;
private ToolShopScreen toolShopScreen;
private GameScreen gameScreen;
private LevelupMessage levelupMessage;
private TutorialView tutorialView;
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
GameLog.d("OnCreate");
super.onCreate(savedInstanceState);
super.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (!hasGLES20())
throw new Exception("OpenGL ES 2.0 not supported");
dataStorageHandler = new DataStorageHandler(this);
dataStorageHandler.readBoughtTools();
user = dataStorageHandler.readUserData(this);
soundManager = new SoundManager(this);
soundManager.setSoundOn(dataStorageHandler.readIsSoundOn());
soundManager.backgroundMusic.getPlayer().setLooping(true);
soundManager.backgroundMusic.start();
levelManager = new LevelManager(this, dataStorageHandler);
this.glSurfaceView = new MyGlSurfaceView(this, new GameRenderer(this));
Typeface typeface = Typeface.createFromAsset(getAssets(), "fontBaron.ttf");
TopBarData topBarData = new TopBarData(this, dataStorageHandler, soundManager, levelManager, user, typeface);
startScreen = new StartScreen(this, glSurfaceView, soundManager, levelManager, user, typeface);
worldsScreen = new WorldsScreen(topBarData);
levelsScreen = new LevelsScreen(topBarData);
toolShopScreen = new ToolShopScreen(topBarData);
gameScreen = new GameScreen(topBarData, glSurfaceView);
levelupMessage = new LevelupMessage(this, typeface, user);
tutorialView = new TutorialView(this);
flipper = new ScreenFlipper(this, startScreen, worldsScreen, levelsScreen, gameScreen, toolShopScreen);
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.addView(glSurfaceView);
relativeLayout.addView(flipper);
relativeLayout.addView(levelupMessage.getLayout());
relativeLayout.addView(tutorialView.getLayout());
//TODO: add Tutorial
//TODO: Scroll up
//TODO: Goal animation!
//TODO: Goal screen animation!
setContentView(relativeLayout);
} catch (Exception e) {
onException(e);
return;
}
}
public void flipToScreen(final Screen.ScreenType screen) {
runOnUiThread(new Runnable() {
@Override
public void run() {
flipper.showScreen(screen);
}
});
}
public void setToolshopCaller(Screen.ScreenType caller) {
toolShopScreen.setCaller(caller);
}
public Screen.ScreenType getCurrentScreenType() {
return flipper.getCurrentScreen().getType();
}
public void selectWorld(LevelPack levelPack) {
levelsScreen.createList(levelPack);
}
public void startGame(final LevelPack levelPack, final Level level) {
runOnUiThread(new Runnable() {
@Override
public void run() {
flipper.showScreen(Screen.ScreenType.GAME);
gameScreen.startGame(levelPack, level);
}
});
}
@Override
public void onLvUp(final int level) {
runOnUiThread(new Runnable() {
@Override
public void run() {
levelupMessage.show(level);
}
});
}
public void showTutorialScreen(final List<BreakPoint> breakPoints) {
runOnUiThread(new Runnable() {
@Override
public void run() {
tutorialView.show(breakPoints);
}
});
}
public void onTutorialViewHidden(){
gameScreen.onResume();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
try {
if (keyCode == KeyEvent.KEYCODE_BACK) {
flipper.getCurrentScreen().onBackKeyDown();
return true;
}
} catch (Exception e) {
onException(e);
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onException(Exception e) {
GameLog.e(e);
super.finish();
}
@Override
protected void onPause() {
GameLog.d("OnPause");
glSurfaceView.onPause();
if (flipper.getCurrentScreen() == gameScreen)
gameScreen.onPause();
soundManager.pause();
super.onPause();
}
@Override
protected void onResume() {
GameLog.d("OnResume");
glSurfaceView.onResume();
soundManager.resume();
super.onResume();
}
@Override
protected void onDestroy() {
GameLog.d("OnDestroy");
soundManager.destroy();
dataStorageHandler.writeSoundOn(soundManager.isSoundOn());
super.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
private boolean hasGLES20() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return info.reqGlEsVersion >= 0x20000;
}
}

View File

@ -1,25 +0,0 @@
package com.example.julian.endlessroll.main;
import android.widget.RelativeLayout;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.main.screens.Screen;
import com.example.julian.endlessroll.main.tutorial.BreakPoint;
import com.example.julian.endlessroll.main.tutorial.Tutorial;
import java.util.List;
/**
* Created by Julian on 08.12.2015.
*/
public interface GameHandler extends ExceptionHandler {
void startInUiThread(Runnable runnable);
void toScreen(Screen.ScreenType screen);
RelativeLayout getRootLayout();
void showTutorialScreen(List<BreakPoint> breakPoints);
}

View File

@ -1,44 +0,0 @@
package com.example.julian.endlessroll.main;
import android.util.Log;
/**
* Created by Julian on 23.11.2015.
*/
public class GameLog {
private final static String TAG = "GameLog";
public static boolean debugging = true;
public static void i(String message) {
Log.i(TAG + getCallerInfo(), message);
}
public static void d(String message) {
if (debugging)
Log.d(TAG + getCallerInfo(), message);
}
public static void e(String message) {
Log.e(TAG + getCallerInfo(), message);
}
public static void e(Throwable error) {
Log.e(TAG + getCallerInfo(), error.getMessage(), error);
}
//Possible to get Method which called i, d, e
//Method found at stack[4]
public static void stack() {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
Log.i(TAG + "Stack", "StackSize: " + stack.length);
for (int i = 0; i < stack.length; i++) {
Log.i(TAG + "Stack", i + ": " + stack[i]);
}
}
private static String getCallerInfo() {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
return "(" + stack[4].getFileName() + ", " + stack[4].getMethodName() + ", " + stack[4].getLineNumber() + ")";
}
}

View File

@ -1,47 +0,0 @@
package com.example.julian.endlessroll.main;
import android.content.Context;
import android.opengl.GLSurfaceView;
import com.example.julian.endlessroll.rendering.Rendering;
import com.example.julian.endlessroll.rendering.renderer.GameRenderer;
/**
* Created by Julian on 30.07.2016.
*/
public class MyGlSurfaceView extends GLSurfaceView {
private GameRenderer renderer;
private boolean rendererSet;
public MyGlSurfaceView(Context context, GameRenderer gameRenderer) throws Exception {
super(context);
this.renderer = gameRenderer;
super.setEGLContextClientVersion(2);
super.setRenderer(renderer);
rendererSet = true;
}
public void addRendering(Rendering rendering) {
renderer.addRendering(rendering);
}
public void setCurrentRendering(Rendering currentRendering) {
super.setOnTouchListener(currentRendering);
renderer.setCurrentRendering(currentRendering);
}
@Override
public void onResume() {
GameLog.i("SurfaceView: onResume");
if (rendererSet)
super.onResume();
}
@Override
public void onPause() {
GameLog.i("SurfaceView: onPause");
if (rendererSet)
super.onPause();
}
}

View File

@ -1,47 +0,0 @@
package com.example.julian.endlessroll.main.game;
import com.example.julian.endlessroll.main.GameLog;
/**
* Created by Julian on 22.05.2017.
*/
public class Camera {
private final float MOVE_SPEED_UP = 0.7f;
private final float MOVE_SPEED_DOWN = 0.7f;
private final float MAX_Y = 0.5f;
private final float MIN_Y = 0;
private float x, y;
public void update(float playerY, Timer timer){
float frameTime = timer.getFrameTimeSeconds() / 1000f;
float maxY = Math.min(playerY - 1 + 0.6f, MAX_Y);
if(playerY >= 0.5f){
y += MOVE_SPEED_UP * frameTime;
if(y > maxY)
y = maxY;
} else if(y > MIN_Y){
y -= MOVE_SPEED_DOWN * frameTime;
if(y < MIN_Y)
y = MIN_Y;
}
}
public void moveX(float move){
x += move;
}
public void reset(){
x = 0;
y = 0;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
}

View File

@ -1,301 +0,0 @@
package com.example.julian.endlessroll.main.game;
import android.view.MotionEvent;
import android.view.View;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.DestroyEffect;
import com.example.julian.endlessroll.entities.Energy;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.Star;
import com.example.julian.endlessroll.entities.collision.CollisionManager;
import com.example.julian.endlessroll.entities.particles.ParticleSystem;
import com.example.julian.endlessroll.entities.textures.TexturePack;
import com.example.julian.endlessroll.entities.tools.ToolType;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.levels.LevelManager;
import com.example.julian.endlessroll.levels.LevelPack;
import com.example.julian.endlessroll.main.DataStorageHandler;
import com.example.julian.endlessroll.main.GameHandler;
import com.example.julian.endlessroll.main.GameLog;
import com.example.julian.endlessroll.main.screens.Screen;
import com.example.julian.endlessroll.main.tutorial.Tutorial;
import com.example.julian.endlessroll.main.tutorial.TutorialManager;
import com.example.julian.endlessroll.rendering.Rendering;
import com.example.julian.endlessroll.sounds.SoundManager;
import com.example.julian.endlessroll.user.LevelUpBounties;
import com.example.julian.endlessroll.user.User;
import com.example.julian.endlessroll.views.MessageType;
import com.example.julian.endlessroll.views.ToolButton;
import com.example.julian.endlessroll.views.ToolButtonBar;
import com.example.julian.endlessroll.views.TopBarData;
import com.example.julian.endlessroll.views.ViewManager;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Julian on 26.11.2015.
*/
public class Game extends Rendering<GameScene> {
private User user;
private DataStorageHandler dataStorageHandler;
private LevelManager levelManager;
private GameHandler handler;
private ViewManager viewManager;
private SoundManager sounds;
private LevelPack levelPack;
private ParticleSystem particleSystem;
private LevelUpBounties levelUpBounties;
private ToolType currentTool;
private Player player;
private Physics physics;
private CollisionManager collisionManager;
private Timer timer;
private GameState gameState = GameState.COUNTDOWN;
private Level level;
private List<Integer> collectedStars = new ArrayList<>();
private boolean energyCollected;
private TutorialManager tutorialManager;
private Tutorial currentTutorial;
public Game(GameHandler handler, TopBarData topBarData) throws Exception {
super(topBarData.getGameActivity());
this.handler = handler;
this.user = topBarData.getUser();
this.levelManager = topBarData.getLevelManager();
this.sounds = topBarData.getSoundManager();
levelUpBounties = new LevelUpBounties(0);
physics = new Physics();
collisionManager = new CollisionManager(this);
particleSystem = new ParticleSystem(getContext());
this.dataStorageHandler = topBarData.getDataStorageHandler();
viewManager = new ViewManager(this, handler, topBarData);
tutorialManager = new TutorialManager();
}
@Override
public GameScene init(TexturePack texturePack, Timer timer, boolean isFirstTime) {
GameLog.d("initGame");
this.timer = timer;
try {
if (isFirstTime) {
scene = new GameScene(texturePack, particleSystem);
if (level != null)
startGame(levelPack, level);
} else {
scene.setTexturePack(texturePack);
}
particleSystem.loadTextures();
} catch (Exception e) {
onException(e);
}
return scene;
}
public void startGame(LevelPack levelPack, Level level) {
GameLog.d("Start game");
try {
this.level = level;
this.levelPack = levelPack;
if (scene != null) {
gameState = GameState.COUNTDOWN;
tutorialManager.resetTutorials();
currentTutorial = tutorialManager.getTutorial(level);
if (level.isFinished())
currentTutorial = null;
collectedStars.clear();
energyCollected = false;
particleSystem.deleteAllSources();
scene.loadLevel(level, levelPack.getWorld());
player = scene.getPlayer();
viewManager.resetViews(user);
currentTool = viewManager.toolButtonBar.getActiveButton().getToolType();
viewManager.startCountdown();
}
} catch (Exception e) {
onException(e);
}
}
public void countdownFinished() {
gameState = GameState.RUNNING;
}
@Override
public void setScreenSize(int width, int height) {
Vector screenSize = new Vector(width, height);
scene.setScreenSize(screenSize);
}
@Override
public void update() {
particleSystem.update(timer);
float playerProgress = 0;
float playerSpeed = 0;
if (player != null) {
playerProgress = player.getProgress();
playerSpeed = player.getSpeed();
}
viewManager.update(gameState == GameState.RUNNING, timer, playerProgress, playerSpeed);
switch (gameState) {
case RUNNING:
if (player.getPosition().y < -2f) {
onGameOver(false);
return;
}
if (player.getPosition().x >= scene.getGoalX()) {
onGoalReached();
return;
}
scene.getCamera().update(player.getPosition().y, timer);
if (currentTutorial != null) {
currentTutorial.update(playerProgress);
if (currentTutorial.isOverNewBreakPoints()) {
gameState = GameState.PAUSED;
handler.showTutorialScreen(currentTutorial.getCurrentBreakPoints());
return;
}
}
physics.applyGravity(scene, timer);
scene.update(timer);
collisionManager.update(physics, scene);
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gameState == GameState.RUNNING) {
ToolButtonBar bar = viewManager.toolButtonBar;
ToolButton button = bar.getByToolType(currentTool);
if (button != null && button.finishedLoading()) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
button.setProgress(0);
addTool(event.getX(), event.getY());
}
}
return true;
}
return false;
}
public void resetViews() {
viewManager.resetViews(user);
}
public void continueGame() {
viewManager.hideShortMenu();
gameState = GameState.COUNTDOWN;
viewManager.startCountdown();
}
public void startNextLevel() {
level = levelPack.getNextLevel(level);
startGame(levelPack, level);
}
public void restartLevel() {
startGame(levelPack, level);
}
public void toLevelsScreen() {
handler.toScreen(Screen.ScreenType.LEVELS);
}
public void setCurrentTool(ToolType toolType) {
currentTool = toolType;
}
public void tryToPause() {
if(gameState == GameState.GAME_OVER || gameState == GameState.PAUSED)
return;
viewManager.showShortMenu();
if (gameState == GameState.COUNTDOWN)
viewManager.stopCountdown();
gameState = GameState.PAUSED;
}
public void setRunning() {
gameState = GameState.RUNNING;
}
private void addTool(float x, float y) {
try {
sounds.playSound(currentTool.getPlacingSound());
scene.addTool(currentTool, x, y);
} catch (Exception e) {
onException(e);
}
}
public void onGameOver(boolean playerExplode) {
if (playerExplode) {
scene.remove(player);
DestroyEffect.EXPLOSION.createEffect(particleSystem, player.getPosition(),
new Vector(player.getWidth(), player.getHeight())).start();
}
gameState = GameState.GAME_OVER;
viewManager.showMessage(false, MessageType.GAME_OVER);
}
private void onGoalReached() {
gameState = GameState.LEVEL_FINISHED;
if (!level.isFinished())
user.gainLvFinishedEp();
level.setFinished(true);
for (int i = 0; i <= 2; i++) {
if (collectedStars.contains(i)) {
level.setStarCollected(i, true);
user.onStarCollected();
}
}
if (energyCollected) {
level.setEnergyCollected(true);
user.onEnergyCollected();
}
viewManager.showMessage(levelPack.isLastLevel(level), MessageType.WIN);
dataStorageHandler.writeLevelProgress(level);
Level nextLevel = levelPack.getNextLevel(level);
if (nextLevel != null) {
nextLevel.setLocked(false);
dataStorageHandler.writeLevelProgress(nextLevel);
} else {
LevelPack nextLevelPack = levelManager.getNextLevelPack(levelPack);
if (nextLevelPack != null) {
nextLevelPack.setLocked(false);
dataStorageHandler.writeLevelPackLocked(nextLevelPack);
}
}
dataStorageHandler.writeUserData(user);
}
public void onStarCollision(Star star) {
scene.onStarCollision(star);
collectedStars.add(star.getIndex());
}
public void onEnergyCollision(Energy energy) {
scene.onEnergyCollision(energy);
energyCollected = true;
}
@Override
public void onException(Exception e) {
handler.onException(e);
}
public GameState getGameState() {
return gameState;
}
}

View File

@ -1,177 +0,0 @@
package com.example.julian.endlessroll.main.game;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.DestroyEffect;
import com.example.julian.endlessroll.entities.Energy;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.Goal;
import com.example.julian.endlessroll.entities.Obstacle;
import com.example.julian.endlessroll.entities.Star;
import com.example.julian.endlessroll.entities.collision.CollisionDetector;
import com.example.julian.endlessroll.entities.particles.ParticleSystem;
import com.example.julian.endlessroll.entities.textures.TexturePack;
import com.example.julian.endlessroll.entities.tools.Bomb;
import com.example.julian.endlessroll.entities.tools.Tool;
import com.example.julian.endlessroll.entities.tools.ToolType;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.levels.ObstacleData;
import com.example.julian.endlessroll.levels.PositionData;
import com.example.julian.endlessroll.levels.worlds.World;
import com.example.julian.endlessroll.main.GameLog;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Created by Julian on 27.11.2015.
*/
public class GameScene extends Scene {
private World currentWorld;
private CollisionDetector collisionDetector;
private Goal goal;
private float goalX;
private List<Obstacle> obstacles = Collections.synchronizedList(new ArrayList<Obstacle>());
private List<Star> stars = Collections.synchronizedList(new ArrayList<Star>());
private List<Tool> tools = Collections.synchronizedList(new ArrayList<Tool>());
private Energy energy;
public GameScene(TexturePack texturePack, ParticleSystem particleSystem) throws Exception {
super(texturePack, particleSystem);
collisionDetector = new CollisionDetector();
goal = new Goal(textures.goal);
}
public void loadLevel(Level level, World world) throws Exception {
this.currentWorld = world;
reset();
background.changeTexture(world.getBackgroundTexture());
terrain.loadData(world, level.getTerrainEdge(), level.getTerrainTiles());
ceiling.loadData(world, level.getCeilingEdge(), level.getCeilingTiles());
super.add(goal);
player.init(terrain.getEdge(), level.getStartSpeed(), level.getEndSpeed());
super.add(player);
tryToAddEnergy(level);
for (ObstacleData data : level.getObstacles())
addObstacle(data);
for (int i = 0; i < level.getStars().size(); i++) {
if (level.isStarCollected(i))
continue;
addStar(i, level.getStars().get(i));
}
goalX = level.getGoalX();
goal.setGoalX(goalX);
GameLog.d("Level " + level.getId() + " successfully loaded");
}
private void tryToAddEnergy(Level level){
PositionData data = level.getEnergyData();
if(data != null && !level.isEnergyCollected()) {
energy = new Energy(textures.energy, data);
super.add(energy);
}
}
private void reset() {
super.clear();
obstacles.clear();
tools.clear();
energy = null;
camera.reset();
background.resetPosition();
}
public void onStarCollision(Star collisionStar) {
synchronized (stars) {
Iterator<Star> iter = stars.iterator();
while (iter.hasNext()) {
Star star = iter.next();
if (star.equals(collisionStar)) {
star.destroy(DestroyEffect.STAR_EXPLOSION);
iter.remove();
}
}
}
}
public void onEnergyCollision(Energy energy){
energy.destroy(DestroyEffect.ENERGY_COLLECT);
}
public void addObstacle(ObstacleData data) {
Obstacle obstacle = new Obstacle(currentWorld, data, terrain.getEdge());
super.add(obstacle);
obstacles.add(obstacle);
}
public void addStar(int index, PositionData data) {
Star star = new Star(index, textures.star, data);
super.add(star);
stars.add(star);
}
public void addTool(ToolType type, float screenX, float screenY) throws Exception {
Vector position = calcWorldFromScreenCoords(screenX, screenY);
Tool tool = type.newInstance(position, particleSystem);
if (tool == null)
throw new Exception("Current ToolType(" + type + ") returns null at method newInstance()");
super.add(tool);
tools.add(tool);
}
@Override
public void update(Timer timer) {
super.update(timer);
player.setSpeedByProgress(player.getProgress() / goalX);
synchronized (tools) {
for (Tool tool : tools) {
if (tool instanceof Bomb) {
Bomb bomb = (Bomb) tool;
if (bomb.isExploding())
bomb.explode(obstacles, collisionDetector);
}
}
}
}
@Override
protected void removeEntityFromAllLists(Entity entity) {
GameLog.i("REMOVE FROM ALL LISTS");
if (!entity.isDestroyed())
entity.destroy(null);
if (entity instanceof Tool)
tools.remove(entity);
if (entity instanceof Obstacle)
obstacles.remove(entity);
}
public synchronized List<Tool> getTools() {
return tools;
}
public synchronized List<Obstacle> getObstacles() {
return obstacles;
}
public synchronized List<Star> getStars() {
return stars;
}
public Energy getEnergy() {
return energy;
}
public boolean hasEnergy(){
return energy != null;
}
public float getGoalX() {
return goalX;
}
}

View File

@ -1,10 +0,0 @@
package com.example.julian.endlessroll.main.game;
/**
* Created by Julian on 02.02.2016.
*/
public enum GameState {
RUNNING, PAUSED, GAME_OVER, LEVEL_FINISHED, COUNTDOWN
}

View File

@ -1,183 +0,0 @@
package com.example.julian.endlessroll.main.game;
import android.support.annotation.Nullable;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.Obstacle;
import com.example.julian.endlessroll.entities.Star;
import com.example.julian.endlessroll.entities.collision.CollisionDetector;
import com.example.julian.endlessroll.entities.collision.collisionData.EntityCollisionData;
import com.example.julian.endlessroll.entities.collision.collisionData.ObstacleCollisionData;
import com.example.julian.endlessroll.entities.collision.collisionData.PlayerCollisionData;
import com.example.julian.endlessroll.entities.collision.collisionData.ToolCollisionData;
import com.example.julian.endlessroll.entities.collision.geometry.Circle;
import com.example.julian.endlessroll.entities.tileLists.Ceiling;
import com.example.julian.endlessroll.entities.tileLists.Terrain;
import com.example.julian.endlessroll.entities.tileLists.Tile;
import com.example.julian.endlessroll.entities.tools.Bomb;
import com.example.julian.endlessroll.entities.tools.Tool;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Julian on 27.11.2015.
*/
public class Physics {
public final float GRAVITY_FORCE = .0000025f;
private CollisionDetector detector;
public Physics() {
detector = new CollisionDetector();
}
public void applyGravity(GameScene scene, Timer timer) {
float gravity = GRAVITY_FORCE * timer.getFrameTimeSeconds();
scene.getPlayer().getMovement().y -= gravity;
synchronized (scene.getTools()) {
for (Tool tool : scene.getTools()) {
if (tool.isFloating())
continue;
if (tool instanceof Bomb) {
for (Obstacle obstacle : scene.getObstacles()) {
if (detector.quadQuadCollision(obstacle, tool)) {
tool.setFloating(true);
tool.getMovement().y = 0;
break;
}
}
if (tool.isFloating())
continue;
}
float terrainEdge = getTerrainEdge(tool, scene.getTerrain());
Obstacle toolIsOver = getObstacleToolIsOver(tool, scene.getObstacles());
float orientingHeight = terrainEdge;
if (toolIsOver != null) {
if (toolIsOver.getBottomEdge() < tool.getTopEdge())
orientingHeight = Math.max(toolIsOver.getTopEdge(), terrainEdge);
else {
orientingHeight = terrainEdge;
}
}
if (tool.getBottomEdge() > orientingHeight) {
tool.getMovement().y -= gravity * 2;
} else {
tool.getMovement().y = 0;
tool.setToTerrain(orientingHeight);
}
}
}
}
@Nullable
private Obstacle getObstacleToolIsOver(Entity tool, List<Obstacle> obstacles) {
Map<Float, Obstacle> isOver = new HashMap<>();
synchronized (obstacles) {
for (Obstacle obstacle : obstacles) {
boolean toolVertexInObstacleEdge = (tool.getLeftEdge() >= obstacle.getLeftEdge() && tool.getLeftEdge() <= obstacle.getRightEdge()) || (tool.getRightEdge() <= obstacle.getRightEdge() && tool.getRightEdge() >= obstacle.getLeftEdge());
boolean obstacleVertexInToolEdge = (obstacle.getLeftEdge() >= tool.getLeftEdge() && obstacle.getLeftEdge() <= tool.getRightEdge()) || (obstacle.getRightEdge() <= tool.getRightEdge() && obstacle.getRightEdge() >= tool.getLeftEdge());
if (toolVertexInObstacleEdge || obstacleVertexInToolEdge)
isOver.put(obstacle.getTopEdge(), obstacle);
}
}
float max = -100;
for (float height : isOver.keySet()) {
if (isOver.get(height).getBottomEdge() < tool.getTopEdge()) {
max = Math.max(max, height);
}
}
if (max != -100)
return isOver.get(max);
return null;
}
private float getTerrainEdge(Entity tool, Terrain terrain) {
for (Tile instance : terrain) {
if ((tool.getLeftEdge() >= instance.getLeftEdge() && tool.getLeftEdge() <= instance.getRightEdge())
|| (tool.getRightEdge() <= instance.getRightEdge() && tool.getRightEdge() >= instance.getLeftEdge())
|| (instance.getLeftEdge() >= tool.getLeftEdge() && instance.getLeftEdge() <= tool.getRightEdge())
|| (instance.getRightEdge() <= tool.getRightEdge() && instance.getRightEdge() >= tool.getLeftEdge()))
return terrain.getEdge();
}
return -10;
}
public PlayerCollisionData getPlayerCollisionData(GameScene scene) {
EntityCollisionData terrainData = playerCollidesWithTerrain(scene);
EntityCollisionData ceilingData = playerCollidesWithCeiling(scene);
ObstacleCollisionData obstacleData = playerCollidesWithObstacle(scene);
ToolCollisionData toolData = playerCollidesWithTool(scene);
EntityCollisionData starData = playerCollidesWithStar(scene);
EntityCollisionData energyData = playerCollidesWithEnergy(scene);
return new PlayerCollisionData(terrainData, ceilingData, obstacleData, toolData, starData, energyData);
}
private EntityCollisionData playerCollidesWithTerrain(GameScene scene) {
Terrain terrain = scene.getTerrain();
for (Tile terrainTile : terrain) {
EntityCollisionData data = detector.playerEntityCollision(scene.getPlayer(), terrainTile);
if (data.isCollision())
return data;
}
return new EntityCollisionData(null, null);
}
private EntityCollisionData playerCollidesWithCeiling(GameScene scene) {
Ceiling ceiling = scene.getCeiling();
for (Tile ceilingTile : ceiling) {
EntityCollisionData data = detector.playerEntityCollision(scene.getPlayer(), ceilingTile);
if (data.isCollision())
return data;
}
return new EntityCollisionData(null, null);
}
private ObstacleCollisionData playerCollidesWithObstacle(GameScene scene) {
List<EntityCollisionData> collisions = new ArrayList<>();
synchronized (scene.getObstacles()) {
for (Obstacle obstacle : scene.getObstacles()) {
EntityCollisionData data = detector.playerEntityCollision(scene.getPlayer(), obstacle);
if (data.isCollision())
collisions.add(data);
}
}
return new ObstacleCollisionData(collisions);
}
private ToolCollisionData playerCollidesWithTool(GameScene scene) {
List<Tool> tools = new ArrayList<>();
Circle circle = new Circle(scene.getPlayer());
synchronized (scene.getTools()) {
for (Tool tool : scene.getTools()) {
if (detector.circleToolCollision(circle, tool.getCollisionBounds()))
tools.add(tool);
}
}
return new ToolCollisionData(tools);
}
private EntityCollisionData playerCollidesWithStar(GameScene scene) {
synchronized (scene.getStars()) {
for (Star star : scene.getStars()) {
EntityCollisionData data = detector.playerEntityCollision(scene.getPlayer(), star);
if (data.isCollision())
return data;
}
}
return new EntityCollisionData(null, null);
}
private EntityCollisionData playerCollidesWithEnergy(GameScene scene) {
if (scene.hasEnergy()) {
EntityCollisionData data = detector.playerEntityCollision(scene.getPlayer(), scene.getEnergy());
return data;
} else
return new EntityCollisionData(null, null);
}
}

View File

@ -1,140 +0,0 @@
package com.example.julian.endlessroll.main.game;
import com.example.julian.endlessroll.data.SynchronizedArrayList;
import com.example.julian.endlessroll.data.Vector;
import com.example.julian.endlessroll.entities.AnimatedEntity;
import com.example.julian.endlessroll.entities.Background;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.Obstacle;
import com.example.julian.endlessroll.entities.Player;
import com.example.julian.endlessroll.entities.particles.ParticleSystem;
import com.example.julian.endlessroll.entities.textures.TexturePack;
import com.example.julian.endlessroll.entities.tileLists.Ceiling;
import com.example.julian.endlessroll.entities.tileLists.Terrain;
import com.example.julian.endlessroll.levels.worlds.World;
import java.util.Iterator;
/**
* Created by Julian on 20.07.2016.
*/
public abstract class Scene extends SynchronizedArrayList<Entity> {
protected Camera camera;
private Vector screenSize;
private Entity playerArrow;
protected ParticleSystem particleSystem;
protected TexturePack textures;
protected Background background;
protected Terrain terrain;
protected Ceiling ceiling;
protected Player player;
public Scene(TexturePack texturePack, ParticleSystem particleSystem) {
this.particleSystem = particleSystem;
setTexturePack(texturePack);
camera = new Camera();
playerArrow = new Entity(textures.playerArrow, new Vector(0, 0.9f), .2f, .2f);
background = new Background(World.GRASSLANDS.getBackgroundTexture());
terrain = new Terrain(World.GRASSLANDS.getTerrainTexture());
ceiling = new Ceiling(World.GRASSLANDS.getTerrainTexture());
player = new Player(textures.player);
}
public void setTexturePack(TexturePack texturePack) {
this.textures = texturePack;
}
public void update(Timer timer) {
synchronized (this) {
Iterator<Entity> iterator = super.iterator();
while (iterator.hasNext()) {
Entity entity = iterator.next();
if(entity instanceof AnimatedEntity)
((AnimatedEntity) entity).update(timer);
Vector movement = entity.getMovement();
Vector finalMovement = new Vector(movement).mul(timer.getFrameTimeSeconds());
entity.move(finalMovement);
if (entity instanceof Obstacle) {
Obstacle obstacle = (Obstacle) entity;
if (obstacle.isMoving())
obstacle.moveWithMoveComponent(timer.getFrameTimeSeconds());
}
if (entity.isDestroyed() && entity.getDestroyEffect() != null)
entity.getDestroyEffect().createEffect(particleSystem, new Vector(entity.getPosition()), new Vector(entity.getWidth(), entity.getHeight())).start();
if (entity.equals(player))
moveEnviroment(finalMovement.x);
else if (entity.getRightEdge() - camera.getX() < -3f || entity.isDestroyed()) {
iterator.remove();
removeEntityFromAllLists(entity);
}
}
}
if (player.getPosition().y >= player.RADIUS + 1 + camera.getY()) {
playerArrow.getPosition().x = player.getPosition().x;
playerArrow.getPosition().y = camera.getY() + 0.9f;
if (!super.contains(playerArrow)) {
super.add(playerArrow);
}
} else super.remove(playerArrow);
}
@Override
public synchronized boolean remove(Object object) {
removeEntityFromAllLists((Entity) object);
return super.remove(object);
}
protected abstract void removeEntityFromAllLists(Entity entity);
private void moveEnviroment(float x) {
camera.moveX(x);
background.move(x * 0.95f, camera.getX());
terrain.update(camera.getX());
ceiling.update(camera.getX());
}
protected Vector calcWorldFromScreenCoords(float screenX, float screenY) throws Exception {
if (screenSize == null)
throw new Exception("ScreenSize not set");
float glCoordWidth = (2f * screenSize.x / screenSize.y);
float x = ((screenX / screenSize.x) * 2f - 1f) * glCoordWidth / 2;
x += camera.getX();
float y = -((screenY / screenSize.y) * 2f - 1f);
return new Vector(x, y);
}
public void setScreenSize(Vector screenSize) {
this.screenSize = screenSize;
}
public synchronized Background getBackground() {
return background;
}
public synchronized Terrain getTerrain() {
return terrain;
}
public synchronized Ceiling getCeiling() {
return ceiling;
}
public Player getPlayer() {
return player;
}
public TexturePack getTextures() {
return textures;
}
public ParticleSystem getParticleSystem() {
return particleSystem;
}
public Camera getCamera() {
return camera;
}
}

View File

@ -1,20 +0,0 @@
package com.example.julian.endlessroll.main.game;
import com.example.julian.endlessroll.entities.Entity;
import com.example.julian.endlessroll.entities.particles.ParticleSystem;
import com.example.julian.endlessroll.entities.textures.TexturePack;
import com.example.julian.endlessroll.levels.worlds.World;
public class StartScene extends Scene {
public StartScene(TexturePack texturePack, ParticleSystem particleSystem) {
super(texturePack, particleSystem);
terrain.createEndless(World.ICY_MOUNTAINS, -.8f);
player.init(terrain.getEdge(), 0.5f, 0.5f);
super.add(player);
}
@Override
protected void removeEntityFromAllLists(Entity entity) {
}
}

View File

@ -1,46 +0,0 @@
package com.example.julian.endlessroll.main.game;
/**
* Created by Julian on 22.11.2015.
*/
public class Timer {
private long lastFpsTime;
private int fpsCounter;
private int fps;
private long lastTime;
private long delta;
public Timer() {
lastTime = System.currentTimeMillis();
lastFpsTime = lastTime;
}
public void update() {
long currentTime = System.currentTimeMillis();
delta = currentTime - lastTime;
lastTime = currentTime;
fpsCounter++;
if (currentTime - lastFpsTime > 1000) {
fps = fpsCounter;
lastFpsTime += 1000;
fpsCounter = 0;
}
}
public float getFrameTimeSeconds() {
return delta;
}
public int getFps() {
return fps;
}
public long getCurrentTime() {
return System.currentTimeMillis();
}
}

View File

@ -1,21 +0,0 @@
package com.example.julian.endlessroll.main.screens;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.view.ViewGroup;
import com.example.julian.endlessroll.main.MyGlSurfaceView;
/**
* Created by Julian on 30.07.2016.
*/
public abstract class GLScreen<V extends ViewGroup> extends Screen<V> {
protected MyGlSurfaceView glView;
public GLScreen(ScreenType type, Context context, @LayoutRes int layoutId, MyGlSurfaceView glView) {
super(type, context, layoutId);
this.glView = glView;
}
}

View File

@ -1,88 +0,0 @@
package com.example.julian.endlessroll.main.screens;
import android.widget.RelativeLayout;
import com.example.julian.endlessroll.R;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.levels.LevelPack;
import com.example.julian.endlessroll.main.GameActivity;
import com.example.julian.endlessroll.main.GameHandler;
import com.example.julian.endlessroll.main.MyGlSurfaceView;
import com.example.julian.endlessroll.main.game.Game;
import com.example.julian.endlessroll.main.tutorial.BreakPoint;
import com.example.julian.endlessroll.views.TopBarData;
import java.util.List;
/**
* Created by Julian on 08.02.2016.
*/
public class GameScreen extends GLScreen<RelativeLayout> {
private GameActivity activity;
private Game game;
public GameScreen(TopBarData topBarData, MyGlSurfaceView glSurfaceView) throws Exception {
super(ScreenType.GAME, topBarData.getGameActivity(), R.layout.game, glSurfaceView);
this.activity = topBarData.getGameActivity();
game = new Game(gameViewHandler, topBarData);
glView.addRendering(game);
}
@Override
public void prepareToBeShown() {
glView.setCurrentRendering(game);
game.resetViews();
}
public void onPause() {
game.tryToPause();
}
public void onResume(){
game.setRunning();
}
@Override
public void onBackKeyDown() {
game.tryToPause();
}
public void startGame(LevelPack levelPack, Level level) {
game.startGame(levelPack, level);
}
public GameHandler getGameViewHandler() {
return gameViewHandler;
}
private GameHandler gameViewHandler = new GameHandler() {
@Override
public void startInUiThread(Runnable runnable) {
activity.runOnUiThread(runnable);
}
@Override
public void toScreen(ScreenType screen) {
glView.setCurrentRendering(null);
activity.flipToScreen(screen);
}
@Override
public RelativeLayout getRootLayout() {
return layout;
}
@Override
public void showTutorialScreen(List<BreakPoint> breakPoints) {
activity.showTutorialScreen(breakPoints);
}
@Override
public void onException(Exception e) {
activity.onException(e);
}
};
}

View File

@ -1,91 +0,0 @@
package com.example.julian.endlessroll.main.screens;
import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import com.example.julian.endlessroll.R;
import com.example.julian.endlessroll.levels.Level;
import com.example.julian.endlessroll.levels.LevelPack;
import com.example.julian.endlessroll.main.GameActivity;
import com.example.julian.endlessroll.views.LevelButton;
import com.example.julian.endlessroll.views.TopBar;
import com.example.julian.endlessroll.views.TopBarData;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Julian on 23.04.2016.
*/
public class LevelsScreen extends Screen<LinearLayout> implements View.OnClickListener {
private LevelPack levelPack;
private Typeface typeface;
private GameActivity activity;
private Map<Integer, LevelButton> levelButtons = new HashMap<>();
private TopBar topBar;
private TableRow topRow;
private TableRow bottomRow;
public LevelsScreen(TopBarData topBarData) {
super(ScreenType.LEVELS, topBarData.getGameActivity(), R.layout.levels);
this.activity = topBarData.getGameActivity();
this.typeface = topBarData.getTypeface();
topBar = new TopBar(topBarData, ScreenType.LEVELS, (RelativeLayout) layout.findViewById(R.id.levels_topbar));
topRow = (TableRow) layout.findViewById(R.id.levels_topRow);
bottomRow = (TableRow) layout.findViewById(R.id.levels_bottomRow);
}
public void createList(LevelPack levelPack) {
this.levelPack = levelPack;
topRow.removeAllViews();
bottomRow.removeAllViews();
levelButtons.clear();
int levelCount = levelPack.getLevels().size();
for (Level level : levelPack.getLevels())
createButton(activity, level, levelCount);
}
private void createButton(Context context, Level level, int levelCount) {
int levelNumber = level.getId();
LevelButton button = new LevelButton(context, typeface, this, levelNumber, level.isLocked());
button.showCollectedCurrency(level.getCollectedStars(), level.isEnergyCollected());
levelButtons.put(levelNumber, button);
int halfLevelCount = levelCount / 2;
if (levelCount % 2 == 1)
halfLevelCount++;
if (levelNumber <= halfLevelCount)
topRow.addView(button);
else
bottomRow.addView(button);
}
@Override
public void prepareToBeShown() {
if (levelPack != null)
createList(levelPack);
topBar.update();
}
@Override
public void onBackKeyDown() {
activity.flipToScreen(ScreenType.WORLDS);
}
@Override
public void onClick(View v) {
for (int levelNumber : levelButtons.keySet()) {
LevelButton button = levelButtons.get(levelNumber);
if (button.equals(v) && !button.isLocked()) {
Level level = levelPack.getLevel(levelNumber);
activity.startGame(levelPack, level);
}
}
}
}

View File

@ -1,52 +0,0 @@
package com.example.julian.endlessroll.main.screens;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.view.LayoutInflater;
import android.view.ViewGroup;
/**
* Created by Julian on 13.02.2016.
*/
public abstract class Screen<V extends ViewGroup> {
public enum ScreenType {
NONE(-1), START(0), WORLDS(1), LEVELS(2), GAME(3), TOOL_SHOP(4);
private int inFlipperPosition;
ScreenType(int inFlipperPosition) {
this.inFlipperPosition = inFlipperPosition;
}
public int getInFlipperPosition() {
return inFlipperPosition;
}
}
private ScreenType type;
protected V layout;
public Screen(ScreenType type, Context context, @LayoutRes int layoutId) {
this.type = type;
layout = inflateLayout(context, layoutId);
}
private V inflateLayout(Context context, @LayoutRes int layoutId) {
LayoutInflater inflater = LayoutInflater.from(context);
return (V) inflater.inflate(layoutId, null);
}
public abstract void prepareToBeShown();
public abstract void onBackKeyDown();
public ScreenType getType() {
return type;
}
public V get() {
return layout;
}
}

View File

@ -1,54 +0,0 @@
package com.example.julian.endlessroll.main.screens;
import android.content.Context;
import android.widget.ViewFlipper;
/**
* Created by Julian on 13.02.2016.
*/
public class ScreenFlipper extends ViewFlipper {
private Screen[] screens;
private Screen currentScreen;
//TODO: animation?
public ScreenFlipper(Context context, Screen... screens) {
super(context);
this.screens = screens;
for (Screen screen : screens)
addView(screen);
currentScreen = screens[0];
showScreen(currentScreen.getType());
}
private void addView(Screen screen) {
super.addView(screen.get(), screen.getType().getInFlipperPosition());
}
public Screen getCurrentScreen() {
return currentScreen;
}
public void showScreen(Screen.ScreenType type) {
Screen screen = findScreen(type);
screen.prepareToBeShown();
int positionDifference = type.getInFlipperPosition() - currentScreen.getType().getInFlipperPosition();
if (positionDifference < 0)
for (; positionDifference != 0; positionDifference++)
super.showPrevious();
else if (positionDifference > 0)
for (; positionDifference != 0; positionDifference--)
super.showNext();
currentScreen = screen;
}
private Screen findScreen(Screen.ScreenType type) {
for (Screen screen : screens)
if (screen.getType().equals(type)) {
return screen;
}
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More