animation
parent
39896ac26f
commit
fac7665f21
@ -0,0 +1,60 @@
|
|||||||
|
#ifndef ANIMATOR_H
|
||||||
|
#define ANIMATOR_H
|
||||||
|
|
||||||
|
#import <raylib.h>
|
||||||
|
#import <yeslib.h>
|
||||||
|
#import <yesmath.h>
|
||||||
|
#import "DialogueBox.h"
|
||||||
|
|
||||||
|
typedef struct Node2D Node2D;
|
||||||
|
|
||||||
|
struct Node2D {
|
||||||
|
Node2D *prev;
|
||||||
|
Node2D *next;
|
||||||
|
Vector2 start; //unused
|
||||||
|
Vector2 end;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef struct Target3D {
|
||||||
|
Vector3 start;
|
||||||
|
Vector3 end;
|
||||||
|
} Target3D;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef union Node {
|
||||||
|
Target2D t2d;
|
||||||
|
Target3D t3d;
|
||||||
|
} Node;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
i could pass in pointers to vectors and animate those
|
||||||
|
or pass a pointer to an object
|
||||||
|
*/
|
||||||
|
|
||||||
|
//array of nodes to move the subject along
|
||||||
|
@interface Animator : YSArray {
|
||||||
|
int speed; //more = slower
|
||||||
|
int left; //ticks left before do thing
|
||||||
|
float increment;
|
||||||
|
id subject;
|
||||||
|
Vector2 nodes[50]; //hardcode 50 for now
|
||||||
|
int nodecnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
+(id) new;
|
||||||
|
-(id) init;
|
||||||
|
-(void) tick;
|
||||||
|
-(void) setSpeed: (int) s;
|
||||||
|
-(void) setTicks: (int) t;
|
||||||
|
-(void) setIncrement: (float) i;
|
||||||
|
-(void) setSubject: (id) sub;
|
||||||
|
-(void) addNode: (Vector2) node;
|
||||||
|
-(void) draw;
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
#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
|
||||||
Loading…
Reference in New Issue