0
|
1 /*
|
|
2 スプライト管理関数
|
|
3 */
|
|
4
|
|
5 //#include<libps.h>
|
|
6 #include <stdio.h>
|
|
7 #include <SDL.h>
|
|
8 #include "SDL_image.h"
|
|
9 #include "SDL_opengl.h"
|
|
10 #include "texture.h"
|
|
11 #include "object.h"
|
|
12 #include "tree_controll.h"
|
|
13 #include "sgoex.h"
|
|
14 #include "trace.h"
|
|
15 #include "syokika.h"
|
|
16 #include "LoadSprite.h"
|
|
17
|
|
18
|
|
19 #define OT_LENGTH 1 /* オーダリングテーブル */
|
|
20 #define MAXOBJ 320 /*スプライト表示上限 */
|
|
21
|
|
22 #define TRUE 1
|
|
23 #define FALSE 0
|
|
24
|
|
25
|
|
26 //static u_short tpage;
|
|
27 //static SDL_Rect rect;
|
|
28
|
|
29 //static int nActiveBuff; /*ばふぁ */
|
|
30 // int i; /* Multi-purpose */
|
|
31 //static int pageno;
|
|
32
|
|
33 //static int padd;
|
|
34
|
|
35 static const int sgo_tpx[12] =
|
|
36 { 0, 64, 128, 192, 256, 320, 0, 64, 128, 192, 256, 320 };
|
|
37 static const int sgo_tpy[12] = { 0, 0, 0, 0, 0, 0, 256, 256, 256, 256, 256, 256 };
|
|
38
|
|
39 /* sgo.h 独自の変数形 */
|
|
40 SpriteTable sptable[DEFOBJ];
|
|
41 // static SpriteView spview[MAXOBJ];
|
|
42
|
|
43 #define IMAGE_ADJUSTMENT (0)
|
|
44
|
|
45 /**
|
|
46 * 一つの画像をpageno(page number)で区切るtexture_page_offsetで
|
|
47 * pagenoに対応した領域のx,yを用意しておく。PlayStationではpageno
|
|
48 * で区切る必要があったのだろうが、PS2では全く意味はなさない。
|
|
49 */
|
|
50 static const struct texture_page_offset {
|
|
51 int x;
|
|
52 int y;
|
|
53 } texpage_offset[] = {
|
|
54 {0, 0}, {128 + IMAGE_ADJUSTMENT, 0}, {256 + IMAGE_ADJUSTMENT, 0}, {384 + IMAGE_ADJUSTMENT, 0}};
|
|
55
|
|
56 /*-------------------------------------------------------------
|
|
57 関数プロトタイプ
|
|
58 ---------------------------------------------------------------*/
|
|
59
|
|
60 void SDL_GL_Enter2DMode()
|
|
61 {
|
|
62 // SDL_Surface *sc = SDL_GetVideoSurface();
|
|
63
|
|
64 /* Note, there may be other things you need to change,
|
|
65 depending on how you have your OpenGL state set up.
|
|
66 */
|
|
67 glPushAttrib(GL_ENABLE_BIT);
|
|
68 glDisable(GL_DEPTH_TEST);
|
|
69 glDisable(GL_CULL_FACE);
|
|
70 glEnable(GL_TEXTURE_2D);
|
|
71
|
|
72 /* This allows alpha blending of 2D textures with the scene */
|
|
73 glEnable(GL_BLEND);
|
|
74 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
75
|
|
76 glViewport(0, 0, screen->w, screen->h);
|
|
77
|
|
78 glMatrixMode(GL_PROJECTION);
|
|
79 glPushMatrix();
|
|
80 glLoadIdentity();
|
|
81
|
|
82 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
|
|
83
|
|
84 glMatrixMode(GL_MODELVIEW);
|
|
85 glPushMatrix();
|
|
86 glLoadIdentity();
|
|
87
|
|
88 // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
89 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
90 }
|
|
91
|
|
92
|
|
93 void SDL_GL_Leave2DMode()
|
|
94 {
|
|
95 glMatrixMode(GL_MODELVIEW);
|
|
96 glPopMatrix();
|
|
97
|
|
98 glMatrixMode(GL_PROJECTION);
|
|
99 glPopMatrix();
|
|
100
|
|
101 glPopAttrib();
|
|
102 }
|
|
103
|
|
104
|
|
105 static int power_of_two(int input)
|
|
106 {
|
|
107 int value = 1;
|
|
108
|
|
109 while ( value < input ) {
|
|
110 value <<= 1;
|
|
111 }
|
|
112 return value;
|
|
113 }
|
|
114
|
19
|
115 void
|
|
116 DefSpriteEx(int number, short middlex, short middley)
|
|
117 {
|
|
118 sptable[number].mx = middlex;
|
|
119 sptable[number].my = middley;
|
|
120 }
|
0
|
121
|
19
|
122 void
|
|
123 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
|
0
|
124 {
|
|
125 SURFACE *surfaces;
|
|
126 surfaces = search_node(obj, name);
|
|
127 if(surfaces == NULL)
|
|
128 {
|
|
129 fprintf(stderr, "can't get node\n");
|
|
130 printf("%s", name);
|
|
131 SDL_Quit();
|
|
132 exit(1);
|
|
133 }
|
|
134 sptable[number].w = w;
|
|
135 sptable[number].h = h;
|
|
136 sptable[number].color = (color & 32);
|
|
137 sptable[number].mx = w / 2;
|
|
138 sptable[number].my = h / 2;
|
|
139 sptable[number].tex_w = power_of_two(sptable[number].w);
|
|
140 sptable[number].tex_h = power_of_two(sptable[number].h);
|
|
141 texMinX[number] = 0.0f;
|
|
142 texMinY[number] = 0.0f;
|
|
143 texMaxX[number] = (GLfloat)sptable[number].w / sptable[number].tex_w;
|
|
144 texMaxY[number] = (GLfloat)sptable[number].h / sptable[number].tex_h;
|
19
|
145 // printf("texMaxX = %f, w = %d, tex_w = %d\n", texMaxX[number], sptable[number].w, sptable[number].tex_w);
|
0
|
146 sptable[number].texture = surfaces->texture;
|
|
147 }
|
|
148
|
19
|
149 void
|
|
150 PutSprite(int zorder, short x, short y, int number)
|
0
|
151 {
|
19
|
152 glBindTexture(GL_TEXTURE_2D, (GLuint&)sptable[number].texture);
|
0
|
153 glEnable(GL_BLEND);
|
|
154 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
155 glBegin(GL_QUADS);
|
|
156 glTexCoord2f(texMinX[number],texMinY[number]); glVertex2i((GLuint)x, (GLuint)y );
|
|
157 glTexCoord2f(texMinX[number],texMaxY[number]); glVertex2i((GLuint)x, (GLuint)(y+sptable[number].tex_h) );
|
|
158 glTexCoord2f(texMaxX[number],texMaxY[number]); glVertex2i((GLuint)(x+sptable[number].tex_w), (GLuint)(y+sptable[number].tex_h));
|
|
159 glTexCoord2f(texMaxX[number],texMinY[number]); glVertex2i((GLuint)(x+sptable[number].tex_w), (GLuint)y);
|
|
160 glEnd();
|
|
161 glDisable(GL_BLEND);
|
|
162 }
|
|
163
|
19
|
164 void
|
|
165 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle)
|
0
|
166 {
|
|
167 SpriteTable *m = &sptable[number];
|
|
168 x -= m->w;
|
|
169 y -= m->h;
|
|
170
|
|
171 SDL_GL_Enter2DMode();
|
|
172 glEnable(GL_TEXTURE_2D);
|
|
173 glEnable(GL_BLEND);
|
|
174 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
19
|
175 glBindTexture(GL_TEXTURE_2D, (GLuint&)sptable[number].texture);
|
0
|
176 glTranslatef(x + m->w/2, y + m->h/2, 0.0);
|
|
177 glRotatef(angle, 0.0, 0.0, 1.0);
|
|
178 glScalef(scalex, scaley, 1.0);
|
|
179 glBegin(GL_TRIANGLE_STRIP);
|
|
180 {
|
|
181 glTexCoord2f(texMinX[number], texMinY[number]); glVertex2i(-m->w/2, -m->h/2);
|
|
182 glTexCoord2f(texMaxX[number], texMinY[number]); glVertex2i( m->w/2, -m->h/2);
|
|
183 glTexCoord2f(texMinX[number], texMaxY[number]); glVertex2i(-m->w/2, m->h/2);
|
|
184 glTexCoord2f(texMaxX[number], texMaxY[number]); glVertex2i( m->w/2, m->h/2);
|
|
185 }
|
|
186 glEnd();
|
|
187 glDisable(GL_TEXTURE_2D);
|
|
188 glDisable(GL_BLEND);
|
|
189 SDL_GL_Leave2DMode();
|
|
190 // SDL_GL_SwapBuffers();
|
|
191 }
|
|
192
|
|
193
|
|
194
|
|
195 struct SGO_PAD pad[2];
|
|
196
|
|
197 #ifdef ENABLE_TRACEMODE
|
|
198 extern int runmode;
|
|
199 #endif //ENABLE_TRACEMODE
|
|
200
|
|
201 /* コントローラ状態の読み込み */
|
|
202 void Pad(SDL_Joystick *joy)
|
|
203 {
|
|
204 Sint16 axis;
|
|
205
|
|
206 SDL_JoystickUpdate();
|
|
207
|
|
208 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED)
|
|
209 pad[0].k0++;
|
|
210 else
|
|
211 pad[0].k0=0;
|
|
212
|
|
213 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED)
|
|
214 pad[0].k1++;
|
|
215 else
|
|
216 pad[0].k1=0;
|
|
217
|
|
218 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED)
|
|
219 pad[0].k3++;
|
|
220 else
|
|
221 pad[0].k3=0;
|
|
222
|
|
223 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED)
|
|
224 pad[0].k4++;
|
|
225 else
|
|
226 pad[0].k4=0;
|
|
227
|
|
228 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED)
|
|
229 pad[0].l1++;
|
|
230 else
|
|
231 pad[0].l1=0;
|
|
232
|
|
233 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED)
|
|
234 pad[0].r1++;
|
|
235 else
|
|
236 pad[0].r1=0;
|
|
237
|
|
238 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED)
|
|
239 pad[0].l2++;
|
|
240 else
|
|
241 pad[0].l2=0;
|
|
242
|
|
243 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED)
|
|
244 pad[0].r2++;
|
|
245 else
|
|
246 pad[0].r2=0;
|
|
247
|
|
248 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED)
|
|
249 pad[0].st++;
|
|
250 else
|
|
251 pad[0].st=0;
|
|
252
|
|
253 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED)
|
|
254 pad[0].se++;
|
|
255 else
|
|
256 pad[0].se=0;
|
|
257
|
|
258 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED)
|
|
259 pad[0].l3++;
|
|
260 else
|
|
261 pad[0].l3=0;
|
|
262
|
|
263 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED)
|
|
264 pad[0].r3++;
|
|
265 else
|
|
266 pad[0].r3=0;
|
|
267 //x
|
|
268 axis=SDL_JoystickGetAxis(joy,0);
|
|
269 if(axis>=3200){
|
|
270 pad[0].left=0;
|
|
271 pad[0].right++;
|
|
272 }
|
|
273 else if(axis<=-3200){
|
|
274 pad[0].right=0;
|
|
275 pad[0].left++;
|
|
276 }
|
|
277 else {
|
|
278 pad[0].right=0;
|
|
279 pad[0].left=0;
|
|
280 }
|
|
281 //y
|
|
282 axis=SDL_JoystickGetAxis(joy,1);
|
|
283 if(axis>=3200){
|
|
284 pad[0].up=0;
|
|
285 pad[0].down++;
|
|
286 }
|
|
287 else if(axis<=-3200){
|
|
288 pad[0].down=0;
|
|
289 pad[0].up++;
|
|
290 }
|
|
291 else {
|
|
292 pad[0].down=0;
|
|
293 pad[0].up=0;
|
|
294 }
|
|
295
|
|
296 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) &&
|
|
297 (pad[0].l2 != 0) && (pad[0].r2 != 0) &&
|
|
298 (pad[0].st != 0) && (pad[0].se != 0)) {
|
|
299 pad[0].quit = 1;
|
|
300 } else {
|
|
301 pad[0].quit = 0;
|
|
302 }
|
|
303
|
|
304 }
|
|
305
|
|
306
|
|
307 void keybord()
|
|
308 {
|
|
309 SDL_PumpEvents();
|
|
310 Uint8 *keys = SDL_GetKeyState(NULL);
|
|
311
|
|
312 if (keys[SDLK_UP]) {
|
|
313 pad[0].up++;
|
|
314 } else {
|
|
315 pad[0].up = 0;
|
|
316 }
|
|
317 if (keys[SDLK_DOWN]) {
|
|
318 pad[0].down++;
|
|
319 } else {
|
|
320 pad[0].down = 0;
|
|
321 }
|
|
322
|
|
323 if (keys[SDLK_RIGHT]) {
|
|
324 pad[0].right++;
|
|
325 } else {
|
|
326 pad[0].right = 0;
|
|
327 }
|
|
328
|
|
329 if (keys[SDLK_LEFT]) {
|
|
330 pad[0].left++;
|
|
331 } else {
|
|
332 pad[0].left = 0;
|
|
333 }
|
|
334
|
|
335 if (keys[SDLK_a]) {
|
|
336 pad[0].k0++;
|
|
337 } else {
|
|
338 pad[0].k0 = 0;
|
|
339 }
|
|
340
|
|
341 if (keys[SDLK_z]) {
|
|
342 pad[0].k1++;
|
|
343 } else {
|
|
344 pad[0].k1 = 0;
|
|
345 }
|
|
346
|
|
347 if (keys[SDLK_s]) {
|
|
348 pad[0].k3++;
|
|
349 } else {
|
|
350 pad[0].k3 = 0;
|
|
351 }
|
|
352
|
|
353 if (keys[SDLK_x]) {
|
|
354 pad[0].k4++;
|
|
355 } else {
|
|
356 pad[0].k4 = 0;
|
|
357 }
|
|
358
|
|
359 if (keys[SDLK_r]) {
|
|
360 pad[0].r2++;
|
|
361 } else {
|
|
362 pad[0].r2 = 0;
|
|
363 }
|
|
364
|
|
365 if (keys[SDLK_e]) {
|
|
366 pad[0].r1++;
|
|
367 } else {
|
|
368 pad[0].r1 = 0;
|
|
369 }
|
|
370
|
|
371 if (keys[SDLK_w]) {
|
|
372 pad[0].l1++;
|
|
373 } else {
|
|
374 pad[0].l1 = 0;
|
|
375 }
|
|
376
|
|
377 if (keys[SDLK_q]) {
|
|
378 pad[0].l2++;
|
|
379 } else {
|
|
380 pad[0].l2 = 0;
|
|
381 }
|
|
382
|
|
383 // START ボタンは Return が似合う気がする
|
|
384 //if(keys[SDLK_1])
|
|
385 if (keys[SDLK_RETURN]) {
|
|
386 pad[0].st++;
|
|
387 } else {
|
|
388 pad[0].st = 0;
|
|
389 }
|
|
390
|
|
391 if (keys[SDLK_2]) {
|
|
392 pad[0].se++;
|
|
393 } else {
|
|
394 pad[0].se = 0;
|
|
395 }
|
|
396
|
|
397 if (keys[SDLK_ESCAPE]) {
|
|
398 SDL_Quit();
|
|
399 exit(1);
|
|
400 //pad[0].st = 1;
|
|
401 //pad[0].se = 1;
|
|
402 }
|
|
403
|
|
404 if (keys[SDLK_0]) {
|
|
405 pad[0].quit = 1;
|
|
406 } else {
|
|
407 pad[0].quit = 0;
|
|
408 }
|
|
409 }
|
|
410
|