2 #define WIN32_LEAN_AND_MEAN
5 #if defined(__APPLE__) && defined(__MACH__)
6 #include <OpenGL/gl.h> // Header File For The OpenGL32 Library
7 #include <OpenGL/glu.h> // Header File For The GLu32 Library
9 #include <GL/gl.h> // Header File For The OpenGL32 Library
10 #include <GL/glu.h> // Header File For The GLu32 Library
13 #include "SDL/SDL_image.h"
14 #include "SDL/SDL_timer.h"
15 #include "SDL/SDL_mixer.h"
16 #include "SDL_Pango.h"
19 #include "ModelType.h"
20 #include "e3d_engine.h"
26 // 640x480 * 2 * 2 = 1280 x 960
28 SDL_Surface
*pixshoot
[NUM_SHOOTS
];
30 e3D_Application
*e3D_App
;
34 e3D_Controller
*Controller
;
36 Mix_Music
*music_intro
;
37 Mix_Music
*music_introgame
;
38 Mix_Music
*music_game
;
40 uint sound_checkpoint1
,
55 GLuint texplanet
[NUM_PLANETS
]; // Storage For NUM_PLANETS Textures
56 GLuint texshoot
[NUM_SHOOTS
]; // Storage For NUM_SHOOTS Textures
58 GLuint cube
; // Storage For The Display List
59 //GLuint top; // Storage For The Second Display List
62 GLuint xloop
; // Loop For X Axis
63 GLuint yloop
; // Loop For Y Axis
66 GLfloat xrot
; // Rotates Cube On The X Axis
67 GLfloat yrot
; // Rotates Cube On The Y Axis
72 matriz camera_position
, camera_orientation
, camera
, perspective
;
75 ModelType MTObject
[15];
77 // Build Cube Display List
81 glNewList(sprite
,GL_COMPILE
);
84 glNormal3f( 0.0f
, 0.0f
, -1.0f
);
85 glTexCoord2f(0.0f
, 0.0f
); glVertex3f(-1.0f
, 1.0f
, 0.0f
);
86 glTexCoord2f(1.0f
, 0.0f
); glVertex3f( 1.0f
, 1.0f
, 0.0f
);
87 glTexCoord2f(1.0f
, 1.0f
); glVertex3f( 1.0f
, -1.0f
, 0.0f
);
88 glTexCoord2f(0.0f
, 1.0f
); glVertex3f(-1.0f
, -1.0f
, 0.0f
);
93 // Load Bitmaps And Convert To Textures
94 void LoadGLTextures(void)
102 pixshoot
[i
] = IMG_Load("images/particles/supernova-256-8.png");
103 if (!pixshoot
[i
]) {SDL_Quit();exit(1);}
105 pixshoot
[i
] = IMG_Load("images/particles/cross1.png");
106 if (!pixshoot
[i
]) {SDL_Quit();exit(1);}
108 pixshoot
[i
] = IMG_Load("images/particles/cross3.png");
109 if (!pixshoot
[i
]) {SDL_Quit();exit(1);}
112 /* SDLPango_Context *pango_test1 = SDLPango_CreateContext();
113 SDLPango_SetDefaultColor(pango_test1, MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
114 SDLPango_SetDpi(pango_test1, TTF_DPI, TTF_DPI);
115 SDLPango_SetMinimumSize(pango_test1, -1, 0);
116 SDLPango_SetMarkup(pango_test1, "world", -1);
117 int ps_w = SDLPango_GetLayoutWidth(pango_test1);
118 int ps_h = SDLPango_GetLayoutHeight(pango_test1);
119 // int margin_x = 10;
120 // int margin_y = 10;
121 // pixshoot[2]= SDLPango_CreateSurfaceDraw(pango_test1);
122 pixshoot[2] = SDL_CreateRGBSurface(SDL_SWSURFACE, ps_w, ps_h,
123 32, (Uint32)(255 << (8 * 0)), (Uint32)(255 << (8 * 1)),
124 (Uint32)(255 << (8 * 2)), (Uint32)(255 << (8 * 3)));
125 SDLPango_Draw(pango_test1, pixshoot[2], 0, 0);
126 //int totalbytes=4*pixshoot[2]->w*pixshoot[2]->h;
129 // Create MipMapped Texture
130 glGenTextures(NUM_SHOOTS
, texshoot
);
132 for (i
=0;i
<NUM_SHOOTS
;i
++)
134 glBindTexture(GL_TEXTURE_2D
, texshoot
[i
]);
135 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MAG_FILTER
,GL_LINEAR
);
136 glTexParameteri(GL_TEXTURE_2D
,GL_TEXTURE_MIN_FILTER
,GL_LINEAR_MIPMAP_LINEAR
);
137 gluBuild2DMipmaps(GL_TEXTURE_2D
, GL_RGB
,
138 pixshoot
[i
]->w
, pixshoot
[i
]->h
, GL_RGB
, GL_UNSIGNED_BYTE
,
139 pixshoot
[i
]->pixels
);
144 /* A general OpenGL initialization function. Sets all of the initial parameters. */
145 void TempInitGL() // We call this right after our OpenGL window is created.
147 LoadGLTextures(); // Load The Texture
148 BuildList(); // Build The Display List
151 /* The main drawing function. */
156 glMatrixMode(GL_MODELVIEW
);
157 glDisable(GL_LIGHTING
);
159 glDisable(GL_ALPHA_TEST
);
160 glDepthMask(GL_FALSE
);
162 glBlendFunc(GL_SRC_ALPHA
,GL_ONE
); // Aditivo
164 glMatrixMode(GL_PROJECTION
);
165 glLoadIdentity(); // Reset The Projection Matrix
166 gluOrtho2D(-1,1,-1,1);
167 glMatrixMode(GL_MODELVIEW
);
169 glDisable(GL_LIGHTING
);
170 glEnable(GL_COLOR_MATERIAL
);
174 void DrawGLScene(float d
=0.03, float angle
=0, float vel
=0)
178 float a
=10/Render
->Ship1
->camlag
;
181 glMatrixMode(GL_MODELVIEW
);
184 glDisable(GL_LIGHTING
);
186 glDisable(GL_ALPHA_TEST
);
187 glDepthMask(GL_FALSE
);
189 glBlendFunc(GL_SRC_ALPHA
,GL_ONE
); // Aditivo
191 glMatrixMode(GL_PROJECTION
);
192 glLoadIdentity(); // Reset The Projection Matrix
193 gluOrtho2D(-1,1,-1,1);
194 glMatrixMode(GL_MODELVIEW
);
196 glDisable(GL_LIGHTING
);
197 glEnable(GL_COLOR_MATERIAL
);
200 static float aux_score
=0;
201 aux_score
=(aux_score
*100+Render
->Ship1
->score
)/101.0;
202 float score_sz
=10+sin(e3D_App
->total_time
/10000.0+aux_score
/10.0);
203 Render
->Score
->setScale(score_sz
,score_sz
);
215 float scaleX
=2,scaleY
=2;
216 Render
->Time
->setAttrs(minX
,minY
,scaleX
,scaleY
);
217 Render
->Score
->setAttrs(minX
,minY
,scaleX
,scaleY
);
218 Render
->Speed
->setAttrs(minX
,minY
,scaleX
,scaleY
);
219 Render
->Fuel
->setAttrs(minX
,minY
,scaleX
,scaleY
);
220 Render
->Time
->x
=-0.50;
221 Render
->Time
->y
=-0.90;
222 Render
->Score
->x
=0.8;
223 Render
->Score
->y
=0.8;
224 Render
->Speed
->x
=0.1;
225 Render
->Speed
->y
=-0.9;
227 Render
->Fuel
->y
=-0.9;
232 char ff
[]="font_family=\"TSCu_Comic\"";
236 sprintf(txt
,"<span %s>Score:%06d</span>",ff
,Render
->Ship1
->score
);
237 Render
->Score
->setText(txt
);
239 sprintf(txt
,"<span %s>Time:%.2f</span>",ff
,(e3D_App
->total_time
-Render
->Ship1
->time_start
)/1000.0);
240 Render
->Time
->setText(txt
);
242 sprintf(txt
,"<span %s>Speed:%.2f</span>",ff
,Render
->Ship1
->lv
);
243 Render
->Speed
->setText(txt
);
245 sprintf(txt
,"<span %s>Fuel:%.2f</span>",ff
,Render
->Ship1
->used_fuel
);
246 Render
->Fuel
->setText(txt
);
253 Render
->Score
->Draw(1);
254 Render
->Time
->Draw(1);
255 Render
->Speed
->Draw(1);
256 Render
->Fuel
->Draw(1);
259 glBindTexture(GL_TEXTURE_2D
, texshoot
[2]);
262 glScalef(d
/(4.0/3.0),d
,1.0f
);
263 //glScalef(5,5,1.0f);
264 glRotatef(angle
,0,0,1);
265 glColor4f(1.0f
,1.0f
,1.0f
,(0.05f
/d
-0.05)*a
);
268 glBindTexture(GL_TEXTURE_2D
, texshoot
[2]);
272 glTranslatef(0.8+1/vel
,-0.8-1/vel
,0);
273 glScalef(3.0/4.0/vel
,1.0f
/vel
,1.0f
);
275 glColor4f(1.0f
,1.0f
,1.0f
,(vel
/10.0)*a
);
282 void nearCallback (void *data
, dGeomID o0
, dGeomID o1
) {
283 e3D_Render
*Render
=(e3D_Render
*)data
;
284 // Create an array of dContact objects to hold the contact joints
285 static const int MAX_CONTACTS
= 10;
286 dContact contact
[MAX_CONTACTS
];
288 for (int i
= 0; i
< MAX_CONTACTS
; i
++)
290 contact
[i
].surface
.mode
= dContactSoftERP
| dContactSoftCFM
;
291 contact
[i
].surface
.mu
= dInfinity
;
292 contact
[i
].surface
.mu2
= 0;
293 contact
[i
].surface
.bounce
= 0.0;
294 contact
[i
].surface
.bounce_vel
= 0.0;
295 contact
[i
].surface
.soft_cfm
= 0.1;
296 contact
[i
].surface
.soft_erp
= 0.1;
298 if (int numc
= dCollide(o0
, o1
, MAX_CONTACTS
, &contact
[0].geom
, sizeof(dContact
)))
300 Sound
->play_sound(sound_shoot1f
,.4);
301 // Get the dynamics body for each geom
302 dBodyID b1
= dGeomGetBody(o0
);
303 dBodyID b2
= dGeomGetBody(o1
);
304 // To add each contact point found to our joint group we call dJointCreateContact which is just one of the many
305 // different joint types available.
306 for (int i
= 0; i
< numc
; i
++)
308 // dJointCreateContact needs to know which world and joint group to work with as well as the dContact
309 // object itself. It returns a new dJointID which we then use with dJointAttach to finally create the
310 // temporary contact joint between the two geom bodies.
311 dJointID c
= dJointCreateContact(Render
->world
, Render
->_contactgroup
, contact
+ i
);
312 dJointAttach(c
, b1
, b2
);
318 void callback_Checkpoint_onChange(int new_checkpoint
)
320 Sound
->play_sound(sound_checkpoint1
);
324 case 0: Sound
->play_sound(sound_checkpoint2a
); break;
325 case 1: Sound
->play_sound(sound_checkpoint2b
); break;
326 case 2: Sound
->play_sound(sound_checkpoint2c
); break;
330 void callback_Checkpoint_done(int checkpoint
, int points_earned
)
335 void hook_musicDone() {
336 Sound
->play_music(music_game
,1);
340 int WINAPI
WinMain (HINSTANCE hInstance
,
341 HINSTANCE hPrevInstance
,
346 int main(int argc
, char **argv
)
356 e3D_App
=new e3D_Application();
357 Sound
=e3D_App
->Sound
;
358 Video
=e3D_App
->Video
;
359 Controller
=e3D_App
->Controller
;
360 Render
=e3D_App
->Render
;
364 Video
->Bitsperpixel
=0;
367 Video
->InitializeVideo();
368 Controller
->SetWarpPos(Video
->Width
/2,Video
->Height
/2);
372 sound_checkpoint1
=Sound
->load_sound("sounds/checkpoint1.ogg");
373 sound_checkpoint2a
=Sound
->load_sound("sounds/checkpoint2a.ogg");
374 sound_checkpoint2b
=Sound
->load_sound("sounds/checkpoint2b.ogg");
375 sound_checkpoint2c
=Sound
->load_sound("sounds/checkpoint2c.ogg");
376 sound_destroyed
=Sound
->load_sound("sounds/destroyed.ogg");
377 sound_engine1
=Sound
->load_sound("sounds/engine1.ogg");
378 sound_planet1a
=Sound
->load_sound("sounds/planet1a.ogg");
379 sound_shoot1dd
=Sound
->load_sound("sounds/shoot1-dd.ogg");
380 sound_shoot1d
=Sound
->load_sound("sounds/shoot1-d.ogg");
381 sound_shoot1f
=Sound
->load_sound("sounds/shoot1-f.ogg");
382 sound_shoot1
=Sound
->load_sound("sounds/shoot1.ogg");
383 sound_shoot2
=Sound
->load_sound("sounds/shoot2.ogg");
385 SDL_Joystick
*joystick
=0;
386 int njj
=SDL_NumJoysticks();
389 cout
<< "Se encontraron " << njj
<< " joysticks." << endl
;
390 joystick
= SDL_JoystickOpen(0);
396 start
=SDL_GetTicks();
397 e3D_Ship
*Nave
=Render
->Ship1
;
398 // e3D_Ship *Nave2=Render->Ship2;
399 // e3D_Ship *Nave3=Render->Ship3;
401 dWorldID world
= Render
->world
;
402 #define MUS_CYRIL "music/CyrilPereira-TheRevengeOfGlory/"
403 music_intro
=Mix_LoadMUS(MUS_CYRIL
"18 - blacksheep alien.ogg");
404 music_introgame
=Mix_LoadMUS(MUS_CYRIL
"01 - Le cercle maudit.ogg");
405 music_game
=Mix_LoadMUS(MUS_CYRIL
"02 - The Revenge Of Glory.ogg");
409 double joyx=0,joycx=0;
410 double joyy=0,joycy=0;
411 double joyz=0,joycz=0;
413 e3D_Ship
*eCamera
=new e3D_Ship(Render
->OG_Ships
,"data/ships/n2.obj",2.50);
415 // e3D_Object *eCamera=new e3D_Object(Render->World);
416 e3D_Text
*text_nespa
= new e3D_Text(Render
->OG_HUD
);
417 e3D_Text
*text_createdby
= new e3D_Text(Render
->OG_HUD
);
418 e3D_Text
*text_hitesc
= new e3D_Text(Render
->OG_HUD
);
419 //char ff[]="font_family=\"TSCu_Comic\"";
420 text_createdby
->setAttrs(0,0,2,2);
421 text_createdby
->setText("<span font_family=\"TSCu_Comic\">A Game Created By: David Martinez Marti</span>");
422 //text_createdby->setText("A Game Created By David Martínez Martí");
423 text_createdby
->y
=0.6;
424 //text_createdby->setScale(0,0);
425 text_createdby
->A
=0.0;
427 text_nespa
->setAttrs(0,0,20,20);
428 text_nespa
->setText("<span face=\"Radis Sans\" color=\"red\">nespa</span>\n<span face=\"Radis Sans\" size=\"3000\" gravity=\"east\"> a starship game</span>");
430 text_nespa
->setScale(0,0);
433 text_hitesc
->setAttrs(0,0,2,2);
434 text_hitesc
->setText("<span face=\"Radis Sans\">Hit <i>[ESC]</i> to Skip Intro</span>");
439 Render
->Camera
=eCamera
;
440 // Render->Camera=Nave;
441 eCamera
->Translate(0,0,2000);
442 uint time_start
=e3D_App
->total_time
;
443 Controller
->UnGrab();
444 zoom_d
=Render
->zoom
=0.4;
446 Sound
->play_music(music_intro
,1);
447 Mix_HookMusicFinished(hook_musicDone
);
449 dBodyAddRelForceAtRelPos(eCamera
->body
,20,20,20,0.001,0.001,-0.01);
450 dBodyDisable(Nave
->body
);
452 cout
<< "Iniciando juego." << endl
;
455 Render
->zoom
=(Render
->zoom
*100+zoom_d
)/101.0;
456 if (e3D_App
->StartFrame())
459 //if (Controller->grab)
463 eCamera
->GetXYZ(&Cx
,&Cy
,&Cz
);
464 Nave
->GetXYZ(&Sx
,&Sy
,&Sz
);
465 float time
=(e3D_App
->total_time
-time_start
)/1000.0;
468 dBodyAddRelForceAtRelPos(eCamera
->body
,2.3,0,90,0,0,-0.01);
470 text_nespa
->y
=(text_nespa
->y
*100+0.4)/101.0;
475 static float accel
=0.0008;
476 text_nespa
->setScale(1000/accel
,1000/accel
);
478 if (accel
<100) accel
*=1.017;
482 if (time
<11) zoom_d
=1; else zoom_d
+=.01;
483 if (text_nespa
->y
>-0.6) text_nespa
->y
-=0.001; else
485 text_nespa
->x
=(text_nespa
->x
*1000.0+0.6)/1001.0;
486 text_nespa
->scaleX
=(text_nespa
->scaleX
*1000.0+70)/1001.0;
487 text_nespa
->scaleY
=(text_nespa
->scaleY
*1000.0+70)/1001.0;
489 if (text_createdby
->A
<0.7) text_createdby
->A
+=0.001;
491 text_createdby
->scaleX
*=1.01;
492 if (text_createdby
->scaleX
>1000) text_createdby
->y
+=.003;
497 const dReal
*AngularVel
, *LinearVel
;
499 AngularVel
=dBodyGetAngularVel(eCamera
->body
);
500 LinearVel
=dBodyGetLinearVel(eCamera
->body
);
502 double AngularVel_x
=AngularVel
[0],AngularVel_y
=AngularVel
[1],AngularVel_z
=AngularVel
[2];
503 double LinearVel_x
=LinearVel
[0],LinearVel_y
=LinearVel
[1],LinearVel_z
=LinearVel
[2];
505 // Fricción simulada / irreal:
506 double ax
=(Sx
-Cx
),ay
=(Sy
-Cy
),az
=(Sz
-Cz
);
507 double dxy
=sqrt(ax
*ax
+ay
*ay
);
508 double d
=sqrt(dxy
*dxy
+az
*az
);
509 double d2
=sqrt(d
)*1.2;
513 dBodyAddTorque(eCamera
->body
,-AngularVel_x
*avd
,-AngularVel_y
*avd
,-AngularVel_z
*avd
);
515 if (time
>15.0) {lvd
=0;d2
/=5.0;}
516 if (time
>24 && zoom_d
>8) {zoom_d
-=0.1; lvd
=0.5;}
517 if (time
>29 && zoom_d
>2) {zoom_d
-=0.02; lvd
=2;}
518 if (time
>33 && zoom_d
>1) {zoom_d
-=0.1; lvd
=5;}
519 dBodyAddForce(eCamera
->body
,-LinearVel_x
*lvd
,-LinearVel_y
*lvd
,-LinearVel_z
*lvd
);
521 // printf("%.2f | %.2f\n",d,d2);
522 dBodyAddForceAtRelPos(eCamera
->body
,ax
/d2
,ay
/d2
,az
/d2
,0,0,-0.01);
524 dBodyAddForceAtRelPos(Nave
->body
,-Sx
/1000000.0,-Sy
/1000000.0,-Sz
/1000000.0,0,0,-100);
527 const dReal
*AngularVel
, *LinearVel
;
528 text_hitesc
->A
=(text_hitesc
->A
*100+sin(time
*10.0)+.5)/101.0;
530 AngularVel
=dBodyGetAngularVel(eCamera
->body
);
531 LinearVel
=dBodyGetLinearVel(eCamera
->body
);
533 double AngularVel_x
=AngularVel
[0],AngularVel_y
=AngularVel
[1],AngularVel_z
=AngularVel
[2];
534 double LinearVel_x
=LinearVel
[0],LinearVel_y
=LinearVel
[1],LinearVel_z
=LinearVel
[2];
536 // Fricción simulada / irreal:
537 double ax
=(-Cx
),ay
=(-Cy
),az
=(-Cz
);
538 double dxy
=sqrt(ax
*ax
+ay
*ay
);
539 double d
=sqrt(dxy
*dxy
+az
*az
);
544 dBodyAddTorque(eCamera
->body
,-AngularVel_x
*avd
,-AngularVel_y
*avd
,-AngularVel_z
*avd
);
546 dBodyAddForce(eCamera
->body
,-LinearVel_x
*lvd
,-LinearVel_y
*lvd
,-LinearVel_z
*lvd
);
548 // printf("%.2f | %.2f\n",d,d2);
549 dBodyAddForceAtRelPos(eCamera
->body
,ax
/d2
,ay
/d2
,az
/d2
,0,0,-0.00001);
552 } else time_start
=e3D_App
->total_time
;
554 dWorldStep(world
,1.0/60.0);
557 //DrawGLScene(1,1,1);
561 text_createdby
->Draw(0);
562 text_hitesc
->Draw(0);
564 SDL_GL_SwapBuffers();
566 done
=Controller
->GetEvents(); // OJO!! Esto asigna *keys.
568 keys
= Controller
->keys
;
569 if ( keys
[SDLK_F7
] == SDL_PRESSED
) Controller
->Grab();
570 if ( keys
[SDLK_F8
] == SDL_PRESSED
) Controller
->UnGrab();
571 if ( keys
[SDLK_F1
] == SDL_PRESSED
) Render
->Camera
=eCamera
;
572 if ( keys
[SDLK_F2
] == SDL_PRESSED
) Render
->Camera
=Nave
;
576 channel_engine
=Sound
->play_sound(sound_engine1
,0,-1);
577 Render
->Camera
=Render
->Ship1
;
580 dBodyEnable(Nave
->body
);
581 dBodySetForce(Nave
->body
, 0,0,0);
582 dBodySetTorque(Nave
->body
, -12,20,0);
583 dWorldStep(world
,.3);
584 dBodySetTorque(Nave
->body
, 0,0,0);
585 dBodySetAngularVel (Nave
->body
,0,0,0);
586 dWorldStep(world
,.3);
589 Sound
->play_music(music_introgame
,1);
590 Mix_HookMusicFinished(hook_musicDone
);
593 if (e3D_App
->StartFrame())
596 if (Controller
->grab
)
598 if (Nave
->camlag
>1) Nave
->camlag
-=.1;
600 Nave
->dfriction
=5.0/(Nave
->lv
+1000)+.02;
601 dSpaceCollide(Render
->space
, Render
, &nearCallback
);
602 dWorldStep(world
,1.0/60.0);
603 dJointGroupEmpty(Render
->_contactgroup
);
608 // Render->LoadCamera(Render->Ship1);
609 // Render->Ship2->GetXYZ(&x2,&y2,&z2);
610 // Render->Ship3->GetXYZ(&x3,&y3,&z3);
612 // Draw only when StartFrame returns True
614 float e1
=Nave
->energy
;
615 if (e1
>1000) e1
=1000;
616 float d
=10.0/e1
*zoom
;
620 // Indicadores varios y disparos
621 DrawGLScene(d
,-weapon1
*90/5,fabs(Nave
->dz
));
622 Mix_Volume(channel_engine
,MIX_MAX_VOLUME
/10.0*sqrt(fabs(Nave
->dz
)));
626 glBindTexture(GL_TEXTURE_2D, texshoot[0]);
628 glScalef(0.1/(4.0/3.0),0.1,1.0f);
629 glTranslated(joyx*fabs(joyx)/10.0,joyy*fabs(joyy)/10.0,0);
630 glColor4f(1.0f,0.0f,0.0f,1.0f);
633 glScalef(0.1/(4.0/3.0),0.1,1.0f);
634 glTranslated(-joycx*5,-joycy*5,0);
635 glColor4f(0.0f,0.0f,1.0f,1.0f);
638 // El HUD / radar que dibuja a los enemigos.
639 /* glBindTexture(GL_TEXTURE_2D, texshoot[1]);
640 if (z2<-500 && Render->Ship2->hull)
645 glScalef(1.0/(4.0/3.0),1,1.0f);
646 glTranslated(x2,y2,0);
647 d=1.8/sqrt(-z2+500)*sqrt(zoom);
655 glColor4f(1.0f,1.0f,1.0f,(0.05f/d-0.05)*a);
658 if (z3<-500 && Render->Ship3->hull)
663 glScalef(1.0/(4.0/3.0),1,1.0f);
664 glTranslated(x3,y3,0);
665 d=1.8/sqrt(-z3+500)*sqrt(zoom);
673 glColor4f(1.0f,1.0f,1.0f,(0.05f/d-0.05)*a);
678 SDL_GL_SwapBuffers();
682 Mix_Volume(channel_engine
,0);
684 done
=Controller
->GetEvents(); // OJO!! Esto asigna *keys.
686 Nave
->ry
=Controller
->mouse_x
/20.0/zoom
;
687 Nave
->rx
=Controller
->mouse_y
/20.0/zoom
;
689 // Suavizado del zoom.
690 zoom
=(zoom_d
+zoom
*50.0)/51.0;
695 /* Check current key state for special commands */
696 keys
= Controller
->keys
;
698 if ( keys
[SDLK_a
] == SDL_PRESSED
) Nave
->rz
-= 0.2f
;
699 if ( keys
[SDLK_s
] == SDL_PRESSED
) Nave
->rz
+= 0.2f
;
701 if ( keys
[SDLK_z
] == SDL_PRESSED
) {Nave
->dz
+=.5;}
702 if ( keys
[SDLK_x
] == SDL_PRESSED
) {Nave
->dz
-=1;}
703 if ( keys
[SDLK_SPACE
] == SDL_PRESSED
&& Nave
->dz
>0 && Nave
->dz
<100) {Nave
->dz
*=1.1;}
704 if (weapon1
<60) weapon1
++;
708 if (keys
[SDLK_v
] == SDL_PRESSED
)
711 Sound
->play_sound(sound_shoot1
,.2);
714 if (keys
[SDLK_b
] == SDL_PRESSED
)
717 Sound
->play_sound(sound_shoot1
,.2);
723 // Sobre música y gramola
724 if ( keys[SDLK_1] == SDL_PRESSED && playing>=0 )
726 if (Mix_FadeOutMusic(10000)) playing=-1;
729 if (playing==-1 || !Mix_PlayingMusic())
731 if (Mix_FadingMusic()==MIX_NO_FADING)
734 Mix_FadeInMusicPos(music[playing],1,10000,0);
741 if ( keys
[SDLK_F1
] == SDL_PRESSED
) Render
->Camera
=Render
->Ship1
;
742 if ( keys
[SDLK_F2
] == SDL_PRESSED
) Render
->Camera
=Render
->Ship2
;
743 if ( keys
[SDLK_F3
] == SDL_PRESSED
) Render
->Camera
=Render
->Ship3
;
745 if ( keys
[SDLK_F7
] == SDL_PRESSED
) Controller
->Grab();
746 if ( keys
[SDLK_F8
] == SDL_PRESSED
) Controller
->UnGrab();
751 if ( keys
[SDLK_LCTRL
])
759 if ( Controller
->mouse_wheel
>0 && zoom_d
< 100) zoom_d
*=1.5;
760 if ( Controller
->mouse_wheel
<0 && zoom_d
> 0.5) zoom_d
/=1.5;
761 if (zoom_d
> 100) zoom_d
=100;
762 if (zoom_d
< 0.5) zoom_d
=0.5;
764 // ********************************************
767 if (joystick
&& SDL_JoystickOpened(0))
769 SDL_JoystickClose(joystick
);