Search in sources :

Example 11 with Rectangle

use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.

the class PlayerControl method shoot.

public void shoot(Point2D direction) {
    Entity bullet = new Entity();
    bullet.getTypeComponent().setValue(FXShooterApp.EntityType.BULLET);
    bullet.getPositionComponent().setValue(getEntity().getComponent(PositionComponent.class).getValue().add(20, 20));
    bullet.getViewComponent().setView(new EntityView(new Rectangle(10, 2, Color.BLACK)), true);
    bullet.addComponent(new CollidableComponent(true));
    bullet.addControl(new OffscreenCleanControl());
    bullet.addControl(new ProjectileControl(direction, 10 * 60));
    BulletComponent bulletData = new BulletComponent();
    bulletData.setDamage(1);
    bulletData.setHp(1);
    bulletData.setSpeed(10);
    bullet.addComponent(bulletData);
    getEntity().getWorld().addEntity(bullet);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) ProjectileControl(com.almasb.fxgl.entity.control.ProjectileControl) OffscreenCleanControl(com.almasb.fxgl.entity.control.OffscreenCleanControl)

Example 12 with Rectangle

use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.

the class SelectedEntitySample method initGame.

@Override
protected void initGame() {
    // 2. create entity and attach to world using fluent API
    Entity e1 = Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(new SelectableComponent(true)).buildAndAttach();
    Entity e2 = Entities.builder().at(300, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new SelectableComponent(true)).buildAndAttach();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle) SelectableComponent(com.almasb.fxgl.entity.component.SelectableComponent)

Example 13 with Rectangle

use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.

the class ViewportZoomSample method initGame.

@Override
protected void initGame() {
    e1 = Entities.builder().at(0, 0).viewFromNodeWithBBox(new Rectangle(40, 40, Color.BLUE)).buildAndAttach(getGameWorld());
    e2 = Entities.builder().at(800, 0).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).buildAndAttach(getGameWorld());
    e3 = Entities.builder().at(600, 560).viewFromNodeWithBBox(new Rectangle(40, 40, Color.GREEN)).buildAndAttach(getGameWorld());
    // 1. bind viewport so it can fit those entities at any time
    getGameScene().getViewport().bindToFit(40, 100, e1, e2, e3);
}
Also used : Rectangle(javafx.scene.shape.Rectangle)

Example 14 with Rectangle

use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.

the class MarioApp method initInput.

@Override
protected void initInput() {
    DSLKt.onKeyDown(KeyCode.K, "G+", () -> {
        getPhysicsWorld().setGravity(0, -getPhysicsWorld().getJBox2DWorld().getGravity().y * 50 + 10);
        System.out.println(-getPhysicsWorld().getJBox2DWorld().getGravity().y * 50);
    });
    DSLKt.onKeyDown(KeyCode.I, "G-", () -> {
        getPhysicsWorld().setGravity(0, -getPhysicsWorld().getJBox2DWorld().getGravity().y * 50 - 10);
        System.out.println(-getPhysicsWorld().getJBox2DWorld().getGravity().y * 50);
    });
    getInput().addAction(new UserAction("Left") {

        @Override
        protected void onAction() {
            playerControl.left();
        }

        @Override
        protected void onActionEnd() {
            playerControl.stop();
        }
    }, KeyCode.A);
    getInput().addAction(new UserAction("Right") {

        @Override
        protected void onAction() {
            playerControl.right();
        }

        @Override
        protected void onActionEnd() {
            playerControl.stop();
        }
    }, KeyCode.D);
    getInput().addAction(new UserAction("Jump") {

        @Override
        protected void onActionBegin() {
            playerControl.jump();
        }
    }, KeyCode.W);
    getInput().addAction(new UserAction("Enter") {

        @Override
        protected void onActionBegin() {
            stepLoop();
        }
    }, KeyCode.L);
    getInput().addAction(new UserAction("Drop rectangle") {

        @Override
        protected void onActionBegin() {
            Entities.builder().type(MarioType.OBSTACLE).at(getInput().getMousePositionWorld()).viewFromNodeWithBBox(new Rectangle(40, 40)).with(new CollidableComponent(true)).with(new ExpireCleanControl(Duration.seconds(2)).animateOpacity()).buildAndAttach();
        }
    }, MouseButton.PRIMARY);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) ExpireCleanControl(com.almasb.fxgl.entity.control.ExpireCleanControl)

Example 15 with Rectangle

use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.

the class ScriptSample method initGame.

@Override
protected void initGame() {
    Entity e = Entities.builder().type(EntityType.PC).at(300, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.BLUE)).with(new CollidableComponent(true)).with(new DeveloperWASDControl()).buildAndAttach(getGameWorld());
    Entities.builder().type(EntityType.NPC).at(400, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    for (int i = 0; i < 3; i++) {
        Entities.builder().type(EntityType.COIN).at(FXGLMath.random(100, 450), 500).viewFromNodeWithBBox(new Circle(20, Color.GOLD)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    }
    getMasterTimer().runAtInterval(() -> {
        getAudioPlayer().playPositionalSound("drop.wav", new Point2D(400, 300), e.getCenter(), 600);
    }, Duration.seconds(2));
}
Also used : DeveloperWASDControl(com.almasb.fxgl.devtools.DeveloperWASDControl) Entity(com.almasb.fxgl.entity.Entity) Circle(javafx.scene.shape.Circle) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)135 Text (javafx.scene.text.Text)23 Entity (com.almasb.fxgl.entity.Entity)21 Point2D (javafx.geometry.Point2D)17 Circle (javafx.scene.shape.Circle)16 Group (javafx.scene.Group)13 Pane (javafx.scene.layout.Pane)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 HitBox (com.almasb.fxgl.physics.HitBox)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Node (javafx.scene.Node)7 PlayerControl (common.PlayerControl)6 Timeline (javafx.animation.Timeline)6 StackPane (javafx.scene.layout.StackPane)6 Stage (javafx.stage.Stage)6 Region (javafx.scene.layout.Region)5