2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
22 evanrinehart@gmail.com
25 /* messages and text */
42 struct treenode
* chartree
= NULL
;
45 int ptrcomp(void* k1
, void* k2
){
49 void set_message(char* str
){
51 int N
= unicode_getc(str
, &u
);
53 vwchar
* C
= tree_search(chartree
, ptrcomp
, (void*)u
);
55 /* append this character to the message
56 if the current word is too long,
57 move the current word to the next line
58 if the current word is longer than a whole line
59 then just break here (would happen with japanese).
64 character not found, so use a rectangle or something
65 use four tiny numbers to indicate the character
69 N
+= unicode_getc(str
+N
, &u
);
75 void advance_message(){
83 void complete_message(){
89 vwchar
* C
= xmalloc(sizeof(vwchar
));
97 chartree
= xmalloc(sizeof(treenode
));
101 chartree
->key
= (void*)' ';
108 vwchar
* load_vwchar(reader
* rd
, int gfx
){
112 int ret
= loader_scanline(rd
, "%256s %d %d %d %d %d\n",str
,&x
,&y
,&w
,&k1
,&k2
);
116 unicode_getc(str
,&u
);
117 vwchar
* C
= xmalloc(sizeof(vwchar
));
129 void print_tree(treenode
* node
){
130 printf("(%lx,",(utf32
)node
->key
);
148 void randomly_insert(vwchar
* C
[], int count
){
150 for(i
=0; i
<count
-1; i
++){
151 int j
= randi(0, count
-i
-1);
152 tree_insert(chartree
, ptrcomp
, (void*)C
[j
]->u
, C
[j
]);
159 int load_font(char* path
){
160 //printf("load_font: loading %s\n",filename);
161 reader
* rd
= loader_open(path
);
163 fatal_error("load_font: cannot open %s\n", path
);
167 loader_scanline(rd
, "%256s", str
);
168 int gfx
= load_bitmap(str
);
170 /* we read 64 characters at a time and insert them
171 randomly into the binary search tree. this is supposed
172 to help produce a more balanced tree. */
176 C
[ptr
] = load_vwchar(rd
, gfx
);
180 randomly_insert(C
, 64);
184 C
[++ptr
] = load_vwchar(rd
, gfx
);
188 randomly_insert(C
, ptr
);
190 printf(" loaded %d characters\n",N);
192 printf(" character tree is the following\n");
193 print_tree(chartree);