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