Example usage for com.badlogic.gdx.math.collision Sphere Sphere

List of usage examples for com.badlogic.gdx.math.collision Sphere Sphere

Introduction

In this page you can find the example usage for com.badlogic.gdx.math.collision Sphere Sphere.

Prototype

public Sphere(Vector3 center, float radius) 

Source Link

Document

Constructs a sphere with the given center and radius

Usage

From source file:com.game.HelloWorld.java

License:Apache License

private void create_tiledMap() {
    final String path = "data/tiledmap/";
    final String mapname = "foret";

    FileHandle mapHandle = Gdx.files.internal(path + mapname + ".tmx");
    FileHandle baseDir = Gdx.files.internal(path);

    this.mMap = TiledLoader.createMap(mapHandle);

    this.mAtlas = new TileAtlas(this.mMap, baseDir);

    int blockWidth = 128;
    int blockHeight = 128;

    mTileMapRenderer = new TileMapRenderer(this.mMap, this.mAtlas, blockWidth, blockHeight, 128, 128);

    for (TiledObjectGroup group : this.mMap.objectGroups) {
        for (TiledObject object : group.objects) {
            // TODO: Draw sprites where objects occur

            positionBoites.add(new Sphere(new Vector3(object.x, object.y, 0), 50));
            System.out.println("Object " + object.name + " x,y = " + object.x + "," + object.y
                    + " width,height = " + object.width + "," + object.height);
        }/*w w  w.java 2s  . com*/
    }

    // float aspectRatio = (float)Gdx.graphics.getWidth() /
    // (float)Gdx.graphics.getHeight();
    // mCam = new OrthographicCamera(100f * aspectRatio, 100f);

    // mCam.position.set(mTileMapRenderer.getMapWidthUnits() / 2,
    // mTileMapRenderer.getMapHeightUnits() / 2, 0);

    // camController = new OrthoCamController(cam);
    // Gdx.input.setInputProcessor(camController);

    // mMaxCamPosition.set(mTileMapRenderer.getMapWidthUnits(),
    // mTileMapRenderer.getMapHeightUnits());
}

From source file:com.game.HelloWorld.java

License:Apache License

private boolean isOnThePlayer(int x, int y) {

    float fingerX = x, fingerY = Gdx.graphics.getHeight() - y;
    float playerX = Gdx.graphics.getWidth() / 2, playerY = Gdx.graphics.getHeight() / 2;

    Sphere sphereFinger = new Sphere(new Vector3(fingerX, fingerY, 0), 40);
    Sphere spherePlayer = new Sphere(new Vector3(playerX, playerY, 0), 40);
    if (sphereFinger.overlaps(spherePlayer)) {
        isOnThePlayer = true;/*from ww  w.  j ava2s. c  om*/
        return true;
    } else {
        isOnThePlayer = false;
        return false;
    }
}

From source file:com.game.HelloWorld.java

License:Apache License

private boolean isCollision(int x, int y) {
    Sphere sphere = new Sphere(new Vector3(x, y, 0), 50);

    Iterator<Sphere> itr = positionBoites.iterator();
    while (itr.hasNext()) {
        Sphere element = itr.next();/*from   www . jav a2 s  . c o  m*/
        if (element.overlaps(sphere))
            return true;
    }

    return false;
}