本文整理汇总了Java中com.badlogic.ashley.core.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于com.badlogic.ashley.core包,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processEntity
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
if (_tile != null) {
_batch.begin();
TextureRegion textureRegion = _tile.getCell().getTile().getTextureRegion();
Sprite sprite = new Sprite(textureRegion);
if (!isLegalPlacement()) {
sprite.setColor(Color.RED);
sprite.setAlpha(0.5f);
} else {
sprite.setColor(Color.GREEN);
sprite.setAlpha(0.5f);
}
sprite.setPosition(_tile.getCords().x, _tile.getCords().y);
sprite.draw(_batch);
_batch.end();
}
}
示例2: createCoinEntity
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
public void createCoinEntity(float x, float y, int moneyValue) {
Entity entity = new Entity();
OffsetComponent ocomp = new OffsetComponent(16, 16);
SkeletonComponent scomp = new SkeletonComponent(Assets.coinSkeleton);
TimeComponent tcomp = new TimeComponent(0.5f);
VelocityComponent vcomp = new VelocityComponent(25f);
PositionComponent pcomp = new PositionComponent(new Vector2(x, y));
MoneyComponent mcomp = new MoneyComponent(moneyValue);
RenderableComponent rcomp = new RenderableComponent();
scomp.animationState.setData(Assets.coinAnimationState.getData());
entity.add(pcomp)//
.add(vcomp)//
.add(tcomp)//
.add(scomp)//
.add(ocomp)//
.add(mcomp)//
.add(rcomp);
_engine.addEntity(entity);
}
示例3: 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;
}
示例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: removeBuilding
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
/**
* Mark a given filled range as free
* The same range must be in the planet already
*
* @param min - the minimum angle
* @param max - the maximum angle
* @param planet - the parent planet
*
* @return whether the component changed
*/
public boolean removeBuilding(float min, float max, Entity planet) {
if (freeSpaces.isEmpty()) return false;
Iterator<AngleRange> iterator = freeSpaces.iterator();
while (iterator.hasNext()) {
AngleRange range = iterator.next();
double rMax = range.getMaxD();
if (rMax > 360) rMax -= 360;
if (rMax == min) {
if (iterator.hasNext()) {
AngleRange nextRange = iterator.next();
range.setMax(nextRange.getMaxD());
}
iterator.remove();
return true;
}
}
return false;
}
示例7: processEntity
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
HealthComponent hpComp = Mappers.HEALTH_M.get(entity);
PositionComponent posComp = Mappers.POSITION_M.get(entity);
EnemyComponent enemyComp = Mappers.ENEMY_M.get(entity);
if (hpComp.isDead) {
float deathX = posComp.position.x;
float deathY = posComp.position.y;
entity.removeAll();
getEngine().removeEntity(entity);
if(enemyComp != null){
PlayState.CURRENT_LIVING_ENEMIES --;
}
_entityFactory.createCoinEntity(deathX, deathY, WaveTimeManager.WAVE + MathUtils.random(1));
}
if(enemyComp != null){
drawHealthBar(hpComp, posComp);
}
}
示例8: updateEntity
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
private void updateEntity(String participantId, ByteBuffer wrap) {
Entity entity = null;
for (Entity syncedEntity : syncedEntities) {
if (idMapper.get(syncedEntity).participantId.equals(participantId)) {
entity = syncedEntity;
break;
}
}
if (entity == null) {
Gdx.app.debug(TAG, "updateEntity: NULL");
return;
}
TransformComponent transformComponent = transformMapper.get(entity);
MovementComponent movement = movementMapper.get(entity);
if (transformComponent == null || movement == null) return;
transformComponent.position.x = wrap.getFloat();
transformComponent.position.y = wrap.getFloat();
transformComponent.rotation.x = wrap.getFloat();
transformComponent.rotation.y = wrap.getFloat();
movement.velocity.x = wrap.getFloat();
movement.velocity.y = wrap.getFloat();
movement.acceleration.x = wrap.getFloat();
movement.acceleration.y = wrap.getFloat();
}
示例9: sendBullet
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
private void sendBullet(Entity entity) {
// Gdx.app.debug(TAG, "sendBullet: ");
IdComponent bulletId = idMapper.get(entity);
IdComponent playerId = idMapper.get(player.first());
if (!Objects.equals(bulletId.participantId, playerId.participantId)) {
return;
}
TransformComponent transform = transformMapper.get(entity);
MovementComponent movement = movementMapper.get(entity);
ByteBuffer buffer = ByteBuffer.allocate(4 * 4 + 1);
buffer.put(BULLET);
buffer.putFloat(transform.position.x);
buffer.putFloat(transform.position.y);
buffer.putFloat(movement.velocity.x);
buffer.putFloat(movement.velocity.y);
networkService.sendUnreliableMessageToOthers(buffer.array());
}
示例10: update
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
@Override
public void update(float deltaTime) {
super.update(deltaTime);
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (Entity entity : getEntities()) {
SpriteComponent sprite = spriteM.get(entity);
TransformComponent transform = positionM.get(entity);
sprite.sprite.setRotation(transform.rotation);
sprite.sprite.setPosition(transform.position.x - tileWidth, transform.position.y - tileWidth);
sprite.sprite.draw(batch);
}
batch.end();
}
示例11: onEntityDestroyed
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
@Override
public void onEntityDestroyed(Engine engine, Entity entity, Entity source) {
IdComponent bulletId = idMapper.get(source);
// TODO: 06-Apr-17 Improve how we find the source
if (bulletId != null) {
for (Entity player : players) {
IdComponent playerId = idMapper.get(player);
if (Objects.equals(playerId.participantId, bulletId.participantId)) {
if (player.isScheduledForRemoval()) return;
ScoreComponent scoreComponent = scoreMapper.get(player);
int oldScore = scoreComponent.score;
scoreComponent.score += SCORE_INCREASE;
notifyListeners(engine, player, oldScore);
return;
}
}
}
// TODO: 05-Apr-17 calculate rounds won
}
示例12: onCancel
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
@Override
public void onCancel(Entity e, Level level) {
if (building != null) {
InContructionComponent icc = InContructionComponent.MAPPER.get(building);
if (icc != null) {
--icc.building;
if (icc.building == 0) {
level.getECS().removeEntity(building);
if (Team1Component.MAPPER.has(building)) {
level.getPlayer1().setMoney(level.getPlayer1().getMoney() + price);
} else if (Team2Component.MAPPER.has(building)) {
level.getPlayer2().setMoney(level.getPlayer2().getMoney() + price);
}
}
}
}
}
示例13: processEntity
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
TransformComponent pos = transformMapper.get(entity);
DrawableComponent drawable = drawableMapper.get(entity);
boolean free = false;
BoundaryComponent boundaryComponent = boundaryMapper.get(entity);
if (boundaryComponent != null && boundaryComponent.boundaryMode == BoundaryComponent.MODE_WRAP) {
free = true;
}
if (pos.position.x + drawable.texture.getRegionHeight() / 2 < 0) {
if (free) pos.position.x = width;
else deleteEntity(entity);
} else if (pos.position.x - drawable.texture.getRegionWidth() / 2 > width) {
if (free) pos.position.x = 0;
else deleteEntity(entity);
} else if (pos.position.y + drawable.texture.getRegionHeight() / 2 < 0) {
if (free) pos.position.y = height;
else deleteEntity(entity);
} else if (pos.position.y - drawable.texture.getRegionHeight() / 2 > height) {
if (free) pos.position.y = 0;
else deleteEntity(entity);
}
}
示例14: getMinMax
import com.badlogic.ashley.core.Entity; //导入依赖的package包/类
/**
* Get the minimum and maximum angles that are ocuppied by a building
*
* @param building - the building
* @param planet - the planet the building is on
* @param positionB - the angle on the planet that the building is on
*
* @return an array of floats where the first float is the minimum angle and the second is the maximum angle
*/
public static float[] getMinMax(Entity building, Entity planet, float positionB) {
SizeComponent size = SizeComponent.MAPPER.get(building);
SizeComponent planetSize = SizeComponent.MAPPER.get(planet);
//Base building position
RotationComponent planetR = RotationComponent.MAPPER.get(planet);
float planetRot = planetR != null ? planetR.r % 360 : 0f;
Vector2 rotatedBuildingVector = new Vector2(1f, 0f).rotate(positionB +
planetRot);
//Desired building position
Vector2 position = rotatedBuildingVector.cpy().scl(planetSize.w / 2, planetSize.h / 2);
//Surface vector
Vector2 surface = rotatedBuildingVector.cpy().rotate90(1);
//Normalize and scale by half of the width
surface.setLength(size.w / 2);
float min = position.cpy().sub(surface).angle() - planetRot;
if (min < 0) min += 360;
float max = position.cpy().add(surface).angle() - planetRot;
if (max < 0) max += 360;
return new float[]{min, max};
}
示例15: 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();
}