#import "Animator.h"

@implementation Animator

+(id) new {
    return [[Animator alloc] init];
}

-(void) tick {
    left = speed;    
    
    if (left-- == 0) {
        left = speed;
    }
}

-(void) setSpeed: (int) s {
    speed = s;
}

-(void) setTicks: (int) t {
    left = t;
}

-(void) setIncrement: (float) i {
    increment = i;
}

-(void) setSubject: (id) sub {
    subject = sub;
}

-(void) addNode: (Vector2) node {
    nodes[nodecnt++] = node;
}

//so it can be called from the renderer
-(void) draw {
    static int i;

    i = i % 50;

    if (i >= nodecnt) {
        [(DialogueBox *)subject animate];
        return;
    }

    //while (!Vector2Equals( [(DialogueBox *)subject pos], nodes[i] )) {
        //if (left == 0)
    [subject setPos: Vector2MoveTowards([(DialogueBox *)subject pos], nodes[i], increment)];
    printf("%f %f %d\n", [subject pos].x, [subject pos].y, i);

    if (Vector2Equals( [(DialogueBox *)subject pos], nodes[i] )) {
        //[(DialogueBox *)subject animate];
        i++;
    }
    //}

    //i++;
}

@end