use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class CirclesSample method initInput.
@Override
protected void initInput() {
onKeyDown(KeyCode.F, () -> {
getGameWorld().getEntitiesCopy().forEach(Entity::removeFromWorld);
for (int i = 0; i < interpolators.size(); i++) {
var interpolator = interpolators.get(i);
var box = new Box(1, 1, 1);
box.setMaterial(new PhongMaterial(Color.BLUE));
var c = entityBuilder().view(box).buildAndAttach();
var center = new Point2D(0, 0);
var point = new Point2D(2 + i * 1, 0.0).add(center);
animationBuilder().duration(Duration.seconds(8)).interpolator(interpolator).animate(new AnimatedValue<>(0.0, 360.0)).onProgress(deg -> {
var p = FXGLMath.rotate(point, center, deg);
c.setX(p.getX());
c.setY(p.getY());
}).buildAndPlay();
}
});
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class BoundingBoxComponentTest method setUp.
@BeforeEach
public void setUp() throws Exception {
Entity entity = new Entity();
position = entity.getTransformComponent();
bbox = entity.getBoundingBoxComponent();
}
use of com.almasb.fxgl.entity.Entity in project FXGL by AlmasB.
the class BoundingBoxComponentTest method testIsCollidingWithAngles.
@Test
public void testIsCollidingWithAngles() throws Exception {
bbox.addHitBox(new HitBox("ARM", BoundingShape.box(40, 60)));
Entity entity2 = new Entity();
entity2.getBoundingBoxComponent().addHitBox(new HitBox("test", BoundingShape.box(50, 50)));
entity2.setPosition(50, 0);
entity2.getTransformComponent().setRotationOrigin(new Point2D(0, 0));
entity2.setRotation(91);
Entity entity3 = new Entity();
entity3.getBoundingBoxComponent().addHitBox(new HitBox("test", BoundingShape.box(50, 50)));
entity3.setPosition(50, 0);
// both identical but e2 is rotated and e3 is not
assertTrue(bbox.isCollidingWith(entity2.getBoundingBoxComponent()));
assertFalse(bbox.isCollidingWith(entity3.getBoundingBoxComponent()));
}
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 = raycastCallback.getFixture().getBody().getEntity();
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 UnoSample method initGame.
@Override
protected void initGame() {
centerCardPosition = new Point2D(getAppWidth() / 2 - 100 / 2, getAppHeight() / 2 - 150 / 2);
getGameWorld().addEntityFactory(new UnoFactory());
spawn("Background");
player = new Hand("Player");
enemy = new Hand("AI");
var currentCard = spawnCard(deck.drawCard());
currentCard.setPosition(centerCardPosition);
set("currentCard", currentCard);
nextHand = player;
cardsLayout.put(player, new Rectangle2D(0, getAppHeight() - 150, getAppWidth(), 150));
cardsLayout.put(enemy, new Rectangle2D(0, 0 - 150, getAppWidth(), 150));
cardsLayout.forEach((hand, bounds) -> {
hand.setChangeCallback(() -> {
hand.cardsProperty().sort(Comparator.comparingInt(e -> {
Card card = e.getObject("card");
return card.getSuit().ordinal() * 1000 + card.getRank().ordinal();
}));
evaluateAndLayout(hand);
});
if (hand == player) {
getWorldProperties().<Entity>addListener("currentCard", (prev, now) -> {
evaluateAndLayout(hand);
});
}
});
for (int i = 0; i < NUM_BASE_CARDS; i++) {
player.addCard(spawnCard(deck.drawCard()));
enemy.addCard(spawnCard(deck.drawCard()));
}
}
Aggregations