use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class MarioApp method initPhysics.
@Override
protected void initPhysics() {
getPhysicsWorld().setGravity(0, 500 * 2.5);
getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.GHOST_PLATFORM) {
@Override
protected void onCollisionBegin(Entity a, Entity platform) {
platform.getView().setVisible(true);
}
@Override
protected void onCollisionEnd(Entity a, Entity platform) {
platform.getView().setVisible(false);
}
});
getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.PORTAL) {
@Override
protected void onCollisionBegin(Entity a, Entity b) {
nextLevel = true;
}
});
getPhysicsWorld().addCollisionHandler(new CollectibleHandler(MarioType.PLAYER, MarioType.COIN, "drop.wav"));
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class PhysicsWorld method raycast.
/**
* Performs a ray cast from start point to end point.
*
* @param start start point
* @param end end point
* @return ray cast result
*/
public RaycastResult raycast(Point2D start, Point2D end) {
raycastCallback.reset();
jboxWorld.raycast(raycastCallback, toPoint(start), toPoint(end));
Entity entity = null;
Point2D point = null;
if (raycastCallback.getFixture() != null)
entity = (Entity) raycastCallback.getFixture().getBody().getUserData();
if (raycastCallback.getPoint() != null)
point = toPoint(raycastCallback.getPoint());
if (entity == null && point == null)
return RaycastResult.NONE;
return new RaycastResult(entity, point);
}
use of com.almasb.fxgl.entity.Entity 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;
}
});
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class AssetsSample method approach2.
private void approach2() {
Entity brick2 = new Entity();
brick2.setPosition(200, 300);
// if you don't need texture reference
brick2.setViewFromTexture("brick.png");
getGameWorld().addEntity(brick2);
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class AnimColorSample method initGame.
@Override
protected void initGame() {
Rectangle playerView = new Rectangle(40, 40);
Entity player = Entities.builder().at(100, 100).viewFromNode(playerView).with(new ColorComponent()).buildAndAttach();
playerView.fillProperty().bind(player.getComponent(ColorComponent.class).valueProperty());
Entities.animationBuilder().duration(Duration.seconds(2)).repeat(4).color(player).fromColor(Color.AQUA).toColor(Color.BURLYWOOD).buildAndPlay();
}
Aggregations