Java 类com.badlogic.gdx.maps.objects.EllipseMapObject 实例源码

项目:joe    文件:TiledMapLevelLoadable.java   
private void processFreeBodies(Array<MapObject> bodies) {
    for (MapObject object : bodies) {
        FixtureBodyDefinition fixtureBodyDefinition;
        if (object instanceof RectangleMapObject) {
            fixtureBodyDefinition = TiledUtils.createRectangleFixtureBodyDef((RectangleMapObject)object);
        } else if (object instanceof CircleMapObject) {
            fixtureBodyDefinition = TiledUtils.createCircleFixtureBodyDef((CircleMapObject)object);
        } else if (object instanceof EllipseMapObject) {
            fixtureBodyDefinition = TiledUtils.createEllipseFixtureBodyDef((EllipseMapObject)object);
        } else if (object instanceof PolylineMapObject || object instanceof PolygonMapObject) {
            fixtureBodyDefinition = TiledUtils.createPolyFixtureBodyDef(object);
        } else {
            throw new InvalidConfigException(filename, "Unknown MapObject type");
        }

        freeBodyDefinitions.add(fixtureBodyDefinition);
    }
}
项目:joe    文件:TiledUtils.java   
public static FixtureDef getFixtureDefFromBodySkeleton(MapObject object) {
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = 1;
    fixtureDef.friction = 0;
    fixtureDef.restitution = 0;

    Shape shape = null;
    if (object instanceof TextureMapObject) {
        shape = getTextureMapShape(object);
    } else if (object instanceof RectangleMapObject) {
        shape = getRectangleShape(object);
    } else if (object instanceof CircleMapObject) {
        shape = getCircleShape(object);
    } else if (object instanceof EllipseMapObject) {
        shape = getEllipseShape(object);
    } else if (object instanceof PolygonMapObject) {
        shape = getPolygonShape(object);
    } else if (object instanceof PolylineMapObject) {
        shape = getPolylineShape(object);
    }

    fixtureDef.shape = shape;

    return fixtureDef;
}
项目: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();
}
项目:Simple-Isometric-Game    文件:MapProcessor.java   
public static Vector2 getPlayerPosition(Map map, MapLayer layer) {
    Vector2 playerPos = new Vector2(0,0);

    for(MapObject object : layer.getObjects()) {
        if(object instanceof EllipseMapObject) {
            EllipseMapObject mapObject = (EllipseMapObject)object;
            Vector3 tempVec3 = new Vector3();
            tempVec3.set(mapObject.getEllipse().x + mapObject.getEllipse().width / 2,
                    mapObject.getEllipse().y + mapObject.getEllipse().height / 2, 0);
            tempVec3.mul(getTransformationMatrix(map));

            playerPos.set(tempVec3.x, tempVec3.y);
        }
    }

    return playerPos;
}
项目:school-game    文件:Crystal.java   
@Override
public void onInit()
{
    crystalAtlas = new TextureAtlas(Gdx.files.internal("data/graphics/packed/crystal.atlas"));
    crystal = crystalAtlas.findRegion("crystal");

    if (rawObject instanceof EllipseMapObject)
    {
        EllipseMapObject ellipseMapObject = (EllipseMapObject) rawObject;
        position = new Vector2(ellipseMapObject.getEllipse().x + ellipseMapObject.getEllipse().width / 2f, ellipseMapObject.getEllipse().y + ellipseMapObject.getEllipse().height / 2f);
    } else {
        Gdx.app.log("WARNING", "Crystal " + objectId + " must be an EllipseMapObject.");
        worldObjectManager.removeObject(this);
    }
}
项目:school-game    文件:EndingWolf.java   
@Override
public void onInit()
{
    wolfAtlas = new TextureAtlas(Gdx.files.internal("data/graphics/packed/wolf.atlas"));
    wolf = wolfAtlas.findRegion("wolf_side", 4);

    if (rawObject instanceof EllipseMapObject)
    {
        EllipseMapObject ellipseMapObject = (EllipseMapObject) rawObject;
        position = new Vector2(ellipseMapObject.getEllipse().x + ellipseMapObject.getEllipse().width / 2f, ellipseMapObject.getEllipse().y + ellipseMapObject.getEllipse().height / 2f);
    } else {
        Gdx.app.log("WARNING", "EndingWolf " + objectId + " must be an EllipseMapObject.");
        worldObjectManager.removeObject(this);
    }
}
项目: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);
    }

}
项目:DropTheCube-LD32    文件:MapControllerSystem.java   
private void createLights(TiledMap tiledMap, int map) {
    MapLayer layer = tiledMap.getLayers().get("PointLights");

    Iterator<MapObject> it = layer.getObjects().iterator();
    while(it.hasNext()){
        MapObject object = it.next();
        //Always going to be a circle
        EllipseMapObject ellipse = (EllipseMapObject) object;

        Entity entity = new Entity();

        PointLightComponent pointComponent = new PointLightComponent();
        pointComponent.color = Values.LIGHT_COLORS[map];
        pointComponent.maxDistance = (float)Math.sqrt((double)ellipse.getEllipse().area());
        pointComponent.numRays = Values.POINT_LIGHT_DEFAULT_NUM_RAYS;
        pointComponent.x = ellipse.getEllipse().x + ellipse.getEllipse().width / 2;
        pointComponent.y = ellipse.getEllipse().y + ellipse.getEllipse().height / 2;

        LightComponent lightComponent = new LightComponent();
        lightComponent.lightType = LightType.PointLight;

        entity.add(pointComponent);
        entity.add(lightComponent);

        engine.addEntity(entity);

        pointLights.add(entity);
    }

}
项目:SupaBax    文件:BodyBuilder.java   
/**
 * 
 * @param world
 * @param map
 */
public void createBodies(ArrayList<Entity> entities, World world, TiledMap map){
    MapObjects objects;

    objects = map.getLayers().get("ground").getObjects();
    for(MapObject object : objects){
        if(object instanceof RectangleMapObject){
            createRectangle(world, (RectangleMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof PolygonMapObject){
            createPolygon(world, (PolygonMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof PolylineMapObject){
            createPolyline(world, (PolylineMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof EllipseMapObject){
            createEllipse(world, (EllipseMapObject) object, 0.5f, 0.4f, 0.6f);
        } else{
            Gdx.app.error("Error", "Invalid map object");
        }
    }

    /*
    objects = map.getLayers().get("dynamic").getObjects();
    for(MapObject object : objects){
        RectangleMapObject entity = (RectangleMapObject) object;
        Rectangle position = entity.getRectangle();
        entities.add(new Box(world, new Vector2(position.x / SupaBox.PPM, position.y / SupaBox.PPM), new Vector2(0f, 0f), 1f, 1f));
    }
    */
}
项目: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;
}
项目: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);
    }
}
项目:libGdx-xiyou    文件:Play.java   
private void createEnemy() {
    mEnemyDaos = new Array<Enemy>();

    Array<MapLayer> mapLayers = new Array<MapLayer>();
    //天兵对象层
    mapLayers.add(mMap.getLayers().get("enemy"));
    mapLayers.add(mMap.getLayers().get("enemyFu"));
    mapLayers.add(mMap.getLayers().get("enemyQiang"));

    for (MapLayer mapLayer : mapLayers) {
        if (mapLayer == null) {
            continue;
        }

        //初始化天兵刚体形状
        BodyDef enemyDef = new BodyDef();
        enemyDef.type = BodyDef.BodyType.DynamicBody;
        //多边形形状
        PolygonShape polygonShape = new PolygonShape();
        //设置夹具
        FixtureDef enemyFixDef = new FixtureDef();

        //遍历enemy对象层
        for (MapObject object : mapLayer.getObjects()) {
            //坐标
            float x = 0;
            float y = 0;
            //获取对象坐标
            if (object instanceof EllipseMapObject) {
                EllipseMapObject ellipseMapObject = (EllipseMapObject) object;
                x = ellipseMapObject.getEllipse().x / Constant.RATE;
                y = ellipseMapObject.getEllipse().y / Constant.RATE;
            }

            //天兵夹具
            polygonShape.setAsBox(30 / Constant.RATE, 60 / Constant.RATE);
            enemyFixDef.shape = polygonShape;
            enemyFixDef.isSensor = true;
            enemyFixDef.filter.categoryBits = Constant.ENEMY_DAO;
            enemyFixDef.filter.maskBits = Constant.PLAYER;

            //设置位置
            enemyDef.position.set(x, y);
            Body enemyBody = mWorld.createBody(enemyDef);
            enemyBody.createFixture(enemyFixDef).setUserData("enemy");

            //创建脚传感器 foot
            polygonShape.setAsBox(28 / Constant.RATE, 3 / Constant.RATE, new Vector2(0, -58 / Constant.RATE), 0);
            enemyFixDef.shape = polygonShape;
            enemyFixDef.filter.categoryBits = Constant.ENEMY_DAO;
            enemyFixDef.filter.maskBits = Constant.BLOCK;
            enemyFixDef.isSensor = false;
            enemyBody.createFixture(enemyFixDef).setUserData("enemyFoot");

            Enemy enemy = new Enemy(enemyBody, mapLayer.getName());
            mEnemyDaos.add(enemy);
            enemyBody.setUserData(enemy);

            Thread thread = new Thread(enemy);
            thread.start();
        }
    }
}
项目:libGdx-xiyou    文件:Play.java   
private void createBoss(int level) {

        MapLayer mapLayer = mMap.getLayers().get("Boss");
        if (mapLayer == null) return;

        //初始化Boss刚体形状
        BodyDef bossDef = new BodyDef();
        bossDef.type = BodyDef.BodyType.DynamicBody;
        //多边形形状
        PolygonShape polygonShape = new PolygonShape();
        //设置夹具
        FixtureDef bossFixDef = new FixtureDef();

        //遍历Boss对象层
        for (MapObject object : mapLayer.getObjects()) {
            //坐标
            float x = 0;
            float y = 0;
            //获取对象坐标
            if (object instanceof EllipseMapObject) {
                EllipseMapObject ellipseMapObject = (EllipseMapObject) object;
                x = ellipseMapObject.getEllipse().x / Constant.RATE;
                y = ellipseMapObject.getEllipse().y / Constant.RATE;
            }

            //设置位置
            bossDef.position.set(x, y);
            Body bossBody = mWorld.createBody(bossDef);

            //二郎神标志
            if (Play.level == 4) {
                polygonShape.setAsBox(20 / Constant.RATE, 10 / Constant.RATE, new Vector2(0, -20 / Constant.RATE), 0);
                bossFixDef.shape = polygonShape;
                bossFixDef.isSensor = true;
                bossBody.createFixture(bossFixDef).setUserData("erlang");
            }

            //boss夹具
            polygonShape.setAsBox(30 / Constant.RATE, 60 / Constant.RATE);
            bossFixDef.shape = polygonShape;
            bossFixDef.isSensor = true;
            bossFixDef.filter.categoryBits = Constant.BOSS;
            bossFixDef.filter.maskBits = Constant.PLAYER;
            bossBody.createFixture(bossFixDef).setUserData("boss");

            //创建脚传感器 foot
            polygonShape.setAsBox(28 / Constant.RATE, 3 / Constant.RATE, new Vector2(0, -58 / Constant.RATE), 0);
            bossFixDef.shape = polygonShape;
            bossFixDef.filter.categoryBits = Constant.BOSS;
            bossFixDef.filter.maskBits = Constant.BLOCK;
            bossFixDef.isSensor = false;
            bossBody.createFixture(bossFixDef).setUserData("bossFoot");

            //设置Boss
            switch (level) {
                case 0:        //第一关
                    mBoss = new Boss(bossBody, MyGdxGame.assetManager.getTextureAtlas(Constant.BOSS_JULING_ROLE));
                    break;
                case 1:        //第二关
                    mBoss = new Boss(bossBody, MyGdxGame.assetManager.getTextureAtlas(Constant.BOSS_ZENGZHANG_ROLE));
                    break;
                case 2:        //第三关
                    mBoss = new Boss(bossBody, MyGdxGame.assetManager.getTextureAtlas(Constant.BOSS_GUANGMU_ROLE));
                    break;
                case 3:        //第四关
                    mBoss = new Boss(bossBody, MyGdxGame.assetManager.getTextureAtlas(Constant.BOSS_DUOWEN_ROLE));
                    break;
                case 4:        //第五关
                    mBoss = new Boss(bossBody, MyGdxGame.assetManager.getTextureAtlas(Constant.BOSS_ERLANG_ROLE));
                    break;
            }
            bossBody.setUserData(mBoss);

            Thread thread = new Thread(mBoss);
            thread.start();
        }
    }
项目:practicos    文件:GeneradorNivel.java   
private void crearColisiones() {

Array<Body> slopes = new Array<Body>();
FixtureDef fixDef = new FixtureDef();


MapObjects objects = cls.getObjects();
Iterator<MapObject> objectIt = objects.iterator();

while(objectIt.hasNext()) {
MapObject object = objectIt.next();

if (object instanceof TextureMapObject){
  continue;
}

Shape shape;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;

if (object instanceof RectangleMapObject) {
    RectangleMapObject rectangle = (RectangleMapObject)object;
    shape = getRectangle(rectangle);
}
else if (object instanceof PolygonMapObject) {
    shape = getPolygon((PolygonMapObject)object);
}
else if (object instanceof PolylineMapObject) {
    shape = getPolyline((PolylineMapObject)object);
}
else if (object instanceof EllipseMapObject) {
    shape = getEllipse((EllipseMapObject)object);
}
else if (object instanceof CircleMapObject) {
    shape = getCircle((CircleMapObject)object);
}
else {
    continue;
}


fixDef.shape = shape;
fixDef.filter.categoryBits = GameWorld.BIT_PARED;
  fixDef.filter.maskBits = GameWorld.BIT_JUGADOR | GameWorld.BIT_ENEMIGOS | GameWorld.BIT_SENSOR;


Body suelo = GameWorld.mundo.createBody(bodyDef);
suelo.createFixture(fixDef).setUserData("cls");

slopes.add(suelo);

shape.dispose();
  }
}