diff --git a/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml b/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml
index 064ce26..84c4f45 100644
--- a/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml
+++ b/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml
@@ -11,7 +11,7 @@
-
+
@@ -33,34 +33,34 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -82,40 +82,40 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -141,31 +141,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -187,19 +187,19 @@
-
+
-
+
-
+
-
+
-
+
@@ -220,16 +220,16 @@
-
+
-
+
-
+
-
+
@@ -251,31 +251,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -297,58 +297,58 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -371,55 +371,55 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -441,94 +441,94 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -549,31 +549,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -599,76 +599,76 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -690,70 +690,70 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -780,88 +780,88 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -883,37 +883,37 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -938,61 +938,61 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/app/src/main/assets/levelpacks/Grasslands.xml b/app/src/main/assets/levelpacks/Grasslands.xml
index 064ce26..84c4f45 100644
--- a/app/src/main/assets/levelpacks/Grasslands.xml
+++ b/app/src/main/assets/levelpacks/Grasslands.xml
@@ -11,7 +11,7 @@
-
+
@@ -33,34 +33,34 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -82,40 +82,40 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -141,31 +141,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -187,19 +187,19 @@
-
+
-
+
-
+
-
+
-
+
@@ -220,16 +220,16 @@
-
+
-
+
-
+
-
+
@@ -251,31 +251,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -297,58 +297,58 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -371,55 +371,55 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -441,94 +441,94 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -549,31 +549,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -599,76 +599,76 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -690,70 +690,70 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -780,88 +780,88 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -883,37 +883,37 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -938,61 +938,61 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/app/src/main/assets/levelpacks/Icy Mountains.xml b/app/src/main/assets/levelpacks/Icy Mountains.xml
index 1c077de..e481e59 100644
--- a/app/src/main/assets/levelpacks/Icy Mountains.xml
+++ b/app/src/main/assets/levelpacks/Icy Mountains.xml
@@ -43,7 +43,7 @@
-
+
@@ -57,13 +57,13 @@
-
+
-
+
-
+
@@ -77,13 +77,197 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/de/frajul/endlessroll/entities/Obstacle.java b/app/src/main/java/de/frajul/endlessroll/entities/Obstacle.java
index d30e13d..7bdfb77 100644
--- a/app/src/main/java/de/frajul/endlessroll/entities/Obstacle.java
+++ b/app/src/main/java/de/frajul/endlessroll/entities/Obstacle.java
@@ -39,8 +39,10 @@ public class Obstacle extends Entity {
gridSize = calcGridSize();
}
- public boolean isInSightDistance(Camera camera) {
- return super.getLeftEdge() <= camera.getX() + 2;
+ public boolean isMovePathInSightDistance(Camera camera) {
+ if (moveComponent == null)
+ return false;
+ return moveComponent.getLeftmostPosition() - super.getWidth() / 2 <= camera.getX() + 2;
}
private Vector calcGridSize() {
@@ -51,14 +53,17 @@ public class Obstacle extends Entity {
return new Vector(gridWidth, gridHeight);
}
- public void moveWithMoveComponent(float frameTime) {
- float distance = frameTime * moveComponent.getSpeed() * 0.001f;
+ public void moveWithMoveComponent(float frameTime, Player player) {
+ if(moveComponent.isHasPlayerXSpeed()){
+ moveComponent.calcSpeedForPlayerSpeed(player);
+ }
+ float distance = frameTime * moveComponent.getSpeed();
moveProgress += moveDirection * distance / moveComponent.getLength();
- if(moveProgress < 0) {
+ if (moveProgress < 0) {
moveProgress *= -1;
moveDirection *= -1;
}
- if(moveProgress > 1) {
+ if (moveProgress > 1) {
moveProgress = 2 - moveProgress;
moveDirection *= -1;
}
diff --git a/app/src/main/java/de/frajul/endlessroll/levels/MoveComponent.java b/app/src/main/java/de/frajul/endlessroll/levels/MoveComponent.java
index 9bd3ef3..7a45e3f 100644
--- a/app/src/main/java/de/frajul/endlessroll/levels/MoveComponent.java
+++ b/app/src/main/java/de/frajul/endlessroll/levels/MoveComponent.java
@@ -1,10 +1,10 @@
package de.frajul.endlessroll.levels;
-import de.frajul.endlessroll.data.Vector;
-import de.frajul.endlessroll.entities.Vertex;
-
import org.simpleframework.xml.Attribute;
+import de.frajul.endlessroll.data.Vector;
+import de.frajul.endlessroll.entities.Player;
+
public class MoveComponent {
@Attribute
@@ -17,12 +17,15 @@ public class MoveComponent {
private float direction;
@Attribute
private float speed;
+ @Attribute
+ private boolean hasPlayerXSpeed;
+ private final float TRANSITION_VALUE = 0.001f;
private Vector position;
private float triangleWidth;
private float triangleHeight;
- public void init(Vector obstaclePosition){
+ public void init(Vector obstaclePosition) {
double rotationRadians = Math.toRadians(getRotation());
double invertRotationRadians = Math.toRadians(90 - getRotation());
@@ -34,6 +37,8 @@ public class MoveComponent {
x -= startOffset * triangleWidth;
y -= startOffset * triangleHeight;
this.position = new Vector(x, y);
+
+ speed *= TRANSITION_VALUE;
}
public float getLength() {
@@ -56,8 +61,24 @@ public class MoveComponent {
return speed;
}
- public Vector getPositionForProgress(float progress){
- return new Vector(position.x + triangleWidth * progress, position.y + triangleHeight * progress);
+ public boolean isHasPlayerXSpeed() {
+ return hasPlayerXSpeed;
+ }
+
+ public void calcSpeedForPlayerSpeed(Player player) {
+ float xSpeed = player.getSpeed();
+ double invertRotationRadians = Math.toRadians(90 - getRotation());
+ float ySpeed = (float) (xSpeed * Math.sin(invertRotationRadians));
+ speed = (float) Math.sqrt(xSpeed * xSpeed + ySpeed * ySpeed);
+ }
+
+ public float getLeftmostPosition() {
+ return triangleWidth >= 0 ? position.x : position.x + triangleWidth;
+ }
+
+ public Vector getPositionForProgress(float progress) {
+ return new Vector(position.x + triangleWidth * progress,
+ position.y + triangleHeight * progress);
}
}
diff --git a/app/src/main/java/de/frajul/endlessroll/main/game/Scene.java b/app/src/main/java/de/frajul/endlessroll/main/game/Scene.java
index 516828d..b6f881f 100644
--- a/app/src/main/java/de/frajul/endlessroll/main/game/Scene.java
+++ b/app/src/main/java/de/frajul/endlessroll/main/game/Scene.java
@@ -9,11 +9,9 @@ import de.frajul.endlessroll.data.Vector;
import de.frajul.endlessroll.entities.AnimatedEntity;
import de.frajul.endlessroll.entities.Background;
import de.frajul.endlessroll.entities.collectables.Collectables;
-import de.frajul.endlessroll.entities.collectables.Energy;
import de.frajul.endlessroll.entities.Entity;
import de.frajul.endlessroll.entities.Obstacle;
import de.frajul.endlessroll.entities.Player;
-import de.frajul.endlessroll.entities.collectables.Star;
import de.frajul.endlessroll.entities.particles.ParticleSystem;
import de.frajul.endlessroll.entities.textures.TexturePack;
import de.frajul.endlessroll.entities.tileLists.Ceiling;
@@ -92,8 +90,8 @@ public abstract class Scene {
Entity entity = iterator.next();
if(entity instanceof Obstacle){
Obstacle obstacle = (Obstacle) entity;
- if (obstacle.isMoving() && obstacle.isInSightDistance(camera))
- obstacle.moveWithMoveComponent(timer.getFrameTimeSeconds());
+ if (obstacle.isMoving() && obstacle.isMovePathInSightDistance(camera))
+ obstacle.moveWithMoveComponent(timer.getFrameTimeSeconds(), player);
}
boolean remove = updateEntity(entity, timer);
if (remove)