Android Open Source - hiddenmarble Default Maze Box






From Project

Back to project page hiddenmarble.

License

The source code is released under:

Apache License

If you think the Android project hiddenmarble 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 com.mygdx.hiddenmarble.entities;
/* w w  w  . j a  v  a 2  s. c o m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import maze.Position;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.Transform;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
import com.mygdx.hiddenmarble.utils.BodyHelper;
import com.mygdx.hiddenmarble.utils.MazeHelper.MazeDef;

/** The default {@link MazeBox} implementation. */
public class DefaultMazeBox extends AbstractEntity implements Entity, MazeBox {
    private List<MazeFixtureDef> data;
    private float width;
    private float height;
    
    /**
     * Creates a maze box from the specified tile maze model.
     * 
     * @param world the Box2D world
     * @param mazeDef the maze definition
     * @param exit the position of the maze's exit tile
     */
    public DefaultMazeBox(World world, MazeDef mazeDef) {
        super(BodyHelper.getMazeBoxBody(world, mazeDef));
        width = mazeDef.maze.getWidth();
        height = mazeDef.maze.getHeight();
        data = initData();
    }

    @Override
    public float getWidth() {
        return width;
    }

    @Override
    public float getHeight() {
        return height;
    }

    @Override
    public Vector2 getTileLocation(Position position) {
        Vector2 ret = new Vector2(position.getX(), getHeight() - position.getY() - 1);
        Transform transform = getTransform();
        transform.mul(ret);
        return ret;
    }
    
    @Override
    public List<MazeFixtureDef> getMazeFixtureDefs() {
        return Collections.unmodifiableList(data);
    }
    
    private List<MazeFixtureDef> initData() {
        Array<Fixture> fixtures = getBody().getFixtureList();
        List<MazeFixtureDef> ret = new ArrayList<MazeFixtureDef>(fixtures.size);
        for (Fixture f : fixtures) {
            MazeFixtureDef d = (MazeFixtureDef)f.getUserData();
            ret.add(d);
        }
        return ret;
    }
}




Java Source Code List

com.mygdx.hiddenmarble.android.AndroidLauncher.java
com.mygdx.hiddenmarble.desktop.DesktopLauncher.java
com.mygdx.hiddenmarble.entities.AbstractDynamicEntity.java
com.mygdx.hiddenmarble.entities.AbstractEntity.java
com.mygdx.hiddenmarble.entities.Borders.java
com.mygdx.hiddenmarble.entities.DefaultBorders.java
com.mygdx.hiddenmarble.entities.DefaultMarble.java
com.mygdx.hiddenmarble.entities.DefaultMazeBox.java
com.mygdx.hiddenmarble.entities.DynamicEntity.java
com.mygdx.hiddenmarble.entities.Entity.java
com.mygdx.hiddenmarble.entities.Marble.java
com.mygdx.hiddenmarble.entities.Material.java
com.mygdx.hiddenmarble.entities.MazeBox.java
com.mygdx.hiddenmarble.entities.MazeFixtureDef.java
com.mygdx.hiddenmarble.ui.GameScreen.java
com.mygdx.hiddenmarble.ui.HiddenMarble.java
com.mygdx.hiddenmarble.ui.WorldRenderer.java
com.mygdx.hiddenmarble.utils.Assets.java
com.mygdx.hiddenmarble.utils.BodyHelper.java
com.mygdx.hiddenmarble.utils.MazeHelper.java
com.mygdx.hiddenmarble.utils.SaveState.java
com.mygdx.hiddenmarble.utils.Serialization.java
com.mygdx.hiddenmarble.utils.SpriteHelper.java
com.mygdx.hiddenmarble.world.GameWorldAdapter.java
com.mygdx.hiddenmarble.world.GameWorldListener.java
com.mygdx.hiddenmarble.world.GameWorld.java