use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class PhysicsSample2 method initGame.
@Override
protected void initGame() {
playerControl = new PlayerControl();
player = Entities.builder().type(Type.PLAYER).at(100, 100).bbox(new HitBox("PLAYER_BODY", BoundingShape.box(250, 40))).viewFromNode(new Rectangle(250, 40, Color.BLUE)).with(playerControl).build();
enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).build();
// 2. we need to add Collidable component and set its value to true
// so that collision system can 'see' our entities
player.addComponent(new CollidableComponent(true));
enemy.addComponent(new CollidableComponent(true));
getGameWorld().addEntities(player, enemy);
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class PlatformerSample method createPlayer.
private Entity createPlayer(double x, double y, double width, double height) {
PhysicsComponent physics = new PhysicsComponent();
physics.setGenerateGroundSensor(true);
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().at(x, y).viewFromNodeWithBBox(new Rectangle(width, height, Color.BLUE)).with(physics).buildAndAttach(getGameWorld());
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class PlatformerSample method createPlatforms.
private void createPlatforms() {
Entities.builder().at(0, 500).viewFromNode(new Rectangle(120, 100, Color.GRAY)).bbox(new HitBox("Main", BoundingShape.chain(new Point2D(0, 0), new Point2D(120, 0), new Point2D(120, 100), new Point2D(0, 100)))).with(new PhysicsComponent()).buildAndAttach(getGameWorld());
Entities.builder().at(180, 500).viewFromNode(new Rectangle(400, 100, Color.GRAY)).bbox(new HitBox("Main", BoundingShape.chain(new Point2D(0, 0), new Point2D(400, 0), new Point2D(400, 100), new Point2D(0, 100)))).with(new PhysicsComponent()).buildAndAttach(getGameWorld());
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class RealPhysicsSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Spawn Box") {
@Override
protected void onActionBegin() {
Entity box = createPhysicsEntity();
// 3. set hit box (-es) to specify bounding shape
box.getBoundingBoxComponent().addHitBox(new HitBox("Left", BoundingShape.box(40, 40)));
box.getBoundingBoxComponent().addHitBox(new HitBox("Right", new Point2D(40, 0), BoundingShape.box(40, 40)));
box.getViewComponent().setView(new Rectangle(80, 40, Color.BLUE));
getGameWorld().addEntity(box);
}
}, MouseButton.PRIMARY);
input.addAction(new UserAction("Spawn Ball") {
@Override
protected void onActionBegin() {
Entity ball = createPhysicsEntity();
// 3. set hit box to specify bounding shape
ball.getBoundingBoxComponent().addHitBox(new HitBox("Test", BoundingShape.circle(20)));
ball.getViewComponent().setView(new Circle(20, Color.RED));
getGameWorld().addEntity(ball);
}
}, MouseButton.SECONDARY);
}
use of javafx.scene.shape.Rectangle in project FXGL by AlmasB.
the class JavaScriptSample method initGame.
@Override
protected void initGame() {
Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40)).with(new JSControl("spin_control.js")).buildAndAttach(getGameWorld());
Entities.builder().at(180, 100).viewFromNode(new Rectangle(40, 40)).with(new JSControl("ccw_spin_control.js")).buildAndAttach(getGameWorld());
getAssetLoader().loadScript("sample.js").call("sample");
}
Aggregations