diff --git a/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml b/app/build/intermediates/assets/debug/levelpacks/Grasslands.xml index 84c4f45..f3f1549 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 84c4f45..f3f1549 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 019adea..6f9fd15 100644 --- a/app/src/main/assets/levelpacks/Icy Mountains.xml +++ b/app/src/main/assets/levelpacks/Icy Mountains.xml @@ -1,290 +1,93 @@ ICY_MOUNTAINS - + - - + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file 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 304870d..af2fd86 100644 --- a/app/src/main/java/de/frajul/endlessroll/entities/Obstacle.java +++ b/app/src/main/java/de/frajul/endlessroll/entities/Obstacle.java @@ -39,10 +39,10 @@ public class Obstacle extends Entity { gridSize = calcGridSize(); } - public boolean isMovePathInSightDistance(Camera camera) { + public boolean isPlayerOverTrigger(Player player) { if (moveComponent == null) return false; - return moveComponent.getLeftmostPosition() - super.getWidth() / 2 <= camera.getX() + 2; + return moveComponent.getLeftmostPosition() - super.getWidth() / 2 - moveComponent.getTriggerDistance() <= player.getRightEdge(); } private Vector calcGridSize() { @@ -67,7 +67,12 @@ public class Obstacle extends Entity { moveProgress = 2 - moveProgress; moveDirection *= -1; } + Vector oldPosition = new Vector(super.getPosition()); super.setPosition(moveComponent.getPositionForProgress(moveProgress)); + Vector newPosition = new Vector(super.getPosition()); + Vector move = newPosition.translate(oldPosition.negate()); + move.mul(1 / frameTime); + super.setMovement(move); } public boolean isMoving() { diff --git a/app/src/main/java/de/frajul/endlessroll/entities/collision/CollisionDetector.java b/app/src/main/java/de/frajul/endlessroll/entities/collision/CollisionDetector.java index a5131a4..d66102d 100644 --- a/app/src/main/java/de/frajul/endlessroll/entities/collision/CollisionDetector.java +++ b/app/src/main/java/de/frajul/endlessroll/entities/collision/CollisionDetector.java @@ -147,7 +147,7 @@ public class CollisionDetector { } private Edge circleQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) { - Vector relativeMovement = circleMovement.translate(quadMovement); + Vector relativeMovement = circleMovement.translate(quadMovement.negate()); //LEFT || TOP || BOTTOM if (relativeMovement.x > 0) { @@ -156,7 +156,7 @@ public class CollisionDetector { float toLeftDistance = quad.getLeftEdge() - circle.getCenter().x - circle.getRadius(); float actualY = toLeftDistance * (relativeMovement.y / relativeMovement.x) + circle .getCenter().y + circle.getRadius(); - if (actualY < quad.getBottomEdge()) + if (actualY <= quad.getBottomEdge()) return Edge.BOTTOM; else return Edge.LEFT; @@ -166,10 +166,10 @@ public class CollisionDetector { float toLeftDistance = quad.getLeftEdge() - circle.getCenter().x - circle.getRadius(); float actualY = toLeftDistance * (relativeMovement.y / relativeMovement.x) + circle .getCenter().y - circle.getRadius(); - if (actualY < quad.getTopEdge()) - return Edge.LEFT; - else + if (actualY > quad.getTopEdge()) return Edge.TOP; + else + return Edge.LEFT; } else { return Edge.LEFT; } @@ -181,7 +181,7 @@ public class CollisionDetector { float toRightDistance = quad.getRightEdge() - circle.getCenter().x + circle.getRadius(); float actualY = toRightDistance * (relativeMovement.y / relativeMovement.x) + circle .getCenter().y + circle.getRadius(); - if (actualY < quad.getBottomEdge()) + if (actualY <= quad.getBottomEdge()) return Edge.BOTTOM; else return Edge.RIGHT; @@ -191,10 +191,10 @@ public class CollisionDetector { float toRightDistance = quad.getRightEdge() - circle.getCenter().x + circle.getRadius(); float actualY = toRightDistance * (relativeMovement.y / relativeMovement.x) + circle .getCenter().y - circle.getRadius(); - if (actualY < quad.getTopEdge()) - return Edge.RIGHT; - else + if (actualY > quad.getTopEdge()) return Edge.TOP; + else + return Edge.RIGHT; } else { return Edge.RIGHT; } 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 e4cfda0..5fce6fd 100644 --- a/app/src/main/java/de/frajul/endlessroll/levels/MoveComponent.java +++ b/app/src/main/java/de/frajul/endlessroll/levels/MoveComponent.java @@ -19,6 +19,8 @@ public class MoveComponent { private float speed; @Attribute private boolean hasPlayerXSpeed; + @Attribute + private float triggerDistance; public final float TRANSITION_VALUE = 0.001f; private Vector position; @@ -63,6 +65,10 @@ public class MoveComponent { return hasPlayerXSpeed; } + public float getTriggerDistance() { + return triggerDistance; + } + public void calcSpeedForPlayerSpeed(Player player) { float xSpeed = player.getSpeed(); double invertRotationRadians = Math.toRadians(90 - getRotation()); 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 b6f881f..a459538 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 @@ -8,10 +8,10 @@ import java.util.List; 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.Entity; import de.frajul.endlessroll.entities.Obstacle; import de.frajul.endlessroll.entities.Player; +import de.frajul.endlessroll.entities.collectables.Collectables; import de.frajul.endlessroll.entities.particles.ParticleSystem; import de.frajul.endlessroll.entities.textures.TexturePack; import de.frajul.endlessroll.entities.tileLists.Ceiling; @@ -38,7 +38,8 @@ public abstract class Scene { protected Ceiling ceiling; protected Player player; - protected List uncategorizedEntities = Collections.synchronizedList(new ArrayList()); + protected List uncategorizedEntities = Collections + .synchronizedList(new ArrayList()); protected List obstacles = Collections.synchronizedList(new ArrayList()); protected List tools = Collections.synchronizedList(new ArrayList()); protected Collectables collectables = new Collectables(); @@ -58,7 +59,7 @@ public abstract class Scene { this.textures = texturePack; } - public void reset(){ + public void reset() { uncategorizedEntities.clear(); obstacles.clear(); tools.clear(); @@ -83,14 +84,14 @@ public abstract class Scene { uncategorizedEntities.remove(playerArrow); } - private void updateEntityList(List list, Timer timer){ - synchronized (list){ + private void updateEntityList(List list, Timer timer) { + synchronized (list) { Iterator iterator = list.iterator(); - while(iterator.hasNext()) { + while (iterator.hasNext()) { Entity entity = iterator.next(); - if(entity instanceof Obstacle){ + if (entity instanceof Obstacle) { Obstacle obstacle = (Obstacle) entity; - if (obstacle.isMoving() && obstacle.isMovePathInSightDistance(camera)) + if (obstacle.isMoving() && obstacle.isPlayerOverTrigger(player)) obstacle.moveWithMoveComponent(timer.getFrameTimeSeconds(), player); } boolean remove = updateEntity(entity, timer); @@ -100,21 +101,22 @@ public abstract class Scene { } } - private boolean updateEntity(Entity entity, Timer timer){ + private boolean updateEntity(Entity entity, Timer timer) { if (entity instanceof AnimatedEntity) ((AnimatedEntity) entity).update(timer); - Vector movement = entity.getMovement(); - Vector finalMovement = new Vector(movement).mul(timer.getFrameTimeSeconds()); - if(finalMovement.y < MAX_Y_MOVEMENT) - finalMovement.y = MAX_Y_MOVEMENT; - entity.move(finalMovement); - if (entity.equals(player)) - moveEnviroment(finalMovement.x); + if (!(entity instanceof Obstacle)) { + Vector movement = entity.getMovement(); + Vector finalMovement = new Vector(movement).mul(timer.getFrameTimeSeconds()); + if (finalMovement.y < MAX_Y_MOVEMENT) + finalMovement.y = MAX_Y_MOVEMENT; + entity.move(finalMovement); + if (entity.equals(player)) + moveEnviroment(finalMovement.x); + } if (entity.isDestroyed() && entity.getDestroyEffect() != null) - entity.getDestroyEffect() - .createEffect(particleSystem, new Vector(entity.getPosition()), - new Vector(entity.getWidth(), entity.getHeight())).start(); + entity.getDestroyEffect().createEffect(particleSystem, new Vector(entity.getPosition()), + new Vector(entity.getWidth(), entity.getHeight())).start(); if (entity.getRightEdge() - camera.getX() < -3f || entity.isDestroyed()) { return true; }