diff --git a/CMakeLists.txt b/CMakeLists.txt index b7f5ec8..0575c03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(SOURCES src/character.c src/player.c src/map.c + src/util.c ) set(ASSETS_cg diff --git a/assets-cg/characters/Tituya.char b/assets-cg/characters/Tituya.char index 7346d07..b45e6dc 100644 --- a/assets-cg/characters/Tituya.char +++ b/assets-cg/characters/Tituya.char @@ -1,4 +1,4 @@ 37 32 Tituya -J'ai toujours aimé ce pont +J'ai toujours aimé ce pont;Pas toi ? diff --git a/assets-cg/converters.py b/assets-cg/converters.py index db411d3..3ae2dcc 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -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() diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..7e80bc2 --- /dev/null +++ b/include/util.h @@ -0,0 +1,3 @@ +#pragma once + +void wait_for_input(int input); \ No newline at end of file diff --git a/src/character.c b/src/character.c index 2951ea1..fd969d9 100644 --- a/src/character.c +++ b/src/character.c @@ -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); } } diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..733d16f --- /dev/null +++ b/src/util.c @@ -0,0 +1,14 @@ +#include +#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(); + } +} \ No newline at end of file