use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class FXShooterApp method spawnEnemy.
private void spawnEnemy() {
Entity enemy = new Entity();
enemy.getTypeComponent().setValue(EntityType.ENEMY);
enemy.getPositionComponent().setValue(getWidth(), 460);
enemy.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.RED)), true);
enemy.addComponent(new CollidableComponent(true));
enemy.addComponent(new HPComponent(5));
enemy.addControl(new EnemyControl(new Point2D(getWidth() / 2, getHeight() / 2)));
getGameWorld().addEntity(enemy);
}
use of com.almasb.fxgl.entity.view.EntityView 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 com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class ViewComponent method setView.
/**
* Set view. The generate bbox flag tells the component
* whether it should generate bbox from the given view.
*
* Note: the generated bounding box is an approximation based on
* the layout bounds of the view object.
*
* @param view the view
* @param generateBoundingBox generate bbox flag
*/
public void setView(Node view, boolean generateBoundingBox) {
EntityView entityView = view instanceof EntityView ? (EntityView) view : new EntityView(view);
this.view.getNodes().setAll(entityView.getNodes());
if (showBBox()) {
this.view.addNode(debugBBox);
}
if (generateBoundingBox) {
generateBBox();
}
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class RaycastSample method initGame.
@Override
protected void initGame() {
spawnWall(500, 100, 50, 50);
spawnWall(550, 150, 50, 50);
spawnWall(600, 200, 50, 50);
spawnWall(600, 400, 50, 50);
spawnWall(300, 450, 50, 50);
spawnWall(500, 550, 50, 50);
spawnWall(300, 300, 50, 50);
laser.setStroke(Color.RED);
laser.setStrokeWidth(2);
laser.setStartY(300);
getGameScene().addGameView(new EntityView(laser));
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class JointSample method initGame.
@Override
protected void initGame() {
getGameWorld().addEntity(Entities.makeScreenBounds(50));
PhysicsComponent physics = new PhysicsComponent();
Entity block = Entities.builder().at(200, 200).viewFromNodeWithBBox(new Rectangle(50, 50)).with(physics).buildAndAttach(getGameWorld());
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball = Entities.builder().at(200, 300).bbox(new HitBox("main", BoundingShape.circle(15))).viewFromNode(getAssetLoader().loadTexture("ball.png", 30, 30)).with(physics2).buildAndAttach(getGameWorld());
Line line = new Line();
line.setStartX(block.getCenter().getX());
line.setStartY(block.getCenter().getY());
// line.startXProperty().bind(block.getPositionComponent().xProperty());
// line.startYProperty().bind(block.getPositionComponent().yProperty());
line.endXProperty().bind(ball.getPositionComponent().xProperty().add(15));
line.endYProperty().bind(ball.getPositionComponent().yProperty().add(15));
getGameScene().addGameView(new EntityView(line));
RevoluteJointDef rDef = new RevoluteJointDef();
rDef.bodyA = physics.getBody();
rDef.bodyB = physics2.getBody();
rDef.collideConnected = false;
rDef.localAnchorA = new Vec2(0, 0);
rDef.localAnchorB = new Vec2(0, 5);
rDef.enableLimit = true;
rDef.lowerAngle = (float) (FXGLMath.toRadians(-180.0f));
rDef.upperAngle = (float) (FXGLMath.toRadians(180.0f));
rDef.enableMotor = true;
rDef.motorSpeed = (float) (FXGLMath.toRadians(30));
rDef.maxMotorTorque = 15.0f;
joint = (RevoluteJoint) getPhysicsWorld().getJBox2DWorld().createJoint(rDef);
}
Aggregations