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 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();
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class DrawableSample method initGame.
@Override
protected void initGame() {
BiConsumer<GraphicsContext, Entity> drawing = (g, entity) -> {
Point2D pos = entity.getPosition();
g.setFill(Color.BLUE);
g.fillRect(pos.getX(), pos.getY(), 40, 40);
};
Entity entity = new Entity();
entity.setPosition(400, 300);
entity.addComponent(new DrawableComponent(drawing));
Entity entity2 = new Entity();
entity2.setPosition(750, 300);
entity2.addComponent(new DrawableComponent(drawing));
getGameWorld().addEntities(entity, entity2);
}
Aggregations