diff --git a/src/Animator.h b/src/Animator.h new file mode 100644 index 0000000..cd74e02 --- /dev/null +++ b/src/Animator.h @@ -0,0 +1,60 @@ +#ifndef ANIMATOR_H +#define ANIMATOR_H + +#import +#import +#import +#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 \ No newline at end of file diff --git a/src/Animator.m b/src/Animator.m new file mode 100644 index 0000000..30cd128 --- /dev/null +++ b/src/Animator.m @@ -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 \ No newline at end of file diff --git a/src/DialogueBox.h b/src/DialogueBox.h index 3d8b557..8493243 100644 --- a/src/DialogueBox.h +++ b/src/DialogueBox.h @@ -31,12 +31,14 @@ static int thiccness; Color text_color; int speed; //speed of text drawing int left; //ticks left before next char draw + int ready; char *full_text; //a buffer to copy text into //display two lines of text char *line_top; char *line_bottom; //dont need + } /* @@ -57,6 +59,10 @@ static int thiccness; -(void) tick; -(void) advance; //advance the text -(void) draw; //draw the rect +-(void) animate; + +-(void) setPos: (Vector2) p; +-(Vector2) pos; @end #endif \ No newline at end of file diff --git a/src/DialogueBox.m b/src/DialogueBox.m index 70364c7..48b7c56 100644 --- a/src/DialogueBox.m +++ b/src/DialogueBox.m @@ -16,14 +16,15 @@ Rectangle make_border(Rectangle r) { if (self) { full_text = text; - pos = (Vector2){0, 0}; - rect = (Rectangle){50, 450, 700, 100}; + rect = (Rectangle){50, 800, 700, 100}; + pos = (Vector2){rect.x, rect.y}; inner_color = WHITE; outer_color = BLACK; text_color = BLACK; thiccness = 2; line_top = malloc(100); speed = 10; + ready = 0; //line_bottom = malloc(100); memcpy(line_top, full_text, 100); //segfault? } @@ -68,15 +69,22 @@ void swap_char(char *str, int len) { str[idx++] = 0; //zero char } +//change to show a png instead of a rectangle later -(void) draw { + rect.x = pos.x; + rect.y = pos.y; DrawRectangleRec(make_border(rect), outer_color); DrawRectangleRec(rect, inner_color); static char c; static int idx; if (left == 0) { + if (!ready) + return; + swap_char(line_top, 100); idx = (idx + 1) % 100; + //[self animate: (float)idx/100]; //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); } +//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 \ No newline at end of file diff --git a/src/InputHandler.m b/src/InputHandler.m index fcb3737..49cf54a 100644 --- a/src/InputHandler.m +++ b/src/InputHandler.m @@ -22,7 +22,7 @@ [controllable moveLeft]; } else if ( set - IsKeyDown(KEY_D) ) { [controllable moveRight]; - } else if ( set - IsKeyDown(KEY_E) ) { + } else if ( IsKeyPressed(KEY_E) ) { [controllable activate]; } diff --git a/src/NPC.h b/src/NPC.h index b718b20..b96beab 100644 --- a/src/NPC.h +++ b/src/NPC.h @@ -8,17 +8,24 @@ #import #import #import "Activator.h" +#import "DialogueBox.h" +#import "Animator.h" +#import "Renderer.h" @interface NPC : YSObject { BoundingBox bbox; Vector3 pos; Texture2D texture; + + Renderer *renderer; } -(id) init; +(id) new; -(void) draw: (Camera3D) camera; -(void) activate; +-(void) setRenderer: (Renderer *) r; +-(void) sendObject: (id) obj to: (Renderer *) receiver; -(BoundingBox) bbox; diff --git a/src/NPC.m b/src/NPC.m index 9d211c5..5bf1d8d 100644 --- a/src/NPC.m +++ b/src/NPC.m @@ -33,7 +33,33 @@ } -(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 \ No newline at end of file diff --git a/src/main.m b/src/main.m index f707d63..44cacc7 100644 --- a/src/main.m +++ b/src/main.m @@ -12,6 +12,7 @@ #import "PhysObject.h" #import "NPC.h" #import "DialogueBox.h" +#import "Animator.h" #import "properties.h" @@ -35,9 +36,12 @@ int main(int argc, const char *argv[]) { InputHandler *input = [[InputHandler alloc] init]; AssetLoader *assetLoader = [[AssetLoader alloc] init]; Renderer *renderer = [[Renderer alloc] init]; + Renderer *renderer2d = [[Renderer alloc] init]; Gravitator *gravitator = [[Gravitator alloc] init]; + Animator *animator = [Animator 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; @@ -47,8 +51,6 @@ int main(int argc, const char *argv[]) { [camera attach: player]; - - [assetLoader loadAssetFile: "assets.al"]; @@ -81,11 +83,13 @@ int main(int argc, const char *argv[]) { [renderer render]; EndMode3D(); + [renderer2d render]; + [camera showPos]; [camera showTarget]; [player showPos]; [camera drawCrosshair]; - [dbox draw]; + //[dbox draw]; //[camera raycast]; //[enemy Render: [camera camera]]; //DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);