Evgeniy Parfenyuk преди 3 седмици
родител
ревизия
332c039f57
променени са 3 файла, в които са добавени 8 реда и са изтрити 1 реда
  1. 2 0
      src/main.c
  2. 4 1
      src/ui/text_box.c
  3. 2 0
      src/ui/text_box.h

+ 2 - 0
src/main.c

@@ -19,6 +19,7 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
 #include "raylib.h"
+#include <stdio.h>
 #include "ui/text_box.h"
 
 int main(void)
@@ -38,6 +39,7 @@ int main(void)
 
     while (!WindowShouldClose())
     {
+        dialogueBox.timer += GetFrameTime();
         BeginDrawing();
             ClearBackground((Color){20, 25, 40, 255});
             TextBoxDraw(&dialogueBox);

+ 4 - 1
src/ui/text_box.c

@@ -32,6 +32,9 @@ void TextBoxInit(TextBox *tb, int screenWidth, int screenHeight)
     tb->text_color = WHITE;
     tb->name_color = RED;
 
+    tb->typing_speed = 25.0f;
+    tb->timer = 0.0f;
+
     memset(tb->name, 0, sizeof(tb->name));
     tb->text = NULL;
     tb->max_text_length = 1024;
@@ -74,7 +77,7 @@ void TextBoxDraw(TextBox *tb)
 
     if (tb->text)
     {
-        DrawTextEx(tb->font, tb->text,
+        DrawTextEx(tb->font, TextSubtext(tb->text, 0, tb->timer * tb->typing_speed),
                    (Vector2){tb->rect.x + 25, tb->rect.y + 25},
                    tb->font_size, 1.2f, tb->text_color);
     }

+ 2 - 0
src/ui/text_box.h

@@ -18,6 +18,8 @@ typedef struct
     Color name_color;
 
     char *text;
+    float typing_speed; // Characters per second
+    float timer;        // How much seconds passed
     int max_text_length;
 } TextBox;