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