package com.spaceproject.systems;


import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.spaceproject.components.HyperDriveComponent;
import com.spaceproject.components.PhysicsComponent;
import com.spaceproject.components.TransformComponent;
import com.spaceproject.utility.Mappers;
import com.spaceproject.utility.MyMath;

public class HyperDriveSystem extends IteratingSystem {
    
    public HyperDriveSystem() {
        super(Family.all(TransformComponent.class, HyperDriveComponent.class).get());
    }
    
    @Override
    protected void processEntity(Entity entity, float deltaTime) {
        HyperDriveComponent hyperDrive = Mappers.hyper.get(entity);
        
        toggleHyperDrive(entity, hyperDrive);
        
        if (hyperDrive.isActive) {
            TransformComponent transform = Mappers.transform.get(entity);
            transform.pos.add(hyperDrive.velocity.cpy().scl(deltaTime));
        }
    }
    
    private void toggleHyperDrive(Entity entity, HyperDriveComponent hyperDrive) {
        if (hyperDrive.activate) {
            if (hyperDrive.coolDownTimer.tryEvent()) {
                PhysicsComponent physicsComp = Mappers.physics.get(entity);
                if (hyperDrive.isActive) {
                    hyperDrive.isActive = false;
                    physicsComp.body.setTransform(entity.getComponent(TransformComponent.class).pos, physicsComp.body.getAngle());
                    physicsComp.body.setActive(true);
                    physicsComp.body.setLinearVelocity(MyMath.vector(physicsComp.body.getAngle(), 20));
                } else {
                    hyperDrive.isActive = true;
                    hyperDrive.velocity.set(MyMath.vector(physicsComp.body.getAngle(), hyperDrive.speed));
                    physicsComp.body.setActive(false);
                }
            }
        }
    }
    
}

@@ -1131,28 +1131,12 @@
 vate
-) %7B%0A            if (
+ && 
 hype
@@ -1166,28 +1166,24 @@
 yEvent()) %7B%0A
-    
             
@@ -1250,28 +1250,24 @@
             
- 
-   
 if (hyperDri
@@ -1273,36 +1273,32 @@
 ive.isActive) %7B%0A
-    
                 
@@ -1334,36 +1334,32 @@
                 
- 
-   
 physicsComp.body
@@ -1461,36 +1461,32 @@
                 
-    
 physicsComp.body
@@ -1511,36 +1511,32 @@
                 
- 
-   
 physicsComp.body
@@ -1615,20 +1615,16 @@
         
-    
 %7D else %7B
@@ -1632,36 +1632,32 @@
                 
- 
-   
 hyperDrive.isAct
@@ -1668,20 +1668,16 @@
 = true;%0A
-    
         
@@ -1779,36 +1779,32 @@
                 
-    
 physicsComp.body
@@ -1826,36 +1826,32 @@
 e);%0A            
-    
 %7D%0A            %7D%0A
@@ -1840,33 +1840,32 @@
   %7D%0A            
-%7D
 %0A        %7D%0A    %7D

Update HyperDriveSystem.java