use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class JointSample method initGame.
@Override
protected void initGame() {
getGameWorld().addEntity(Entities.makeScreenBounds(50));
PhysicsComponent physics = new PhysicsComponent();
Entity block = Entities.builder().at(200, 200).viewFromNodeWithBBox(new Rectangle(50, 50)).with(physics).buildAndAttach(getGameWorld());
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball = Entities.builder().at(200, 300).bbox(new HitBox("main", BoundingShape.circle(15))).viewFromNode(getAssetLoader().loadTexture("ball.png", 30, 30)).with(physics2).buildAndAttach(getGameWorld());
Line line = new Line();
line.setStartX(block.getCenter().getX());
line.setStartY(block.getCenter().getY());
// line.startXProperty().bind(block.getPositionComponent().xProperty());
// line.startYProperty().bind(block.getPositionComponent().yProperty());
line.endXProperty().bind(ball.getPositionComponent().xProperty().add(15));
line.endYProperty().bind(ball.getPositionComponent().yProperty().add(15));
getGameScene().addGameView(new EntityView(line));
RevoluteJointDef rDef = new RevoluteJointDef();
rDef.bodyA = physics.getBody();
rDef.bodyB = physics2.getBody();
rDef.collideConnected = false;
rDef.localAnchorA = new Vec2(0, 0);
rDef.localAnchorB = new Vec2(0, 5);
rDef.enableLimit = true;
rDef.lowerAngle = (float) (FXGLMath.toRadians(-180.0f));
rDef.upperAngle = (float) (FXGLMath.toRadians(180.0f));
rDef.enableMotor = true;
rDef.motorSpeed = (float) (FXGLMath.toRadians(30));
rDef.maxMotorTorque = 15.0f;
joint = (RevoluteJoint) getPhysicsWorld().getJBox2DWorld().createJoint(rDef);
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class SaveSample method initGame.
private void initGame(Point2D playerPos, Point2D enemyPos) {
playerPosition = playerPos;
enemyPosition = enemyPos;
player = new Entity();
player.getTypeComponent().setValue(Type.PLAYER);
player.getPositionComponent().setValue(playerPosition);
player.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.BLUE)));
playerControl = new PlayerControl();
player.addControl(playerControl);
enemy = new Entity();
enemy.getTypeComponent().setValue(Type.ENEMY);
enemy.getPositionComponent().setValue(enemyPosition);
enemy.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.RED)));
getGameWorld().addEntities(player, enemy);
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class ClockSample method initGame.
@Override
protected void initGame() {
clock = getGameplay().getClock();
clock.start();
Rectangle rect = new Rectangle(50, 50);
rect.fillProperty().bind(Bindings.when(clock.dayProperty()).then(Color.YELLOW).otherwise(Color.RED));
getGameScene().addUINode(rect);
clock.runAt(() -> {
System.out.println("It's 02:30");
}, 2, 30);
clock.runAtHour(() -> {
System.out.println("It's 06:00");
}, 6);
clock.gameHourProperty().addListener((obs, o, newValue) -> {
System.out.println(newValue);
});
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class SmokeSample method initGame.
@Override
protected void initGame() {
getGameScene().setBackgroundColor(Color.BLACK);
e = ParticleEmitters.newSmokeEmitter();
e.setBlendMode(BlendMode.SRC_OVER);
e.setSize(15, 30);
e.setNumParticles(10);
e.setEmissionRate(0.25);
e.setStartColor(Color.color(0.6, 0.55, 0.5, 0.47));
e.setEndColor(Color.BLACK);
e.setExpireFunction((i, x, y) -> Duration.seconds(16));
e.setVelocityFunction((i, x, y) -> new Point2D(FXGLMath.random() - 0.5, 0));
e.setAccelerationFunction(() -> new Point2D((FXGLMath.noise1D(7776 + getTick()) - 0.5) * 0.02, 0));
// e.setSpawnPointFunction((i, x, y) -> new Point2D(x + FXGLMath.noise1D(333 + getTick()) * 150 - 75, y + FXGLMath.noise1D(getTick()) * 150 - 75));
// Entities.builder()
// .at(getWidth() / 2, getHeight() - 100)
// .with(new ParticleControl(e), new RandomMoveControl(2))
// .buildAndAttach(getGameWorld());
emitter = ParticleEmitters.newFireEmitter();
emitter.setSize(5, 15);
emitter.setVelocityFunction((i, x, y) -> new Point2D(FXGLMath.random() - 0.5, -FXGLMath.random() * 3));
emitter.setAccelerationFunction(() -> new Point2D(0, 0.05));
emitter.setExpireFunction((i, x, y) -> Duration.seconds(3));
emitter.setScaleFunction((i, x, y) -> new Point2D(FXGLMath.random(0, 0.01), FXGLMath.random(-0.05, 0.05)));
emitter.setStartColor(Color.YELLOW);
emitter.setEndColor(Color.RED);
// emitter.setBlendMode(BlendMode.SRC_OVER);
// emitter.setSourceImage(getAssetLoader().loadTexture("particleTexture2.png").toColor(Color.rgb(230, 75, 40)).getImage());
entity = Entities.builder().at(getWidth() / 2, getHeight() / 2).with(new ParticleControl(emitter)).buildAndAttach(getGameWorld());
Entities.builder().at(250, 250).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(new CircularMovementControl(10, 25)).buildAndAttach(getGameWorld());
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class NoiseSample method initGame.
@Override
protected void initGame() {
Entities.builder().at(100, 100).viewFromNodeWithBBox(new Rectangle(40, 40)).with(new RandomMoveControl(100, 50, 350, new Rectangle2D(0, 0, X_MAX - 0, Y_MAX - 0))).buildAndAttach(getGameWorld());
Entities.builder().at(50, 350).viewFromNode(new Rectangle(15, 15, Color.DARKCYAN)).buildAndAttach(getGameWorld());
}
Aggregations