package com.deftwun.zombiecopter.systems;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.deftwun.zombiecopter.ComponentMappers;
import com.deftwun.zombiecopter.App;
import com.deftwun.zombiecopter.components.Collectable;
import com.deftwun.zombiecopter.components.Collector;
import com.deftwun.zombiecopter.components.PhysicsComponent;

public class CollectableSystem extends IteratingSystem {
	
	@SuppressWarnings("unchecked")
	public CollectableSystem() {
		super(Family.all(PhysicsComponent.class,Collector.class).get());
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void processEntity(Entity entity, float deltaTime) {
		ComponentMappers maps =App.engine.mappers;
		PhysicsComponent physics = maps.physics.get(entity);
		Collector collector = maps.collector.get(entity);
		
		for (Entity e : App.engine.getEntitiesFor(Family.all(Collectable.class).get())){
			Collectable c = maps.collectable.get(e);
			PhysicsComponent p = maps.physics.get(e);
			if (c!= null && p != null){
				if (p.getPosition().sub(physics.getPosition()).len() < c.pickupRange){
					if (c.type == Collectable.ItemType.Civilian && collector.civilians < collector.maxCivilians) {
						collector.civilians += 1;
						App.engine.removeEntity(p.ownerEntity);
					}
				}
			}
		}
	}

}

@@ -53,129 +53,174 @@
 com.
-badlogic.ashley.core.Entity;%0D%0Aimport com.badlogic.ashley.core.Family;%0D%0Aimport com.badlogic.ashley.systems.IteratingSystem
+artemis.Aspect;%0D%0Aimport com.artemis.Entity;%0D%0Aimport com.artemis.systems.EntityProcessingSystem;%0D%0Aimport com.artemis.utils.IntBag;%0D%0Aimport com.deftwun.zombiecopter.App
 ;%0D%0Ai
@@ -273,46 +273,8 @@
 s;%0D%0A
-import com.deftwun.zombiecopter.App;%0D%0A
 impo
@@ -488,28 +488,69 @@
 nds 
-IteratingSystem %7B%0D%0A%09
+EntityProcessingSystem %7B%0D%0A%0D%0A%09private Entity collectableFly;%0D%0A
 %0D%0A%09@
@@ -619,22 +619,22 @@
 %09%09super(
-Family
+Aspect
 .all(Phy
@@ -653,16 +653,17 @@
 t.class,
+ 
 Collecto
@@ -674,19 +674,130 @@
 ass)
-.get());%0D%0A%09
+);%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09protected void initialize() %7B%0D%0A%09%09super.initialize();%0D%0A%09%09collectableFly = createFlyweightEntity();%0D%0A
 %7D%0D%0A%0D
@@ -865,22 +865,16 @@
  process
-Entity
 (Entity 
@@ -883,25 +883,8 @@
 tity
-, float deltaTime
 ) %7B%0D
@@ -1043,29 +1043,39 @@
 );%0D%0A
-%09%09
 %0D%0A%09%09f
-or (Entity e :
+inal IntBag collectables =
  App
@@ -1101,14 +1101,14 @@
 For(
-Family
+Aspect
 .all
@@ -1130,17 +1130,113 @@
 ass)
-.get()))%7B
+);%0D%0A%09%09for (int i = 0, s = collectables.size(); i %3C s; i++) %7B%0D%0A%09%09%09collectableFly.id = collectables.get(i);
 %0D%0A%09%09
@@ -1269,25 +1269,38 @@
 ectable.get(
-e
+collectableFly
 );%0D%0A%09%09%09Physi
@@ -1332,17 +1332,30 @@
 ics.get(
-e
+collectableFly
 );%0D%0A%09%09%09i

Migrate CollectableSystem.java