dialogue scrolling
parent
4f7e0a31b0
commit
39896ac26f
@ -0,0 +1,62 @@
|
|||||||
|
#ifndef DBOX_H
|
||||||
|
#define DBOX_H
|
||||||
|
|
||||||
|
//a dialogue box for dialogue
|
||||||
|
#import <string.h>
|
||||||
|
#import <raylib.h>
|
||||||
|
#import <yeslib.h>
|
||||||
|
#import <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
functionality of dbox:
|
||||||
|
it will display a rectangle or place to hold text
|
||||||
|
it will gradually print text within the box
|
||||||
|
it will pause when a certain delimiter is reached
|
||||||
|
or other method of pausing the text
|
||||||
|
it will continue when it is send a continue message
|
||||||
|
|
||||||
|
optional but requirement for quality:
|
||||||
|
change text speed upon reaching delimiter
|
||||||
|
or other method, probably something in a script
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int thiccness;
|
||||||
|
|
||||||
|
@interface DialogueBox : YSObject {
|
||||||
|
Vector2 pos;
|
||||||
|
Rectangle rect;
|
||||||
|
Color inner_color;
|
||||||
|
Color outer_color;
|
||||||
|
Color text_color;
|
||||||
|
int speed; //speed of text drawing
|
||||||
|
int left; //ticks left before next char draw
|
||||||
|
|
||||||
|
char *full_text; //a buffer to copy text into
|
||||||
|
|
||||||
|
//display two lines of text
|
||||||
|
char *line_top;
|
||||||
|
char *line_bottom; //dont need
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
method of gradually printing text:
|
||||||
|
copy the string and slide a null byte through it
|
||||||
|
|
||||||
|
method of controlling speed:
|
||||||
|
count ticks until 0
|
||||||
|
|
||||||
|
slide in animation:
|
||||||
|
box moves towards target pos then stops
|
||||||
|
*/
|
||||||
|
|
||||||
|
-(id) initWithText: (char *) text;
|
||||||
|
+(id) newWithText: (char *) text;
|
||||||
|
//-(void) setText;
|
||||||
|
-(void) setSpeed: (int) s; //set speed of text
|
||||||
|
-(void) tick;
|
||||||
|
-(void) advance; //advance the text
|
||||||
|
-(void) draw; //draw the rect
|
||||||
|
|
||||||
|
@end
|
||||||
|
#endif
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
#import "DialogueBox.h"
|
||||||
|
|
||||||
|
@implementation DialogueBox
|
||||||
|
|
||||||
|
Rectangle make_border(Rectangle r) {
|
||||||
|
return (Rectangle) {
|
||||||
|
.x = r.x - thiccness,
|
||||||
|
.y = r.y - thiccness,
|
||||||
|
.width = r.width + thiccness + thiccness,
|
||||||
|
.height = r.height + thiccness + thiccness,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
-(id) initWithText: (char *) text {
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if (self) {
|
||||||
|
full_text = text;
|
||||||
|
pos = (Vector2){0, 0};
|
||||||
|
rect = (Rectangle){50, 450, 700, 100};
|
||||||
|
inner_color = WHITE;
|
||||||
|
outer_color = BLACK;
|
||||||
|
text_color = BLACK;
|
||||||
|
thiccness = 2;
|
||||||
|
line_top = malloc(100);
|
||||||
|
speed = 10;
|
||||||
|
//line_bottom = malloc(100);
|
||||||
|
memcpy(line_top, full_text, 100); //segfault?
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
+(id) newWithText: (char *) text {
|
||||||
|
return [[DialogueBox alloc] initWithText: text];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) setSpeed: (int) s {
|
||||||
|
speed = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) tick {
|
||||||
|
left = speed;
|
||||||
|
|
||||||
|
if (left-- == 0) {
|
||||||
|
left = speed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) advance {
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap_char(char *str, int len) {
|
||||||
|
//might need to add reset function
|
||||||
|
//or not use static variables.
|
||||||
|
static int idx;
|
||||||
|
static char chr;
|
||||||
|
|
||||||
|
idx = idx % len;
|
||||||
|
|
||||||
|
//put back char
|
||||||
|
if (idx) {
|
||||||
|
str[idx - 1] = chr;
|
||||||
|
}
|
||||||
|
|
||||||
|
chr = str[idx]; //save char
|
||||||
|
|
||||||
|
str[idx++] = 0; //zero char
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) draw {
|
||||||
|
DrawRectangleRec(make_border(rect), outer_color);
|
||||||
|
DrawRectangleRec(rect, inner_color);
|
||||||
|
static char c;
|
||||||
|
static int idx;
|
||||||
|
|
||||||
|
if (left == 0) {
|
||||||
|
swap_char(line_top, 100);
|
||||||
|
idx = (idx + 1) % 100;
|
||||||
|
//idx = (idx + 1) % len(current_text)
|
||||||
|
}
|
||||||
|
|
||||||
|
//line_top[idx] = full_text[idx];
|
||||||
|
|
||||||
|
|
||||||
|
DrawText(line_top, rect.x + 1, rect.y, 20, text_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef MAPLOADER_H
|
||||||
|
#define MAPLOADER_H
|
||||||
|
|
||||||
|
#import <raylib.h>
|
||||||
|
#import <yeslib.h>
|
||||||
|
#import "parser.h"
|
||||||
|
//import all the stuff
|
||||||
|
|
||||||
|
/*
|
||||||
|
this might do things like
|
||||||
|
load the map
|
||||||
|
set the current map
|
||||||
|
unload some other map
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
I may need a way to keep things persistent
|
||||||
|
across maps.
|
||||||
|
|
||||||
|
either by giving certain objects a persist flag
|
||||||
|
or by putting them in a different array, or
|
||||||
|
by copying the handler they're in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@interface MapLoader : YSObject {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) loadMap: (const char *) path;
|
||||||
|
-(void) sendObject: (id) obj to: (YSArray *) receiver;
|
||||||
|
|
||||||
|
@end
|
||||||
|
#endif
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
#include "MapLoader.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NONE = 0,
|
||||||
|
MAP = 1,
|
||||||
|
BLOCK,
|
||||||
|
TILE,
|
||||||
|
NPC,
|
||||||
|
PLAYER_SPAWN,
|
||||||
|
LIGHT,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
@implementation MapLoader
|
||||||
|
|
||||||
|
|
||||||
|
-(void) loadMap: (const char *) path {
|
||||||
|
char *file_buffer = load_file(path);
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
for(line = get_next_line(file_buffer, 0); line != NULL; line = get_next_line(file_buffer, 0)) {
|
||||||
|
//depending on what keyword it reads
|
||||||
|
//it makes that type of object
|
||||||
|
|
||||||
|
id parse_line(char *file_buffer);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-(void) sendObject: (id) obj to: (YSArray *) receiver {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
Loading…
Reference in New Issue