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);
}
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();
}
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);
}
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);
}
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));
}
Aggregations