From 45a3db587db4b49ededc3ed4a118d31c4b33e462 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Sat, 4 Mar 2023 17:28:42 -0800 Subject: [PATCH] Constant line height, more training, todo --- assets/testsmalllevel.json | 19 +++++++++++++++---- main.c | 30 ++++++++++++++++++++++-------- server/training_data.txt | 21 +++++++++++++++++++++ todo.txt | 7 +++++-- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/assets/testsmalllevel.json b/assets/testsmalllevel.json index 666d188..b7da54e 100644 --- a/assets/testsmalllevel.json +++ b/assets/testsmalllevel.json @@ -30,12 +30,23 @@ "class":"", "height":31.604938271605, "id":1, - "name":"PLAYER", + "name":"MERCHANT", "rotation":0, "visible":true, "width":29.9415204678363, - "x":97, - "y":96 + "x":167, + "y":81.5 + }, + { + "class":"", + "height":31.6049, + "id":2, + "name":"PLAYER", + "rotation":0, + "visible":true, + "width":29.9415, + "x":68.02925, + "y":88.19755 }], "opacity":1, "type":"objectgroup", @@ -63,7 +74,7 @@ "y":0 }], "nextlayerid":4, - "nextobjectid":2, + "nextobjectid":3, "orientation":"orthogonal", "renderorder":"right-down", "tiledversion":"1.9.2", diff --git a/main.c b/main.c index 26a0d5c..bd20922 100644 --- a/main.c +++ b/main.c @@ -224,12 +224,15 @@ void make_space_and_append(Dialog *d, Sentence *s) { if(d->cur_index >= ARRLEN(d->data)) { - assert(ARRLEN(d->data) >= 1); - for(int i = 0; i < ARRLEN(d->data) - 1; i++) + for(int remove_i = 0; remove_i < 2; remove_i++) { - d->data[i] = d->data[i + 1]; + assert(ARRLEN(d->data) >= 1); + for(int i = 0; i < ARRLEN(d->data) - 1; i++) + { + d->data[i] = d->data[i + 1]; + } + d->cur_index--; } - d->cur_index--; } BUFF_APPEND(d, *s); @@ -294,8 +297,6 @@ void request_do_damage(Entity *to, Vec2 from_point, float damage) #include "prompts.gen.h" -// just straight up gpt generation function, calls to golang backend -char *get_ai_response(char* prompt); void begin_text_input(); // called when player engages in dialog, must say something and fill text_input_buffer // a callback, when 'text backend' has finished making text void end_text_input(char *what_player_said) @@ -398,7 +399,7 @@ void end_text_input(char *what_player_said) player->talking_to->gen_request_id = req_id; #endif #ifdef DESKTOP - add_new_npc_sentence(player->talking_to, "ALright. *moves*"); + add_new_npc_sentence(player->talking_to, "......"); #endif } } @@ -687,6 +688,7 @@ AnimatedSprite death_idle = }; sg_image image_font = {0}; +float font_line_advance = 0.0f; const float font_size = 32.0; stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs @@ -787,7 +789,18 @@ void init(void) .size = (size_t)(512 * 512 * 4), } } ); + + stbtt_fontinfo font; + stbtt_InitFont(&font, fontBuffer, 0); + int ascent = 0; + int descent = 0; + int lineGap = 0; + float scale = stbtt_ScaleForPixelHeight(&font, font_size); + stbtt_GetFontVMetrics(&font, &ascent, &descent, &lineGap); + font_line_advance = (float)(ascent - descent + lineGap) * scale * 0.75f; + free(font_bitmap_rgba); + free(fontBuffer); } state.bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc) @@ -1578,7 +1591,8 @@ float draw_wrapped_text(bool dry_run, Vec2 at_point, float max_width, char *text memcpy(line_to_draw, sentence_to_draw, chars_from_sentence); memcpy(colors_to_draw, colors, chars_from_sentence*sizeof(Color)); - float line_height = line_bounds.upper_left.Y - line_bounds.lower_right.Y; + //float line_height = line_bounds.upper_left.Y - line_bounds.lower_right.Y; + float line_height = font_line_advance * text_scale; AABB drawn_bounds = draw_text((TextParams){true, dry_run, line_to_draw, AddV2(cursor, V2(0.0f, -line_height)), BLACK, text_scale, clip_to, colors_to_draw}); if(!dry_run) dbgrect(drawn_bounds); diff --git a/server/training_data.txt b/server/training_data.txt index e5af541..83bc3ca 100644 --- a/server/training_data.txt +++ b/server/training_data.txt @@ -206,6 +206,27 @@ Death: "..." Player: "move out of the way" Death: "*moves*" +Player: "Can you help me fight?" +Death: ".....NO" +Player: "Why not?" +Death: ".....MOVE" +Player: "Move what" +Death: "...FORWARD" +Player: "Can I move?" +Death: "...ASIDE" +Player: "Yes" +Death: ".......ALLOW" +Player: "Allow what" +Death: "..." +Player: "hat" +Death: ".....ADVICE" +Player: "What advice" +Death: "...MOVE...FORWARD" +Player: "Move aside" +Death: "...FORWARD" +Player: "Move out of the way" +Death: "*moves*" + Player: "Get me off" Death: "......NO" Player: "No" diff --git a/todo.txt b/todo.txt index 43afc44..d6b7ee4 100644 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,13 @@ DONE - make npcs resiliant to player asking for stuff - ask death to come help you fight, new action + - Animate text characters coming in - Space and e for attack and roll, tooltip - - Get rid of enters in javascript input box - + - Get rid of enters and stars in javascript input box +DONE - Constant height for lines of text in dialog + - Sword improvements, deflect bullets, player knockback - Escape exits typing - Save every request and response + - Sound - Don't flip player direction when you walk vertically - Perfect dodge roll just after you roll, sound effect and particles. Lets you keep momentum. Each dodge roll