-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameCore.cpp
2849 lines (2193 loc) · 105 KB
/
gameCore.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
** gameCore é utilizada para renderização, pegar todas as informações e **
** gerencialas para que o jogo funcione de forma correta **
** Criado por Lucas P. Stark **
** Nightmare Fiction Engine - NFE **
***************************************************************************/
#include "gameCore.h"
// All global variable here is used to some importants functions on engine
// like which menu we are and bla bla
// It will handle all possibles menus, ie: "inGame, MainMenu, Credits [...]"
int gameState = 0;
/* This is the main menu machine state */
unsigned char mainMenu = 0x0;
/* This is used by Select Character Screen */
unsigned char selectState = 0x0;
unsigned char charSelectNum = 0x0;
unsigned char charMusicNum = 0x0;
float nextCharAngle = 0.0f;
bool nextCharTransition = false;
bool charNextStep = false;
/* This is used by menu's */
unsigned char menuArrow = 0x0;
unsigned char menuUpDown = 0x0;
// In Game
unsigned char inGame = 0x0;
bool inBlood = false;
unsigned char bloodAnimNum = 0;
bool specialEnemy = false;
// System Time, you can do a delay with it
int timer1_start = 0;
int timer2_start = 0;
int delay_sys = 0;
RDT playerRDT;
PLD modelList_2[MAX_MODEL];
EMD modelList[MAX_MODEL];
PLW testGun;
EMD1 testModel;
float bR = 1.0f;
float bG = 1.0f;
float bB = 0.1f;
float bA = 1.0f;
bool colorBlow = false;
unsigned int tmr1000 = 0;
float mobListX[] = {-2500.0f, 5701.0f, -3049.0f, 2373.0f, -2729.0f};
float mobListY[] = {8200.0f, -2860.0f, 4126.0f, 257.0f, -3828.0f};
// engineBackground é utilizado para carregar os backgrounds de cada .RDT
// que o player se encontra.
// engineFont é a fonte utilizad para desenhar textos, como so dedos
// de debug
// engineThisGame é a primeira imagem que aparece quando você abre o jogo
// dizendo que o jogo contem cenas bla bla e o mainMenu é o menu de start
BITMAP engineBackground;
BITMAP engineThisGame;
BITMAP engineMainMenu;
BITMAP engineLogo;
BITMAP engineSelectChar;
BITMAP engineCharMenu;
BITMAP engineResult;
BITMAP engineCredits;
BITMAP engineBlood;
NFP shadow;
NFP tile;
NFP tileBG;
player mainPlayer;
gameMath mathEngine;
gameSound soundEngine;
std::vector<enemy> enemyList;
gameMisc miscStuff;
/* Room transition */
unsigned int roomNum = -1;
/* Debug Menu Features */
bool wireFrameMode = false;
SDL_Surface *bg[0xFF];
unsigned int tmr60FPS = 0;
unsigned int fpsGyver = 0;
unsigned int fpsCnt = 0;
unsigned int tmrAnim = 0;
unsigned int tmrAnim2 = 0;
float bloodX = 0;
float bloodY = 0;
float bloodZ = 0;
bool shootSound = false;
bool hitState = false;
/* Debug Room */
debugRoom debugR[0xFF];
bool jumpToRun = false;
int debug_jRoomNum = 0;
gameCore *core;
gameCore::gameCore(int argc, char** argv) {
/* start glut */
glutInit(&argc, argv);
/* clear timer */
coreTmr_anim = 0;
/* game name */
memset(GAME_NAME, 0x0, 20);
strcpy(GAME_NAME, "Resident Evil : Nightmare Fiction");
/* set all bacgrkoudns to null ptr */
for (int i = 0; i < 0xFF; i++)
bg[i] = NULL;
for (int i = 0; i < 0x10; i++)
keyList[i] = false;
oldAnim = -1;
inInterpolation = false;
}
gameCore::~gameCore() {
for (int i = 0; i < 0xFF; i++)
SDL_FreeSurface(bg[i]);
for (unsigned int i = 0; i < mixList.size(); i++) {
Mix_FreeChunk(mixList[i]);
}
}
/*
* background_Loader
* This function is a crapy .bss loader
* thanks to EPSX Emulator
*/
void background_Loader(std::string roomName) {
// TESTE NOW ROOM109.BSS
SDL_RWops *src;
Uint8 *dstBuffer;
int dstBufLen;
src = SDL_RWFromFile(roomName.c_str(), "rb");
if (!src) {
fprintf(stderr, "Can not open %s for reading\n", roomName.c_str());
exit (0);
}
int i = 0;
int length = SDL_RWseek(src, 0, RW_SEEK_END);
SDL_RWseek(src, 0, RW_SEEK_SET);
while (SDL_RWseek(src, 0, RW_SEEK_CUR) < length) {
vlc_depack(src, &dstBuffer, &dstBufLen);
int pos = SDL_RWseek(src, 0, RW_SEEK_CUR);
if ((pos & 0x7fff) != 0) SDL_RWseek(src, (pos & ~0x7fff) + 0x8000, RW_SEEK_SET);
if (dstBuffer && dstBufLen) {
SDL_RWops *mdec_src;
mdec_src = SDL_RWFromMem(dstBuffer, dstBufLen);
if (mdec_src) {
Uint8 *dstMdecBuf;
int dstMdecLen;
mdec_depack(mdec_src, &dstMdecBuf, &dstMdecLen, 320,240);
SDL_RWclose(mdec_src);
if (dstMdecBuf && dstMdecLen) {
SDL_Surface *image = mdec_surface(dstMdecBuf,320,240,0);
if (image) {
if (bg[i] != NULL)
SDL_FreeSurface(bg[i]);
bg[i] = image;
i++;
}
free(dstMdecBuf);
}
}
free(dstBuffer);
}
}
}
/*
* renderLoadResource
* This function is the hardcoded game initialization
*/
void gameCore::renderLoadResource() {
enemy gameEnemy;
Mix_Chunk *node = NULL;
// Clear Timer
timer1_start = 0;
// The game should start on Main Menu
gameState = STATE_MAIN_MENU;
mainMenu = MAIN_MENU_ENGINE_LOGO;
// RDT do Início do Player
playerRDT.rdtRE1LoadFile("resource/stages/re1/ROOM1060.RDT");
/*
* Player Selection Sound
*/
if (soundEngine.engineSoundInit()) {
soundEngine.engineLoadSound("resource/ost/7.mp3");
}
// Alguns gráficos que são carregados na memória
modelList[0].emdLoadFile("resource/models/Leon_sel_1.EMD");
/* Leon S. Kennedy RE2 */
modelList[1].emdLoadFile("resource/models/EM050.EMD");
/* Chris Redfield RE2 */
modelList[2].emdLoadFile("resource/models/2.EMD");
modelList[3].emdLoadFile("resource/models/PL0BCH.EMD");
modelList[4].emdLoadFile("resource/models/EM01E.EMD");
modelList[5].emdLoadFile("resource/models/EM030.EMD");
modelList[6].emdLoadFile("resource/models/EM005.EMD");
modelList[7].emdLoadFile("resource/models/EM010.EMD");
modelList[8].emdLoadFile("resource/models/EM031.EMD");
modelList[8].emdTotalObj = 18;
testModel.loadFile("resource/models/EM1110.EMD");
testGun.readFile("resource/models/PL00W05.PLW");
/*
* Load all sound effects
*/
// Som do click
node = Mix_LoadWAV("resource/sfx/click.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/title3.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/next.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/gun_1.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/hit.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/zw_1.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/zp_2.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/step.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/step2.wav");
mixList.push_back(node);
node = Mix_LoadWAV("resource/sfx/g.wav");
mixList.push_back(node);
// Algumas imagens carregadas na memória
engineThisGame.loaderFile ("resource/menus/intro_2.bmp",0);
engineLogo.loaderFile ("resource/menus/intro_1.bmp",0);
engineMainMenu.loaderFile ("resource/menus/mainMenu.bmp",0);
engineSelectChar.loaderFile("resource/menus/selectChar.bmp", 0);
engineCharMenu.loaderFile ("resource/menus/charMenu.bmp", 1);
engineResult.loaderFile ("resource/menus/RESULT.BMP", 0);
engineBlood.loaderFile ("resource/texture/blood_1.bmp", 1);
engineCredits.loaderFile ("resource/texture/bg.bmp", 0);
shadow.loadImage ("resource/texture/1.png");
tile.loadImage ("resource/texture/dojo_tile.png");
tileBG.loadImage ("resource/texture/ray.png");
// Carrega o background com número 5
background_Loader("resource/stages/re1/ROOM106.BSS");
// HardCode, modelo inicial, X,Y,Z e Número da câmera
mainPlayer.setModel(0);
mainPlayer.setX(0.0f);
mainPlayer.setY(0.0f);
mainPlayer.setZ(0.0f);
mainPlayer.setHitPoints(5);
mainPlayer.setCam(CAMERA_STYLE_SEL_CHAR);
mainPlayer.setAngle(90.0);
srand(time(NULL));
for (int i = 0; i < VR_ENEMY_NUM; i++) {
gameEnemy.setX(mobListX[i]);
gameEnemy.setZ(mobListY[i]);
gameEnemy.setY(0);
int x = rand() % 3;
switch (x) {
case 0:
gameEnemy.setModel(4);
break;
case 1:
gameEnemy.setModel(7);
break;
case 2:
gameEnemy.setModel(6);
break;
case 3:
printf("k\n");
break;
}
gameEnemy.setAngle(0);
gameEnemy.setState(AI_STATE_BEGIN);
gameEnemy.setType(AI_TYPE_ZOMBIE_RE2);
gameEnemy.setAnimSection(EMD_SECTION_4);
gameEnemy.setAnimType(ZOMBIE_SEC4_ANIM_IDLE);
gameEnemy.setHitPoints(3);
enemyList.push_back(gameEnemy);
}
gameEnemy.setX(-2000.0f);
gameEnemy.setZ(-5000.0f);
gameEnemy.setModel(8);
gameEnemy.setAngle(0);
gameEnemy.setState(AI_STATE_BEGIN);
gameEnemy.setAnimSection(EMD_SECTION_2);
gameEnemy.setAnimType(G_VIRUS_SEC2_FORM_2_PRESENT, false);
gameEnemy.setHitPoints(20);
enemyList.push_back(gameEnemy);
/* Hardcoded Debug Room X,Y,Z,RoomNum and RoomName !*/
debugR[0].roomName = "Main Hall";
debugR[0].roomNum = 6;
debugR[0].x = 17060.0f;
debugR[0].y = 0.0f;
debugR[0].z = 11933.0f;
debugR[1].roomName = "Testee ha!";
debugR[1].roomNum = 5;
debugR[1].x = 30900.0f;
debugR[1].y = 0.0f;
debugR[1].z = 8300.0f;
miscStuff.setupFadeEffect(TYPE_FADE_IN, 0, 0, 0, 60);
}
/* All stuff related with debug menu goes here */
void gameCore::eventSystem_debugMenu() {
/*
char jump_to[20];
miscStuff.renderText(0.42, 0.30, 0.0f, TEXT_TYPE_LITTLE, "--Debug Menu--");
sprintf(jump_to, "Jump %03x %s",debugR[debug_jRoomNum].roomNum, debugR[debug_jRoomNum].roomName.c_str());
miscStuff.renderText(0.35, 0.35, 0.0f, TEXT_TYPE_LITTLE, jump_to);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
glBegin(GL_QUADS);
glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
glVertex3f(-0.64f, 0.25f, -1.0f);
glVertex3f( 0.64f, 0.25f, -1.0f);
glVertex3f( 0.64f,-0.25f, -1.0f);
glVertex3f(-0.64f,-0.25f, -1.0f);
glEnd();
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
*/
}
void renderFloor(){
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
glLoadIdentity();
core->camMode.camList(mainPlayer.getCam(), mainPlayer.getX(), mainPlayer.getY(),
mainPlayer.getZ(), mainPlayer.getAngle());
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tile.getWidth(), tile.getHeight(), 0,GL_RGBA, GL_UNSIGNED_BYTE, tile.getPixelData());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
float x=0.0f,y=0.0f,z=0.0f;
glBegin(GL_QUADS);
glColor4f(bR, bG, bB, 1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f((x - 200000.0f), 70.0f, (z - 200000.0f));
glTexCoord2f(200.0f,0.0f);
glVertex3f((x + 200000.0f), 70.0f, (z - 200000.0f));
glTexCoord2f(200.0f,200.0f);
glVertex3f((x + 200000.0f), 70.0f, (z + 200000.0f));
glTexCoord2f(0.0f,200.0f);
glVertex3f((x - 200000.0f), 70.0f, (z + 200000.0f));
/*glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(20000.0f, (y - 20000.0f), (z - 20000.0f));
glTexCoord2f(10.0f,0.0f);
glVertex3f(20000.0f, y, (z - 20000.0f));
glTexCoord2f(10.0f,20.0f);
glVertex3f(20000.0f, y, (z + 20000.0f));
glTexCoord2f(0.0f,20.0f);
glVertex3f(20000.0f, (y - 20000.0f), (z + 20000.0f));
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-20000.0f, (y - 20000.0f), (z - 20000.0f));
glTexCoord2f(10.0f,0.0f);
glVertex3f(-20000.0f, y, (z - 20000.0f));
glTexCoord2f(10.0f,20.0f);
glVertex3f(-20000.0f, y, (z + 20000.0f));
glTexCoord2f(0.0f,20.0f);
glVertex3f(-20000.0f, (y - 20000.0f), (z + 20000.0f));
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f((x - 20000.0f), (y - 20000.0f), 20000.0f);
glTexCoord2f(10.0f,0.0f);
glVertex3f((x - 20000.0f), y, 20000.0f);
glTexCoord2f(10.0f,20.0f);
glVertex3f((x + 20000.0f), y, 20000.0f);
glTexCoord2f(0.0f,20.0f);
glVertex3f((x + 20000.0f), (y - 20000.0f), 20000.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f((x - 20000.0f), (y - 20000.0f), -20000.0f);
glTexCoord2f(10.0f,0.0f);
glVertex3f((x - 20000.0f), y, -20000.0f);
glTexCoord2f(10.0f,20.0f);
glVertex3f((x + 20000.0f), y, -20000.0f);
glTexCoord2f(0.0f,20.0f);
glVertex3f((x + 20000.0f), (y - 20000.0f), -20000.0f);*/
glEnd();
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);
}
void eventSystem_debugJumpToRun() {
/* Fade black effect
if (inFadeBlack) {
if (fadeBlackNormal) {
if (timer1_start < glutGet(GLUT_ELAPSED_TIME)) {
if (fadeBlackEffect <= 1.0) {
fadeBlackEffect += 0.1;
} else {
fadeBlackNormal = false;
fadeBlackReverse = true;
sprintf(rdt, "resource/stages/re1/ROOM%X%02X0.RDT", (STAGE(debugR[debug_jRoomNum].roomNum) > 0 ? STAGE(debugR[debug_jRoomNum].roomNum) : 1),
ROOM(debugR[debug_jRoomNum].roomNum));
sprintf(bss, "resource/stages/re1/ROOM%X%02X.BSS", (STAGE(debugR[debug_jRoomNum].roomNum) > 0 ? STAGE(debugR[debug_jRoomNum].roomNum) : 1),
ROOM(debugR[debug_jRoomNum].roomNum));
std::cout << bss << std::endl;
std::cout << rdt << std::endl;
Load BSS and RDT
background_Loader(bss);
Set Player new X,Y,Z
mainPlayer.setX(debugR[debug_jRoomNum].x);
mainPlayer.setY(debugR[debug_jRoomNum].y);
mainPlayer.setZ(debugR[debug_jRoomNum].z);
playerRDT.rdtRE1LoadFile(rdt);
mainPlayer.setCam(playerRDT.rdtRE1CameraSwitch[0].from);
}
timer1_start = (glutGet(GLUT_ELAPSED_TIME) + 50);
}
} else {
if (timer1_start < glutGet(GLUT_ELAPSED_TIME)) {
if (fadeBlackEffect > 0.0) {
fadeBlackEffect -= 0.1;
} else {
fadeBlackEffect = 0.0;
fadeBlackReverse = false;
fadeBlackNormal = false;
inFadeBlack = false;
jumpToRun = false;
gameState = STATE_IN_GAME;
}
timer1_start = (glutGet(GLUT_ELAPSED_TIME) + 50);
}
}
}
*/
}
/* Here all stuff related with new room/stage goes here */
void eventSystem_newRoom() {
/* Fade black effect
if (inFadeBlack) {
if (fadeBlackNormal) {
if (timer1_start < glutGet(GLUT_ELAPSED_TIME)) {
if (fadeBlackEffect <= 1.0) {
fadeBlackEffect += 0.1;
} else {
fadeBlackNormal = false;
fadeBlackReverse = true;
printf("valor que eu quero: %d\n", playerRDT.door_set_re1[roomNum].next_stage_and_room);
sprintf(rdt, "resource/stages/re1/ROOM%X%02X0.RDT", (STAGE(playerRDT.door_set_re1[roomNum].next_stage_and_room) > 0 ? STAGE(playerRDT.door_set_re1[roomNum].next_stage_and_room) : 1),
ROOM(playerRDT.door_set_re1[roomNum].next_stage_and_room));
sprintf(bss, "resource/stages/re1/ROOM%X%02X.BSS", (STAGE(playerRDT.door_set_re1[roomNum].next_stage_and_room) > 0 ? STAGE(playerRDT.door_set_re1[roomNum].next_stage_and_room) : 1),
ROOM(playerRDT.door_set_re1[roomNum].next_stage_and_room));
std::cout << bss << std::endl;
std::cout << rdt << std::endl;
Load BSS and RDT
background_Loader(bss);
Set Player new X,Y,Z
mainPlayer.setX(playerRDT.door_set_re1[roomNum].next_x);
mainPlayer.setY(playerRDT.door_set_re1[roomNum].next_y);
mainPlayer.setZ(playerRDT.door_set_re1[roomNum].next_z);
playerRDT.rdtRE1LoadFile(rdt);
mainPlayer.setCam(playerRDT.rdtRE1CameraSwitch[0].from);
}
timer1_start = (glutGet(GLUT_ELAPSED_TIME) + 50);
}
} else {
if (timer1_start < glutGet(GLUT_ELAPSED_TIME)) {
if (fadeBlackEffect > 0.0) {
fadeBlackEffect -= 0.1;
} else {
fadeBlackEffect = 0.0;
fadeBlackReverse = false;
fadeBlackNormal = false;
inFadeBlack = false;
gameState = STATE_IN_GAME;
}
timer1_start = (glutGet(GLUT_ELAPSED_TIME) + 50);
}
}
}
*/
}
void gameCore::eventSystem_downKey(int key, int x, int y) {
switch (gameState) {
case STATE_MAIN_MENU:
if (mainMenu == MAIN_MENU_START) {
switch (key) {
case GLUT_KEY_UP:
soundEngine.enginePlaySoundEffect(mixList[0]);
if (menuArrow > 0)
menuArrow--;
break;
case GLUT_KEY_DOWN:
soundEngine.enginePlaySoundEffect(mixList[0]);
if (menuArrow < 2)
menuArrow++;
break;
default:
break;
}
}
break;
/*
* Character Selection Menu
*/
case STATE_SEL_CHAR: {
case GLUT_KEY_LEFT:
if (!charNextStep) {
if (!nextCharTransition) {
soundEngine.enginePlaySoundEffect(mixList[2]);
menuArrow ^= 1;
nextCharTransition = true;
}
}
break;
case GLUT_KEY_RIGHT:
if (!charNextStep) {
if (!nextCharTransition) {
soundEngine.enginePlaySoundEffect(mixList[2]);
menuArrow ^= 1;
nextCharTransition = true;
}
}
break;
}
break;
case STATE_IN_DEBUG:
switch (key) {
case GLUT_KEY_LEFT:
if (debug_jRoomNum > 0)
debug_jRoomNum--;
break;
case GLUT_KEY_RIGHT:
if (debug_jRoomNum < 2)
debug_jRoomNum++;
break;
default:
break;
}
break;
case STATE_IN_GAME:
switch (key) {
case GLUT_KEY_UP:
eventSystem_gameAction(EVENT_SYSTEM_KEY_UP, true);
break;
case GLUT_KEY_DOWN:
eventSystem_gameAction(EVENT_SYSTEM_KEY_DOWN, true);
break;
case GLUT_KEY_LEFT:
eventSystem_gameAction(EVENT_SYSTEM_KEY_LEFT, true);
break;
case GLUT_KEY_RIGHT:
eventSystem_gameAction(EVENT_SYSTEM_KEY_RIGHT, true);
break;
}
break;
default:
break;
}
}
void gameCore::eventSystem_upKey(int key, int x, int y) {
switch (gameState) {
case STATE_MAIN_MENU:
break;
case STATE_IN_GAME:
switch (key) {
case GLUT_KEY_UP:
eventSystem_gameAction(EVENT_SYSTEM_KEY_UP, false);
break;
case GLUT_KEY_DOWN:
eventSystem_gameAction(EVENT_SYSTEM_KEY_DOWN, false);
break;
case GLUT_KEY_LEFT:
eventSystem_gameAction(EVENT_SYSTEM_KEY_LEFT, false);
break;
case GLUT_KEY_RIGHT:
eventSystem_gameAction(EVENT_SYSTEM_KEY_RIGHT, false);
break;
}
break;
default:
break;
}
}
void gameCore::eventSystem_keyboardDown(unsigned char key, int x, int y) {
switch (gameState) {
/*
* This is MainMenu State
*/
case STATE_MAIN_MENU: {
if (mainMenu == MAIN_MENU_START) {
if (key == 'x') {
if (menuArrow == 0) {
soundEngine.enginePlaySoundEffect(mixList[1]);
mainMenu = MAIN_MENU_GAME;
miscStuff.setupFadeEffect(TYPE_FADE_SPECIAL, 0, 0, 0, 70);
glutIgnoreKeyRepeat(1);
} else if (menuArrow == 1) {
soundEngine.enginePlaySoundEffect(mixList[1]);
soundEngine.engineLoadSound("resource/ost/11.mp3");
mainMenu = MAIN_MENU_GAME;
miscStuff.setupFadeEffect(TYPE_FADE_SPECIAL, 0, 0, 0, 70);
glutIgnoreKeyRepeat(1);
} else if (menuArrow == 2) {
exit(0);
}
}
}
}
break;
case STATE_SEL_CHAR:
if (key == 0x9) {
charMusicNum > 2 ? charMusicNum = 0 : charMusicNum++;
}
if (key == 'x') {
if (!charNextStep) {
miscStuff.setupFadeEffect(TYPE_FADE_SPECIAL, 0, 0, 0, 70);
mainPlayer.setAnimSection(EMD_SECTION_2);
mainPlayer.setAnimType(SPECIAL_SEC2_ANIM_CHOICE, false);
selectState = SEL_PLAYER_START;
charNextStep = true;
}
}
break;
case STATE_IN_DEBUG:
switch (key) {
case 'z':
gameState = STATE_IN_GAME;
break;
case 'x':
jumpToRun = true;
break;
default:
break;
}
break;
case STATE_IN_GAME:
switch (key) {
case 'x':
eventSystem_gameAction(EVENT_SYSTEM_KEY_X, true);
break;
case 'z':
eventSystem_gameAction(EVENT_SYSTEM_KEY_Z, true);
break;
case 'c':
eventSystem_gameAction(EVENT_SYSTEM_KEY_C, true);
break;
case 'a':
break;
default:
break;
}
break;
default:
break;
}
}
void gameCore::eventSystem_keyboardUp(unsigned char key, int x, int y) {
switch (gameState) {
case STATE_IN_GAME:
switch (key) {
case 'x':
eventSystem_gameAction(EVENT_SYSTEM_KEY_X, false);
break;
case 'z':
eventSystem_gameAction(EVENT_SYSTEM_KEY_Z, false);
break;
case 'c':
eventSystem_gameAction(EVENT_SYSTEM_KEY_C, false);
break;
case 'a':
break;
default:
break;
}
break;
}
}
/*
* engineAnimation
* Here all game animation is handled
*/
void gameCore::engineAnimation(entity *e) {
/*
* Verify if is the same animation, if not, should interpolate the animation
*/
if ((inInterpolation == 0) && ((oldAnim != e->getAnimType())
|| (oldSection != e->getAnimSection()))) {
if ((oldSection == EMD_SECTION_4) && (oldAnim == STAND_SEC4_ANIM_IDLE)) {
if ((e->getAnimType() == STAND_SEC2_ANIM_BACKWARD) && (e->getAnimSection() == EMD_SECTION_2)) {
// inInterpolation = 1;
}
}
}
switch (inInterpolation) {
/*
* play normal animations
*/
case 0: {
switch (e->getAnimSection()) {
case EMD_SECTION_2: {
if (e->getAnimCount() < (modelList[e->getModel()].emdSec2AnimInfo[e->getAnimType()].animCount-1))
e->setAnimCount(e->getAnimCount() + 1);
else {
if (e->getAnimRepeat()) {
e->setAnimCount(0);
}
}
e->setAnimFrame(modelList[e->getModel()].emdSec2Data[e->getAnimCount()+modelList[e->getModel()].emdSec2AnimInfo[e->getAnimType()].animStart]);
}
break;
case EMD_SECTION_4: {
if (e->getAnimCount() < (modelList[e->getModel()].emdSec4AnimInfo[e->getAnimType()].animCount-1))
e->setAnimCount(e->getAnimCount() + 1);
else {
if (e->getAnimRepeat()) {
switch (e->getAnimType()) {
case STAND_SEC4_ANIM_S_SHOOT:
e->setAnimType(STAND_SEC4_ANIM_AIM);
break;
}
e->setAnimCount(0);
}
}
e->setAnimFrame(modelList[e->getModel()].emdSec4Data[e->getAnimCount()+modelList[e->getModel()].emdSec4AnimInfo[e->getAnimType()].animStart]);
}
break;
}
}
break;
/*
* does the interpolation
*/
case 1: {
interAnimation.clear();
switch (oldSection) {
case EMD_SECTION_2: {
EMD_SEC2_DATA_T node; // new animation (interpolated)
EMD_SEC2_DATA_T *node_2; // old animation
EMD_SEC2_DATA_T *node_3; // new animation
unsigned int i_2 = 0;
float p_factor = (1.0f / ((modelList[e->getModel()].emdSec2AnimInfo[oldAnim].animCount-1) - e->getAnimCount()));
float p = 0.0f;
for (unsigned int i = e->getAnimCount(); i < (modelList[e->getModel()].emdSec2AnimInfo[oldAnim].animCount-1); i++, p += p_factor) {
node_2 = &modelList[e->getModel()].emdSec2Data[i+modelList[e->getModel()].emdSec2AnimInfo[oldAnim].animStart];
switch (e->getAnimSection()) {
case EMD_SECTION_2:
node_3 = &modelList[e->getModel()].emdSec2Data[i_2+modelList[e->getModel()].emdSec2AnimInfo[e->getAnimType()].animStart];
for (unsigned int t = 0; t < modelList[e->getModel()].emdTotalObj; t++) {
node.vector[t].x = mathEngine.interpolation(node_2->vector[t].x, node_3->vector[t].x, p);
node.vector[t].y = mathEngine.interpolation(node_2->vector[t].y, node_3->vector[t].y, p);
node.vector[t].z = mathEngine.interpolation(node_2->vector[t].z, node_3->vector[t].z, p);
}
if (i_2 < (modelList[e->getModel()].emdSec2AnimInfo[e->getAnimType()].animCount-1))
i_2++;
else
i_2 = 0;
interAnimation.push_back(node);
break;
case EMD_SECTION_4:
node_3 = &modelList[e->getModel()].emdSec4Data[i_2+modelList[e->getModel()].emdSec4AnimInfo[e->getAnimType()].animStart];
for (unsigned int t = 0; t < modelList[e->getModel()].emdTotalObj; t++) {
node.vector[t].x = mathEngine.interpolation(node_2->vector[t].x, node_3->vector[t].x, p);
node.vector[t].y = mathEngine.interpolation(node_2->vector[t].y, node_3->vector[t].y, p);
node.vector[t].z = mathEngine.interpolation(node_2->vector[t].z, node_3->vector[t].z, p);
}
if (i_2 < (modelList[e->getModel()].emdSec4AnimInfo[e->getAnimType()].animCount-1))
i_2++;
else
i_2 = 0;
interAnimation.push_back(node);
break;
}
}
e->setAnimCount(0);
inInterpolation = 2;
}
break;
case EMD_SECTION_4: {
EMD_SEC2_DATA_T node; // new animation (interpolated)
EMD_SEC2_DATA_T *node_2; // old animation
EMD_SEC2_DATA_T *node_3; // new animation
unsigned int i_2 = 0;
float p_factor = (1.0f / 3.0f);
float p = 0.0f;
for (unsigned int i = 0; i < 3; i++, p += p_factor) {
node_2 = &modelList[e->getModel()].emdSec4Data[i+modelList[e->getModel()].emdSec4AnimInfo[oldAnim].animStart];
switch (e->getAnimSection()) {
case EMD_SECTION_2:
node_3 = &modelList[e->getModel()].emdSec2Data[i_2+modelList[e->getModel()].emdSec2AnimInfo[e->getAnimType()].animStart];
// here
for (unsigned int t = 0; t < modelList[e->getModel()].emdTotalObj; t++) {
node.vector[t].x = mathEngine.interpolation(node_2->vector[t].x, node_3->vector[t].x, p);
printf("node.x: %.2f node_2.x %.2f node_3.x %.2f p: %.2f\n", node.vector[t].x, node_2->vector[t].x, node_3->vector[t].x, p);
node.vector[t].y = mathEngine.interpolation(node_2->vector[t].y, node_3->vector[t].y, p);
printf("node.y: %.2f node_2.y %.2f node_3.y %.2f p: %.2f\n", node.vector[t].y, node_2->vector[t].y, node_3->vector[t].y, p);
node.vector[t].z = mathEngine.interpolation(node_2->vector[t].z, node_3->vector[t].z, p);
printf("node.z: %.2f node_2.z %.2f node_3.z %.2f p: %.2f\n", node.vector[t].z, node_2->vector[t].z, node_3->vector[t].z, p);
}
if (i_2 < (modelList[e->getModel()].emdSec2AnimInfo[e->getAnimType()].animCount-1))
i_2++;