Mercurial > hg > old > magoroku_racing
annotate gFont.c @ 91:cb6c6de125dc
halfway
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 May 2011 14:44:03 +0900 |
parents | 8edae89a3877 |
children | 0b65ca27f113 |
rev | line source |
---|---|
0 | 1 /* |
18 | 2 * $Id$ |
0 | 3 * |
88 | 4 * フォント表示。といっても結局スプライトです。 |
5 * gSprite.c と一緒にしてもよかったんだけど | |
6 * 文字は文字でいろいろあるので分けてみる | |
0 | 7 */ |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
10 #include <stdbool.h> |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
11 //#include "libps2.h" |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
12 //#include "ps2util.h" |
0 | 13 #include "gSprite.h" |
14 | |
15 #define DEFOBJ 120 | |
16 #define SPRITE_COL 0x4f | |
17 #define SCREEN_HALF_W 320 | |
18 #define SCREEN_HALF_H 240 | |
19 #define CHAR_W_SIZE 17 | |
20 #define CHAR_H_SIZE 34 | |
21 | |
22 static SpriteTable sptable[DEFOBJ]; | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
23 //static ps2utilSprite sp[DEFOBJ*2]; // 表示スプライト用スタック |
0 | 24 static unsigned int sp_counter; |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
25 static bool flag_spriteInited = false; // スプライトロードフラグ |
0 | 26 |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
27 //static TEXTURE *font_tex; |
0 | 28 |
29 static void | |
30 gFont_Init_Png(char *texname) | |
31 { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
32 /* if (!(font_tex = read_png_file(texname))) { |
0 | 33 fprintf(stderr, |
34 "cannot creat texture - gFont_Init_Png().\n"); | |
35 fflush(stderr); | |
36 exit(EXIT_FAILURE); | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
37 }*/ |
0 | 38 |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
39 /* if (ps2util_tex_Set(font_tex) == -1) { |
0 | 40 fprintf(stderr, |
41 "cannot set texture - gFont_Init_Png().\n"); | |
42 fflush(stderr); | |
43 exit(EXIT_FAILURE); | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
44 }*/ |
0 | 45 } |
46 | |
47 static void | |
48 gFont_Create() | |
49 { | |
50 int i; | |
51 | |
52 for (i=0; i<DEFOBJ; i++) { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
53 /* if (ps2util_sprite_Create(&sp[i], font_tex) == -1) { |
0 | 54 fprintf(stderr, |
55 "cannot create sprite - gFont_Create()\n"); | |
56 fflush(stderr); | |
57 exit(EXIT_FAILURE); | |
58 } | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
59 ps2util_sprite_Unuse_alpha(&sp[i]);*/ |
0 | 60 } |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
61 flag_spriteInited = true; |
0 | 62 } |
63 | |
64 static void | |
65 gFont_DefSprite(int number, int x, int y, int w, int h) | |
66 { | |
67 sptable[number].tx = x; | |
68 sptable[number].ty = y; | |
69 sptable[number].tw = w; | |
70 sptable[number].th = h; | |
71 } | |
72 | |
73 void | |
74 gFont_Init() | |
75 { | |
76 int i, j; | |
77 int number = 0; | |
78 | |
79 gFont_Init_Png("img/font.png"); | |
88 | 80 gFont_Create(); // スプライト生成 |
0 | 81 |
82 for (i=0; i<7; i++) { | |
83 for (j=0; j<15; j++) { | |
84 gFont_DefSprite(number, j*17, i*34, 17, 34); | |
85 number++; | |
86 } | |
87 } | |
88 } | |
89 | |
90 | |
91 static void | |
92 gFont_PutSprite(int number, int x, int y) | |
93 { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
94 // ps2utilSprite *p = &sp[sp_counter]; |
0 | 95 |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
96 /* ps2util_sprite_Set_basicAttribute( |
0 | 97 p, |
98 (ushort)x, (ushort)y, | |
99 (ushort)sptable[number].tw*1.5, (ushort)sptable[number].th*1.5, | |
100 (ushort)sptable[number].tx, (ushort)sptable[number].ty, | |
101 (ushort)sptable[number].tw, (ushort)sptable[number].th, | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
102 SPRITE_PRIO_FOREGROUND);*/ |
0 | 103 |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
104 // ps2util_sprite_Request(p); |
0 | 105 sp_counter++; |
106 } | |
107 | |
108 | |
109 static void | |
110 gFont_Clear() | |
111 { | |
112 int i; | |
113 | |
114 for (i=0; i<DEFOBJ; i++) { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
115 // sprite_disappear(&sp[i].attribute); |
0 | 116 } |
117 sp_counter = 0; | |
118 } | |
119 | |
120 void | |
121 gFont_Draw_Reset() | |
122 { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
123 if (flag_spriteInited == true) { |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
124 gFont_Clear(); |
0 | 125 } |
126 } | |
127 | |
128 static int | |
129 get_number_char(char a) | |
130 { | |
131 return (int)a-32; | |
132 } | |
133 | |
134 /* | |
88 | 135 * str をスプライド表示 |
0 | 136 */ |
137 void | |
138 gFont_SetString(char *str, int x, int y) | |
139 { | |
140 int number; | |
141 | |
142 while (*str != '\0') { | |
143 number = get_number_char(*str); | |
144 gFont_PutSprite(number, x, y); | |
145 str++; | |
146 x += (int)CHAR_W_SIZE*1.5; | |
147 } | |
148 } | |
149 | |
150 /* | |
88 | 151 * numを文字列に変換してSetStringに渡す |
0 | 152 */ |
153 void | |
154 gFont_SetStringInt(int num, int x, int y) | |
155 { | |
156 char bufp[256]; | |
157 | |
158 snprintf(bufp, 256, "%d", num); | |
159 gFont_SetString(bufp, x, y); | |
160 } | |
161 | |
162 void | |
163 gFont_SetFont_OP() | |
164 { | |
165 } |