SBird1337 7 lat temu
rodzic
commit
24dbf137a0
2 zmienionych plików z 105 dodań i 1 usunięć
  1. 1
    1
      sots-private
  2. 104
    0
      src/overworld/tileset_animation/text_animator.c

+ 1
- 1
sots-private

@@ -1 +1 @@
1
-Subproject commit 4dd2d429868e571fc666cb1e56006429f25301f2
1
+Subproject commit 3fcf11213bdacaa682f324dd53cae7d90dad333d

+ 104
- 0
src/overworld/tileset_animation/text_animator.c Wyświetl plik

@@ -0,0 +1,104 @@
1
+#include <pokeagb/pokeagb.h>
2
+#include <tileset_animation/font.h>
3
+
4
+#define CANVAS_X_START (22)
5
+#define CANVAS_Y_START (35)
6
+#define CANVAS_X_SECOND (22)
7
+#define CANVAS_Y_SECOND (36)
8
+
9
+#define CANVAS_FIRST (u8 *)(574 * 0x20 + 0x06000000)
10
+#define CANVAS_SECOND (u8 *)(592 * 0x20 + 0x06000000)
11
+
12
+s16 char_to_tile_index(char chr) {
13
+    if (chr >= 'A' && chr <= 'P')
14
+        return chr - 'A';
15
+    if (chr >= 'Q' && chr <= 'Z')
16
+        return (16 * 2) + (chr - 'Q');
17
+    if (chr >= '0' && chr <= '9')
18
+        return (16 * 8) + (chr - '0');
19
+    if (chr >= 'a' && chr <= 'p')
20
+        return (16 * 4) + (chr - 'a');
21
+    if (chr >= 'q' && chr <= 'z')
22
+        return (16 * 6) + (chr - 'q');
23
+    if (chr == '<')
24
+        return char_to_tile_index('z') + 1;
25
+    if (chr == '>')
26
+        return char_to_tile_index('z') + 2;
27
+    if (chr == ' ')
28
+        return char_to_tile_index('9') + 1;
29
+    return -1;
30
+}
31
+
32
+void draw_text_on_canvas(const char *txt) {
33
+    u16 current_tile = 0;
34
+    while (*txt) {
35
+        s16 tile = char_to_tile_index(*txt);
36
+        if (tile != -1) {
37
+            void *first = CANVAS_FIRST + (current_tile * 0x20);
38
+            void *second = CANVAS_SECOND + (current_tile * 0x20);
39
+            memcpy(first, fontTiles + (tile * 0x20), 0x20);
40
+            memcpy(second, fontTiles + (16 * 0x20) + (tile * 0x20), 0x20);
41
+        }
42
+        txt++;
43
+        current_tile++;
44
+    }
45
+}
46
+
47
+u8 get_pixel(u8 x, u8 y, u16 *start) {
48
+    u16 block = start[16 * (x / 4) + 2 * y + ((x % 4) / 2)];
49
+    if (x % 2 == 0)
50
+        return block & 0xFF;
51
+
52
+    return (block >> 8);
53
+}
54
+
55
+void set_pixel(u8 x, u8 y, u16 *start, u16 pixel) {
56
+    pixel &= 0xFF;
57
+    u16 *addr = &start[16 * (x / 4) + 2 * y + ((x % 4) / 2)];
58
+    if (x % 2 == 0)
59
+        *addr = (*addr & 0xFF00) | (pixel);
60
+    else
61
+        *addr = (*addr & 0x00FF) | (pixel << 8);
62
+}
63
+
64
+void text_animator(u16 current_frame) {
65
+    if ((current_frame % 7) == 0) {
66
+        u8 outer_pixels[16] = {
67
+            *(CANVAS_FIRST + 0),   *(CANVAS_FIRST + 4),   *(CANVAS_FIRST + 8),   *(CANVAS_FIRST + 12),
68
+            *(CANVAS_FIRST + 16),  *(CANVAS_FIRST + 20),  *(CANVAS_FIRST + 24),  *(CANVAS_FIRST + 28),
69
+            *(CANVAS_SECOND + 0),  *(CANVAS_SECOND + 4),  *(CANVAS_SECOND + 8),  *(CANVAS_SECOND + 12),
70
+            *(CANVAS_SECOND + 16), *(CANVAS_SECOND + 20), *(CANVAS_SECOND + 24), *(CANVAS_SECOND + 28)};
71
+
72
+        for (u8 i = 0; i < 71; ++i) {
73
+            for (u8 j = 0; j < 8; ++j) {
74
+                set_pixel(i, j, (u16 *)CANVAS_FIRST, get_pixel(i + 1, j, (u16 *)CANVAS_FIRST));
75
+                set_pixel(i, j, (u16 *)CANVAS_SECOND, get_pixel(i + 1, j, (u16 *)CANVAS_SECOND));
76
+            }
77
+        }
78
+
79
+        for (u8 y = 0; y < 8; ++y) {
80
+            set_pixel(71, y, (u16 *)CANVAS_FIRST, outer_pixels[y]);
81
+            set_pixel(71, y, (u16 *)CANVAS_SECOND, outer_pixels[y + 8]);
82
+        }
83
+    }
84
+}
85
+
86
+void anim_init_text(void) {
87
+    blockset_one_current_tile = 0;
88
+    blockset_one_max_tile = 0x280;
89
+    blockset_one_animator = text_animator;
90
+
91
+    switch (saveblock1->location.bank) {
92
+    case 3: {
93
+        switch (saveblock1->location.map) {
94
+        case 0:
95
+            draw_text_on_canvas("    < Carun City");
96
+            break;
97
+        case 1:
98
+            draw_text_on_canvas("    < Route 3");
99
+        }
100
+    } break;
101
+    default:
102
+        break;
103
+    }
104
+}