package me.hammerle.supersnuvi.entity.components.ai;

import me.hammerle.supersnuvi.entity.Entity;
import me.hammerle.supersnuvi.tiles.Location;
import me.hammerle.supersnuvi.util.Face;

public class WalkController extends EntityController
{
    private double motion;
    
    public WalkController(Entity ent, double motion)
    {
        super(ent);
        this.motion = motion;
    }

    @Override
    public void tick() 
    {
        ent.setMotionX(motion);
    }

    @Override
    public void onCollideWithEntity(Entity ent, Face face) 
    {
        switchDirection(face);
    }

    @Override
    public void onCollideWithTile(Location loc, Face face) 
    {
        switchDirection(face);
    }
    
    private void switchDirection(Face face)
    {
        if(face == Face.LEFT)
        {
            motion = -Math.abs(motion);
        }
        else if(face == Face.RIGHT)
        {
            motion = Math.abs(motion);
        }
    }
}
