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