use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class ScifiFactory method newPlayer.
@Spawns("player")
public Entity newPlayer(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
BodyDef bd = new BodyDef();
bd.setFixedRotation(true);
physics.setBodyDef(bd);
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().from(data).type(ScifiType.PLAYER).bbox(new HitBox("main", BoundingShape.circle(15))).bbox(new HitBox("lower", new Point2D(15 - 5, 30), BoundingShape.box(10, 10))).with(physics, new CollidableComponent(true)).with(new PlayerControl()).build();
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class MarioFactory method newPlayer.
@Spawns("player")
public Entity newPlayer(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
physics.setGenerateGroundSensor(true);
BodyDef bd = new BodyDef();
bd.setFixedRotation(true);
physics.setBodyDef(bd);
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().from(data).type(MarioType.PLAYER).bbox(new HitBox("main", BoundingShape.circle(15))).bbox(new HitBox("lower", new Point2D(15 - 5, 30), BoundingShape.box(10, 10))).with(physics, new CollidableComponent(true)).with(new PlayerControl()).build();
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class MarioFactory method newGhostPlatform.
@Spawns("ghost_platform")
public Entity newGhostPlatform(SpawnData data) {
Entity platform = Entities.builder().from(data).type(MarioType.GHOST_PLATFORM).viewFromTexture("ghost_platform.png").bbox(new HitBox("main", BoundingShape.box(data.<Integer>get("width"), data.<Integer>get("height")))).with(new PhysicsComponent(), new CollidableComponent(true)).build();
platform.getView().setVisible(false);
return platform;
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class Entities method makeScreenBounds.
/**
* Create an entity with bounding box around the screen with given thickness.
*
* @param thickness thickness of hit boxes around the screen
* @return entity with screen bounds
*/
public static Entity makeScreenBounds(double thickness) {
double w = FXGL.getSettings().getWidth();
double h = FXGL.getSettings().getHeight();
Entity bounds = new Entity();
bounds.getBoundingBoxComponent().addHitBox(new HitBox("LEFT", new Point2D(-thickness, 0), BoundingShape.box(thickness, h)));
bounds.getBoundingBoxComponent().addHitBox(new HitBox("RIGHT", new Point2D(w, 0), BoundingShape.box(thickness, h)));
bounds.getBoundingBoxComponent().addHitBox(new HitBox("TOP", new Point2D(0, -thickness), BoundingShape.box(w, thickness)));
bounds.getBoundingBoxComponent().addHitBox(new HitBox("BOT", new Point2D(0, h), BoundingShape.box(w, thickness)));
bounds.addComponent(new PhysicsComponent());
return bounds;
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class PhysicsPlaygroundSample method spawnBlock.
private void spawnBlock(double x, double y) {
var p = new PhysicsComponent();
p.setBodyType(BodyType.DYNAMIC);
p.setFixtureDef(new FixtureDef().friction(fieldFriction.getFloat()).density(fieldDensity.getFloat()).restitution(fieldRestitution.getFloat()));
BoundingShape shape;
Node view;
switch(cb.getValue()) {
case BOX:
shape = BoundingShape.box(40, 40);
break;
case CIRCLE:
shape = BoundingShape.circle(20);
break;
case TRIANGLE:
default:
shape = BoundingShape.polygon(new Point2D(0, 40), new Point2D(20, 0), new Point2D(40, 40));
break;
}
switch(cb.getValue()) {
case BOX:
view = new Rectangle(40, 40, Color.BLUE);
((Rectangle) view).setStroke(Color.DARKBLUE);
break;
case CIRCLE:
view = new Circle(20, 20, 20, Color.YELLOW);
((Circle) view).setStroke(Color.ORANGE);
break;
case TRIANGLE:
default:
view = new Polygon(0, 40, 20, 0, 40, 40);
((Polygon) view).setFill(Color.RED);
((Polygon) view).setStroke(Color.DARKRED);
break;
}
entityBuilder().at(x, y).bbox(shape).view(view).with(p).buildAndAttach();
}
Aggregations