Android Open Source - acceptableLosses Map Tools






From Project

Back to project page acceptableLosses.

License

The source code is released under:

MIT License

If you think the Android project acceptableLosses listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package acceptableLosses.map;
//from www .j av  a2s. c  om
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.stewsters.util.math.Point2i;

import java.util.LinkedList;

public class MapTools {


    public static Vector2 getDirectionVector(int x1, int y1, int x2, int y2) {
        Vector2 cell1 = world2window(x1, y1);
        Vector2 cell2 = world2window(x2, y2);
        return new Vector2(cell2.x - cell1.x, cell2.y - cell1.y);
    }

    public static int manhattanDistance(int x, int y, int x1, int y1) {

        return Math.abs(x - x1) + Math.abs(y - y1);
    }

    public static LinkedList<Point2i> getNeighbors(int x, int y, int range) {

        LinkedList<Point2i> results = new LinkedList<Point2i>();
        for (int x1 = x - range; x1 < x + range; x1++) {
            for (int y1 = y - range; y1 < y + range; y1++) {
                if (x1 == x || y1 == y)
                    continue;
                if (manhattanDistance(x, y, x1, y1) <= range) {
                    results.add(new Point2i(x1, y1));
                }

            }
        }

        return results;
    }

    public static LinkedList<Point2i> getNeighbors(int x, int y) {

        return getNeighbors(x, y, 1);
    }

    public static Point2i window2world(int x, int y, OrthographicCamera camera) {
        Vector3 pos = new Vector3(x, y, 0);
        camera.unproject(pos);

        return new Point2i((int) ((pos.x) + 0.5), (int) ((pos.y) + 0.5));
    }

    public static Vector2 world2window(float x, float y) {


        return new Vector2(x, y);
    }


    public static Point2i libgdx2world(float x, float y) {
        return new Point2i((int) (x), (int) (y));
    }
}




Java Source Code List

acceptableLosses.AcceptableLossesGame.java
acceptableLosses.android.AndroidLauncher.java
acceptableLosses.assets.AssetLoader.java
acceptableLosses.assets.FurnitureType.java
acceptableLosses.assets.TileType.java
acceptableLosses.components.Appearance.java
acceptableLosses.components.Cargo.java
acceptableLosses.components.Citizen.java
acceptableLosses.components.Destination.java
acceptableLosses.components.Health.java
acceptableLosses.components.Path.java
acceptableLosses.components.Position.java
acceptableLosses.components.Resume.java
acceptableLosses.components.Sentience.java
acceptableLosses.components.Task.java
acceptableLosses.controls.GestureDetectorController.java
acceptableLosses.controls.InputManager.java
acceptableLosses.controls.ZoomInputProcessor.java
acceptableLosses.controls.commands.Command.java
acceptableLosses.controls.commands.TapCommand.java
acceptableLosses.desktop.DesktopLauncher.java
acceptableLosses.desktop.ImagePacker.java
acceptableLosses.map.AsteroidGenerator.java
acceptableLosses.map.Chunk.java
acceptableLosses.map.Furniture.java
acceptableLosses.map.MapTools.java
acceptableLosses.map.Region.java
acceptableLosses.map.Spawner.java
acceptableLosses.pathing.FastNonOptimalHeuristic.java
acceptableLosses.screens.GameScreen.java
acceptableLosses.screens.SplashScreen.java
acceptableLosses.systems.AiSystem.java
acceptableLosses.systems.AppearanceRenderSystem.java
acceptableLosses.systems.ElevationSystem.java
acceptableLosses.systems.FurnitureRenderSystem.java
acceptableLosses.systems.JobAssignerSystem.java
acceptableLosses.systems.MapRenderSystem.java
acceptableLosses.systems.MovementSystem.java
acceptableLosses.systems.PathFinderSystem.java
acceptableLosses.work.CivilianMover.java
acceptableLosses.work.jobs.DigJob.java
acceptableLosses.work.jobs.Job.java