Search in sources :

Example 1 with PhysicsWorld

use of com.almasb.fxgl.physics.PhysicsWorld in project FXGL by AlmasB.

the class PhysicsSample method initPhysics.

@Override
protected void initPhysics() {
    // 3. get physics world and register a collision handler
    // between Type.PLAYER and Type.ENEMY
    PhysicsWorld physics = getPhysicsWorld();
    physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {

        @Override
        protected void onHitBoxTrigger(Entity player, Entity enemy, HitBox playerBox, HitBox enemyBox) {
            System.out.println(playerBox.getName() + " X " + enemyBox.getName());
        }

        // the order of entities is determined by
        // the order of their types passed into constructor
        @Override
        protected void onCollisionBegin(Entity player, Entity enemy) {
            System.out.println("On Collision Begin");
        }

        @Override
        protected void onCollision(Entity player, Entity enemy) {
            System.out.println("On Collision");
        }

        @Override
        protected void onCollisionEnd(Entity player, Entity enemy) {
            System.out.println("On Collision End");
        }
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) PhysicsWorld(com.almasb.fxgl.physics.PhysicsWorld)

Example 2 with PhysicsWorld

use of com.almasb.fxgl.physics.PhysicsWorld in project FXGL by AlmasB.

the class PhysicsCollisionSample method initPhysics.

@Override
protected void initPhysics() {
    PhysicsWorld physics = FXGL.getPhysicsWorld();
    physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {

        @Override
        protected void onHitBoxTrigger(Entity player, Entity enemy, HitBox playerBox, HitBox enemyBox) {
            System.out.println(playerBox.getName() + " X " + enemyBox.getName());
        }

        @Override
        protected void onCollisionBegin(Entity player, Entity enemy) {
            System.out.println("On Collision Begin");
        }

        @Override
        protected void onCollision(Entity player, Entity enemy) {
            System.out.println("On Collision");
        }

        @Override
        protected void onCollisionEnd(Entity player, Entity enemy) {
            System.out.println("On Collision End");
        }
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) PhysicsWorld(com.almasb.fxgl.physics.PhysicsWorld)

Example 3 with PhysicsWorld

use of com.almasb.fxgl.physics.PhysicsWorld in project FXGL by AlmasB.

the class PhysicsSample2 method initPhysics.

@Override
protected void initPhysics() {
    // 3. get physics world and register a collision handler
    // between Type.PLAYER and Type.ENEMY
    PhysicsWorld physics = getPhysicsWorld();
    physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {

        @Override
        protected void onCollision(Entity player, Entity enemy) {
            isColliding = true;
        }
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) PhysicsWorld(com.almasb.fxgl.physics.PhysicsWorld)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)3 CollisionHandler (com.almasb.fxgl.physics.CollisionHandler)3 PhysicsWorld (com.almasb.fxgl.physics.PhysicsWorld)3 HitBox (com.almasb.fxgl.physics.HitBox)2