package nz.ac.massey.javaecs.examples.Systems;

import java.util.BitSet;

import nz.ac.massey.javaecs.ECSSystem;
import nz.ac.massey.javaecs.Engine;
import nz.ac.massey.javaecs.Entity;
import nz.ac.massey.javaecs.examples.Components.DirectionComponent;
import nz.ac.massey.javaecs.examples.Components.PositionComponent;

public class MovementSystem extends ECSSystem {
    Engine ecs;

    public MovementSystem(Engine ecs){
        this.ecs = ecs;
        registrationSet = new BitSet();
        registrationSet.set(ecs.getComponentIndex(PositionComponent.class));
        registrationSet.set(ecs.getComponentIndex(DirectionComponent.class));
    }

    @Override
    public void init() {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void update(double dt) {
        for (Entity entity : entities) {
            PositionComponent position = (PositionComponent)ecs.getComponentData(entity, PositionComponent.class);
            DirectionComponent direction = (DirectionComponent)ecs.getComponentData(entity, DirectionComponent.class);
            position.x += direction.x * dt;
            position.y += direction.y * dt;
        }
        
        
    }
    
}
