Mercurial > hg > old > magoroku_racing.bad
annotate gSprite.c @ 95:b0249b856488
change_ps2util
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 May 2011 18:13:40 +0900 |
parents | cb6c6de125dc |
children | 0b65ca27f113 |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
91 | 3 #include "libps2.h" |
4 #include "ps2util.h" | |
0 | 5 #include "gSprite.h" |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
6 #include <stdbool.h> |
0 | 7 |
8 #define DEFOBJ 100 | |
9 #define SPRITE_COL 0x4f | |
10 #define SCREEN_HALF_W 320 | |
11 #define SCREEN_HALF_H 240 | |
12 | |
13 static SpriteTable sptable[DEFOBJ]; | |
91 | 14 static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック |
0 | 15 static unsigned int sp_counter; |
91 | 16 static bool flag_spriteInited = false; // スプライトロードフラグ |
0 | 17 |
91 | 18 static TEXTURE *sprite_tex; |
0 | 19 |
20 void | |
21 gSprite_DefSprite(int number, int tx, int ty, int tw, int th) | |
22 { | |
23 sptable[number].tx = tx; | |
24 sptable[number].ty = ty; | |
25 sptable[number].tw = tw; | |
26 sptable[number].th = th; | |
27 } | |
28 | |
29 void | |
30 gSprite_PutSprite(int number, int x, int y) | |
31 { | |
95 | 32 ps2utilSprite *p = &sp[sp_counter]; |
0 | 33 |
95 | 34 ps2util_sprite_Set_basicAttribute( |
0 | 35 p, |
95 | 36 (unsigned short)x, (unsigned short)y, |
37 (unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2, | |
38 (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty, | |
39 (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th, | |
40 SPRITE_PRIO_FOREGROUND); | |
0 | 41 |
95 | 42 ps2util_sprite_Request(p); |
0 | 43 sp_counter++; |
44 } | |
45 | |
46 void | |
47 gSprite_PutSpriteEx(int number, int x, int y, float w, float h) | |
48 { | |
95 | 49 ps2utilSprite *p = &sp[sp_counter]; |
0 | 50 |
95 | 51 ps2util_sprite_Set_basicAttribute( |
0 | 52 p, |
95 | 53 (unsigned short)x, (unsigned short)y, |
54 (unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h, | |
55 (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty, | |
56 (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th, | |
57 SPRITE_PRIO_FOREGROUND); | |
0 | 58 |
95 | 59 ps2util_sprite_Request(p); |
0 | 60 sp_counter++; |
61 } | |
62 | |
95 | 63 |
0 | 64 static void |
65 gSprite_Init_Png(char *texname) | |
66 { | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
67 if (!(sprite_tex = read_png_file(texname))) { |
0 | 68 fprintf(stderr, |
69 "cannot creat texture - init_png().\n"); | |
70 fflush(stderr); | |
71 exit(EXIT_FAILURE); | |
72 } | |
73 | |
74 if (ps2util_tex_Set(sprite_tex) == -1) { | |
75 fprintf(stderr, | |
76 "cannot set texture - init_png().\n"); | |
77 fflush(stderr); | |
78 exit(EXIT_FAILURE); | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
79 } |
0 | 80 |
81 } | |
95 | 82 |
0 | 83 |
95 | 84 |
0 | 85 static void |
86 gSprite_Create() | |
87 { | |
88 int i; | |
89 | |
90 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
|
91 if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) { |
0 | 92 fprintf(stderr, |
93 "cannot create sprite No.%d - create_sprite()\n", i); | |
94 fflush(stderr); | |
95 exit(EXIT_FAILURE); | |
96 } | |
97 ps2util_sprite_Unuse_alpha(&sp[i]); | |
98 } | |
99 | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
100 flag_spriteInited = false; |
0 | 101 } |
95 | 102 |
0 | 103 |
95 | 104 void |
0 | 105 gSprite_Init() |
106 { | |
95 | 107 ps2util_graphic_Init(); |
108 gSprite_Init_Png("img/main2.png"); | |
109 gSprite_Create(); // スプライト生成 | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
110 |
0 | 111 |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
112 // スプライトの登録 |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
113 gSprite_DefSprite(10, 1, 1, 512, 666); // タイトル |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
114 gSprite_DefSprite(17, 1, 35, 33, 33); // 選択マーク |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
115 gSprite_DefSprite(23, 1, 1, 106, 34); // スピードメーター |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
116 gSprite_DefSprite(24, 51, 40, 18, 20); // 右矢印 |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
117 gSprite_DefSprite(25, 33, 40, 17, 20); // 左矢印 |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
118 gSprite_DefSprite(26, 56, 89, 55, 26); // km/h |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
119 gSprite_DefSprite(27, 62, 62, 39, 26); // Rap |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
120 gSprite_DefSprite(28, 430, 62, 53, 46); // 1p |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
121 gSprite_DefSprite(29, 460, 6, 53, 46); // 2P |
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
122 gSprite_DefSprite(51, 333, 116, 165, 140); // 選択画面の車 |
0 | 123 gSprite_DefSprite(52, 181, 116, 165, 140); |
124 gSprite_DefSprite(53, 12, 116, 165, 140); | |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
125 gSprite_DefSprite(81, 115, 1, 148, 114); // 選択画面のコース |
88 | 126 // 本当は (82, 272,...)です。二つ目のコース絵がないので |
0 | 127 gSprite_DefSprite(82, 272, 1, 148, 114); |
128 | |
95 | 129 } |
90
8edae89a3877
compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
130 |
95 | 131 |
0 | 132 static void |
133 gSprite_Clear() | |
134 { | |
135 int i; | |
136 | |
137 for (i=0; i<DEFOBJ; i++) { | |
138 sprite_disappear(&sp[i].attribute); | |
139 } | |
140 sp_counter = 0; | |
141 } | |
95 | 142 |
0 | 143 |
95 | 144 |
0 | 145 void |
146 gSprite_Draw_Reset() | |
147 { | |
95 | 148 if (flag_spriteInited == true) { |
0 | 149 gSprite_Clear(); |
150 } | |
151 } | |
95 | 152 |
0 | 153 |
95 | 154 |
0 | 155 void |
156 gSprite_PutSprite_Pause() | |
157 { | |
158 } | |
95 | 159 |