Tools are now moved to left if colliding with obstacle which is moving left
This commit is contained in:
parent
b49fa71d1f
commit
0ce9ca1c17
@ -2,6 +2,7 @@ package de.frajul.endlessroll.entities.collision;
|
|||||||
|
|
||||||
import de.frajul.endlessroll.data.Vector;
|
import de.frajul.endlessroll.data.Vector;
|
||||||
import de.frajul.endlessroll.entities.Entity;
|
import de.frajul.endlessroll.entities.Entity;
|
||||||
|
import de.frajul.endlessroll.entities.Obstacle;
|
||||||
import de.frajul.endlessroll.entities.Player;
|
import de.frajul.endlessroll.entities.Player;
|
||||||
import de.frajul.endlessroll.entities.collision.collisionData.EntityCollisionData;
|
import de.frajul.endlessroll.entities.collision.collisionData.EntityCollisionData;
|
||||||
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
import de.frajul.endlessroll.entities.collision.geometry.Circle;
|
||||||
@ -201,7 +202,6 @@ public class CollisionDetector {
|
|||||||
return new EntityCollisionData(null, null);
|
return new EntityCollisionData(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Edge circleQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
private Edge circleQuadCollisionEdge(Circle circle, Vector circleMovement, Quad quad, Vector quadMovement) {
|
||||||
boolean circleFullyInsideQuad = false;
|
boolean circleFullyInsideQuad = false;
|
||||||
if (circle.getPosition().getX() + circle.getRadius() <= quad.getRightEdge() && circle
|
if (circle.getPosition().getX() + circle.getRadius() <= quad.getRightEdge() && circle
|
||||||
|
@ -19,7 +19,7 @@ public enum ToolType {
|
|||||||
RAMP(R.string.tool_name_ramp, R.string.tool_description_ramp, R.drawable.tools_ramp,
|
RAMP(R.string.tool_name_ramp, R.string.tool_description_ramp, R.drawable.tools_ramp,
|
||||||
R.drawable.tools_ramp_button, 0, 1, 5,
|
R.drawable.tools_ramp_button, 0, 1, 5,
|
||||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 3000, 1000)),
|
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 3000, 1000)),
|
||||||
SPRING(R.string.tool_name_spring, R.string.tool_description_spring, R.drawable.tools_spring,
|
SPRING(R.string.tool_name_spring, R.string.tool_description_spring, R.drawable.tools_spring_2,
|
||||||
R.drawable.tools_spring_button, 5, 2, 5,
|
R.drawable.tools_spring_button, 5, 2, 5,
|
||||||
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 4000, 2000)),
|
new ToolUpgrade(ToolUpgradeType.COOLDOWN, 4000, 2000)),
|
||||||
BOMB(R.string.tool_name_bomb, R.string.tool_description_bomb, R.drawable.tools_bomb,
|
BOMB(R.string.tool_name_bomb, R.string.tool_description_bomb, R.drawable.tools_bomb,
|
||||||
|
@ -83,7 +83,7 @@ public class GameScene extends Scene {
|
|||||||
|
|
||||||
public Tool addTool(ToolType type, Vector position, Physics physics) throws Exception {
|
public Tool addTool(ToolType type, Vector position, Physics physics) throws Exception {
|
||||||
Tool tool = type.newInstance(position, particleSystem, gameActivity.getSoundManager());
|
Tool tool = type.newInstance(position, particleSystem, gameActivity.getSoundManager());
|
||||||
physics.checkSingleToolCollision(tool, this);
|
physics.checkSingleToolCollision(tool, this, true);
|
||||||
|
|
||||||
if (tool == null)
|
if (tool == null)
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -30,6 +30,7 @@ import de.frajul.endlessroll.main.game.Timer;
|
|||||||
public class Physics {
|
public class Physics {
|
||||||
|
|
||||||
public final float GRAVITY_FORCE = .0000025f;
|
public final float GRAVITY_FORCE = .0000025f;
|
||||||
|
private final float MAX_TOOL_OBST_LEFT_EDGE_TOLERANCE = 0.05f;
|
||||||
private CollisionDetector detector;
|
private CollisionDetector detector;
|
||||||
|
|
||||||
public Physics() {
|
public Physics() {
|
||||||
@ -53,12 +54,12 @@ public class Physics {
|
|||||||
public synchronized void checkToolCollision(Scene scene) {
|
public synchronized void checkToolCollision(Scene scene) {
|
||||||
synchronized (scene.getTools()) {
|
synchronized (scene.getTools()) {
|
||||||
for (Tool tool : scene.getTools()) {
|
for (Tool tool : scene.getTools()) {
|
||||||
checkSingleToolCollision(tool, scene);
|
checkSingleToolCollision(tool, scene, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void checkSingleToolCollision(Tool tool, Scene scene) {
|
public synchronized void checkSingleToolCollision(Tool tool, Scene scene, boolean toolWasJustPlaced) {
|
||||||
if (tool.isFloating())
|
if (tool.isFloating())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -69,10 +70,16 @@ public class Physics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Obstacle collidingObstacle = getHighestObstacleToolIsCollidingWith(tool, scene);
|
Obstacle collidingObstacle = getHighestObstacleToolIsCollidingWith(tool, scene);
|
||||||
if (collidingObstacle != null && tool.getBottomEdge() <= collidingObstacle.getTopEdge()) {
|
if(collidingObstacle != null){
|
||||||
tool.getMovement().y = 0;
|
if(!toolWasJustPlaced && collidingObstacle.isMoving() && isToolCollidingWithMoveableObstacleOnLeftEdge(tool, collidingObstacle)){
|
||||||
tool.setToTerrain(collidingObstacle.getTopEdge());
|
tool.getPosition().x = collidingObstacle.getPosition().x - collidingObstacle.getWidth() / 2 - tool.getWidth() / 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tool.getMovement().y = 0;
|
||||||
|
tool.setToTerrain(collidingObstacle.getTopEdge());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -178,4 +185,14 @@ public class Physics {
|
|||||||
} else
|
} else
|
||||||
return new EntityCollisionData(null, null);
|
return new EntityCollisionData(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isToolCollidingWithMoveableObstacleOnLeftEdge(Tool tool, Obstacle obstacle){
|
||||||
|
if(obstacle.getMovement().getX() < 0)
|
||||||
|
{
|
||||||
|
if(Math.abs(tool.getRightEdge() - obstacle.getLeftEdge()) <= MAX_TOOL_OBST_LEFT_EDGE_TOLERANCE)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user