-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
1092 lines (925 loc) · 40.1 KB
/
main.cpp
File metadata and controls
1092 lines (925 loc) · 40.1 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
//
// main.cpp
// FFFF
//
// Created by Casey Hanley on 3/27/14.
// Copyright (c) 2014 Casey Hanley. All rights reserved.
//
#include <iostream>
#include <SDL2/SDL.h>
#include "SDL2_image/SDL_image.h"
#include "SDL2_ttf/SDL_ttf.h"
#include "SDL2_mixer/SDL_mixer.h"
#include <stdio.h>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include "Dot.h"
#include "LTexture.h"
#include "CharacterView.h"
#include "Settings.h"
#include "TextView.h"
using namespace std;
//The dimensions of the level (if you change this, change it in Dot.cpp, too)
const int LEVEL_WIDTH[8] = {1200,1312,1312,1792,1344,1312,1312,1312};
const int LEVEL_HEIGHT[8] = {656,880,2400,704,1248,2400,2400,2400};
//Screen dimension constants (if you change this, change it in Dot.cpp, too)
const int SCREEN_WIDTH = 1200;
const int SCREEN_HEIGHT = 650;
//------------------------------------------------------------------------------
// INITIALIZE VARIABLES/FUNCTIONS
//------------------------------------------------------------------------------
//Key press surfaces constants
enum KeyPressSurfaces{
KEY_PRESS_SURFACE_DEFAULT,
KEY_PRESS_SURFACE_UP,
KEY_PRESS_SURFACE_DOWN,
KEY_PRESS_SURFACE_LEFT,
KEY_PRESS_SURFACE_RIGHT,
KEY_PRESS_SURFACE_TOTAL
};
enum WindowLayouts{
BATTLE_LAYOUT,
OPEN_LAYOUT
};
enum MainCharacters{
ALBUS,
ELSA,
JACK,
KAT
};
enum Direction{
UP,
DOWN,
LEFT,
RIGHT
};
//Starts up SDL and creates window
bool init();
//Loads media
bool loadMedia();
//Frees media and shuts down SDL
void close();
//The window we'll be rendering to
SDL_Window * gWindow = NULL;
//The window renderer
SDL_Renderer * gRenderer = NULL;
//Globally used font
TTF_Font * gFont = NULL;
//Text texture
LTexture textAndaleTexture;
//Battle Images
LTexture elsaBattleTexture;
LTexture katBattleTexture;
LTexture jackBattleTexture;
LTexture albusBattleTexture;
//Dialogue Images
LTexture elsaDialogueTexture;
LTexture katDialogueTexture;
LTexture jackDialogueTexture;
LTexture albusDialogueTexture;
//Sprites
LTexture elsaSpriteSide;
LTexture katSpriteSide;
LTexture jackSpriteSide;
LTexture albusSpriteSide;
LTexture elsaSpriteFront;
LTexture katSpriteFront;
LTexture jackSpriteFront;
LTexture albusSpriteFront;
LTexture elsaSpriteBack;
LTexture katSpriteBack;
LTexture jackSpriteBack;
LTexture albusSpriteBack;
//Background Images
LTexture ArendelleTexture;
LTexture NorthMountBGTexture;
LTexture CaveBGTexture;
LTexture IslandBGTexture;
LTexture ForestBGTexture;
LTexture BViewTexture; //bottom viewport boxes
//Map Textures
LTexture mapTexture[8];
//The music that will be played
Mix_Music *elsaMusic = NULL;
Mix_Music *albusMusic = NULL;
Mix_Music *katMusic = NULL;
Mix_Music *jackMusic = NULL;
Mix_Music *cityMusic = NULL;
Mix_Music *mustafarMusic = NULL;
//The sound effects that will be used
Mix_Chunk *soundEffect1 = NULL;
Mix_Chunk *albusSoundEffect = NULL;
Mix_Chunk *elsaSoundEffect = NULL;
Mix_Chunk *jackSoundEffect = NULL;
Mix_Chunk *katSoundEffect = NULL;
//------------------------------------------------------------------------------
// RUN INITIALIZATION FUNCTION
//------------------------------------------------------------------------------
bool init(){
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create window
gWindow = SDL_CreateWindow( "Final Fantasy", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
success = false;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
//Initialize SDL_mixer
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
}
}
}
return success;
}
//------------------------------------------------------------------------------
// LOAD ALL IMAGES/SPRITES/MUSIC FILES
//------------------------------------------------------------------------------
bool loadMedia(){
//Loading success flag
bool success = true;
//Load Sprite Side Views
if( !katSpriteSide.loadFromFile( pathForFile("Images/katSpriteSide.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !albusSpriteSide.loadFromFile( pathForFile("Images/albusSpriteSide.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !elsaSpriteSide.loadFromFile( pathForFile("Images/elsaSpriteSide.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !jackSpriteSide.loadFromFile( pathForFile("Images/jackSpriteSide.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
//load Sprite Front Views
if( !katSpriteFront.loadFromFile( pathForFile("Images/katSpriteFront.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !albusSpriteFront.loadFromFile( pathForFile("Images/albusSpriteFront.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !elsaSpriteFront.loadFromFile( pathForFile("Images/elsaSpriteFront.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !jackSpriteFront.loadFromFile( pathForFile("Images/jackSpriteFront.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
//load sprite Back Views
if( !katSpriteBack.loadFromFile( pathForFile("Images/katSpriteBack.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !albusSpriteBack.loadFromFile( pathForFile("Images/albusSpriteBack.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !elsaSpriteBack.loadFromFile( pathForFile("Images/elsaSpriteBack.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
if( !jackSpriteBack.loadFromFile( pathForFile("Images/jackSpriteBack.png"), gRenderer ) )
{
printf( "Failed to load kat's sprite texture image!\n" );
success = false;
}
//Load background textures
if( !ArendelleTexture.loadFromFile( pathForFile("Images/arendelle.jpg"), gRenderer ) )
{
printf( "Failed to load north mountain background texture image!\n" );
success = false;
}
if( !NorthMountBGTexture.loadFromFile( pathForFile("Images/battleNorthMountain.jpg"), gRenderer ) )
{
printf( "Failed to load north mountain background texture image!\n" );
success = false;
}
//Load Maps
if( !mapTexture[0].loadFromFile( pathForFile("Images/map0.png"), gRenderer ) )
{
printf( "Failed to load map0 background texture image!\n" );
success = false;
}
if( !mapTexture[1].loadFromFile( pathForFile("Images/map1.png"), gRenderer ) )
{
printf( "Failed to load map1 background texture image!\n" );
success = false;
}
if( !mapTexture[2].loadFromFile( pathForFile("Images/map2.png"), gRenderer ) )
{
printf( "Failed to load map2 background texture image!\n" );
success = false;
}
if( !mapTexture[3].loadFromFile( pathForFile("Images/map3.png"), gRenderer ) )
{
printf( "Failed to load map3 background texture image!\n" );
success = false;
}
if( !mapTexture[4].loadFromFile( pathForFile("Images/map4.png"), gRenderer ) )
{
printf( "Failed to load map4 background texture image!\n" );
success = false;
}
// if( !mapTexture[5].loadFromFile( pathForFile("Images/map5.png"), gRenderer ) )
// {
// printf( "Failed to load map5 background texture image!\n" );
// success = false;
// }
// if( !mapTexture[6].loadFromFile( pathForFile("Images/map6.png"), gRenderer ) )
// {
// printf( "Failed to load map6 background texture image!\n" );
// success = false;
// }
// if( !mapTexture[7].loadFromFile( pathForFile("Images/map7.png"), gRenderer ) )
// {
// printf( "Failed to load map7 background texture image!\n" );
// success = false;
// }
//Load bottom viewport texture
if( !BViewTexture.loadFromFile( pathForFile("Images/BattleStats.jpg"), gRenderer ) )
{
printf( "Failed to load bottom viewport texture image!\n" );
success = false;
}
//Load music
elsaMusic = Mix_LoadMUS( "LetItGo.wav" );
if( elsaMusic == NULL )
{
printf( "Failed to load Elsa music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
jackMusic = Mix_LoadMUS( "hesAPirate.wav" );
if( jackMusic == NULL )
{
printf( "Failed to load Jack Music SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
katMusic = Mix_LoadMUS( "ArrowsAtTheSky.wav" );
if( katMusic == NULL )
{
printf( "Failed to load Kat music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
albusMusic = Mix_LoadMUS( "hedwigsTheme.wav" );
if( katMusic == NULL )
{
printf( "Failed to load Albus music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
cityMusic = Mix_LoadMUS( "GoT.wav" );
if( cityMusic == NULL )
{
printf( "Failed to load city music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
mustafarMusic = Mix_LoadMUS( "anakinVSobi.wav" );
if( cityMusic == NULL )
{
printf( "Failed to load mustafar music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
//Load sound effects
elsaSoundEffect = Mix_LoadWAV( "elsaSoundEffect.wav" );
if( katMusic == NULL )
{
printf( "Failed to load kat sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
jackSoundEffect = Mix_LoadWAV( "jackSoundEffect.wav" );
if( katMusic == NULL )
{
printf( "Failed to load jack sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
katSoundEffect = Mix_LoadWAV( "katSoundEffect.wav" );
if( katMusic == NULL )
{
printf( "Failed to load kat sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
albusSoundEffect = Mix_LoadWAV( "albusSoundEffect.wav" );
if( katMusic == NULL )
{
printf( "Failed to load albus sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
return success;
}
//------------------------------------------------------------------------------
// FREE SOME MEMORY
//------------------------------------------------------------------------------
void close(){
//Free loaded images
elsaBattleTexture.free();
katBattleTexture.free();
jackBattleTexture.free();
albusBattleTexture.free();
elsaDialogueTexture.free();
katDialogueTexture.free();
jackDialogueTexture.free();
albusDialogueTexture.free();
elsaSpriteSide.free();
katSpriteSide.free();
jackSpriteSide.free();
albusSpriteSide.free();
elsaSpriteFront.free();
katSpriteFront.free();
jackSpriteFront.free();
albusSpriteFront.free();
elsaSpriteBack.free();
katSpriteBack.free();
jackSpriteBack.free();
albusSpriteBack.free();
ArendelleTexture.free();
mapTexture[1].free();
mapTexture[2].free();
CaveBGTexture.free();
IslandBGTexture.free();
ForestBGTexture.free();
BViewTexture.free();
textAndaleTexture.free();
//Free the music
Mix_FreeMusic( elsaMusic );
Mix_FreeMusic( katMusic );
Mix_FreeMusic( jackMusic );
Mix_FreeMusic( albusMusic );
elsaMusic = NULL;
katMusic = NULL;
jackMusic = NULL;
albusMusic = NULL;
//Free the sound effects
Mix_FreeChunk( soundEffect1 );
soundEffect1 = NULL;
Mix_FreeChunk( elsaSoundEffect );
elsaSoundEffect = NULL;
Mix_FreeChunk( jackSoundEffect );
jackSoundEffect = NULL;
Mix_FreeChunk( katSoundEffect );
katSoundEffect = NULL;
Mix_FreeChunk( albusSoundEffect );
albusSoundEffect = NULL;
//Free global font
TTF_CloseFont( gFont );
gFont = NULL;
//Destroy window
SDL_DestroyRenderer( gRenderer );
SDL_DestroyWindow( gWindow );
gWindow = NULL;
gRenderer = NULL;
//Quit SDL subsystems
Mix_Quit();
IMG_Quit();
TTF_Quit();
SDL_Quit();
}
//------------------------------------------------------------------------------
// PLAY THE GAME WITH USER INPUT
//------------------------------------------------------------------------------
int main( int argc, char* args[] )
{
//Start up SDL and create window
if( !init() )
{
printf( "Failed to initialize!\n" );
}
else
{
//Load media
if( !loadMedia() )
{
printf( "Failed to load media!\n" );
}
else
{
//Main loop flag
bool quit = false;
//------------------------------------------------------------------------------
// INITIALIZE VARIABLES
//------------------------------------------------------------------------------
//Characters for Battle
CharacterView Elsa(720,500, pathForFile("Images/elsaBattle.png"), gRenderer);
CharacterView Albus(750,350, pathForFile("Images/albusBattle.png"), gRenderer);
CharacterView Jack(650,430, pathForFile("Images/jackBattle.png"), gRenderer);
CharacterView Kat(850,430, pathForFile("Images/katBattle.png"), gRenderer);
CharacterView elsaDialogue(10, 2*SCREEN_HEIGHT/3+50, pathForFile("Images/elsaDialogue.png"), gRenderer);
CharacterView katDialogue(0, 2*SCREEN_HEIGHT/3+40, pathForFile("Images/katDialogue.png"), gRenderer);
CharacterView jackDialogue(10, 2*SCREEN_HEIGHT/3+60, pathForFile("Images/jackDialogue.png"), gRenderer);
CharacterView albusDialogue(20, 2*SCREEN_HEIGHT/3+50, pathForFile("Images/albusDialogue.png"), gRenderer);
//TextView for displaying dialogue/stats
TextView text;
//Event handler
SDL_Event e;
//Play the music
//initial layout
WindowLayouts layout=OPEN_LAYOUT;
int layoutReset=1;
//initial active character
MainCharacters activeCharacter=ELSA;
//initial Character Direction
Direction charDir=UP;
//Angle of rotation iterator for oscillating
float elsaRotIterator=0;
float jackRotIterator=0;
float albusRotIterator=0;
float katRotIterator=0;
//open dialogue file
string filename=pathForFile("Dialogue/SampleScript.dialogue");
ifstream file(filename.c_str());
//check for open
if (!file) {
cout<<"File "<<filename<<" failed to open"<<endl;
}
//declare dialogue line
string diaLine;
//initialize color
SDL_Color whiteColor = { 255, 255, 255};
//read from file
getline(file,diaLine);
//initialize step counter for battles
int stepCount=0;
//the dot to move around the screen
Dot leader;
//The camera area
SDL_Rect blank = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
SDL_Rect camera[8];
for(int q=0;q<8;q++) camera[q]= blank;
//initialize map number
int mapNumber=0;
//initialize character direction
int charDirTemp=1;
//initialize zone as valid
int zone=9;
Dot mapScout;
int startPosX[8];
for(int q=0; q<8; q++) startPosX[q]=50;
int startPosY[8];
for(int q=0; q<8; q++) startPosY[q]=50;
startPosX[0]=752;
startPosY[0]=176;
startPosX[1]=80;
startPosY[1]=784;
startPosX[2]=544;
startPosY[2]=2300;
startPosX[3]=1728;
startPosY[3]=304;
//While application is running
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
//------------------------------------------------------------------------------
// HANDLE KEYPRESSES
//------------------------------------------------------------------------------
//Process User Input
else if( e.type == SDL_KEYDOWN )
{
switch( e.key.keysym.sym )
{
//move character up
case SDLK_UP:
if(activeCharacter==ELSA) Elsa.moveRel(0,-15);
if(activeCharacter==KAT) Kat.moveRel(0,-15);
if(activeCharacter==JACK) Jack.moveRel(0,-15);
if(activeCharacter==ALBUS) Albus.moveRel(0,-15);
stepCount++;
if(layout==OPEN_LAYOUT) cout<<"Steps: "<<stepCount<<endl;
break;
//move character down
case SDLK_DOWN:
if(activeCharacter==ELSA) Elsa.moveRel(0,15);
if(activeCharacter==KAT) Kat.moveRel(0,15);
if(activeCharacter==JACK) Jack.moveRel(0,15);
if(activeCharacter==ALBUS) Albus.moveRel(0,15);
stepCount++;
if(layout==OPEN_LAYOUT) cout<<"Steps: "<<stepCount<<endl;
break;
//move character left
case SDLK_LEFT:
if(activeCharacter==ELSA){
Elsa.moveRel(-15,0);
Elsa.flipLeft();
}
if(activeCharacter==KAT){
Kat.moveRel(-15,0);
Kat.flipLeft();
}
if(activeCharacter==JACK){
Jack.moveRel(-15,0);
Jack.flipLeft();
}
if(activeCharacter==ALBUS){
Albus.moveRel(-15,0);
Albus.flipLeft();
}
stepCount++;
if(layout==OPEN_LAYOUT) cout<<"Steps: "<<stepCount<<endl;
break;
//move character right
case SDLK_RIGHT:
if(activeCharacter==ELSA){
Elsa.moveRel(15,0);
Elsa.flipRight();
}
if(activeCharacter==KAT){
Kat.moveRel(15,0);
Kat.flipRight();
}
if(activeCharacter==JACK){
Jack.moveRel(15,0);
Jack.flipRight();
}
if(activeCharacter==ALBUS){
Albus.moveRel(15,0);
Albus.flipRight();
}
stepCount++;
if(layout==OPEN_LAYOUT) cout<<"Steps: "<<stepCount<<endl;
break;
//cycle through dialogue
case SDLK_RETURN:
getline(file,diaLine);
break;
//set Albus as active
case SDLK_1:
activeCharacter=ALBUS;
Mix_PlayChannel( -1, albusSoundEffect, 0 );
break;
//set Elsa as active
case SDLK_2:
activeCharacter=ELSA;
Mix_PlayChannel( -1, elsaSoundEffect, 0 );
break;
//set Jack as active
case SDLK_3:
activeCharacter=JACK;
Mix_PlayChannel( -1, jackSoundEffect, 0 );
break;
//set Kat as active
case SDLK_4:
activeCharacter=KAT;
Mix_PlayChannel( -1, katSoundEffect, 0 );
break;
//set battle layout
case SDLK_b:
layout=BATTLE_LAYOUT;
layoutReset=1;
Mix_HaltMusic();
break;
}
}
//Handle input for the character and scout
leader.handleEvent( e );
mapScout.handleEvent( e );
//check for layout switch
if(zone != 9 && layout==OPEN_LAYOUT){
switch(zone){
case 0:
mapNumber=0;
layoutReset=1;
mapScout.initializeMap(0);
Mix_HaltMusic();
break;
case 1:
mapNumber=1;
layoutReset=1;
mapScout.initializeMap(1);
Mix_HaltMusic();
break;
case 2:
mapNumber=2;
layoutReset=1;
mapScout.initializeMap(2);
Mix_HaltMusic();
break;
case 3:
mapNumber=3;
layoutReset=1;
mapScout.initializeMap(3);
Mix_HaltMusic();
break;
case 4:
mapNumber=4;
layoutReset=1;
mapScout.initializeMap(4);
Mix_HaltMusic();
break;
case 5:
mapNumber=5;
layoutReset=1;
mapScout.initializeMap(5);
Mix_HaltMusic();
break;
case 10:
layout=BATTLE_LAYOUT;
layoutReset=1;
Mix_HaltMusic();
break;
case 11:
mapNumber=0;
layoutReset=1;
mapScout.initializeMap(0);
Mix_HaltMusic();
break;
default: break;
}
}
}
//------------------------------------------------------------------------------
// MOVE THE CHARACTERS AND CAMERA
//------------------------------------------------------------------------------
//Move the character
if(!layoutReset && layout==OPEN_LAYOUT){
mapScout.moveSmoothUnrestricted(mapNumber); //move scout ahead
zone = mapScout.checkZone(mapNumber); //determine the zone
//switch character direction
charDirTemp = leader.getCharDir( mapScout.getPosX(), mapScout.getPosY(), charDirTemp );
switch(charDirTemp){
case 0: charDir = UP; break;
case 1: charDir = DOWN; break;
case 2: charDir = LEFT; break;
case 3: charDir = RIGHT; break;
}
mapScout.moveBackSmooth(mapNumber); //move scout back
leader.moveSmooth(zone,mapNumber); //move character ahead
mapScout.moveSmooth(zone,mapNumber); //move scout ahead, too
}
//Center the camera over the dot
camera[mapNumber].x = ( leader.getPosX() + Dot::DOT_WIDTH / 2 ) - SCREEN_WIDTH / 2;
camera[mapNumber].y = ( leader.getPosY() + Dot::DOT_HEIGHT / 2 ) - SCREEN_HEIGHT / 2;
//Keep the camera in bounds
if( camera[mapNumber].x < 0 )
{
camera[mapNumber].x = 0;
}
if( camera[mapNumber].y < 0 )
{
camera[mapNumber].y = 0;
}
if( camera[mapNumber].x > LEVEL_WIDTH[mapNumber] - camera[mapNumber].w )
{
camera[mapNumber].x = LEVEL_WIDTH[mapNumber] - camera[mapNumber].w;
}
if( camera[mapNumber].y > LEVEL_HEIGHT[mapNumber] - camera[mapNumber].h )
{
camera[mapNumber].y = LEVEL_HEIGHT[mapNumber] - camera[mapNumber].h;
}
//Clear screen
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
SDL_RenderClear( gRenderer );
//declare viewports
SDL_Rect fullViewport;
SDL_Rect topViewport;
SDL_Rect bottomViewport;
//------------------------------------------------------------------------------
// BATTLE LAYOUT
//------------------------------------------------------------------------------
switch(layout){
case BATTLE_LAYOUT:
if( Mix_PlayingMusic() == 0 )
{
//Play the music
Mix_PlayMusic( elsaMusic, -1 );
}
if(layoutReset){
//reset positions
Elsa.moveAbs(720,500);
Albus.moveAbs(750, 350);
Jack.moveAbs(650, 430);
Kat.moveAbs(850, 430);
Elsa.flipLeft();
Albus.flipLeft();
Jack.flipLeft();
Kat.flipLeft();
layoutReset=0;
}
//Top viewport
topViewport.x = 0;
topViewport.y = SCREEN_HEIGHT / 3;
topViewport.w = SCREEN_WIDTH;
topViewport.h = SCREEN_HEIGHT;
SDL_RenderSetViewport( gRenderer, &topViewport );
//Render background texture to screen
ArendelleTexture.render(gRenderer, 0,150);
//Render battle characters to the screen
Elsa.draw(gRenderer);
Kat.draw(gRenderer);
Jack.draw(gRenderer);
Albus.draw(gRenderer);
//Check for Rendering Dialogue Textures to the Screen
if(activeCharacter==ELSA) elsaDialogue.draw(gRenderer);
if(activeCharacter==KAT) katDialogue.draw(gRenderer);
if(activeCharacter==JACK) jackDialogue.draw(gRenderer);
if(activeCharacter==ALBUS) albusDialogue.draw(gRenderer);
//Bottom viewport
bottomViewport.x = 0;
bottomViewport.y = 0;
bottomViewport.w = SCREEN_WIDTH;
bottomViewport.h = SCREEN_HEIGHT / 3;
SDL_RenderSetViewport( gRenderer, &bottomViewport );
//Render battleStat boxes to the screen
BViewTexture.render(gRenderer, 0,0);
//Render text
text.draw("1: Choose Albus", 20, 20, gRenderer);
text.draw("2: Choose Elsa", 20, 45, gRenderer);
text.draw("3: Choose Jack", 20, 70, gRenderer);
text.draw("4: Choose Kat", 20, 95, gRenderer);
text.draw("Arrow Keys: Move", 20, 120, gRenderer);
text.draw("5: Elsa's Theme", 380, 20, gRenderer);
text.draw("6: Jack's Theme", 380, 45, gRenderer);
text.draw("7: Kat's Theme", 380, 70, gRenderer);
text.draw("8: Albus' Theme", 380, 95, gRenderer);
text.draw(diaLine, 380, 120, gRenderer);
//jiggle the characters
if (activeCharacter==ELSA){
elsaRotIterator++;
Elsa.setDegs(Elsa.getDegs()+sin(elsaRotIterator));
}
else if (activeCharacter==ALBUS){
albusRotIterator++;
Albus.setDegs(Albus.getDegs()+sin(albusRotIterator));
}
else if (activeCharacter==JACK){
jackRotIterator++;
Jack.setDegs(Jack.getDegs()+sin(jackRotIterator));
}
else if (activeCharacter==KAT){
katRotIterator++;
Kat.setDegs(Kat.getDegs()+sin(katRotIterator));
}
break;
//------------------------------------------------------------------------------
// OPEN LAYOUT
//------------------------------------------------------------------------------
case OPEN_LAYOUT:
if( Mix_PlayingMusic() == 0 )
{
switch(mapNumber){
case 0:
Mix_PlayMusic( cityMusic, -1 );
break;
case 1:
Mix_PlayMusic( mustafarMusic, -1 );
break;
case 2:
Mix_PlayMusic( elsaMusic, -1 );
break;
case 3:
Mix_PlayMusic( katMusic, -1 );
break;
case 4:
Mix_PlayMusic( albusMusic, -1 );
break;
case 5:
Mix_PlayMusic( jackMusic, -1 );
break;
}
}
//Top viewport
topViewport.x = 0;
topViewport.y = SCREEN_HEIGHT / 4;
topViewport.w = SCREEN_WIDTH;
topViewport.h = SCREEN_HEIGHT;
//Bottom viewport
bottomViewport.x = 0;
bottomViewport.y = 0;
bottomViewport.w = SCREEN_WIDTH;
bottomViewport.h = SCREEN_HEIGHT / 4;
//fullViewport
fullViewport.x = 0;
fullViewport.y = 0;
fullViewport.w = SCREEN_WIDTH;