-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.cpp
More file actions
2766 lines (2249 loc) · 72.2 KB
/
Function.cpp
File metadata and controls
2766 lines (2249 loc) · 72.2 KB
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
#include "Function.h"
void Title_Screen()
{
bool Editor = false;
int Button = 0;
SDL_SetAlpha( ScreenEffects, SDL_SRCALPHA, 255 );
while (Game_Mode == START_MENU)
{
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
Button = Button_Command();
if (Button == SPACE)
{
SDL_SetAlpha( ScreenEffects, SDL_SRCALPHA, 0 );
Game_Mode = GAMEPLAY_MODE;
}
}
Apply_Surface( 0, 0, ScreenEffects, Screen, &Screen_Effects_Clips[0] ) ;
SDL_Flip( Screen );
}
}
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized surface
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old surface
SDL_FreeSurface( loadedImage );
//If the surface was optimized
if( optimizedImage != NULL )
{
//Color key surface
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
}
}
//Return the optimized surface
return optimizedImage;
}
void Apply_Surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip )
{
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}
Uint32 Get_Pixel32(int x, int y, SDL_Surface *font)
{
Uint32 *pixels = (Uint32 *)font-> pixels;
return pixels [( y * font->w ) + x ];
}
bool Init()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
Screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( Screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Sup Bitches", NULL );
//If everything initialized fine
return true;
}
bool Load_Files()
{
//Loading the files needed
Character1 = load_image("Character1.png");
if( Character1 == NULL ){return false;}
CryonTanryokuSheet = load_image("CryonTanryokuSheet.png");
if( CryonTanryokuSheet == NULL ){return false;}
ShadowCryonTanryokuSheet = load_image("ShadowCryonTanryokuSheet.png");
if( ShadowCryonTanryokuSheet == NULL ){return false;}
FloorTileSheet = load_image("FloorTileSheet.png");
if( FloorTileSheet == NULL ){return false;}
FloatTileSheet = load_image("FloatTileSheet.png");
if( FloatTileSheet == NULL ){return false;}
TransparentFloatTileSheet = load_image("FloatTileSheet.png");
if( TransparentFloatTileSheet == NULL ){return false;}
ShadowFloatTileSheet = load_image("ShadowFloatTileSheet.png");
if( ShadowFloatTileSheet == NULL ){return false;}
ExitTileSheet = load_image("ExitTileSheet.png");
if( ExitTileSheet == NULL ){return false;}
ScreenEffects = load_image("ScreenEffects.png");
if( ScreenEffects == NULL ){return false;}
OnScreen = load_image("OnScreen.png");
if(OnScreen == NULL ){return false;}
OnScreenBG = load_image("ScreenEffects.png");
if( OnScreenBG == NULL ){return false;}
SkyLine = load_image("ScreenEffects.png");
if( SkyLine == NULL ){return false;}
YstarFont = load_image("YstarFont.png");
if( YstarFont == NULL ){return false;}
EnemySheet = load_image("EnemySheet.png");
if(EnemySheet == NULL ){return false;}
ChromeCrystalMasterGray = load_image("ChromeCrystalMasterGraySheet.png");
if(ChromeCrystalMasterGray == NULL){return false;}
//If everything loaded fine
return true;
}
void Clean_Up( Soul *Spirit[] )
{
//Free the surfaces
SDL_FreeSurface( Screen );
SDL_FreeSurface( ScreenEffects );
SDL_FreeSurface( SkyLine );
SDL_FreeSurface( OnScreen);
SDL_FreeSurface( Character1 );
SDL_FreeSurface( CryonTanryokuSheet );
SDL_FreeSurface( ShadowCryonTanryokuSheet );
SDL_FreeSurface( FloorTileSheet );
SDL_FreeSurface( FloatTileSheet );
SDL_FreeSurface( ShadowFloatTileSheet );
SDL_FreeSurface( ExitTileSheet );
//Free the tiles
//Free the tiles
for( int t = 0; t < MAX_GAME_OBJECTS ; t++ )
{
if (Spirit[t] == NULL)
{
break;
}
delete Spirit[ t ];
}
}
// W = Base character. Y = Cornice characeter. V = E base. S = E cornice SHADOW FUNCTIONS.
bool Shadow_Enable(Square W, Square Y, Square V, Square S )
{
//The sides of the rectangles
int S_left, S_right, S_top, S_bottom;
int V_left, V_right, V_top, V_bottom;
int W_left, W_right, W_top, W_bottom;
int Y_left, Y_right, Y_top, Y_bottom;
//Calculate the sides of rect S
S_left = S.x;
S_right = S.x + S.w;
S_top = S.y;
S_bottom = S.y + S.h;
//Calculate the sides of rect V
V_left = V.x;
V_right = V.x + V.w;
V_top = V.y;
V_bottom = V.y + V.h;
//Calculate the sides of rect W
W_left = W.x;
W_right = W.x + W.w;
W_top = W.y;
W_bottom = W.y + W.h;
//Calculate the sides of rect V
Y_left = Y.x;
Y_right = Y.x + Y.w;
Y_top = Y.y;
Y_bottom = Y.y + Y.h;
if(( W_bottom >= V_top ) &&(W_top < V_bottom ) &&( W_right >= V_left ) && ( W_left <= V_right ) )
{
if (Y_bottom >= S_bottom)
{
return true;
}
}
// May be upgraded later. Collision for circles yo be added later.
return false;
}
int Drop_Shadow_Enable(Square W, Square Y, Square V, Square S )
{
//The sides of the rectangles
int S_left, S_right, S_top, S_bottom, S_height;
int V_left, V_right, V_top, V_bottom;
int W_left, W_right, W_top, W_bottom, W_base_point;
int Y_left, Y_right, Y_top, Y_bottom;
int Tracking = 0;
//Calculate the sides of rect S
S_left = S.x;
S_right = S.x + S.w;
S_top = S.y;
S_bottom = S.y + S.h;
S_height = S.front_cliff;
//Calculate the sides of rect V
V_left = V.x;
V_right = V.x + V.w;
V_top = V.y;
V_bottom = V.y + V.h;
//Calculate the sides of rect W
W_left = W.x;
W_right = W.x + W.w;
W_top = W.y;
W_bottom = W.y + W.h;
W_base_point = W.front_cliff;
//Calculate the sides of rect V
Y_left = Y.x;
Y_right = Y.x + Y.w;
Y_top = Y.y;
Y_bottom = Y.y + Y.h;
//if (returner == 0)
//{
if(( W_bottom >= V_top ) &&(W_top < V_bottom ) &&( W_right >= V_left ) && ( W_left <= V_right ) )
{
Tracking = W_base_point - V_top - W.h/2;
if (Y_top <= S_top + Tracking)
{
return S_top + Tracking ;
}
}
//}
//Shadow at the base. Might be used later for game mechanic Ideas
/*if (returner == 1)
{
if(( W_bottom >= V_top ) &&(W_top < V_bottom ) &&( W_right >= V_left ) && ( W_left <= V_right ) )
{
Tracking = W_base_point - V_top;
if (Y_top <= V_top - Tracking)
{
return V_top + Tracking - S_height - 1 ;
}
}
}*/
// May be upgraded later. Collision for circles yo be added later.
return -1;
}
bool Transparent_Enable(Square W, Square Y, Square V, Square S)
{
//The sides of the rectangles
int W_left, W_right, W_top, W_bottom;
int Y_left, Y_right, Y_top, Y_bottom;
int V_left, V_right, V_top, V_bottom;
int S_left, S_right, S_top, S_bottom;
//Calculate the sides of rect W
W_left = W.x;
W_right = W.x + W.w;
W_top = W.y;
W_bottom = W.y + W.h;
//Calculate the sides of rect V
Y_left = Y.x;
Y_right = Y.x + Y.w;
Y_top = Y.y;
Y_bottom = Y.y + Y.h;
//Calculate the sides of rect V
V_left = V.x;
V_right = V.x + V.w;
V_top = V.y;
V_bottom = V.y + V.h;
//Calculate the sides of rect S
S_left = S.x;
S_right = S.x + S.w;
S_top = S.y;
S_bottom = S.y + S.h;
if (W_bottom < V_top )
{
if ((Y_bottom >= S_top ) && (Y_top <= S_bottom) && (Y_left <= S_right) && (Y_right >= S_left))
{
return true;
}
}
return false;
}
//Before deletion study for future uses//////////////////////////////////////////////////////
/*bool Load_New_Level_Loader_Objects(External_Configuration *object[])
{
// Erase the level's Exit tiles.
for (int tz = 0; tz < MAX_LEVEL_EXIT_OBJECTS; tz++)
{
if (object[tz] == NULL)
{
break;
}
if (object[tz] != NULL)
{
delete object[ tz ];
}
}
std::ifstream Load( "current_location" ); if( Load == NULL ) {Load.close(); return false; }
int x = 0, y = 0, z = 0;
int Total_Exit_Objects;
int Level_Value;
//Name of the level
std::string Level;
std::string READ_FILE;
getline( Load, READ_FILE);
getline( Load, Level );
// Level value is to make the code flexible
Level_Value = Object_Setting_Helper(Level);
std::ifstream Lv1AExits ("Lv1AExits.map" );if( Lv1AExits == NULL ) {Lv1AExits.close(); return false; }
std::ifstream Lv1BExits ("Lv1BExits.map" );if( Lv1AExits == NULL ) {Lv1BExits.close(); return false; }
switch (Level_Value)
{
case LEVEL_1_A: Lv1AExits >> Total_Exit_Objects; break;
case LEVEL_1_B: Lv1BExits >> Total_Exit_Objects; break;
}
//Initialize the tiles
for( int t = 0; t < Total_Exit_Objects; t++ )
{
int TileType = -1;
switch (Level_Value)
{ //MUST BE READ IN THIS ORDER NO EXCEPTIONS!
case LEVEL_1_A: Lv1AExits >> TileType; Lv1AExits >> x; Lv1AExits >> y; Lv1AExits >> z; break;
case LEVEL_1_B: Lv1BExits >> TileType; Lv1BExits >> x; Lv1BExits >> y; Lv1BExits >> z; break;
}
//If the was a problem in reading the map
if( Lv1AExits.fail() == true )
{
//CLOSE ALL FILES
Lv1AExits.close();
Load.close();
Lv1BExits.close();
return false;
}
//If the number is a valid tile number
if( ( TileType >= 0 ) && ( TileType <= MAX_LEVEL_EXIT_OBJECTS ) )
{
//CRITICAL! CRITICAL! CRITICAL!!!!!! MUST BE DEALLOCATED IN CLEANUP
object[ t ] = new External_Configuration( x, y, z, TileType);
}
//If we don't recognize the tile type
else
{
//CLOSE ALL FILES
Load.close();
Lv1AExits.close();
Lv1BExits.close();
return false;
}
}
for( int z = Total_Exit_Objects; z < MAX_LEVEL_EXIT_OBJECTS; z++ )
{
object[ z ] = NULL;
}
Load.close();
Lv1AExits.close();
Lv1BExits.close();
return true;
}*/
/////////////////////////////////////////////////////////////////////////////////////////////
//Generate the level during Start point of the game.
//Uses all the functions to create the world
bool Set_Objects(Soul *Spirit[], External_Configuration &config)
{
///int Start_Num;
int Level_Value;
std::string Level;
//Special spirits not related to the physical world manually made. Used alot and no need of duplication.
//KNOTE!! Everything will be it's owe object until the 2nd game's optimization.
Spirit[ XGHOSTX]= new Character();
Spirit[ XCYRON_TANRYOKUX]= new Cyron_Tanryoku();
Spirit[ XTHE_YS_GUYX]= new The_Ys_Guy();
Spirit[ XCXX120X]= new Cxx120();
Spirit[XRETURN_MENU_BUTTONX]= new On_Screen_Config_Object(450, 20, RETURN_MENU_BUTTON);
Spirit[XSWITCH_MENU_BUTTONX]= new On_Screen_Config_Object(450, 100, SWITCH_MENU_BUTTON);
Spirit[XSWITCH_MENU_BUTTON_EXPAND1X]= new On_Screen_Config_Object(275, 100, SWITCH_MENU_BUTTON_EXPAND1);
Spirit[XSAVE_MENU_BUTTONX]= new On_Screen_Config_Object(450, 180, SAVE_MENU_BUTTON);
Spirit[XCYRON_GAUGEX]= new On_Screen_Object(0, 360, CYRON_GAUGE);
Spirit[XYS_GAUGEX]= new On_Screen_Object(0, 360, YS_GAUGE);
Spirit[XCXX120_GAUGEX]= new On_Screen_Object(0, 360, CXX120_GAUGE);
Spirit[XTARGET_REDICALX ]= new On_Screen_Object(0, 0, TARGET_REDICAL);
Spirit[XHEALTH_BARX ]= new On_Screen_Object(30, 463, HEALTH_BAR);
Spirit[ XBITMAP_TEXT_STARTX] = new Bitmap_Text_Pool_Object(0,0,0, YstarFont);
Spirit[ XBITMAP_TEXT2X] = new Bitmap_Text_Pool_Object(0,0,0, YstarFont);
// Spirit[ XBITMAP_TEXT3X] = new Bitmap_Text_Object(0,0,0, YstarFont);
Spirit[ XBITMAP_TEXT_ENDX] = new Bitmap_Text_Pool_Object(0,0,0, YstarFont);
Spirit[XBLACK_BGX]= new On_Screen_BG_Object(0, 0, BLACK_BG);
Level = config.Get_Level_Name();
Level_Value = Object_Setting_Helper(Level);
if (Pick_Start_Level(Spirit, config, Level_Value) == false)
{
return false;
}
/*
Start_Num = LAST + 1;
//Create the world. The last element of the enum + 1
Start_Num = Set_Floor_Objects(Start_Num, Spirit, config );
if(Start_Num != -1)
{
Start_Num = Set_Floating_Objects( Start_Num, Spirit, config);
if ( Start_Num != -1)
{
Start_Num = Set_Config_Objects( Start_Num, Spirit, config);
if ( Start_Num != -1)
{
}
}
}
//Set the remaining unused object to null.
for (int z = Start_Num; z < MAX_GAME_OBJECTS; z++)
{
Spirit[ z ] = NULL;
}
if(Start_Num == -1)
{
return false;
}*/
return true;
}
bool Pick_Start_Level(Soul *Spirit[], External_Configuration &config, int level)
{
switch (level)
{
case LEVEL_1_A: if (Load_Level_LEVEL_1_A(Spirit, config, 1) == false)
{
return false;
}
break;
case LEVEL_1_B: if (Load_Level_LEVEL_1_B(Spirit, config, 1 ) == false)
{
return false;
} break;
}
for (int tz = 0; tz < MAX_GAME_OBJECTS; tz++)
{
if (Spirit[tz] == NULL)
{
break;
}
if(Spirit[ tz ]->Get_Object_Type() < AI_SMART) // Temporary testing
{
Spirit[ tz ]->Move_Special_Object();
}
}
return true;
}
bool Set_Grounded_Objects( Environment_Objects *object[], External_Configuration config)
{
int x = 0, y = 0, z = 0;
int Total_Ground_Objects;
int Level_Value;
bool Failure = false;
bool True = true;
//Name of the level
std::string Level = config.Get_Level_Name();
// Level value is to make the code flexible
Level_Value = Object_Setting_Helper(Level);
std::ifstream Lv1AGround ("Lv1AGround.map" );if( Lv1AGround == NULL ) {Lv1AGround.close(); return false; }
std::ifstream Lv1BGround ("Lv1BGround.map" );if( Lv1BGround == NULL ) {Lv1BGround.close(); return false; }
switch (Level_Value)
{
// Open one of these file ONLY for reading.
case LEVEL_1_A: Lv1AGround >> Total_Ground_Objects; break;
case LEVEL_1_B: Lv1BGround >> Total_Ground_Objects; break;
}
//Initialize the tiles
for( int t = 0; t < Total_Ground_Objects; t++ )
{
int TileType = -1;
switch (Level_Value)
{ //MUST BE READ IN THIS ORDER NO EXCEPTIONS!
case LEVEL_1_A: Lv1AGround>> TileType; Lv1AGround>> x; Lv1AGround >> y; Lv1AGround>> z;
if( Lv1AGround.fail() == true ) {Failure = true;} break;
case LEVEL_1_B: Lv1BGround>> TileType; Lv1BGround>> x; Lv1BGround >> y; Lv1BGround>> z;
if( Lv1BGround.fail() == true ) {Failure = true;} break;
}
//If the was a problem in reading the map
if( Failure == true )
{
//CLOSE ALL FILES
Lv1AGround.close();
Lv1BGround.close();
return false;
}
//If the number is a valid tile number
if( ( TileType >= 0 ) && ( TileType <= GROUNDED_TILE_SPRITES ) )
{
object[ t ] = new Environment_Objects ( True ,x, y, z, TileType );
}
//If we don't recognize the tile type
else
{
//CLOSE ALL FILES
Lv1AGround.close();
Lv1BGround.close();
return false;
}
}
for( int z = Total_Ground_Objects; z < MAX_GROUND_OBJECTS; z++ )
{
object[ z ] = NULL;
}
Lv1AGround.close();
Lv1BGround.close();
return true;
}
/*bool Set_Enemy_Objects( Enemy_Object *object[], External_Configuration config)
{
int x = 0, y = 0, z = 0;
int Total_Enemy_Objects;
int Level_Value;
bool Failure = false;
//Name of the level
std::string Level = config.Get_Level_Name();
// Level value is to make the code flexible
Level_Value = Object_Setting_Helper(Level);
std::ifstream Lv1AEnemy ("Lv1AEnemy.map" );if( Lv1AEnemy == NULL ) {Lv1AEnemy.close(); return false; }
//std::ifstream Lv1BFloatingXYZ ("Lv1AEnemy.map" );if( Lv1BFloatingXYZ == NULL ) {Lv1BFloatingXYZ.close(); return false; }
switch (Level_Value)
{
// Open one of these file ONLY for reading.
case LEVEL_1_A: Lv1AEnemy >> Total_Enemy_Objects; break;
// case LEVEL_1_B: Lv1BFloatingXYZ >> Total_Enemy_Objects; break;
}
//Initialize the tiles
for( int t = 0; t < Total_Enemy_Objects; t++ )
{
int TileType = -1;
switch (Level_Value)
{ //MUST BE READ IN THIS ORDER NO EXCEPTIONS!
case LEVEL_1_A: Lv1AEnemy >> TileType; Lv1AEnemy >> x; Lv1AEnemy >> y; Lv1AEnemy >> z;
if( Lv1AEnemy.fail() == true ) { Failure = true; }break;
// case LEVEL_1_B: Lv1BFloatingXYZ >> TileType; Lv1BFloatingXYZ >> x; Lv1BFloatingXYZ >> y; Lv1BFloatingXYZ >> z;
// if( Lv1BFloatingXYZ.fail() == true ) { Failure = true; }break;
}
//If the was a problem in reading the map
if( Failure == true )
{
//CLOSE ALL FILES
Lv1AEnemy.close();
//Lv1BFloatingXYZ.close();
return false;
}
//If the number is a valid tile number
if( ( TileType >= 0 ) && ( TileType <= ENEMY_TILE_SPRITES ) )
{
object[ t ] = new Enemy_Object( x, y, z, TileType );
}
//If we don't recognize the tile type
else
{
//CLOSE ALL FILES
Lv1AEnemy.close();
//Lv1BFloatingXYZ.close();
return false;
}
}
for( int z = Total_Enemy_Objects; z <MAX_ENEMY_OBJECTS; z++ )
{
object[ z ] = NULL;
}
Lv1AEnemy.close();
//Lv1BFloatingXYZ.close();
return true;
}
*/
void Set_Bullet_Objects( Bullet_Object *object[])
{
//Initialize the tiles
for( int t = 0; t < MAX_BULLET_OBJECTS; t++ )
{
object[ t ] = new Bullet_Object();
}
}
int Object_Setting_Helper(std::string level_name)
{
if (level_name == "Lv1A") {return LEVEL_1_A;}
if (level_name == "Lv1B") {return LEVEL_1_B;}
return -1;
}
std::string Level_Identitfier(int exit_type)
{
int Exit_Name = exit_type;
//std::string Level_Name;
switch (Exit_Name)
{
case LV1A_1: return "Lv1A"; break;
case LV1A_2: return "Lv1A"; break;
case LV1A_3: return "Lv1A"; break;
case LV1B_1: return "Lv1B"; break;
}
return "Secret_World";
}
int Character_Coords_Matcher(int exit_type, int returner)
{
int Return = returner;
int Exit_Type = exit_type;
// DECIDE RATHER TO RETURN X Y OR Z COORDINATES
// 0 = X, 1 = Y, 2 = Z
// Depending on the the value of the exit type detirmine the coorsponding coords/
if (Return == 0)
{
// USE THE
switch (Exit_Type)
{
case LV1A_1: return X_LV1A_1;
case LV1B_1: return X_LV1B_1;
}
}
if (Return == 1)
{
switch (Exit_Type)
{
case LV1A_1: return Y_LV1A_1;
case LV1B_1: return Y_LV1B_1;
}
}
if (Return == 2)
{
switch (Exit_Type)
{
case LV1A_1: return Z_LV1A_1;
case LV1B_1: return Z_LV1B_1;
}
}
return 0;
}
bool Write_Current_Location(int Exit, std::string level_name, int x, int y, int z)
{
std::ofstream Load( "current_location" );
if( Load == NULL ){ return false;}
Load << "Level_Name \n";
Load << level_name;
Load << "\n \n" ;
Load <<"Exit_Type \n";
Load << Exit;
Load << "\n \n" ;
Load <<"Character_Coord \n";
Load << x;
Load << " ";
Load << y;
Load << " ";
Load << z;
Load << " ";
Load.close();
return true;
}
bool Write_Save_Game_Pad(Soul *Spirit[])
{
//Saving the game is a complex problem. Certain things will be as clear as day but character health and
// Other dispoable stats will be encyrted in binary without mentions what they are. Hacker will hack but
// Average players will not
////////////////////////////////////////////////////////////
//DECLARATIONS
////////////////////////////////////////////////////////////
int x, y, z;
int Health = 0;
std::string READ_FILE;
std::string Level_Name;
std::ofstream Load( "game_save_pad" );
if( Load == NULL ){ return false;}
std::ifstream Read( "current_location ");
if( Read == NULL ){ return false;}
x = Spirit[Selected_Spirit]->Get_X();
y = Spirit[Selected_Spirit]->Get_Y();
z = Spirit[Selected_Spirit]->Get_Z();
//Health = ??????????????
/////////////////////////////////////////
// READ!!!!
////////////////////////////////////////////
getline( Read, READ_FILE);
Read >> Level_Name;
/////////////////////////////////////////
// WRITE!!!!!
////////////////////////////////////////////
Load << "LEVEL_NAME\n";
Load << Level_Name;
Load << "\n \n" ;
Load <<"CHARACTER_COORD\n";
Load << x;
Load << " ";
Load << y;
Load << " ";
Load << z;
Load << " ";
Load << "\n \n" ;
Load <<"CHARACTER_HEALTH\n";
Load << Health;
Load.close();
Read.close();
return true;
}
double Distance( int x1, int y1, int x2, int y2 )
{
int Squared_x = x2 - x1;
int Squared_y = y2 - y1;
double value;
value = sqrt(((double)(x2 - x1)* Squared_x) + ((double)(y2 - y1)* Squared_y));
//Return the distance between the two points
//ORIGINAL // return sqrt(((int)(x2 - x1)* Squared_x) + ((int)(y2 - y1)* Squared_y));
return value;
}
double Direction(int x1, int y1, int x2, int y2)
{
//Unit circle
//Oppositie wall / adjacent floor.
double Value;
int Adj, Opp;
double Hyp;
if (x1 <= x2){ Adj = x2 - x1;}
else{ Adj = x1 - x2;}
if (y1 <= y2){ Opp = y1 - y2;}
else {Opp = y2 - y1;}
Hyp = Opp/Adj;
Value = atan(Hyp);
return Value;
}
// All purpose square on sqyuare collsion detection. Used by the enviroment.
bool Square_Object_Detection(Square V, Square S )
{
//The sides of the rectangles
int S_left, S_right, S_top, S_bottom;
int V_left, V_right, V_top, V_bottom;
//Calculate the sides of rect S
S_left = S.x;
S_right = S.x + S.w;
S_top = S.y;
S_bottom = S.y + S.h;
//Calculate the sides of rect V
V_left = V.x;
V_right = V.x + V.w;
V_top = V.y;
V_bottom = V.y + V.h;
//When the character jumps on top of a block
if(( S_bottom >= V_top ) &&(S_top < V_bottom ) &&( S_right >= V_left ) && ( S_left <= V_right ) )
{
return true;
}
// May be upgraded later. Collision for circles yo be added later.
return false;
}
int Tracking(int returner, Square character_base, Square square_base)
{
enum {RETURN_UPPER, RETURN_BOTTOM};
//The sides of the rectangles
int Square_Base_Left, Square_Base_Right, Square_Base_Top, Square_Base_Bottom, Square_Base_Front_Cliff;
//The Character's based
int Character_Base_Left, Character_Base_Right, Character_Base_Top, Character_Base_Bottom, Character_Base_Point;
int Starting_Point_One, Starting_Point_Two;
// Track the player's movement on an rectangle
int Upper_Track, Bottom_Track;
int Returner;
/************************************************************
// DEFINING OF ALL VARIABLES //
************************************************************/
//Calculate the sides of rect A
Square_Base_Left = square_base.x;
Square_Base_Right = square_base.x + square_base.w;
Square_Base_Top = square_base.y;
Square_Base_Bottom = square_base.y + square_base.h;
Square_Base_Front_Cliff = square_base.front_cliff;
Character_Base_Left = character_base.x;
Character_Base_Right = character_base.x + character_base.w;
Character_Base_Top = character_base.y;
Character_Base_Bottom = character_base.y + character_base.h;
Character_Base_Point = character_base.front_cliff;
Starting_Point_One = Square_Base_Top - CHARACTER_LENGHT;
Starting_Point_Two = Square_Base_Bottom + CHARACTER_LENGHT;
Upper_Track = Character_Base_Point - Starting_Point_One;
Bottom_Track = Starting_Point_Two - Character_Base_Point;