Search in sources :

Example 56 with Rectangle

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);
}
Also used : Line(javafx.scene.shape.Line) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) EntityView(com.almasb.fxgl.entity.view.EntityView) Vec2(com.almasb.fxgl.core.math.Vec2) Rectangle(javafx.scene.shape.Rectangle) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef) RevoluteJointDef(com.almasb.fxgl.physics.box2d.dynamics.joints.RevoluteJointDef)

Example 57 with Rectangle

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);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Example 58 with Rectangle

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);
    });
}
Also used : Rectangle(javafx.scene.shape.Rectangle)

Example 59 with Rectangle

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());
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle) ParticleControl(com.almasb.fxgl.effect.ParticleControl) CircularMovementControl(com.almasb.fxgl.entity.control.CircularMovementControl)

Example 60 with Rectangle

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());
}
Also used : RandomMoveControl(com.almasb.fxgl.entity.control.RandomMoveControl) Rectangle(javafx.scene.shape.Rectangle) Rectangle2D(javafx.geometry.Rectangle2D)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)190 Point2D (javafx.geometry.Point2D)33 Text (javafx.scene.text.Text)28 Entity (com.almasb.fxgl.entity.Entity)27 Circle (javafx.scene.shape.Circle)20 Color (javafx.scene.paint.Color)18 HitBox (com.almasb.fxgl.physics.HitBox)16 Pane (javafx.scene.layout.Pane)16 Group (javafx.scene.Group)15 Node (javafx.scene.Node)14 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)12 Scene (javafx.scene.Scene)12 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Bounds (javafx.geometry.Bounds)7 KeyCode (javafx.scene.input.KeyCode)7