animation

main
sandyx86 1 year ago
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

@ -31,12 +31,14 @@ static int thiccness;
Color text_color; Color text_color;
int speed; //speed of text drawing int speed; //speed of text drawing
int left; //ticks left before next char draw int left; //ticks left before next char draw
int ready;
char *full_text; //a buffer to copy text into char *full_text; //a buffer to copy text into
//display two lines of text //display two lines of text
char *line_top; char *line_top;
char *line_bottom; //dont need char *line_bottom; //dont need
} }
/* /*
@ -57,6 +59,10 @@ static int thiccness;
-(void) tick; -(void) tick;
-(void) advance; //advance the text -(void) advance; //advance the text
-(void) draw; //draw the rect -(void) draw; //draw the rect
-(void) animate;
-(void) setPos: (Vector2) p;
-(Vector2) pos;
@end @end
#endif #endif

@ -16,14 +16,15 @@ Rectangle make_border(Rectangle r) {
if (self) { if (self) {
full_text = text; full_text = text;
pos = (Vector2){0, 0}; rect = (Rectangle){50, 800, 700, 100};
rect = (Rectangle){50, 450, 700, 100}; pos = (Vector2){rect.x, rect.y};
inner_color = WHITE; inner_color = WHITE;
outer_color = BLACK; outer_color = BLACK;
text_color = BLACK; text_color = BLACK;
thiccness = 2; thiccness = 2;
line_top = malloc(100); line_top = malloc(100);
speed = 10; speed = 10;
ready = 0;
//line_bottom = malloc(100); //line_bottom = malloc(100);
memcpy(line_top, full_text, 100); //segfault? memcpy(line_top, full_text, 100); //segfault?
} }
@ -68,15 +69,22 @@ void swap_char(char *str, int len) {
str[idx++] = 0; //zero char str[idx++] = 0; //zero char
} }
//change to show a png instead of a rectangle later
-(void) draw { -(void) draw {
rect.x = pos.x;
rect.y = pos.y;
DrawRectangleRec(make_border(rect), outer_color); DrawRectangleRec(make_border(rect), outer_color);
DrawRectangleRec(rect, inner_color); DrawRectangleRec(rect, inner_color);
static char c; static char c;
static int idx; static int idx;
if (left == 0) { if (left == 0) {
if (!ready)
return;
swap_char(line_top, 100); swap_char(line_top, 100);
idx = (idx + 1) % 100; idx = (idx + 1) % 100;
//[self animate: (float)idx/100];
//idx = (idx + 1) % len(current_text) //idx = (idx + 1) % len(current_text)
} }
@ -86,4 +94,18 @@ void swap_char(char *str, int len) {
DrawText(line_top, rect.x + 1, rect.y, 20, text_color); DrawText(line_top, rect.x + 1, rect.y, 20, text_color);
} }
//text box slide in
-(void) animate {
ready = 1;
//rect.y = lerp(800, 450, t);
}
-(void) setPos: (Vector2) p {
pos = p;
}
-(Vector2) pos {
return pos;
}
@end @end

@ -22,7 +22,7 @@
[controllable moveLeft]; [controllable moveLeft];
} else if ( set - IsKeyDown(KEY_D) ) { } else if ( set - IsKeyDown(KEY_D) ) {
[controllable moveRight]; [controllable moveRight];
} else if ( set - IsKeyDown(KEY_E) ) { } else if ( IsKeyPressed(KEY_E) ) {
[controllable activate]; [controllable activate];
} }

@ -8,17 +8,24 @@
#import <yeslib.h> #import <yeslib.h>
#import <stdio.h> #import <stdio.h>
#import "Activator.h" #import "Activator.h"
#import "DialogueBox.h"
#import "Animator.h"
#import "Renderer.h"
@interface NPC : YSObject <Receiver> { @interface NPC : YSObject <Receiver> {
BoundingBox bbox; BoundingBox bbox;
Vector3 pos; Vector3 pos;
Texture2D texture; Texture2D texture;
Renderer *renderer;
} }
-(id) init; -(id) init;
+(id) new; +(id) new;
-(void) draw: (Camera3D) camera; -(void) draw: (Camera3D) camera;
-(void) activate; -(void) activate;
-(void) setRenderer: (Renderer *) r;
-(void) sendObject: (id) obj to: (Renderer *) receiver;
-(BoundingBox) bbox; -(BoundingBox) bbox;

@ -33,7 +33,33 @@
} }
-(void) activate { -(void) activate {
printf("%s\n", "wow i did it"); DialogueBox *dbox = [DialogueBox newWithText: "Cock and ball torture, from wikipedia, the free encyclopedia,\nat wikipedia.org"];
Animator *anim = [Animator new];
[anim addNode: (Vector2){50.0f, 450.0f}];
[anim addNode: (Vector2){20.0f, 300.0f}];
[anim addNode: (Vector2){90.0f, 250.0f}];
[anim addNode: (Vector2){20.0f, 220.0f}];
[anim addNode: (Vector2){50.0f, 450.0f}];
[anim setSubject: dbox];
[anim setSpeed: 30];
[anim setIncrement: 16.66];
[self sendObject: dbox to: renderer];
[self sendObject: anim to: renderer];
//[dbox slideIn];
//printf("%s\n", "activated");
//[dbox slideIn];
}
-(void) setRenderer: (Renderer *) r {
renderer = r;
//printf("%s\n", "set renderer");
}
-(void) sendObject: (id) obj to: (Renderer *) receiver {
[receiver addObject: obj];
//printf("%s\n", "sent obj to renderer");
} }
@end @end

@ -12,6 +12,7 @@
#import "PhysObject.h" #import "PhysObject.h"
#import "NPC.h" #import "NPC.h"
#import "DialogueBox.h" #import "DialogueBox.h"
#import "Animator.h"
#import "properties.h" #import "properties.h"
@ -35,9 +36,12 @@ int main(int argc, const char *argv[]) {
InputHandler *input = [[InputHandler alloc] init]; InputHandler *input = [[InputHandler alloc] init];
AssetLoader *assetLoader = [[AssetLoader alloc] init]; AssetLoader *assetLoader = [[AssetLoader alloc] init];
Renderer *renderer = [[Renderer alloc] init]; Renderer *renderer = [[Renderer alloc] init];
Renderer *renderer2d = [[Renderer alloc] init];
Gravitator *gravitator = [[Gravitator alloc] init]; Gravitator *gravitator = [[Gravitator alloc] init];
Animator *animator = [Animator new];
NPC *npc = [NPC new]; NPC *npc = [NPC new];
DialogueBox *dbox = [DialogueBox newWithText: "Cock and ball torture, from wikipedia, the free encyclopedia,\nat wikipedia.org"]; [npc setRenderer: renderer2d];
//DialogueBox *dbox = [DialogueBox newWithText: "Cock and ball torture, from wikipedia, the free encyclopedia,\nat wikipedia.org"];
input->controllable = player; input->controllable = player;
@ -47,8 +51,6 @@ int main(int argc, const char *argv[]) {
[camera attach: player]; [camera attach: player];
[assetLoader loadAssetFile: "assets.al"]; [assetLoader loadAssetFile: "assets.al"];
@ -81,11 +83,13 @@ int main(int argc, const char *argv[]) {
[renderer render]; [renderer render];
EndMode3D(); EndMode3D();
[renderer2d render];
[camera showPos]; [camera showPos];
[camera showTarget]; [camera showTarget];
[player showPos]; [player showPos];
[camera drawCrosshair]; [camera drawCrosshair];
[dbox draw]; //[dbox draw];
//[camera raycast]; //[camera raycast];
//[enemy Render: [camera camera]]; //[enemy Render: [camera camera]];
//DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE); //DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);

Loading…
Cancel
Save