package com.phr.main.systems;

import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.Filter;
import com.artemis.managers.GroupManager;
import com.artemis.systems.EntityProcessingSystem;
import com.phr.main.components.DamageComp;
import com.phr.main.components.DimensionComp;
import com.phr.main.components.FireRateComp;
import com.phr.main.components.PositionComp;
import com.phr.main.components.VelocityComp;
import com.phr.main.util.EntityFactory;

public class BulletSystem extends EntityProcessingSystem {

	private ComponentMapper<PositionComp> pcm;
	private ComponentMapper<FireRateComp> frcm;
	private ComponentMapper<DimensionComp> dcm;
	private ComponentMapper<VelocityComp> vcm;
	private ComponentMapper<DamageComp> dmcm;

	@SuppressWarnings("unchecked")
	public BulletSystem() {
		super(Filter.allComponents(PositionComp.class, FireRateComp.class));
	}

	@Override
	public void initialize() {
		pcm = world.getMapper(PositionComp.class);
		frcm = world.getMapper(FireRateComp.class);
		dcm = world.getMapper(DimensionComp.class);
		vcm = world.getMapper(VelocityComp.class);
		dmcm = world.getMapper(DamageComp.class);
	}

	@Override
	protected void process(Entity e) {
		FireRateComp frc = frcm.get(e);

		frc.nextShot -= world.getDelta();
		if (frc.nextShot <= 0) {
			GroupManager gm = world.getManager(GroupManager.class);
			PositionComp pc = pcm.get(e);
			DimensionComp dc = dcm.get(e);
			VelocityComp vc = vcm.get(e);
			EntityFactory.createBullet(world, pc.position.x + dc.width / 2
					- EntityFactory.BULLET_SIZE / 2, pc.position.y + dc.height
					/ 2 - EntityFactory.BULLET_SIZE / 2, vc.velocity.y < 0 ? -1
					: 1, dmcm.get(e).damage,
					gm.getGroups(e).contains(EntityFactory.PLAYER, true));

			frc.nextShot = frc.fireRate;
		}
	}

}

@@ -337,24 +337,67 @@
 reRateComp;%0A
+import com.phr.main.components.PlayerComp;%0A
 import com.p
@@ -421,32 +421,32 @@
 s.PositionComp;%0A
-
 import com.phr.m
@@ -795,16 +795,61 @@
 p%3E dmcm;
+%0A%09%0A%09private ComponentMapper%3CPlayerComp%3E plcm;
 %0A%0A%09@Supp
@@ -1239,16 +1239,60 @@
 class);%0A
+%09%09plcm = world.getMapper(PlayerComp.class);%0A
 %09%7D%0A%0A%09@Ov
@@ -1591,16 +1591,53 @@
 get(e);%0A
+%09%09%09PlayerComp plc = plcm.getSafe(e);%0A
 %09%09%09Entit
@@ -1804,25 +1804,21 @@
  2, 
-vc.velocity.y %3C 0
+(plc == null)
  ? -

Make player bullets always shoot up