diff --git a/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java b/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java index f98dc363ed75c2d7e7b905905492b4e1166e3597..aeec7a1a8046f2edb410a5bdc5d8203767cfcfd1 100644 --- a/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java +++ b/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java @@ -3,7 +3,6 @@ package cz.nic.tablexia.game.games.pursuit; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.math.Bezier; import com.badlogic.gdx.math.CatmullRomSpline; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Action; @@ -21,7 +20,6 @@ import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.Viewport; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -155,10 +153,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { private String clickMapTextureName; private String mapTextureName; - // TODO: 21.6.16 remove temporary listener - private List<Vector2> tempPositions = new ArrayList<Vector2>(); - - @Override protected Viewport createViewport() { return new ExtendViewport(0, TablexiaSettings.getMinWorldHeight()); @@ -253,17 +247,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { contentGroup = new Group(); ScaleUtil.setFullScreen(contentGroup, getStage()); getStage().addActor(contentGroup); - - getStage().addListener(new ClickListener(){ - - @Override - public void clicked(InputEvent event, float x, float y) { - - tempPositions.add(new Vector2((x-grid.getX())/grid.getWidth(),(y-grid.getY())/grid.getHeight())); - - super.clicked(event, x, y); - } - }); prepareBackground(); prepareGrid(); @@ -419,7 +402,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { private void prepareVehicle() { VehicleType vehicleType = TextureHelper.getVehicleTextureName(getRandom(), mapNumber); - Point vehiclePosition = new Point(0, 0); + final Point vehiclePosition = new Point(0, 0); Point vehicleSize = new Point(vehicleType.getVehicleSize().x, vehicleType.getVehicleSize().y); Music[] vehicleSounds = getVehicleSounds(vehicleType); @@ -454,13 +437,12 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { Point vehicleCenter = new Point(vehicle.getX()+vehicle.getWidth()/2, vehicle.getY()+vehicle.getHeight()/2); Point flagCenter = new Point(finishFlag.getX()+finishFlag.getWidth()/2, finishFlag.getY()+finishFlag.getHeight()/2); - float angle = (float) Math.toDegrees(Math.atan2(x, y)); - float vhtoflagAngle = (float) Math.toDegrees(Math.atan2(flagCenter.x-vehicleCenter.x,flagCenter.y-vehicleCenter.y)); - if (Math.abs(angle - vhtoflagAngle) < 15) { - float offsetX = 0; - float offsetY = -grid.getY(); -// Vector2[] points = {new Vector2(offsetX + 0.86f * grid.getWidth(), offsetY + 0.1f * grid.getHeight()), new Vector2(offsetX + 0.86f * grid.getWidth(), offsetY + 0.2f * grid.getHeight()), new Vector2(offsetX + 0.79f * grid.getWidth(), offsetY + 0.3f * grid.getHeight()), new Vector2(offsetX + 0.67f * grid.getWidth(), offsetY + 0.25f * grid.getHeight()), new Vector2(offsetX + 0.53f * grid.getWidth(), offsetY + 0.2f * grid.getHeight()), new Vector2(offsetX + 0.4f * grid.getWidth(), offsetY + 0.2f * grid.getHeight()), new Vector2(offsetX + 0.3f * grid.getWidth(), offsetY + 0.31f * grid.getHeight()), new Vector2(offsetX + 0.26f * grid.getWidth(), offsetY + 0.45f * grid.getHeight()), new Vector2(offsetX + 0.22f * grid.getWidth(), offsetY + 0.61f * grid.getHeight()), new Vector2(offsetX + 0.22f * grid.getWidth(), offsetY + 0.72f * grid.getHeight()), new Vector2(offsetX + 0.23f * grid.getWidth(), offsetY + 0.83f * grid.getHeight())}; - final CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(Maps.values()[mapNumber].getPursuitPositionDefinition().getPointsWithRotation(grid.getRotation()),false); + float touchAngle = (float) Math.toDegrees(Math.atan2(x, y)); + float vehicleToFlagAngle = (float) Math.toDegrees(Math.atan2(flagCenter.x-vehicleCenter.x,flagCenter.y-vehicleCenter.y)); + + double distance = Math.hypot(x - start.x, y - start.y); + if (Math.abs(touchAngle - vehicleToFlagAngle) < 20 && distance > 20) { + final CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(Maps.values()[mapNumber].getPursuitPositionDefinition().getPointsWithRotation(grid.getRotation(), vehiclePosition.x,vehiclePosition.y),false); path.approxLength(100); MoveAlongAction moveAlongAction = new MoveAlongAction(path, 5f){ @@ -480,18 +462,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { vehicle.addAction(Actions.sequence(moveAlongAction,new RunnableAction() { @Override public void run() { -// Log.debug(getClass(),"Map # : " + mapNumber); -// String tmp = ""; -// String map = "MAP_"+(mapNumber+1)+"(" +"new Vector2(" + Maps.values()[mapNumber].getStartPointCoords().x+"f,"+ Maps.values()[mapNumber].getStartPointCoords().y+"f)"; -// for(Vector2 v : tempPositions){ -// MAP_11(new Vector2(0,0),new Vector2(100,100),new Vector2(0,0),new Vector2(100,100),new Vector2(0,0),new Vector2(100,100)), -// Log.debug(getClass(),"MAP_"+mapNumber+"(x:" + v.x + " y: " + v.y); -// tmp+=",new Vector2("+round2(v.x)+"f,"+round2(v.y)+"f)"; - -// } -// tmp+=", new Vector2("+Maps.values()[mapNumber].getEndPointCoords().x+"f," + Maps.values()[mapNumber].getEndPointCoords().y +"f )),"; -// Log.debug("POINTS",map+tmp); - tempPositions.clear(); showGameResultDialog(); vehicle.clear(); vehicle.remove(); @@ -509,14 +479,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { vehicle.setVisible(false); } - public static float round2(float number) { - int pow = 10; - for (int i = 1; i < 3; i++) - pow *= 10; - float tmp = number * pow; - return (float) (int) ((tmp - (int) tmp) >= 0.5f ? tmp + 1 : tmp) / pow; - } - private void prepareFinishFlag() { finishFlag = new Image(getScreenTextureRegion(TextureHelper.getFinishFlagTextureName())); finishFlag.setSize(TextureHelper.FINISH_FLAG_SIZE.x, TextureHelper.FINISH_FLAG_SIZE.y); diff --git a/core/src/cz/nic/tablexia/game/games/pursuit/helper/PositionHelper.java b/core/src/cz/nic/tablexia/game/games/pursuit/helper/PositionHelper.java index 1e3144fe69394c4a0a8440d55912b0c54aa6517c..08b028e3e51380d27cc4a952947cc15227d465ec 100644 --- a/core/src/cz/nic/tablexia/game/games/pursuit/helper/PositionHelper.java +++ b/core/src/cz/nic/tablexia/game/games/pursuit/helper/PositionHelper.java @@ -36,22 +36,21 @@ public class PositionHelper { public enum PursuitPositionDefinition { - // FIXME: 20.6.16 missing first position // TODO: 21.6.16 correct some positions - MAP_1(new Point(0.866f, 0.1f), new Point(0.859f, 0.211f), new Point(0.824f, 0.276f), new Point(0.792f, 0.312f), new Point(0.719f, 0.268f), new Point(0.666f, 0.241f), new Point(0.608f, 0.221f), new Point(0.534f, 0.203f), new Point(0.448f, 0.194f), new Point(0.374f, 0.224f), new Point(0.328f, 0.286f), new Point(0.293f, 0.37f), new Point(0.265f, 0.469f), new Point(0.237f, 0.575f), new Point(0.215f, 0.671f), new Point(0.228f, 0.772f), new Point(0.258f, 0.846f), new Point(0.26f, 0.85f)), - MAP_2(new Point(0.64f, 0.11f), new Point(0.68f, 0.214f), new Point(0.738f, 0.308f), new Point(0.777f, 0.395f), new Point(0.683f, 0.449f), new Point(0.613f, 0.509f), new Point(0.54f, 0.573f), new Point(0.473f, 0.658f), new Point(0.4f, 0.728f), new Point(0.322f, 0.711f), new Point(0.26f, 0.666f), new Point(0.208f, 0.757f), new Point(0.22f, 0.75f)), - MAP_3(new Point(0.08f, 0.41f), new Point(0.182f, 0.461f), new Point(0.271f, 0.466f), new Point(0.368f, 0.475f), new Point(0.376f, 0.599f), new Point(0.387f, 0.698f), new Point(0.398f, 0.755f), new Point(0.361f, 0.824f), new Point(0.394f, 0.868f), new Point(0.461f, 0.877f), new Point(0.531f, 0.85f), new Point(0.627f, 0.897f), new Point(0.691f, 0.899f), new Point(0.77f, 0.903f), new Point(0.776f, 0.855f), new Point(0.758f, 0.811f), new Point(0.776f, 0.754f), new Point(0.79f, 0.71f)), - MAP_4(new Point(0.95f, 0.33f), new Point(0.866f, 0.307f), new Point(0.766f, 0.342f), new Point(0.709f, 0.391f), new Point(0.588f, 0.452f), new Point(0.512f, 0.497f), new Point(0.425f, 0.588f), new Point(0.355f, 0.667f), new Point(0.278f, 0.595f), new Point(0.19f, 0.574f), new Point(0.18f, 0.57f)), - MAP_5(new Point(0.94f, 0.12f), new Point(0.928f, 0.333f), new Point(0.784f, 0.373f), new Point(0.678f, 0.412f), new Point(0.645f, 0.525f), new Point(0.578f, 0.582f), new Point(0.549f, 0.649f), new Point(0.597f, 0.733f), new Point(0.68f, 0.77f), new Point(0.784f, 0.793f), new Point(0.863f, 0.843f), new Point(0.86f, 0.82f)), - MAP_6(new Point(0.95f, 0.17f), new Point(0.85f, 0.18f), new Point(0.763f, 0.171f), new Point(0.68f, 0.136f), new Point(0.602f, 0.092f), new Point(0.538f, 0.036f), new Point(0.509f, 0.081f), new Point(0.438f, 0.077f), new Point(0.392f, 0.142f), new Point(0.369f, 0.199f), new Point(0.377f, 0.251f), new Point(0.436f, 0.306f), new Point(0.45f, 0.32f)), - MAP_7(new Point(0.56f, 0.07f), new Point(0.43f, 0.16f), new Point(0.347f, 0.246f), new Point(0.373f, 0.36f), new Point(0.443f, 0.465f), new Point(0.499f, 0.58f), new Point(0.431f, 0.657f), new Point(0.379f, 0.738f), new Point(0.356f, 0.825f), new Point(0.36f, 0.83f)), - MAP_8(new Point(0.16f, 0.19f), new Point(0.237f, 0.255f), new Point(0.287f, 0.316f), new Point(0.351f, 0.354f), new Point(0.285f, 0.44f), new Point(0.212f, 0.521f), new Point(0.134f, 0.597f), new Point(0.071f, 0.679f), new Point(0.118f, 0.718f), new Point(0.204f, 0.754f), new Point(0.272f, 0.733f), new Point(0.343f, 0.798f), new Point(0.425f, 0.856f), new Point(0.496f, 0.919f), new Point(0.596f, 0.853f), new Point(0.672f, 0.823f), new Point(0.759f, 0.82f), new Point(0.818f, 0.828f), new Point(0.825f, 0.801f), new Point(0.83f, 0.79f)), - MAP_9(new Point(0.15f, 0.11f), new Point(0.193f, 0.179f), new Point(0.255f, 0.19f), new Point(0.164f, 0.426f), new Point(0.234f, 0.494f), new Point(0.307f, 0.661f), new Point(0.356f, 0.723f), new Point(0.435f, 0.776f), new Point(0.509f, 0.805f), new Point(0.622f, 0.831f), new Point(0.719f, 0.837f), new Point(0.808f, 0.834f), new Point(0.81f, 0.83f)), - MAP_10(new Point(0.22f, 0.07f), new Point(0.214f, 0.293f), new Point(0.204f, 0.421f), new Point(0.449f, 0.422f), new Point(0.574f, 0.561f), new Point(0.678f, 0.49f), new Point(0.806f, 0.75f), new Point(0.761f, 0.838f), new Point(0.76f, 0.84f)), - MAP_11(new Point(0.61f, 0.11f), new Point(0.582f, 0.258f), new Point(0.571f, 0.364f), new Point(0.599f, 0.442f), new Point(0.641f, 0.499f), new Point(0.646f, 0.584f), new Point(0.702f, 0.626f), new Point(0.81f, 0.644f), new Point(0.801f, 0.693f), new Point(0.678f, 0.683f), new Point(0.553f, 0.688f), new Point(0.366f, 0.697f), new Point(0.302f, 0.688f), new Point(0.214f, 0.697f), new Point(0.21f, 0.69f)), - MAP_12(new Point(0.89f, 0.17f), new Point(0.806f, 0.118f), new Point(0.565f, 0.111f), new Point(0.43f, 0.102f), new Point(0.385f, 0.164f), new Point(0.436f, 0.294f), new Point(0.473f, 0.442f), new Point(0.492f, 0.562f), new Point(0.444f, 0.676f), new Point(0.385f, 0.792f), new Point(0.278f, 0.803f), new Point(0.223f, 0.843f), new Point(0.208f, 0.868f), new Point(0.2f, 0.85f)), - MAP_13(new Point(0.08f, 0.06f), new Point(0.189f, 0.227f), new Point(0.414f, 0.316f), new Point(0.665f, 0.51f), new Point(0.797f, 0.632f), new Point(0.88f, 0.735f), new Point(0.88f, 0.73f)), - MAP_14(new Point(0.18f, 0.08f), new Point(0.212f, 0.239f), new Point(0.29f, 0.321f), new Point(0.399f, 0.382f), new Point(0.342f, 0.503f), new Point(0.311f, 0.659f), new Point(0.308f, 0.773f), new Point(0.324f, 0.843f), new Point(0.32f, 0.84f)); + MAP_1(new Point(0.866f, 0.1f),new Point(0.866f, 0.1f), new Point(0.859f, 0.211f), new Point(0.824f, 0.276f), new Point(0.792f, 0.312f), new Point(0.719f, 0.268f), new Point(0.666f, 0.241f), new Point(0.608f, 0.221f), new Point(0.534f, 0.203f), new Point(0.448f, 0.194f), new Point(0.374f, 0.224f), new Point(0.328f, 0.286f), new Point(0.293f, 0.37f), new Point(0.265f, 0.469f), new Point(0.237f, 0.575f), new Point(0.215f, 0.671f), new Point(0.228f, 0.772f), new Point(0.258f, 0.846f), new Point(0.26f, 0.85f)), + MAP_2(new Point(0.64f, 0.11f),new Point(0.64f, 0.11f), new Point(0.68f, 0.214f), new Point(0.738f, 0.308f), new Point(0.777f, 0.395f), new Point(0.683f, 0.449f), new Point(0.613f, 0.509f), new Point(0.54f, 0.573f), new Point(0.473f, 0.658f), new Point(0.4f, 0.728f), new Point(0.322f, 0.711f), new Point(0.26f, 0.666f), new Point(0.208f, 0.757f), new Point(0.22f, 0.75f)), + MAP_3(new Point(0.08f, 0.41f),new Point(0.08f, 0.41f), new Point(0.182f, 0.461f), new Point(0.271f, 0.466f), new Point(0.368f, 0.475f), new Point(0.376f, 0.599f), new Point(0.387f, 0.698f), new Point(0.398f, 0.755f), new Point(0.361f, 0.824f), new Point(0.394f, 0.868f), new Point(0.461f, 0.877f), new Point(0.531f, 0.85f), new Point(0.627f, 0.897f), new Point(0.691f, 0.899f), new Point(0.77f, 0.903f), new Point(0.776f, 0.855f), new Point(0.758f, 0.811f), new Point(0.776f, 0.754f), new Point(0.79f, 0.71f)), + MAP_4(new Point(0.95f, 0.33f),new Point(0.95f, 0.33f), new Point(0.866f, 0.307f), new Point(0.766f, 0.342f), new Point(0.709f, 0.391f), new Point(0.588f, 0.452f), new Point(0.512f, 0.497f), new Point(0.425f, 0.588f), new Point(0.355f, 0.667f), new Point(0.278f, 0.595f), new Point(0.19f, 0.574f), new Point(0.18f, 0.57f)), + MAP_5(new Point(0.94f, 0.12f),new Point(0.94f, 0.12f), new Point(0.928f, 0.333f), new Point(0.784f, 0.373f), new Point(0.678f, 0.412f), new Point(0.645f, 0.525f), new Point(0.578f, 0.582f), new Point(0.549f, 0.649f), new Point(0.597f, 0.733f), new Point(0.68f, 0.77f), new Point(0.784f, 0.793f), new Point(0.863f, 0.843f), new Point(0.86f, 0.82f)), + MAP_6(new Point(0.95f, 0.17f),new Point(0.95f, 0.17f), new Point(0.85f, 0.18f), new Point(0.763f, 0.171f), new Point(0.68f, 0.136f), new Point(0.602f, 0.092f), new Point(0.538f, 0.036f), new Point(0.509f, 0.081f), new Point(0.438f, 0.077f), new Point(0.392f, 0.142f), new Point(0.369f, 0.199f), new Point(0.377f, 0.251f), new Point(0.436f, 0.306f), new Point(0.45f, 0.32f)), + MAP_7(new Point(0.56f, 0.07f),new Point(0.56f, 0.07f), new Point(0.43f, 0.16f), new Point(0.347f, 0.246f), new Point(0.373f, 0.36f), new Point(0.443f, 0.465f), new Point(0.499f, 0.58f), new Point(0.431f, 0.657f), new Point(0.379f, 0.738f), new Point(0.356f, 0.825f), new Point(0.36f, 0.83f)), + MAP_8(new Point(0.16f, 0.19f),new Point(0.16f, 0.19f), new Point(0.237f, 0.255f), new Point(0.287f, 0.316f), new Point(0.351f, 0.354f), new Point(0.285f, 0.44f), new Point(0.212f, 0.521f), new Point(0.134f, 0.597f), new Point(0.071f, 0.679f), new Point(0.118f, 0.718f), new Point(0.204f, 0.754f), new Point(0.272f, 0.733f), new Point(0.343f, 0.798f), new Point(0.425f, 0.856f), new Point(0.496f, 0.919f), new Point(0.596f, 0.853f), new Point(0.672f, 0.823f), new Point(0.759f, 0.82f), new Point(0.818f, 0.828f), new Point(0.825f, 0.801f), new Point(0.83f, 0.79f)), + MAP_9(new Point(0.15f, 0.11f),new Point(0.15f, 0.11f), new Point(0.193f, 0.179f), new Point(0.255f, 0.19f), new Point(0.164f, 0.426f), new Point(0.234f, 0.494f), new Point(0.307f, 0.661f), new Point(0.356f, 0.723f), new Point(0.435f, 0.776f), new Point(0.509f, 0.805f), new Point(0.622f, 0.831f), new Point(0.719f, 0.837f), new Point(0.808f, 0.834f), new Point(0.81f, 0.83f)), + MAP_10(new Point(0.22f, 0.07f),new Point(0.22f, 0.07f), new Point(0.214f, 0.293f), new Point(0.204f, 0.421f), new Point(0.449f, 0.422f), new Point(0.574f, 0.561f), new Point(0.678f, 0.49f), new Point(0.806f, 0.75f), new Point(0.761f, 0.838f), new Point(0.76f, 0.84f)), + MAP_11(new Point(0.61f, 0.11f),new Point(0.61f, 0.11f), new Point(0.582f, 0.258f), new Point(0.571f, 0.364f), new Point(0.599f, 0.442f), new Point(0.641f, 0.499f), new Point(0.646f, 0.584f), new Point(0.702f, 0.626f), new Point(0.81f, 0.644f), new Point(0.801f, 0.693f), new Point(0.678f, 0.683f), new Point(0.553f, 0.688f), new Point(0.366f, 0.697f), new Point(0.302f, 0.688f), new Point(0.214f, 0.697f), new Point(0.21f, 0.69f)), + MAP_12(new Point(0.89f, 0.17f),new Point(0.89f, 0.17f), new Point(0.806f, 0.118f), new Point(0.565f, 0.111f), new Point(0.43f, 0.102f), new Point(0.385f, 0.164f), new Point(0.436f, 0.294f), new Point(0.473f, 0.442f), new Point(0.492f, 0.562f), new Point(0.444f, 0.676f), new Point(0.385f, 0.792f), new Point(0.278f, 0.803f), new Point(0.223f, 0.843f), new Point(0.208f, 0.868f), new Point(0.2f, 0.85f)), + MAP_13(new Point(0.08f, 0.06f),new Point(0.08f, 0.06f), new Point(0.189f, 0.227f), new Point(0.414f, 0.316f), new Point(0.665f, 0.51f), new Point(0.797f, 0.632f), new Point(0.88f, 0.735f), new Point(0.88f, 0.73f)), + MAP_14(new Point(0.18f, 0.08f),new Point(0.18f, 0.08f), new Point(0.212f, 0.239f), new Point(0.29f, 0.321f), new Point(0.399f, 0.382f), new Point(0.342f, 0.503f), new Point(0.311f, 0.659f), new Point(0.308f, 0.773f), new Point(0.324f, 0.843f), new Point(0.32f, 0.84f)); private Point[] points; @@ -63,7 +62,7 @@ public class PositionHelper { return points; } - public Vector2[] getPointsWithRotation(float rotation) { + public Vector2[] getPointsWithRotation(float rotation, float x, float y) { RotationDefinition rotationDefinition = RotationDefinition.getRotationDefinition(rotation); Vector2[] rotatedPositions = new Vector2[points.length];