本文整理汇总了Java中com.badlogic.ashley.core.PooledEngine类的典型用法代码示例。如果您正苦于以下问题:Java PooledEngine类的具体用法?Java PooledEngine怎么用?Java PooledEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PooledEngine类属于com.badlogic.ashley.core包,在下文中一共展示了PooledEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCollision
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
public boolean onCollision(PooledEngine engine, Entity source, Entity target) {
if (!checkProcessing()) return false;
HealthComponent healthComponent = healthMapper.get(target);
DamageComponent damageComponent = damageMapper.get(source);
if (healthComponent == null || damageComponent == null) return false;
if (damageComponent.ignoredEntities != null && damageComponent.ignoredEntities.matches(target))
return false;
if (healthComponent.ignoredEntities != null && healthComponent.ignoredEntities.matches(source))
return false;
healthComponent.hitPoints -= damageComponent.damage;
if (healthComponent.damageHandler != null) {
healthComponent.damageHandler.onDamageTaken(getEngine(), target, source, damageComponent.damage);
}
notifyDamageListeners(target, source, damageComponent.damage);
if (healthComponent.hitPoints <= 0) {
if (healthComponent.damageHandler != null)
healthComponent.damageHandler.onEntityDestroyed(getEngine(), target, source);
}
notifyDestroyedListeners(target, source);
return true;
}
示例2: applyEffect
import com.badlogic.ashley.core.PooledEngine; //导入依赖的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();
}
示例3: setup
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Before
public void setup() {
Gdx.app = mock(Application.class);
engine = mock(PooledEngine.class);
when(engine.createComponent(HealthComponent.class)).thenReturn(new HealthComponent());
when(engine.createComponent(DamageComponent.class)).thenReturn(new DamageComponent());
ServiceLocator.appComponent = mock(AppComponent.class);
when(ServiceLocator.getAppComponent().getAudioService()).thenReturn(mock(AudioService.class));
ServiceLocator.entityComponent = mock(EntityComponent.class);
when(ServiceLocator.getEntityComponent().getEffectTextureFactory()).thenReturn(mock(EffectTextureFactory.class));
entity = mock(Entity.class);
fixture = new EffectComponent();
effect1 = Mockito.spy(BaseEffect.class);
when(effect1.tick(any(PooledEngine.class), any(Entity.class), any(EffectComponent.class), anyFloat())).thenReturn(false, false, false, true);
effect2 = Mockito.spy(BaseEffect.class);
}
示例4: addedToEngine
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
public void addedToEngine(Engine engine) {
this.engine = (PooledEngine) engine;
entities = engine.getEntitiesFor(Family.all(PlainPosition.class).get());
// engine.addEntityListener(new EntityListener() {
//
// @Override
// public void entityRemoved(Entity entity) {
// entities.remove(entity.getIndex());
// }
//
// @Override
// public void entityAdded(Entity entity) {
// entities.put(entity.getIndex(), entity);
// }
// });
for (int i = 0; ENTITY_COUNT > i; i++)
createEntity();
}
示例5: EntityFactory
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Inject
public EntityFactory(PooledEngine engine, IDrawableComponentFactory drawableComponentFactory,
IGameConfig gameSettings, AnimationFactory animationFactory) {
this.engine = engine;
this.drawableComponentFactory = drawableComponentFactory;
this.gameSettings = gameSettings;
this.animationFactory = animationFactory;
}
示例6: DefaultDrawableComponentFactory
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Inject
public DefaultDrawableComponentFactory(PooledEngine engine, AssetService assetService) {
this.engine = engine;
this.assetService = assetService;
playerTextures.add(PLAYER_BLUE);
playerTextures.add(PLAYER_RED);
playerTextures.add(PLAYER_GREEN);
playerTextures.add(PLAYER_YELLOW);
}
示例7: addEffect
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
public void addEffect(PooledEngine engine, Entity target, IEffect newEffect) {
if (effects.containsKey(newEffect.getEffectClass())) {
IEffect currentEffect = effects.get(newEffect.getEffectClass());
if (newEffect.getClass().equals(currentEffect.getClass())) {
currentEffect.refresh(engine, target, this, newEffect);
} else {
currentEffect.replace(engine, target, this, newEffect);
effects.put(newEffect.getEffectClass(), newEffect);
}
} else {
effects.put(newEffect.getEffectClass(), newEffect);
}
}
示例8: tick
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
public void tick(PooledEngine engine, Entity entity, float delta) {
Iterator<Map.Entry<Class, IEffect>> iterator = effects.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Class, IEffect> next = iterator.next();
boolean expired = next.getValue().tick(engine, entity, this, delta);
if (expired) iterator.remove();
}
}
示例9: processEntity
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
if (entity.isScheduledForRemoval()) return;
CollisionComponent thisCollision = collisionMapper.get(entity);
BoundsComponent bounds = boundsMapper.get(entity);
if (thisCollision == null || bounds == null) return;
for (Entity other : getEntities()) {
if (thisCollision.handledCollisions.contains(other)) continue;
if (entity == other) continue;
if (other.isScheduledForRemoval()) continue;
if (thisCollision.ignoredEntities != null
&& thisCollision.ignoredEntities.matches(other)) continue;
BoundsComponent otherBounds = boundsMapper.get(other);
CollisionComponent otherCollision = collisionMapper.get(other);
if (otherBounds == null || otherCollision == null) continue;
otherCollision.handledCollisions.add(entity);
if (bounds.overlaps(otherBounds)) {
boolean validEvent = true;
if (thisCollision.collisionHandler != null) {
validEvent = thisCollision.collisionHandler.onCollision((PooledEngine) getEngine(), entity, other);
}
if (validEvent && otherCollision.collisionHandler != null)
validEvent = otherCollision.collisionHandler.onCollision((PooledEngine) getEngine(), other, entity);
if (validEvent) {
notifyListeners(entity, other);
notifyListeners(other, entity);
}
}
}
thisCollision.handledCollisions.clear();
bounds.getCenter(thisCollision.preCollisionPosition);
}
示例10: tick
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
public boolean tick(PooledEngine engine, Entity entity, EffectComponent component, float deltaTime) {
if (!applied) {
applyEffectInternal(engine, entity, component);
return false;
} else if (remainingDuration > 0) {
remainingDuration -= deltaTime;
return false;
} else {
removeEffectInternal(engine, entity, component);
return true;
}
}
示例11: applyEffectInternal
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
private void applyEffectInternal(PooledEngine engine, Entity entity, EffectComponent effectComponent) {
applyEffect(engine, entity, effectComponent);
audioService.playSound(AssetService.SoundAsset.SOUND_POWERUP_WAV);
setTexture(entity);
remainingDuration = getDuration();
applied = true;
}
示例12: onCollision
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
public boolean onCollision(PooledEngine engine, Entity source, Entity target) {
if (playerMapper.has(target)) {
IdComponent sourceId = idMapper.get(source);
IdComponent targetId = idMapper.get(target);
if ((sourceId.participantId.equals(targetId.participantId))) {
return false;
} else {
removeBullet(engine, source);
}
} else if (obstacleMapper.has(target)) {
removeBullet(engine, source);
}
return true;
}
示例13: onCollision
import com.badlogic.ashley.core.PooledEngine; //导入依赖的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;
}
示例14: handle
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
public void handle(PooledEngine engine, Entity controlledEntity) {
IdComponent idComponent = idMapper.get(controlledEntity);
for (int i = 0; i < numBullets; ++i) {
Entity bullet = entityFactory.createBullet(idComponent.participantId);
TransformComponent playerPosition = ComponentMappers.transformMapper.get(controlledEntity);
TransformComponent bulletPosition = bullet.getComponent(TransformComponent.class);
bulletPosition.position.set(playerPosition.position);
MovementComponent bulletMovement = bullet.getComponent(MovementComponent.class);
float rotation = spreadDegrees * numBullets / 2 - i * spreadDegrees;
bulletMovement.velocity.set(playerPosition.rotation).rotate(rotation).setLength(bulletSpeed);
engine.addEntity(bullet);
}
}
示例15: handle
import com.badlogic.ashley.core.PooledEngine; //导入依赖的package包/类
@Override
public void handle(PooledEngine engine, Entity controlledEntity) {
IdComponent idComponent = idMapper.get(controlledEntity);
Entity bullet = factory.createBomb(idComponent.participantId);
TransformComponent playerPosition = ComponentMappers.transformMapper.get(controlledEntity);
TransformComponent bulletPosition = bullet.getComponent(TransformComponent.class);
bulletPosition.position.set(playerPosition.position);
engine.addEntity(bullet);
}