use of com.almasb.fxgl.entity.component.CollidableComponent 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.entity.component.CollidableComponent 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));
}
use of com.almasb.fxgl.entity.component.CollidableComponent in project FXGL by AlmasB.
the class ScriptSample2 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());
}
use of com.almasb.fxgl.entity.component.CollidableComponent in project FXGL by AlmasB.
the class BasicGameApp3 method initGame.
@Override
protected void initGame() {
player = Entities.builder().type(EntityType.PLAYER).at(300, 300).viewFromTextureWithBBox("brick.png").with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
Entities.builder().type(EntityType.COIN).at(500, 200).viewFromNodeWithBBox(new Circle(15, Color.YELLOW)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
}
use of com.almasb.fxgl.entity.component.CollidableComponent in project FXGL by AlmasB.
the class PhysicsSample 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(40, 40))).viewFromNode(new Rectangle(40, 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);
}
Aggregations