comparison gSprite.cc @ 99:c534f339ee8b

change c++
author e085768
date Thu, 02 Jun 2011 17:51:41 +0900
parents gSprite.c@0b65ca27f113
children e5f2eb98b575
comparison
equal deleted inserted replaced
98:1033fece71ce 99:c534f339ee8b
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "libps2.h"
4 #include "ps2util.h"
5 #include "gSprite.h"
6 #include <stdbool.h>
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];
14 static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
15 static unsigned int sp_counter;
16 static bool flag_spriteInited = false; // スプライトロードフラグ
17
18 static TEXTURE *sprite_tex;
19
20
21 void
22 gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
23 {
24 sptable[number].tx = tx;
25 sptable[number].ty = ty;
26 sptable[number].tw = tw;
27 sptable[number].th = th;
28 }
29
30 void
31 gSprite_PutSprite(int number, int x, int y)
32 {
33 ps2utilSprite *p = &sp[sp_counter];
34
35 ps2util_sprite_Set_basicAttribute(
36 p,
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);
42
43 ps2util_sprite_Request(p);
44 sp_counter++;
45 }
46
47 void
48 gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
49 {
50 ps2utilSprite *p = &sp[sp_counter];
51
52 ps2util_sprite_Set_basicAttribute(
53 p,
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);
59
60 ps2util_sprite_Request(p);
61 sp_counter++;
62 }
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 = false;
100 }
101
102
103 void
104 gSprite_Init()
105 {
106 ps2util_graphic_Init();
107 gSprite_Init_Png("img/main2.png");
108 gSprite_Create(); // スプライト生成
109
110
111 // スプライトの登録
112 gSprite_DefSprite(10, 1, 1, 512, 666); // タイトル
113 gSprite_DefSprite(17, 1, 35, 33, 33); // 選択マーク
114 gSprite_DefSprite(23, 1, 1, 106, 34); // スピードメーター
115 gSprite_DefSprite(24, 51, 40, 18, 20); // 右矢印
116 gSprite_DefSprite(25, 33, 40, 17, 20); // 左矢印
117 gSprite_DefSprite(26, 56, 89, 55, 26); // km/h
118 gSprite_DefSprite(27, 62, 62, 39, 26); // Rap
119 gSprite_DefSprite(28, 430, 62, 53, 46); // 1p
120 gSprite_DefSprite(29, 460, 6, 53, 46); // 2P
121 gSprite_DefSprite(51, 333, 116, 165, 140); // 選択画面の車
122 gSprite_DefSprite(52, 181, 116, 165, 140);
123 gSprite_DefSprite(53, 12, 116, 165, 140);
124 gSprite_DefSprite(81, 115, 1, 148, 114); // 選択画面のコース
125 // 本当は (82, 272,...)です。二つ目のコース絵がないので
126 gSprite_DefSprite(82, 272, 1, 148, 114);
127
128 }
129
130
131 static void
132 gSprite_Clear()
133 {
134 int i;
135
136 for (i=0; i<DEFOBJ; i++) {
137 sprite_disappear(&sp[i].attribute);
138 }
139 sp_counter = 0;
140 }
141
142
143
144 void
145 gSprite_Draw_Reset()
146 {
147 if (flag_spriteInited == true) {
148 gSprite_Clear();
149 }
150 }
151
152
153
154 void
155 gSprite_PutSprite_Pause()
156 {
157 }