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