當前位置: 首頁>>代碼示例>>Java>>正文


Java World.rayCast方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.physics.box2d.World.rayCast方法的典型用法代碼示例。如果您正苦於以下問題:Java World.rayCast方法的具體用法?Java World.rayCast怎麽用?Java World.rayCast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.physics.box2d.World的用法示例。


在下文中一共展示了World.rayCast方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkMovable

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
private boolean checkMovable(Body body, Vector2 from, Vector2 to) {
    World b2dWorld = body.getWorld();
    moveable = true;

    RayCastCallback rayCastCallback = new RayCastCallback() {
        @Override
        public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
            if (fixture.getFilterData().categoryBits == GameManager.INDESTRUCTIIBLE_BIT
                    | fixture.getFilterData().categoryBits == GameManager.BREAKABLE_BIT
                    | fixture.getFilterData().categoryBits == GameManager.BOMB_BIT
                    | fixture.getFilterData().categoryBits == GameManager.ENEMY_BIT
                    | fixture.getFilterData().categoryBits == GameManager.PLAYER_BIT) {
                moveable = false;
                return 0;
            }
            return 0;
        }
    };

    b2dWorld.rayCast(rayCastCallback, from, to);
    return moveable;
}
 
開發者ID:yichen0831,項目名稱:Bomberman_libGdx,代碼行數:23,代碼來源:BombSystem.java

示例2: checkMovable

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
private boolean checkMovable(Body body, MoveDir dir) {
    canMove = true;
    World world = body.getWorld();

    RayCastCallback rayCastCallback = new RayCastCallback() {
        @Override
        public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
            if (fixture.getFilterData().categoryBits == GameManager.WALL_BIT || fixture.getFilterData().categoryBits == GameManager.GATE_BIT) {
                canMove = false;
                return 0;
            }
            return 0;
        }
    };

    for (int i = 0; i < 2; i++) {
        tmpV1.set(body.getPosition());
        switch (dir) {
            case UP:
                tmpV2.set(body.getPosition().x - (i - 0.5f) * 0.2f, body.getPosition().y + 0.6f);
                break;
            case DOWN:
                tmpV2.set(body.getPosition().x - (i - 0.5f) * 0.2f, body.getPosition().y - 0.6f);
                break;
            case LEFT:
                tmpV2.set(body.getPosition().x - 0.6f, body.getPosition().y - (i - 0.5f) * 0.2f);
                break;
            case RIGHT:
                tmpV2.set(body.getPosition().x + 0.6f, body.getPosition().y - (i - 0.5f) * 0.2f);
                break;
            default:
                break;
        }

        world.rayCast(rayCastCallback, tmpV1, tmpV2);
    }

    return canMove;
}
 
開發者ID:yichen0831,項目名稱:Pacman_libGdx,代碼行數:40,代碼來源:PlayerSystem.java

示例3: hitSomethingVertical

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
protected boolean hitSomethingVertical(final Body body, Vector2 fromV, Vector2 toV) {
    World b2dWorld = body.getWorld();
    hit = false;

    RayCastCallback rayCastCallback = new RayCastCallback() {

        @Override
        public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
            // if hit the player, ignore it
            if (fixture.getFilterData().categoryBits == GameManager.PLAYER_BIT || fixture.getFilterData().categoryBits == GameManager.POWERUP_BIT) {
                return 0;
            }

            if (fraction < 1.0f) {
                hit = true;
            }
            return 0;
        }
    };

    for (int i = 0; i < 3; i++) {
        Vector2 tmpV = new Vector2(toV);
        b2dWorld.rayCast(rayCastCallback, fromV, tmpV.add((1 - i) * 0.4f, 0));

    }
    return hit;
}
 
開發者ID:yichen0831,項目名稱:Bomberman_libGdx,代碼行數:28,代碼來源:EnemySystem.java

示例4: hitSomethingHorizontal

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
protected boolean hitSomethingHorizontal(final Body body, Vector2 fromV, Vector2 toV) {
    World b2dWorld = body.getWorld();
    hit = false;

    RayCastCallback rayCastCallback = new RayCastCallback() {

        @Override
        public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
            // if hit the player or power-up item, ignore it
            if (fixture.getFilterData().categoryBits == GameManager.PLAYER_BIT || fixture.getFilterData().categoryBits == GameManager.POWERUP_BIT) {
                return 0;
            }

            if (fraction < 1.0f) {
                hit = true;
            }
            return 0;
        }
    };

    for (int i = 0; i < 3; i++) {
        Vector2 tmpV = new Vector2(toV);
        b2dWorld.rayCast(rayCastCallback, fromV, tmpV.add(0, (1 - i) * 0.4f));

    }
    return hit;
}
 
開發者ID:yichen0831,項目名稱:Bomberman_libGdx,代碼行數:28,代碼來源:EnemySystem.java

示例5: cast

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
public boolean cast(World world,PhysicsComponent phys0, PhysicsComponent phys1){
	reset();
	if (phys0.getPosition().dst(phys1.getPosition()) <= 0) return true;
	world.rayCast(this, phys0.getPosition(), phys1.getPosition());
	return fixture != null && physics == phys1;
}
 
開發者ID:Deftwun,項目名稱:ZombieCopter,代碼行數:7,代碼來源:RayCast.java


注:本文中的com.badlogic.gdx.physics.box2d.World.rayCast方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。