当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableArray类代码示例

本文整理汇总了Java中com.badlogic.ashley.utils.ImmutableArray的典型用法代码示例。如果您正苦于以下问题:Java ImmutableArray类的具体用法?Java ImmutableArray怎么用?Java ImmutableArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ImmutableArray类属于com.badlogic.ashley.utils包,在下文中一共展示了ImmutableArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: placeTowers

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的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;
	}
}
 
开发者ID:JoakimRW,项目名称:ExamensArbeteTD,代码行数:17,代码来源:InputHandler.java

示例2: calcForce

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
@Override
public Vector3f calcForce(Entity target, ImmutableArray<Entity> neighbours) {
	Pose p = target.getComponent(Pose.class);
	
	Vector3f approximatePos = new Vector3f(p.position);
	approximatePos.add(p.velocity);	// add velocity to position to estimate future position
	
	float nearestCurveValue = curve.approximate(new Vector3(approximatePos.x,approximatePos.y,approximatePos.z));

	Vector3f desired_velocity = new Vector3f();
	if(!Float.isNaN(nearestCurveValue)){
		Vector3 point = new Vector3();
		curve.valueAt(point, nearestCurveValue);
		Vector3f nearestCurvePoint = new Vector3f(point.x, point.y, point.z);
		Vector3f positionToNearestCurvePoint = nearestCurvePoint.sub(p.position);
		if(positionToNearestCurvePoint.lengthSquared() >= pathRadius){
			desired_velocity = positionToNearestCurvePoint.normalize().mul(Boid.maxSpeed);
		}else{
			desired_velocity.zero();
		}
	}
	
	return desired_velocity.mul(weight);
}
 
开发者ID:urstruktur,项目名称:zierfisch,代码行数:25,代码来源:RulePathFollow.java

示例3: update

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
/**
 * Updates all the systems in this Engine.
 * @param deltaTime The time passed since the last frame.
 */
public void update(float deltaTime){
	if (updating) {
		throw new IllegalStateException("Cannot call update() on an Engine that is already updating.");
	}
	
	updating = true;
	ImmutableArray<EntitySystem> systems = systemManager.getSystems();
	for (int i = 0; i < systems.size(); ++i) {
		EntitySystem system = systems.get(i);
		
		if (system.checkProcessing()) {
			system.update(deltaTime);
		}

		componentOperationHandler.processOperations();
		entityManager.processPendingOperations();
	}
	updating = false;
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:24,代码来源:Engine.java

示例4: registerFamily

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
private ImmutableArray<Entity> registerFamily(Family family) {
	ImmutableArray<Entity> entitiesInFamily = immutableFamilies.get(family);

	if (entitiesInFamily == null) {
		Array<Entity> familyEntities = new Array<Entity>(false, 16);
		entitiesInFamily = new ImmutableArray<Entity>(familyEntities);
		families.put(family, familyEntities);
		immutableFamilies.put(family, entitiesInFamily);
		entityListenerMasks.put(family, new Bits());

		for (Entity entity : entities){
			updateFamilyMembership(entity);
		}
	}

	return entitiesInFamily;
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:18,代码来源:FamilyManager.java

示例5: intervalSystem

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
@Test
public void intervalSystem () {
	Engine engine = new Engine();
	IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy();
	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(IntervalComponentSpy.class).get());
	ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class);

	engine.addSystem(intervalSystemSpy);

	for (int i = 0; i < 10; ++i) {
		Entity entity = new Entity();
		entity.add(new IntervalComponentSpy());
		engine.addEntity(entity);
	}

	for (int i = 1; i <= 10; ++i) {
		engine.update(deltaTime);

		for (int j = 0; j < entities.size(); ++j) {
			assertEquals(i / 2, im.get(entities.get(j)).numUpdates);
		}
	}
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:24,代码来源:IntervalIteratingTest.java

示例6: systemUpdateOrder

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
@Test
public void systemUpdateOrder () {
	Array<Integer> updates = new Array<Integer>();

	SystemListenerSpy systemSpy = new SystemListenerSpy();
	SystemManager manager = new SystemManager(systemSpy);
	EntitySystemMock system1 = new EntitySystemMockA(updates);
	EntitySystemMock system2 = new EntitySystemMockB(updates);

	system1.priority = 2;
	system2.priority = 1;

	manager.addSystem(system1);
	manager.addSystem(system2);

	ImmutableArray<EntitySystem> systems = manager.getSystems();
	assertEquals(system2, systems.get(0));
	assertEquals(system1, systems.get(1));
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:20,代码来源:SystemManagerTests.java

示例7: entityForFamilyWithRemoval

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
@Test
public void entityForFamilyWithRemoval () {
	// Test for issue #13
	Engine engine = new Engine();

	Entity entity = new Entity();
	entity.add(new ComponentA());

	engine.addEntity(entity);

	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(ComponentA.class).get());

	assertEquals(1, entities.size());
	assertTrue(entities.contains(entity, true));

	engine.removeEntity(entity);

	assertEquals(0, entities.size());
	assertFalse(entities.contains(entity, true));
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:21,代码来源:EngineTests.java

示例8: entitySystemRemovalWhileIterating

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
@Test
public void entitySystemRemovalWhileIterating () {
	Engine engine = new Engine();

	engine.addSystem(new CounterSystem());

	for (int i = 0; i < 20; ++i) {
		Entity entity = new Entity();
		entity.add(new CounterComponent());
		engine.addEntity(entity);
	}

	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(CounterComponent.class).get());

	for (int i = 0; i < entities.size(); ++i) {
		assertEquals(0, entities.get(i).getComponent(CounterComponent.class).counter);
	}

	engine.update(deltaTime);

	for (int i = 0; i < entities.size(); ++i) {
		assertEquals(1, entities.get(i).getComponent(CounterComponent.class).counter);
	}
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:25,代码来源:EngineTests.java

示例9: getEntities

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
@Test
public void getEntities () {
	int numEntities = 10;
	
	Engine engine = new Engine();
	
	Array<Entity> entities = new Array<Entity>();
	
	for (int i = 0; i < numEntities; ++i) {
		Entity entity = new Entity();
		entities.add(entity);
		engine.addEntity(entity);
	}
	
	ImmutableArray<Entity> engineEntities = engine.getEntities();
	
	assertEquals(entities.size, engineEntities.size());
	
	for (int i = 0; i < numEntities; ++i) {
		assertEquals(entities.get(i), engineEntities.get(i));
	}
	
	engine.removeAllEntities();
	
	assertEquals(0, engineEntities.size());
}
 
开发者ID:DevelopersGuild,项目名称:Planetbase,代码行数:27,代码来源:EngineTests.java

示例10: clearTarget

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
public static void clearTarget (Entity target) {
	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(TargetComponent.class).get());
	
	for (Entity entity : entities) {
		TargetComponent targetComp = Components.TARGET.get(entity);
		if (targetComp.getTarget() == target) {
			targetComp.setTarget(null);

			//Dispatch a message to the entites FSM that there target was removed from the engine
			if (Components.FSM.has(entity)) {
				FSMComponent fsm = Components.FSM.get(entity);
				MessageManager.getInstance().dispatchMessage(null, fsm, TelegramMessage.TARGET_REMOVED.ordinal(), target);
			}
		}

	}
}
 
开发者ID:libgdx-jam,项目名称:GDXJam,代码行数:18,代码来源:EntityUtils.java

示例11: clearTarget

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
public void clearTarget (Entity target) {
	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(TargetComponent.class, SquadComponent.class).get());
	
	for (Entity squad : entities) {
		SquadComponent squadComp = Components.SQUAD.get(squad);
		squadComp.untrack(squad, target);	//The squad no longer will track the target
		
		TargetComponent targetComp = Components.TARGET.get(squad);
		//If we were targeting that squad we remove it from our target
		if (targetComp.getTarget() == target) {
			targetComp.setTarget(null);

			//Dispatch a message to the entites FSM that there target was removed from the engine
			if (Components.FSM.has(squad)) {
				FSMComponent fsm = Components.FSM.get(squad);
				MessageManager.getInstance().dispatchMessage(null, fsm, TelegramMessage.TARGET_REMOVED.ordinal(), target);
			}
		}

	}
}
 
开发者ID:libgdx-jam,项目名称:GDXJam,代码行数:22,代码来源:SquadEntityListener.java

示例12: closestEntity

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
public static Entity closestEntity(Vector3 position, ImmutableArray<Entity> entities) {
	if (entities == null || entities.size() == 0)
		return null;
	
	Entity targetEntity = entities.first();
	float targetDist = MyMath.distance(position, Mappers.transform.get(targetEntity).pos);
	for (Entity searchEnt : entities) {
		float dist = MyMath.distance(Mappers.transform.get(searchEnt).pos, position);
		if (dist < targetDist) {
			targetDist = dist;
			targetEntity = searchEnt;
		}
	}

	return targetEntity;
}
 
开发者ID:0XDE57,项目名称:SpaceProject,代码行数:17,代码来源:Misc.java

示例13: printUserData

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
public void printUserData() {
    Family market = Family.all(MarketItemComponent.class, PriceComponent.class, NameComponent.class, PriceHistoryComponent.class).get();
    ImmutableArray<Entity> marketItemEntities = entityEngine.getEntitiesFor(market);

    Family players = Family.all(WalletComponent.class, NameComponent.class, InventoryComponent.class).get();
    for (Entity player : entityEngine.getEntitiesFor(players)) {
        NameComponent nc = player.getComponent(NameComponent.class);
        WalletComponent wc = player.getComponent(WalletComponent.class);
        InventoryComponent ic = player.getComponent(InventoryComponent.class);
        System.out.println("Name: " + nc.name);
        ic.printInventory(marketItemEntities);
        long value = ic.getInventoryValue(marketItemEntities);
        System.out.println("Inventory Value: $" + value);
        System.out.println(" Wallet Balance: $" + wc.balance);
        System.out.println("    Total Value: $" + (value + wc.balance));
    }
}
 
开发者ID:ahammer,项目名称:StockSimulator,代码行数:18,代码来源:GameState.java

示例14: printMarketHistory

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
public void printMarketHistory() {
    Family market = Family.all(MarketItemComponent.class, PriceComponent.class, NameComponent.class, PriceHistoryComponent.class).get();
    ImmutableArray<Entity> entities = entityEngine.getEntitiesFor(market);

    System.out.println("Current Prices: ");
    for (Entity e : entities) {
        PriceComponent p = e.getComponent(PriceComponent.class);
        NameComponent n = e.getComponent(NameComponent.class);
        PriceHistoryComponent history = e.getComponent(PriceHistoryComponent.class);

        Iterator itr;

        System.out.print(n.name + " Resolution 1 \n");
        itr = history.getPriceHistory().iterator();
        while (itr.hasNext()) System.out.print((Integer) itr.next() + "\n");
        System.out.print(n.name + " Resolution 5\n");
        itr = history.getPriceHistorySkipFive().iterator();
        while (itr.hasNext()) System.out.print((Integer) itr.next() + "\n");

        System.out.print(n.name + " Resolution 15\n");
        itr = history.getPriceHistorySkipFifteen().iterator();
        while (itr.hasNext()) System.out.print((Integer) itr.next() + "\n");

    }

}
 
开发者ID:ahammer,项目名称:StockSimulator,代码行数:27,代码来源:GameState.java

示例15: saveToJson

import com.badlogic.ashley.utils.ImmutableArray; //导入依赖的package包/类
public String saveToJson() {
    gameState.stopThread();
    try {
        ImmutableArray<Entity> entities = gameState.getEntityEngine().getEntities();
        SavedGame savedGame = new SavedGame();
        for (Entity entity : entities) {
            List<ComponentContainer> componentContainers = new ArrayList<ComponentContainer>();
            for (Component c : entity.getComponents()) {
                componentContainers.add(new ComponentContainer(c));
            }
            EntityContainer entityContainer = new EntityContainer(entity.getId(), entity.getClass().getName(), componentContainers);
            savedGame.entitiesContainers.add(entityContainer);

        }

        return new GsonBuilder().enableComplexMapKeySerialization().create().toJson(savedGame);
    } catch (Exception e) {
        e.printStackTrace();
    }
    gameState.startThread();
    return "Failed";
}
 
开发者ID:ahammer,项目名称:StockSimulator,代码行数:23,代码来源:GameSaver.java


注:本文中的com.badlogic.ashley.utils.ImmutableArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。