dialogue scrolling

main
sandyx86 1 year ago
parent 4f7e0a31b0
commit 39896ac26f

@ -21,7 +21,7 @@ Vector3 parse_pos(char *buffer) {
vec.x = strtof( buffer, NULL);
vec.y = strtof( get_next_token(buffer, ", ", 0), NULL);
vec.z = strtof( get_next_token(buffer, ", ", 0), NULL);
printf("got vector: %f %f %f\n", vec.x, vec.y, vec.z);
//printf("got vector: %f %f %f\n", vec.x, vec.y, vec.z);
return vec;
}
@ -50,15 +50,19 @@ Resource parse_line(char *buffer) {
goto GET_POS;
}
goto END; //debug
GET_PATH:
r.path = get_next_token(buffer, ": ", 0);
printf("got path: %s\n", r.path);
goto END;
GET_POS:
r.pos = parse_pos( get_next_token(buffer, ": ", 0) );
printf("got pos: %f %f %f\n", r.pos.x, r.pos.y, r.pos.z);
END:
get_next_token(NULL, NULL, 1);
get_next_token(NULL, NULL, 1);
return r;
}
@ -73,7 +77,8 @@ END:
for (line = get_next_line(file, 0); line != NULL; line = get_next_line(file, 0)) {
//debug
Resource r = parse_line(line);
Resource r = {0};
r = parse_line(line);
if (r.path == NULL) {
goto SKIP_PATH;

@ -31,7 +31,7 @@
-(void) showTarget;
-(void) drawCrosshair;
-(void) drawWeapon;
-(bool) raycast;
-(bool) raycast: (BoundingBox) bbox;
-(Camera3D *) addressOfCamera;
@end

@ -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

@ -24,7 +24,7 @@
-(id) init;
-(void) showPos;
-(void) attack;
-(bool) activate;
-(void) activate;
-(void) moveForward;
-(void) moveBack;
-(void) moveLeft;

@ -28,7 +28,7 @@
}
}
-(bool) activate {
-(void) activate {
int i;
for (i = 0; i < activators->count; i++) {
if ( [attachedCamera raycast: [activators->array[i] bbox]] ) {

@ -11,6 +11,7 @@
#import "Gravitator.h"
#import "PhysObject.h"
#import "NPC.h"
#import "DialogueBox.h"
#import "properties.h"
@ -19,12 +20,9 @@ const int winHeight = 600;
int main(int argc, const char *argv[]) {
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//insert custom properties loader here
YSConstantString *cs = @"yes";
InitWindow(default_properties.width, default_properties.height, "Game :3");
SetTargetFPS(60);
@ -34,14 +32,12 @@ int main(int argc, const char *argv[]) {
[camera init];
Player *player = [[Player alloc] init];
//SoundPlayer *sp = [[SoundPlayer alloc] init];
//Enemy *enemy = [[Enemy alloc] init];
InputHandler *input = [[InputHandler alloc] init];
AssetLoader *assetLoader = [[AssetLoader alloc] init];
Renderer *renderer = [[Renderer alloc] init];
Gravitator *gravitator = [[Gravitator alloc] init];
NPC *npc = [NPC new];
DialogueBox *dbox = [DialogueBox newWithText: "Cock and ball torture, from wikipedia, the free encyclopedia,\nat wikipedia.org"];
input->controllable = player;
@ -69,13 +65,10 @@ int main(int argc, const char *argv[]) {
while (!WindowShouldClose()) {
[camera update];
//hard coded input handler
[input handleInput];
[gravitator applyGravity];
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera->camera);
@ -92,6 +85,7 @@ int main(int argc, const char *argv[]) {
[camera showTarget];
[player showPos];
[camera drawCrosshair];
[dbox draw];
//[camera raycast];
//[enemy Render: [camera camera]];
//DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);

Loading…
Cancel
Save