Android Open Source - blocks-game Hex Set






From Project

Back to project page blocks-game.

License

The source code is released under:

Apache License

If you think the Android project blocks-game 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 cz.kotu.game.blocks.hex;
/*  ww w.  j  a v a  2s .  co  m*/
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;

import java.util.HashSet;

/**
 * @author tkotula
 */
public class HexSet extends HashSet<Hex> {

    Color color = new Color(hashCode());

    void drawHexGrid(HexCoords3 hexCoords3, ShapeRenderer shapeRenderer) {

        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);

        for (Hex hex : this) {

            shapeRenderer.setColor(color);

            hexCoords3.drawHex(hex, shapeRenderer);

        }

        shapeRenderer.end();

    }

    void move(Vector3 dirCube) {

        for (Hex hex : this) {
            hex.center.add(dirCube);
        }

    }

    Hex getHex(Vector3 cube) {
        for (Hex hex : this) {
            if (hex.contains(cube)) {
                return hex;
            }
        }
        return null;
    }

    boolean intersects(HexCoords3 coords3, Vector3 cube) {
        for (Hex hex : this) {
            if (hex.contains(cube)) return true;
        }
        return false;
    }

    boolean intersects(HexSet other) {
        for (Hex hext : this) {
            for (Hex hexo : other) {
                if (hext.intersects(hexo)) {
                    return true;
                }
            }
        }
        return false;
    }

    HexSet intersection(HexSet other) {
        // TODO this is complicated with float coordinates
        HexSet intersection = new HexSet();
        intersection.addAll(this);
        intersection.retainAll(other);
        return intersection;
    }

    Hex addHex(Axial axial) {
        return addHex(axial.q, axial.r);
    }

    Hex addHex(int q, int r) {
        Hex hex = new Hex();
        hex.size = 0.9f;
        hex.setCenterAxial(q, r);
        add(hex);
        return hex;
    }
}




Java Source Code List

com.badlogic.gradletest.DesktopLauncher.java
com.badlogicgames.gradletest.MainActivity.java
cz.kotu.game.blocks.BaseStage.java
cz.kotu.game.blocks.Block.java
cz.kotu.game.blocks.Draggable.java
cz.kotu.game.blocks.Follower.java
cz.kotu.game.blocks.GridStage.java
cz.kotu.game.blocks.GridUtils.java
cz.kotu.game.blocks.HelloApp.java
cz.kotu.game.blocks.MoveUtils.java
cz.kotu.game.blocks.Slider.java
cz.kotu.game.blocks.T.java
cz.kotu.game.blocks.hex.Axial.java
cz.kotu.game.blocks.hex.HexCoords3.java
cz.kotu.game.blocks.hex.HexGrid.java
cz.kotu.game.blocks.hex.HexGroup.java
cz.kotu.game.blocks.hex.HexPos.java
cz.kotu.game.blocks.hex.HexSet.java
cz.kotu.game.blocks.hex.HexStage.java
cz.kotu.game.blocks.hex.Hex.java
cz.kotu.grids.Dir.java
cz.kotu.grids.GenericGrid.java
cz.kotu.grids.LinPos.java
cz.kotu.grids.LinearGrid.java
cz.kotu.grids.Pos.java