Characters can have longer dialog separate by ;

This commit is contained in:
bgiraudr 2021-08-17 22:19:19 +02:00
parent 788e5cfd1a
commit 0f16d9545e
6 changed files with 33 additions and 16 deletions

View File

@ -27,6 +27,7 @@ set(SOURCES
src/character.c
src/player.c
src/map.c
src/util.c
)
set(ASSETS_cg

View File

@ -1,4 +1,4 @@
37
32
Tituya
J'ai toujours aimé ce pont
J'ai toujours aimé ce pont;Pas toi ?

View File

@ -54,8 +54,7 @@ def convert_map(input, output, params, target):
pass
#Extract from the json the width, height and layers of the map
w = data["layers"][0]["width"]
h = data["layers"][0]["height"]
w, h = data["width"], data["height"]
nblayer = len(data["layers"])
o = fxconv.ObjectData()

3
include/util.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void wait_for_input(int input);

View File

@ -4,6 +4,7 @@
#include "character.h"
#include "engine.h"
#include "map.h"
#include "util.h"
struct Character character_default = {
.x = 0,
@ -14,19 +15,18 @@ struct Character character_default = {
/*draw the dialog of a specified character*/
void draw_dialog(struct Character *character) {
drect(20,10,370,80,C_WHITE);
dprint(25,20, C_BLACK, "(%d,%d)", character->x, character->y);
dprint(25,40, C_BLACK, "%s", character->name);
dprint(25,60, C_BLACK, "%s", character->dialog);
dupdate();
int buffer = 1;
while(1) {
clearevents();
if(keydown(KEY_SHIFT)) {
if(buffer) buffer = 0;
else break;
}
while(keydown(KEY_SHIFT)) clearevents();
const char *delim = ";";
char *str = strdup(character->dialog);
char *curr_line = strtok(str, delim);
while(curr_line != NULL) {
drect(20,10,370,80,C_WHITE);
dprint(25,20, C_BLACK, "%s", character->name);
dprint(25,40, C_BLACK, "%s", curr_line);
dupdate();
curr_line = strtok(NULL, delim);
wait_for_input(KEY_SHIFT);
}
}

14
src/util.c Normal file
View File

@ -0,0 +1,14 @@
#include <gint/keyboard.h>
#include "util.h"
void wait_for_input(int input) {
int buffer = 1;
while(1) {
clearevents();
if(keydown(input)) {
if(buffer) buffer = 0;
else break;
}
while(keydown(input)) clearevents();
}
}