Java 类com.badlogic.gdx.math.Ellipse 实例源码

项目:fabulae    文件:GameMapLoader.java   
private Vector2 getPositionFromMapObject(MapObject mapObject) {
    if (mapObject instanceof PolygonMapObject) {
        Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
        return new Vector2(polygon.getX(), polygon.getY());
    } else if (mapObject instanceof RectangleMapObject) {
        Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
        return new Vector2(rectangle.getX(), rectangle.getY());
    } else if (mapObject instanceof EllipseMapObject) {
        Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
        return new Vector2(ellipse.x, ellipse.y);
    } else if (mapObject instanceof CircleMapObject) {
        Circle circle = ((CircleMapObject) mapObject).getCircle();
        return new Vector2(circle.x, circle.y);
    }
    throw new GdxRuntimeException("Only Polygons, Rectangles, Ellipses and Circles are supported!");
}
项目:SupaBax    文件:BodyBuilder.java   
/**
 * 
 * @param world
 * @param ellipseObject
 * @param density
 * @param friction
 * @param restitution
 */
private void createEllipse(World world, EllipseMapObject ellipseObject, float density, float friction, float restitution){
    Ellipse circle = ellipseObject.getEllipse();
    CircleShape shape = new CircleShape();
    shape.setRadius(circle.width / 2f / SupaBox.PPM);

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.position.set(new Vector2((circle.x + circle.width / 2f) / SupaBox.PPM, (circle.y + circle.width / 2f) / SupaBox.PPM));

    Body body = world.createBody(bodyDef);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.restitution = restitution;

    body.createFixture(fixtureDef);

    shape.dispose();
}
项目:gdx-cclibs    文件:EllipseSerializer.java   
@Override
public void write(Kryo kryo, Output output, Ellipse ellipse) {
    output.writeFloat(ellipse.x);
    output.writeFloat(ellipse.y);
    output.writeFloat(ellipse.width);
    output.writeFloat(ellipse.height);
}
项目:gdx-cclibs    文件:EllipseSerializer.java   
@Override
public Ellipse read(Kryo kryo, Input input, Class<Ellipse> type) {
    float x = input.readFloat();
    float y = input.readFloat();
    float width = input.readFloat();
    float height = input.readFloat();
    return new Ellipse(x, y, width, height);
}
项目:school-game    文件:PhysicsTileMapBuilder.java   
/**
 * Erzeugt aus einem EllipseMapObject ein CircleShape.
 *
 * Ellipsen werden von Box2D nicht unterstützt, Tiled erzeugt aber auch bei Kreisen EllipseMapObjects.
 * Deshalb ermittelt diese Methode den kleineren Radius und benutzt diesen um einen Kreis zu erstellen.
 *
 * @param ellipseObject das MapObject
 * @return die entsprechende Form
 */
public static CircleShape createCircle(EllipseMapObject ellipseObject)
{
    Ellipse ellipse = ellipseObject.getEllipse();
    CircleShape circle = new CircleShape();

    circle.setPosition(new Vector2(ellipse.x + ellipse.width * 0.5f, ellipse.y + ellipse.height * 0.5f).scl(Physics.MPP));
    circle.setRadius(Math.min(ellipse.width, ellipse.height) * 0.5f * Physics.MPP);

    return circle;
}
项目:joe    文件:TiledUtils.java   
public static FixtureBodyDefinition createEllipseFixtureBodyDef(EllipseMapObject object) {
    BodyDef bodyDef = new BodyDef();
    Ellipse ellipse = object.getEllipse();
    bodyDef.position.x = ellipse.x + (ellipse.width / 2);
    bodyDef.position.y = ellipse.y + (ellipse.height / 2);
    bodyDef.position.scl(MainCamera.getInstance().getTileMapScale());
    bodyDef.type = getBodyType(object);

    FixtureDef fixtureDef = getFixtureDefFromBodySkeleton(object);

    return new FixtureBodyDefinition(fixtureDef, bodyDef);
}
项目:joe    文件:TiledUtils.java   
private static Shape getEllipseShape(MapObject object) {
    Ellipse circle = ((EllipseMapObject)object).getEllipse();
    CircleShape shape = new CircleShape();
    shape.setRadius(circle.width / 2 * MainCamera.getInstance().getTileMapScale());

    return shape;
}
项目:fabulae    文件:GameMap.java   
/**
 * Returns the coordinates where the PCs should
 * appear when they enter this map.
 * 
 * @return
 */
public Vector2 getStartCoordinates() {
    if (startCoordinates == null) {
        MapLayer npcLayer = tiledMap.getLayers().get(LAYER_SPECIAL);
        if (npcLayer != null && npcLayer.getObjects().getCount() > 0) {
            MapObject startLocation = npcLayer.getObjects().get(0);
            if (startLocation instanceof EllipseMapObject) {
                Ellipse center = ((EllipseMapObject)startLocation).getEllipse();
                startCoordinates = new Vector2((int)(center.x/getTileSizeX()), (int)(center.y/getTileSizeY()));
            }
        }
    }
    return startCoordinates;
}
项目:DropTheCube-LD32    文件:MapControllerSystem.java   
private void spawnEnemies(TiledMap tiledMap, int level) {
    Array<Vector2> spawnpoints = new Array<Vector2>();

    MapLayer layer = tiledMap.getLayers().get("EnemySpawnPoints");

    Iterator<MapObject> it = layer.getObjects().iterator();
    while(it.hasNext()){
        MapObject object = it.next();
        EllipseMapObject ellipseMapObject = (EllipseMapObject) object;
        Ellipse ellipse = ellipseMapObject.getEllipse();

        spawnpoints.add(new Vector2(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2));
    }

    int numberOfEnemies = level / 6 + 1;
    if(numberOfEnemies >= 8){
        numberOfEnemies = 8;
    }
    float speed = (float) Math.pow(1.045, level);

    for(int i = 0; i < numberOfEnemies; i++){
        int random = MathUtils.random(0, spawnpoints.size - 1);
        Vector2 vec = spawnpoints.get(random);
        spawnpoints.removeIndex(random);
        Entity enemy = EntityUtils.createEnemyAStar(vec.x, vec.y, speed);
        enemies.add(enemy);
        engine.addEntity(enemy);
    }

}
项目:practicos    文件:GeneradorNivel.java   
private Shape getEllipse(EllipseMapObject ellipseObject) {
    Ellipse ellipse = ellipseObject.getEllipse();
    CircleShape ellipseShape = new CircleShape();
    ellipseShape.setRadius((ellipse.width/2) / GameWorld.units);
    ellipseShape.setPosition(new Vector2(ellipse.x / GameWorld.units, ellipse.y / GameWorld.units));

    return ellipseShape;
}
项目:gdx-cclibs    文件:EllipseSerializer.java   
@Override
public Ellipse copy (Kryo kryo, Ellipse original) {
    return new Ellipse(original);
}
项目:school-game    文件:TutorialDummy.java   
/**
 * Initialisierung
 */
@Override
public void onInit()
{
    super.onInit();

    dummyAtlas = new TextureAtlas(Gdx.files.internal("data/graphics/packed/chicken.atlas"));
    dummy = dummyAtlas.findRegion("chicken");
    dummy_hit = dummyAtlas.findRegion("chicken_hit");

    if (rawObject instanceof EllipseMapObject)
    {
        EllipseMapObject ellipseObject = (EllipseMapObject) rawObject;
        Ellipse ellipse = ellipseObject.getEllipse();

        Vector2 startPos = new Vector2(ellipse.x + ellipse.width / 2f, ellipse.y + ellipse.height / 2f);

        body = createCircleBody(startPos, 10);

        handler = new AttackHandler(worldObjectManager);
        handler.setAttackedCallback(new AttackHandler.AttackedCallback()
        {
            @Override
            public boolean run(Player player, int damage)
            {
                health -= damage;

                if (health <= 0)
                {
                    if (deathCallback != null)
                        deathCallback.run();

                    worldObjectManager.removeObject(TutorialDummy.this);
                } else {
                    hitTimer += 0.6f;
                }

                return true;
            }
        });

        handler.createAttackFixture(body, Physics.createRectangle(64, 64, new Vector2(0, 0)));

    } else {
        Gdx.app.log("WARNING", "Tutorial Dummy " + objectId + " must have an EllipseMapObject!");
        worldObjectManager.removeObject(this);
    }
}
项目:school-game    文件:Crab.java   
/**
 * Initialisierung
 */
@Override
public void onInit()
{
    super.onInit();

    direction = new Vector2(MathUtils.random(-1f, 1f), MathUtils.random(-1f, 1f)).scl(4f);

    crabAtlas = new TextureAtlas(Gdx.files.internal("data/graphics/packed/krab.atlas"));
    crabAnimation = new Animation<TextureRegion>(1/7f, crabAtlas.findRegions("krab"), Animation.PlayMode.LOOP);

    if (rawObject instanceof EllipseMapObject)
    {
        EllipseMapObject ellipseObject = (EllipseMapObject) rawObject;
        Ellipse ellipse = ellipseObject.getEllipse();

        Vector2 startPos = new Vector2(ellipse.x + ellipse.width / 2f, ellipse.y + ellipse.height / 2f);

        body = createCircleBody(startPos, 10);

        handler = new AttackHandler(worldObjectManager);
        handler.setAttackedCallback(new AttackHandler.AttackedCallback()
        {
            @Override
            public boolean run(Player player, int damage)
            {
                health -= damage;

                if (health <= 0)
                {
                    if (deathCallback != null)
                        deathCallback.run();

                    worldObjectManager.removeObject(Crab.this);
                } else {
                    hitTimer += 0.6f;
                }

                return true;
            }
        });

        handler.createAttackFixture(body, Physics.createRectangle(64, 64, new Vector2(0, 0)));

    } else {
        Gdx.app.log("WARNING", "Crab " + objectId + " must have an EllipseMapObject!");
        worldObjectManager.removeObject(this);
    }
}
项目:school-game    文件:Level.java   
/**
 * Parst die Map: Sucht nach Objekten.
 *
 * Wird von {@link #parseMap()} ()} aufgerufen.
 */
private void parseMapObjects()
{
    MapLayer objectLayer = tileMap.getLayers().get(LevelConstants.TMX_OBJECT_LAYER);

    if (objectLayer == null)
    {
        Gdx.app.log("ERROR", "Missing object layer!");
        levelManager.exitToMenu();
        return;
    }

    for (MapObject tileObject : objectLayer.getObjects())
    {
        Gdx.app.log("LEVEL", "Found object '" + tileObject.getName() + "'");

        /*
        // Testcode um alle Eigenschaften auszugeben.
        Iterator<String> props = tileObject.getProperties().getKeys();
        while (props.hasNext())
        {
            String key = props.next();
            Gdx.app.log("LEVEL", "Property: " + key + " - " + tileObject.getProperties().get(key).toString());
        }
        */

        if (tileObject.getProperties().containsKey("type"))
        {
            String type = tileObject.getProperties().get(LevelConstants.TMX_TYPE, String.class);
            if (type.equals(LevelConstants.TMX_TYPE_START_POSITION) && tileObject instanceof EllipseMapObject)
            {
                EllipseMapObject start = (EllipseMapObject) tileObject;
                Ellipse startEllipse = start.getEllipse();
                player.setPosition(startEllipse.x + startEllipse.width / 2f, startEllipse.y + startEllipse.height / 2f);
            }
            else if (type.equals(LevelConstants.TMX_TYPE_WORLD_OBJECT)) {

                if (!tileObject.getName().isEmpty() &&
                    (tileObject instanceof EllipseMapObject || tileObject instanceof RectangleMapObject ||
                     tileObject instanceof PolygonMapObject || tileObject instanceof PolylineMapObject))
                {
                    worldObjectManager.initObject(tileObject.getName(), tileObject);
                } else {
                    Gdx.app.log("WARNING", "Missing object name or wrong class.");
                }
            } else {
                Gdx.app.log("LEVEL", "Object: " + tileObject.getName() + " -> Unkown type: " + type);
            }
        } else {
            Gdx.app.log("LEVEL", "Object: " + tileObject.getName() + " -> Missing type!");
        }
    }
    tileMap.getLayers().remove(objectLayer);
}
项目:Tilo-game-framework    文件:math.java   
public Ellipse ellipse() {
    return ellipse(0, 0, 0, 0);
}
项目:Tilo-game-framework    文件:math.java   
public Ellipse ellipse(float x, float y, float width, float height) {
    return new Ellipse(x, y, width, height);
}
项目:Tilo-game-framework    文件:math.java   
public Ellipse ellipse() {
    return ellipse(0, 0, 0, 0);
}
项目:Tilo-game-framework    文件:math.java   
public Ellipse ellipse(float x, float y, float width, float height) {
    return new Ellipse(x, y, width, height);
}
项目:libgdxcn    文件:EllipseMapObject.java   
/** @return ellipse shape */
public Ellipse getEllipse () {
    return ellipse;
}
项目:libgdxcn    文件:EllipseMapObject.java   
/** Creates an {@link Ellipse} object with the given X and Y coordinates along with a specified width and height.
 * 
 * @param x X coordinate
 * @param y Y coordinate
 * @param width Width in pixels
 * @param height Height in pixels */
public EllipseMapObject (float x, float y, float width, float height) {
    super();
    ellipse = new Ellipse(x, y, width, height);
}