本文整理汇总了Java中com.badlogic.ashley.core.Entity.add方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.add方法的具体用法?Java Entity.add怎么用?Java Entity.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.ashley.core.Entity
的用法示例。
在下文中一共展示了Entity.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOpponent
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createOpponent(String participantId, String displayName) {
Entity entity = new Entity();
entity.add(new PlayerClass(displayName));
entity.add(new IdComponent(participantId));
int rotationX = 1;
int rotationY = 0;
int positionX = Asteroids.VIRTUAL_WIDTH / 2;
int positionY = Asteroids.VIRTUAL_HEIGHT / 2;
entity.add(new TransformComponent(positionX, positionY, rotationX, rotationY));
entity.add(new MovementComponent());
entity.add(new BoundaryComponent());
entity.add(new CircularBoundsComponent());
entity.add(new HealthComponent(3));
entity.add(new ScoreComponent());
entity.add(drawableComponentFactory.getMultiPlayer());
entity.add(new GravityComponent(gameSettings.getPlayerGravity()));
entity.add(engine.createComponent(CollisionComponent.class));
return entity;
}
示例2: createBullet
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createBullet(String playerId) {
Entity entity = engine.createEntity();
entity.add(engine.createComponent(BulletClass.class));
IdComponent idComponent = engine.createComponent(IdComponent.class);
idComponent.participantId = playerId;
entity.add(idComponent);
entity.add(engine.createComponent(TransformComponent.class));
entity.add(engine.createComponent(MovementComponent.class));
entity.add(engine.createComponent(CircularBoundsComponent.class));
entity.add(engine.createComponent(DamageComponent.class));
entity.add(engine.createComponent(NetworkAddComponent.class));
entity.add(drawableComponentFactory.getProjectile());
CollisionComponent collisionComponent = engine.createComponent(CollisionComponent.class);
collisionComponent.collisionHandler = bulletCollisionHandler;
collisionComponent.ignoredEntities = BULLET_COLLISION_IGNORE;
entity.add(collisionComponent);
return entity;
}
示例3: createMissile
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createMissile(String playerId) {
Entity entity = engine.createEntity();
entity.add(engine.createComponent(BulletClass.class));
IdComponent idComponent = engine.createComponent(IdComponent.class);
idComponent.participantId = playerId;
entity.add(idComponent);
entity.add(engine.createComponent(TransformComponent.class));
entity.add(engine.createComponent(MovementComponent.class));
entity.add(engine.createComponent(CircularBoundsComponent.class));
entity.add(engine.createComponent(DamageComponent.class));
entity.add(engine.createComponent(NetworkAddComponent.class));
entity.add(drawableComponentFactory.getMissile());
AnimationComponent animation = engine.createComponent(AnimationComponent.class);
entity.add(animation);
animation.delay = gameSettings.getMissileDelay();
animation.scale.set(1.5f, 1.5f);
animation.removeDuringAnimation.add(MovementComponent.class);
animation.removeEntityAfterAnimation = true;
animation.soundOnStart = AssetService.SoundAsset.SOUND_EXPLOSION_WAV;
animation.frames.addAll(animationFactory.getShortExplosion());
CollisionComponent collisionComponent = engine.createComponent(CollisionComponent.class);
collisionComponent.collisionHandler = bulletCollisionHandler;
collisionComponent.ignoredEntities = BULLET_COLLISION_IGNORE;
entity.add(collisionComponent);
return entity;
}
示例4: createBomb
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createBomb(String playerId) {
Entity entity = engine.createEntity();
entity.add(engine.createComponent(BulletClass.class));
IdComponent idComponent = engine.createComponent(IdComponent.class);
idComponent.participantId = playerId;
entity.add(idComponent);
entity.add(engine.createComponent(TransformComponent.class));
entity.add(engine.createComponent(CircularBoundsComponent.class));
entity.add(engine.createComponent(DamageComponent.class));
entity.add(engine.createComponent(NetworkAddComponent.class));
entity.add(drawableComponentFactory.getBomb());
AnimationComponent animation = engine.createComponent(AnimationComponent.class);
entity.add(animation);
animation.soundOnStart = AssetService.SoundAsset.SOUND_EXPLOSION_WAV;
animation.delay = gameSettings.getBombDelay();
animation.scale.set(2.5f, 2.5f);
animation.removeEntityAfterAnimation = true;
animation.frames.addAll(animationFactory.getLongExplosion());
CollisionComponent collisionComponent = engine.createComponent(CollisionComponent.class);
collisionComponent.collisionHandler = bulletCollisionHandler;
collisionComponent.ignoredEntities = BULLET_COLLISION_IGNORE;
entity.add(collisionComponent);
return entity;
}
示例5: createObstacle
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createObstacle() {
Entity entity = engine.createEntity();
entity.add(engine.createComponent(ObstacleClass.class));
entity.add(engine.createComponent(TransformComponent.class));
entity.add(engine.createComponent(MovementComponent.class));
entity.add(engine.createComponent(CircularBoundsComponent.class));
entity.add(engine.createComponent(HealthComponent.class));
HealthComponent healthComponent = healthMapper.get(entity);
healthComponent.damageHandler = OBSTACLE_DAMAGE_HANDLER;
entity.add(engine.createComponent(DamageComponent.class));
entity.add(engine.createComponent(NetworkAddComponent.class));
entity.add(drawableComponentFactory.getObstacle());
CollisionComponent collisionComponent = engine.createComponent(CollisionComponent.class);
collisionComponent.ignoredEntities = OBSTACLE_COLLISION_IGNORE;
entity.add(collisionComponent);
return entity;
}
示例6: applyEffect
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
@Override
protected void
applyEffect(PooledEngine engine, Entity entity, EffectComponent effectComponent) {
damageComponent = damageMapper.get(entity);
if (damageComponent != null) {
damageComponent.ignoredEntities = null;
} else {
damageComponent = engine.createComponent(DamageComponent.class);
entity.add(damageComponent);
}
healthComponent = healthMapper.get(entity);
if (healthComponent == null) {
healthComponent = engine.createComponent(HealthComponent.class);
entity.add(healthComponent);
}
oldHealthIgnore = healthComponent.ignoredEntities;
healthComponent.ignoredEntities = Family.one(ObstacleClass.class, BulletClass.class).get();
}
示例7: newTower
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public static Entity newTower(Vector2 spawn) {
Entity entity = ENGINE.createEntity();
CoordinateUtil.alignToGrid(spawn);
SpriteComponent spriteComponent = ENGINE.createComponent(SpriteComponent.class);
spriteComponent.sprite = SPRITE;
entity.add(spriteComponent);
TransformComponent transformComponent = ENGINE.createComponent(TransformComponent.class);
transformComponent.position = spawn;
entity.add(transformComponent);
TurretComponent turretComponent = ENGINE.createComponent(TurretComponent.class);
entity.add(turretComponent);
ENGINE.addEntity(entity);
return entity;
}
示例8: placeTowers
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
private void placeTowers(int button) {
if (_isPlacementMode) {
Tile tile = getTileAtMouse();
ImmutableArray<Entity> towerEntitys = getAshleyEngine().getEntitiesFor(_towerFamily);
Entity first = towerEntitys.first();
first.remove(MouseImageComponent.class);
first.getComponent(PositionComponent.class).position.x = tile.getCords().x;
first.getComponent(PositionComponent.class).position.y = tile.getCords().y;
first.add(new OffsetComponent(16, 16));
tile.setType(TileType.WALL);
tile.setEntity(first);
getAshleyEngine().getSystem(TowerPlacementSystem.class).tintTile(null);
InputHandler.setPlacementMode(false);
_ef.getPlayer().getComponent(MoneyComponent.class).money -= first.getComponent(TowerStatComponent.class)._buyCost;
}
}
示例9: update
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
@Override
public void update(Entity e, float deltaTime, Level level) {
if (done) return;
PositionComponent pos = PositionComponent.MAPPER.get(e);
VelocityComponent vel = VelocityComponent.MAPPER.get(e);
if (vel == null) {
vel = new VelocityComponent();
e.add(vel);
}
ShipComponent ship = ShipComponent.MAPPER.get(e);
if (speed < 0) speed = ship.moveSpeed;
double dx = x - pos.getX();
double dy = y - pos.getY();
double dist = Math.hypot(dx, dy);
if (dist < speed * deltaTime) {
done = true;
pos.setX((float) x);
pos.setY((float) y);
e.remove(VelocityComponent.class);
} else {
vel.vx = (float) (speed * dx / dist);
vel.vy = (float) (speed * dy / dist);
}
}
示例10: update
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
@Override
public void update(Entity e, float deltaTime, Level level) {
if (done) {
return;
}
PositionComponent pos = PositionComponent.MAPPER.get(e);
VelocityComponent vel = VelocityComponent.MAPPER.get(e);
if (vel == null) {
vel = new VelocityComponent();
e.add(vel);
}
double dx = x - pos.getX();
double dy = y - pos.getY();
if (time < 0) {
done = true;
pos.setX((float) x);
pos.setY((float) y);
e.remove(VelocityComponent.class);
} else {
vel.vx = (float) (dx / time);
vel.vy = (float) (dy / time);
time -= deltaTime;
}
}
示例11: createPlayer
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createPlayer(String id, String displayName, boolean multiplayer) {
Entity entity = new Entity();
PlayerClass playerClass = new PlayerClass(displayName);
entity.add(new IdComponent(id));
playerClass.isSelf = true;
entity.add(playerClass);
int rotationX = 1;
int rotationY = 0;
int positionX = Asteroids.VIRTUAL_WIDTH / 2;
int positionY = Asteroids.VIRTUAL_HEIGHT / 2;
if (multiplayer) {
positionX = (int) (Asteroids.VIRTUAL_WIDTH * MathUtils.random());
positionY = (int) (Asteroids.VIRTUAL_HEIGHT * MathUtils.random());
entity.add(new NetworkSyncComponent());
entity.add(new HealthComponent(3));
entity.add(drawableComponentFactory.getPlayer(false));
} else {
entity.add(new HealthComponent(1));
entity.add(new EffectComponent());
entity.add(drawableComponentFactory.getPlayer(true));
}
entity.add(new TransformComponent(positionX, positionY, rotationX, rotationY));
MovementComponent movementComponent = new MovementComponent();
movementComponent.accelerationScalar = gameSettings.getAccelerationScalar();
entity.add(movementComponent);
entity.add(new GravityComponent(gameSettings.getPlayerGravity()));
entity.add(new CircularBoundsComponent());
entity.add(new ShootComponent(new MultiShotHandler()));
entity.add(new ScoreComponent());
entity.add(new AchievementComponent());
entity.add(new BoundaryComponent(BoundaryComponent.MODE_WRAP));
CollisionComponent collisionComponent = new CollisionComponent();
entity.add(collisionComponent);
return entity;
}
示例12: createPowerup
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
public Entity createPowerup(IEffect effect) {
Entity entity = engine.createEntity();
PowerupClass powerup = engine.createComponent(PowerupClass.class);
powerup.effect = effect;
entity.add(powerup);
entity.add(engine.createComponent(CircularBoundsComponent.class));
entity.add(drawableComponentFactory.getPowerup(effect));
CollisionComponent collisionComponent = engine.createComponent(CollisionComponent.class);
collisionComponent.ignoredEntities = POWERUP_COLLISION_IGNORE;
collisionComponent.collisionHandler = POWERUP_COLLISION_HANDLER;
entity.add(collisionComponent);
entity.add(engine.createComponent(MovementComponent.class));
entity.add(engine.createComponent(TransformComponent.class));
return entity;
}
示例13: onEntityDestroyed
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
@Override
public void onEntityDestroyed(Engine engine, Entity entity, Entity source) {
spawnPowerup(engine, entity);
AnimationComponent animation = new AnimationComponent();
animation.removeEntityAfterAnimation = true;
animation.frames.addAll(ServiceLocator.getAppComponent().getAnimationFactory().getMediumExplosion());
animation.soundOnStart = AssetService.SoundAsset.SOUND_EXPLOSION_WAV;
animation.removeDuringAnimation.add(CollisionComponent.class);
animation.removeDuringAnimation.add(MovementComponent.class);
entity.add(animation);
// TODO: 31-Mar-17 Figure out why this line sometime causes a null reference
}
示例14: onCollision
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
@Override
public boolean onCollision(PooledEngine engine, Entity source, Entity target) {
EffectComponent effectComponent = effectMapper.get(target);
if (effectComponent == null) {
return false;
}
PowerupClass powerup = powerupMapper.get(source);
effectComponent.addEffect(engine, target, powerup.effect);
target.add(effectComponent);
AnimationComponent pickupAnimation = createAnimationComponent();
target.add(pickupAnimation);
engine.removeEntity(source);
return true;
}
示例15: onEntityDestroyed
import com.badlogic.ashley.core.Entity; //导入方法依赖的package包/类
@Override
public void onEntityDestroyed(Engine engine, Entity entity, Entity source) {
AnimationComponent animation = new AnimationComponent();
// TODO: 31-Mar-17 Figure out why this line sometime causes a null reference
animation.removeEntityAfterAnimation = true;
animation.frames.addAll(ServiceLocator.getAppComponent().getAnimationFactory().getMediumExplosion());
entity.add(animation);
world.audioService.playSound(AssetService.SoundAsset.SOUND_EXPLOSION_WAV);
entity.remove(CollisionComponent.class);
entity.remove(MovementComponent.class);
}