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