-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBattleArena.cpp
More file actions
1927 lines (1683 loc) · 74.9 KB
/
BattleArena.cpp
File metadata and controls
1927 lines (1683 loc) · 74.9 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
//Mazharul Maaz ICS3U January 19th 2018 Ms. Cullum
//This program lets two players go against each other in a Pokemon Battle
//Same concept as a normal Pokemon with limited functionalities
#pragma warning(disable:4996)
// You must include the allegro header files
#include <allegro5/allegro.h>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_primitives.h>
#include <stdio.h>
#include <string.h>
//Allegro stuff that needs to be declared and initialized for most of the functions to work
ALLEGRO_EVENT_QUEUE* event_queue = nullptr;
ALLEGRO_DISPLAY* display = nullptr;
ALLEGRO_BITMAP* background1 = nullptr;
ALLEGRO_BITMAP* background2 = nullptr;
ALLEGRO_BITMAP* background3 = nullptr;
ALLEGRO_FONT* font1 = nullptr;
ALLEGRO_FONT* font2 = nullptr;
ALLEGRO_EVENT ev;
bool game = true;
//Variables for colors
#define RED al_map_rgb(230, 25, 75)
#define GREEN al_map_rgb(60, 180, 75)
#define YELLOW al_map_rgb(255, 225, 25)
#define BLUE al_map_rgb(0, 130, 200)
#define ORANGE al_map_rgb(245, 130, 48)
#define PURPLE al_map_rgb(145, 30, 180)
#define BROWN al_map_rgb(170, 110, 40)
#define BLACK al_map_rgb(0, 0, 0)
//Structure for the abilities of Pokemons
struct Abilities {
char abilityName[20];
char abilityType[5];
int damage;
int counter;
};
//Structures for the Pokemons themselves
struct Pokemons {
char pokeType[8];
char pokeName[20];
Abilities ability1;
Abilities ability2;
Abilities ability3;
int health;
};
//Structure for player
struct Player {
char name[10];
Pokemons pokemon[3];
};
int initializeAllegro();
void refreshScreen1();
void refreshScreen2();
void refreshScreen3();
void printName(char player1Name[]);
void pickPokemons(char pokeName[], char playerName[]);
void drawPokemons(char playerName[]);
void readAbilities(char pokemon[], char ability1[], char ability2[], char ability3[], char type[]);
void initializePokemons(Pokemons& pokemon);
void drawPokeBattle(char pokemon1[], int x1, int y1, char pokemon2[], int x2, int y2, char word1[], char word2[], char word3[], int& health1, int& health2, int counter1, int counter2, char player1Name[], char player2Name[], char poke1Type[], char poke2Type[]);
void userBattle(Pokemons& pokemon1, Pokemons& pokemon2, int x1, int x2, int y1, int y2, char player1Name[], char player2Name[], char attackerType[], char defenderType[], int beforeHealth1, int beforeHealth2, int& damage1, char& damage2);
void drawAttack(Pokemons& pokemon1, Pokemons& pokemon2, int x1, int x2, int y1, int y2, char player1Name[], char player2Name[], char attackerType[], char defenderType[], int beforeHealth1, int beforeHealth2, int& damage1, char& damage2);
char attack2Damage(char ability[]);
int attackDamage(int& health, int damage, char attackerType[], char defenderType[]);
void drawHealth(int& health1, int& health2);
void damageDone(int& player1Health, int& player2Health, int player1Damage, char player1Special, int player2Damage, char player2Special, bool& dragonRage1, bool& dragonRage2);
int battleScene(Pokemons& pokemon1, Pokemons& pokemon2, char player1Name[], char player2Name[]);
void winnerScene(Player player);
void showTutorial();
int main(int argc, char* argv[]) {
//Creates two variables to store in information on both players
Player player1;
Player player2;
//Initializes all the allegro stuff to make sure the display is correct
initializeAllegro();
showTutorial();
//Creates the picking stage background
refreshScreen1();
//Initializes the names of the players
strcpy(player1.name, " ");
strcpy(player2.name, " ");
int i = 0;
//Draws text
al_draw_text(font1, BLACK, 75, 435, ALLEGRO_ALIGN_LEFT, "Player1, what is your first name:");
al_flip_display();
//Loop was created so that player has to at least have 1 letter in their name
while (strcmp(player1.name, " ") == 0) {
//player 1 types their name and as they do that, the text is displayed on screen
printName(player1.name);
}
//Refreshes the picking stage background
refreshScreen1();
al_draw_textf(font1, BLACK, 75, 435, ALLEGRO_ALIGN_LEFT, "%s, pick your Pokemons!", player1.name);
al_flip_display();
//Draws the Pokemon on the screen
drawPokemons(player1.name);
game = true;
//ev.keyboard.keycode set to a key outside of the keyboard so that the program doesn't consider one key for several input; Essentially resetting the value to default
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
//Function to pick first Pokemon
pickPokemons(player1.pokemon[0].pokeName, player1.name);
//Lets player 1 pick 3 different Pokemon
//Loop was created so that player can't pick the same Pokemon multiple times
do {
//ev.keyboard.keycode set to a key outside of the keyboard so that the program doesn't consider one key for several input; Essentially resetting the value to default
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
//Function to pick second Pokemon
pickPokemons(player1.pokemon[1].pokeName, player1.name);
} while (strcmp(player1.pokemon[0].pokeName, player1.pokemon[1].pokeName) == 0);
do {
//ev.keyboard.keycode set to a key outside of the keyboard so that the program doesn't consider one key for several input; Essentially resetting the value to default
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
//Function to pick third Pokemon
pickPokemons(player1.pokemon[2].pokeName, player1.name);
} while (strcmp(player1.pokemon[2].pokeName, player1.pokemon[1].pokeName) == 0 || strcmp(player1.pokemon[0].pokeName, player1.pokemon[2].pokeName) == 0);
//These lines were copy and pasted off lines 102-143. Same comments apply
refreshScreen1();
al_draw_text(font1, BLACK, 75, 435, ALLEGRO_ALIGN_LEFT, "Player2, what is your first name:");
al_flip_display();
while (strcmp(player2.name, " ") == 0) {
printName(player2.name);
}
refreshScreen1();
al_draw_textf(font1, BLACK, 75, 435, ALLEGRO_ALIGN_LEFT, "%s, pick your Pokemons!", player2.name);
al_flip_display();
drawPokemons(player2.name);
game = true;
i = 0;
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
pickPokemons(player2.pokemon[0].pokeName, player2.name);
do {
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
pickPokemons(player2.pokemon[1].pokeName, player2.name);
} while (strcmp(player2.pokemon[0].pokeName, player2.pokemon[1].pokeName) == 0);
do {
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
pickPokemons(player2.pokemon[2].pokeName, player2.name);
} while (strcmp(player2.pokemon[2].pokeName, player2.pokemon[1].pokeName) == 0 || strcmp(player2.pokemon[0].pokeName, player2.pokemon[2].pokeName) == 0);
//Initializes all the Pokemon picked for both players.
while (i < 3) {
readAbilities(player2.pokemon[i].pokeName, player2.pokemon[i].ability1.abilityName, player2.pokemon[i].ability2.abilityName, player2.pokemon[i].ability3.abilityName, player2.pokemon[i].pokeType);
readAbilities(player1.pokemon[i].pokeName, player1.pokemon[i].ability1.abilityName, player1.pokemon[i].ability2.abilityName, player1.pokemon[i].ability3.abilityName, player1.pokemon[i].pokeType);
initializePokemons(player1.pokemon[i]);
initializePokemons(player2.pokemon[i]);
i++;
}
//Function for Player1 Pokemon1 VS Player2 Pokemon1
battleScene(player1.pokemon[0], player2.pokemon[0], player1.name, player2.name);
//Extremely long and complicated if statements that goes through all the possible outcomes of which Pokemon faint first and at the end, determines who wins the game.
//Goes into this if loop if player 2's first Pokemon destroys player 1's first Pokemon
if (player1.pokemon[0].health <= 0) {
battleScene(player1.pokemon[1], player2.pokemon[0], player1.name, player2.name);
if (player2.pokemon[0].health <= 0) {
battleScene(player2.pokemon[1], player1.pokemon[1], player2.name, player1.name);
if (player1.pokemon[1].health <= 0) {
battleScene(player1.pokemon[2], player2.pokemon[1], player1.name, player2.name);
if (player1.pokemon[2].health <= 0) {
//Function for displaying end game scene
winnerScene(player2);
}
if (player2.pokemon[1].health <= 0) {
battleScene(player2.pokemon[2], player1.pokemon[2], player2.name, player1.name);
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
}
}
if (player2.pokemon[1].health <= 0) {
battleScene(player2.pokemon[2], player1.pokemon[1], player2.name, player1.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[1].health <= 0) {
battleScene(player1.pokemon[2], player2.pokemon[2], player1.name, player2.name);
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
}
}
}
if (player1.pokemon[1].health <= 0) {
battleScene(player1.pokemon[2], player2.pokemon[0], player1.name, player2.name);
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
if (player2.pokemon[0].health <= 0) {
battleScene(player2.pokemon[1], player1.pokemon[2], player2.name, player1.name);
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
if (player2.pokemon[1].health <= 0) {
battleScene(player2.pokemon[2], player1.pokemon[2], player2.name, player1.name);
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
}
}
}
}
//Goes into this if loop if player 1's first Pokemon destroys player 2's first Pokemon
if (player2.pokemon[0].health <= 0) {
battleScene(player2.pokemon[1], player1.pokemon[0], player2.name, player1.name);
if (player1.pokemon[0].health <= 0) {
battleScene(player1.pokemon[1], player2.pokemon[1], player1.name, player2.name);
if (player2.pokemon[1].health <= 0) {
battleScene(player2.pokemon[2], player1.pokemon[1], player2.name, player1.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[1].health <= 0) {
battleScene(player1.pokemon[2], player2.pokemon[2], player1.name, player2.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
}
}
if (player1.pokemon[1].health <= 0) {
battleScene(player1.pokemon[2], player2.pokemon[1], player1.name, player2.name);
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
if (player2.pokemon[1].health <= 0) {
battleScene(player2.pokemon[2], player1.pokemon[2], player2.name, player1.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
}
}
}
if (player2.pokemon[1].health <= 0) {
battleScene(player2.pokemon[2], player1.pokemon[0], player2.name, player1.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[0].health <= 0) {
battleScene(player1.pokemon[1], player2.pokemon[2], player1.name, player2.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[1].health <= 0) {
battleScene(player1.pokemon[2], player2.pokemon[2], player1.name, player2.name);
if (player2.pokemon[2].health <= 0) {
winnerScene(player1);
}
if (player1.pokemon[2].health <= 0) {
winnerScene(player2);
}
}
}
}
}
// Free memory and return with successful return code.
al_destroy_display(display);
al_destroy_bitmap(background1);
al_destroy_bitmap(background2);
al_destroy_bitmap(background3);
return 0;
}
int initializeAllegro() {
//Initializes all the Allegro stuff.
const int SCREEN_W = 960; // screen width
const int SCREEN_H = 560; // screen height
// Initialize Allegro
al_init();
// Initialize image add on
if (!al_init_image_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize image addon!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
// Initialize display
display = al_create_display(SCREEN_W, SCREEN_H);
if (!display) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_set_window_title(display, "Pokemon Game");
// Initialize primative add on
if (!al_init_primitives_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize primatives addon!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
event_queue = al_create_event_queue();
if (!event_queue) {
al_show_native_message_box(display, "Error", "Error", "Failed to create event_queue!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return -1;
}
// Initialize keyboard routines
if (!al_install_keyboard()) {
al_show_native_message_box(display, "Error", "Error", "failed to initialize the keyboard!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
al_init_font_addon(); // initialize the font1 addon
al_init_ttf_addon();// initialize the ttf (True Type font1) addon
// load the specific font1 you want
font1 = al_load_ttf_font("Pokemon GB.ttf", 18, 0);
if (!font1) {
al_show_native_message_box(display, "Error", "Error", "Could not load Pokemon GB.ttf", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
font2 = al_load_ttf_font("Pokemon GB.ttf", 32, 0);
if (!font2) {
al_show_native_message_box(display, "Error", "Error", "Could not load Pokemon GB.ttf", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
return -1;
}
// Load the bitmap into the Bitmap structure
// image file must be in same directory.
// Particularly check return code of this type of function that will fail if file not found.
background1 = al_load_bitmap("PickingScene.jpg");
if (!background1) {
al_show_native_message_box(display, "Error", "Error", "Failed to load background1!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return -1;
}
background2 = al_load_bitmap("BattleScene.png");
if (!background2) {
al_show_native_message_box(display, "Error", "Error", "Failed to load background2!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return -1;
}
background3 = al_load_bitmap("WinnerScene.png");
if (!background3) {
al_show_native_message_box(display, "Error", "Error", "Failed to load background3!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return -1;
}
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_keyboard_event_source());
}
void refreshScreen1() {
//Function for the picking stage background
al_draw_bitmap(background1, 0, 0, 0);
al_flip_display();
}
void refreshScreen2() {
//Function for the fighting stage background
al_draw_bitmap(background2, 0, 0, 0);
al_flip_display();
}
void refreshScreen3() {
//Function for the winning stage background
al_draw_bitmap(background3, 0, 0, 0);
al_flip_display();
}
void printName(char playerName[]) {
//Function to display the name of the player and set the value to player1.name
ALLEGRO_BITMAP* backSpace = nullptr;
backSpace = al_load_bitmap("Backspace.jpg");
int i = 0;
game = true;
//Loops until either the max number of letters is reached or enter is pressed
while (game == true) {
//Code for if the user presses any letters, space bar, enter or backspace
al_wait_for_event(event_queue, &ev);
if (i < 10) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_A:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "A");
playerName[i] = 'A';
i++;
}
break;
case ALLEGRO_KEY_B:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "B");
playerName[i] = 'B';
i++;
}
break;
case ALLEGRO_KEY_C:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "C");
playerName[i] = 'C';
i++;
}
break;
case ALLEGRO_KEY_D:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "D");
playerName[i] = 'D';
i++;
}
break;
case ALLEGRO_KEY_E:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "E");
playerName[i] = 'E';
i++;
}
break;
case ALLEGRO_KEY_F:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "F");
playerName[i] = 'F';
i++;
}
break;
case ALLEGRO_KEY_G:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "G");
playerName[i] = 'G';
i++;
}
break;
case ALLEGRO_KEY_H:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "H");
playerName[i] = 'H';
i++;
}
break;
case ALLEGRO_KEY_I:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "I");
playerName[i] = 'I';
i++;
}
break;
case ALLEGRO_KEY_J:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "J");
playerName[i] = 'J';
i++;
}
break;
case ALLEGRO_KEY_K:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "K");
playerName[i] = 'K';
i++;
}
break;
case ALLEGRO_KEY_L:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "L");
playerName[i] = 'L';
i++;
}
break;
case ALLEGRO_KEY_M:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "M");
playerName[i] = 'M';
i++;
}
break;
case ALLEGRO_KEY_N:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "N");
playerName[i] = 'N';
i++;
}
break;
case ALLEGRO_KEY_O:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "O");
playerName[i] = 'O';
i++;
}
break;
case ALLEGRO_KEY_P:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "P");
playerName[i] = 'P';
i++;
}
break;
case ALLEGRO_KEY_Q:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "Q");
playerName[i] = 'Q';
i++;
}
break;
case ALLEGRO_KEY_R:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "R");
playerName[i] = 'R';
i++;
}
break;
case ALLEGRO_KEY_S:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "S");
playerName[i] = 'S';
i++;
}
break;
case ALLEGRO_KEY_T:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "T");
playerName[i] = 'T';
i++;
}
break;
case ALLEGRO_KEY_U:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "U");
playerName[i] = 'U';
i++;
}
break;
case ALLEGRO_KEY_V:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "V");
playerName[i] = 'V';
i++;
}
break;
case ALLEGRO_KEY_W:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "W");
playerName[i] = 'W';
i++;
}
break;
case ALLEGRO_KEY_X:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "X");
playerName[i] = 'X';
i++;
}
break;
case ALLEGRO_KEY_Y:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "Y");
playerName[i] = 'Y';
i++;
}
break;
case ALLEGRO_KEY_Z:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, "Z");
playerName[i] = 'Z';
i++;
}
break;
case ALLEGRO_KEY_SPACE:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
al_draw_text(font1, BLACK, 125 + 25 * i, 470, ALLEGRO_ALIGN_LEFT, " ");
playerName[i] = ' ';
i++;
}
break;
case ALLEGRO_KEY_BACKSPACE:
//Overlaps the last letter with the background color and moves the cursor one letter behind
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
if (i > 0) {
i--;
playerName[i] = ' ';
al_draw_bitmap(backSpace, 125 + 25 * i, 465, 0);
}
}
break;
case ALLEGRO_KEY_ENTER:
//Breaks out of function
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
game = false;
}
break;
}
al_flip_display();
//ev.keyboard.keycode set to a key outside of the keyboard so that the program doesn't consider one key for several input; Essentially resetting the value to default
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
}
else {
//goes to this loop if max number of letters reached
game = false;
}
}
}
void drawPokemons(char playerName[]) {
//Declares and initializes all the images of Pokemon
ALLEGRO_BITMAP* alakazam = nullptr;
ALLEGRO_BITMAP* articuno = nullptr;
ALLEGRO_BITMAP* blastoise = nullptr;
ALLEGRO_BITMAP* charizard = nullptr;
ALLEGRO_BITMAP* gengar = nullptr;
ALLEGRO_BITMAP* machamp = nullptr;
ALLEGRO_BITMAP* moltres = nullptr;
ALLEGRO_BITMAP* onix = nullptr;
ALLEGRO_BITMAP* venusaur = nullptr;
ALLEGRO_BITMAP* zapdos = nullptr;
//Draws all the Pokemon
alakazam = al_load_bitmap("alakazam.png");
al_draw_bitmap(alakazam, 50, 0, 0);
articuno = al_load_bitmap("articuno.png");
al_draw_bitmap(articuno, 50, 130, 0);
blastoise = al_load_bitmap("blastoise.png");
al_draw_bitmap(blastoise, 220, 0, 0);
charizard = al_load_bitmap("charizard.png");
al_draw_bitmap(charizard, 220, 130, 0);
gengar = al_load_bitmap("gengar.png");
al_draw_bitmap(gengar, 390, 0, 0);
machamp = al_load_bitmap("machamp.png");
al_draw_bitmap(machamp, 390, 130, 0);
moltres = al_load_bitmap("moltres.png");
al_draw_bitmap(moltres, 560, 0, 0);
onix = al_load_bitmap("onix.png");
al_draw_bitmap(onix, 560, 130, 0);
venusaur = al_load_bitmap("venusaur.png");
al_draw_bitmap(venusaur, 730, 0, 0);
zapdos = al_load_bitmap("zapdos.png");
al_draw_bitmap(zapdos, 730, 130, 0);
//Draws text
al_draw_textf(font1, BLACK, 75, 435, ALLEGRO_ALIGN_LEFT, "%s, pick your Pokemons!", playerName);
al_flip_display();
}
void pickPokemons(char pokeName[], char playerName[]) {
//Function used to move the square around and determine which Pokemon the player wants.
int x = 0;
int y = 0;
//every time the square moves, the background and Pokemon are redrawn
refreshScreen1();
drawPokemons(playerName);
al_draw_rectangle(50, 0, 190, 135, BLACK, 10);
al_flip_display();
game = true;
while (game == true) {
//ev.keyboard.keycode set to a key outside of the keyboard so that the program doesn't consider one key for several input; Essentially resetting the value to default
ev.keyboard.keycode = ALLEGRO_KEY_BUTTON_L1;
al_wait_for_event(event_queue, &ev);
//Switch statement for where the square is drawn if the player presses the arrow keys. Also tracks the x and y coordinates of the square to find out which pokemon was picked
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_UP:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
if (y > 0) {
refreshScreen1();
drawPokemons(playerName);
y--;
al_draw_rectangle(50 + x * 170, 5 + y * 140, 190 + x * 170, 135 + y * 140, BLACK, 10);
al_flip_display();
}
}
break;
case ALLEGRO_KEY_DOWN:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
if (y < 1) {
refreshScreen1();
drawPokemons(playerName);
y++;
al_draw_rectangle(50 + x * 170, 5 + y * 140, 190 + x * 170, 135 + y * 140, BLACK, 10);
al_flip_display();
}
}
break;
case ALLEGRO_KEY_LEFT:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
if (x > 0) {
refreshScreen1();
drawPokemons(playerName);
x--;
al_draw_rectangle(50 + x * 170, 5 + y * 140, 190 + x * 170, 135 + y * 140, BLACK, 10);
al_flip_display();
}
}
break;
case ALLEGRO_KEY_RIGHT:
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
if (x < 4) {
refreshScreen1();
drawPokemons(playerName);
x++;
al_draw_rectangle(50 + x * 170, 5 + y * 140, 190 + x * 170, 135 + y * 140, BLACK, 10);
al_flip_display();
}
}
break;
case ALLEGRO_KEY_ENTER:
//Another switch statement for the program to figure out which Pokemon the user picked and sets that name into the variable
if (ALLEGRO_EVENT_KEY_UP == ev.type) {
switch (y) {
case 0:
switch (x) {
case 0:
strcpy(pokeName, "Alakazam");
break;
case 1:
strcpy(pokeName, "Blastoise");
break;
case 2:
strcpy(pokeName, "Gengar");
break;
case 3:
strcpy(pokeName, "Moltres");
break;
case 4:
strcpy(pokeName, "Venusaur");
break;
}
break;
case 1:
switch (x) {
case 0:
strcpy(pokeName, "Articuno");
break;
case 1:
strcpy(pokeName, "Charizard");
break;
case 2:
strcpy(pokeName, "Machamp");
break;
case 3:
strcpy(pokeName, "Onix");
break;
case 4:
strcpy(pokeName, "Zapdos");
break;
}
break;
}
game = false;
}
}
}
}
void readAbilities(char pokemon[], char ability1[], char ability2[], char ability3[], char type[]) {
//Function to read in the abilities and what type of Pokemon it is from a text file
char junk[30];
FILE* fptr;
fptr = fopen("Abilities.txt", "r");
//Used a very inefficient way of reading the text file. Sorry
if (strcmp(pokemon, "Alakazam") == 0) {
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Blastoise") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Gengar") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Moltres") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Venusaur") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Articuno") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Charizard") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Machamp") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Onix") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
if (strcmp(pokemon, "Zapdos") == 0) {
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", junk, junk, junk, junk);
fscanf(fptr, "%s %s %s %s", type, ability1, ability2, ability3);
}
fclose(fptr);
}
void initializePokemons(Pokemons& pokemon) {
//Initialize the default Pokemon structure
pokemon.ability3.damage = 20;
pokemon.ability1.damage = 50;
pokemon.health = 100;
pokemon.ability1.counter = 1;
pokemon.ability2.counter = 3;
}
void drawPokeBattle(char pokemon1[], int x1, int y1, char pokemon2[], int x2, int y2, char word1[], char word2[], char word3[], int& health1, int& health2, int counter1, int counter2, char player1Name[], char player2Name[], char poke1Type[], char poke2Type[]) {
//Function used to redraw the entire battle scene when the box is moved to minimize code
//Figures out which the aggressive and the defensive Pokemon are and draws them accordingly
if (strcmp(pokemon1, "Alakazam") == 0) {
ALLEGRO_BITMAP* alakazam = nullptr;
alakazam = al_load_bitmap("alakazam.png");
al_draw_bitmap(alakazam, x1, y1, 0);
}
if (strcmp(pokemon1, "Articuno") == 0) {
ALLEGRO_BITMAP* articuno = nullptr;
articuno = al_load_bitmap("articuno.png");
al_draw_bitmap(articuno, x1, y1, 0);
}
if (strcmp(pokemon1, "Blastoise") == 0) {
ALLEGRO_BITMAP* blastoise = nullptr;
blastoise = al_load_bitmap("blastoise.png");
al_draw_bitmap(blastoise, x1, y1, 0);
}
if (strcmp(pokemon1, "Charizard") == 0) {
ALLEGRO_BITMAP* charizard = nullptr;
charizard = al_load_bitmap("charizard.png");
al_draw_bitmap(charizard, x1, y1, 0);
}
if (strcmp(pokemon1, "Gengar") == 0) {
ALLEGRO_BITMAP* gengar = nullptr;
gengar = al_load_bitmap("gengar.png");
al_draw_bitmap(gengar, x1, y1, 0);
}
if (strcmp(pokemon1, "Machamp") == 0) {
ALLEGRO_BITMAP* machamp = nullptr;
machamp = al_load_bitmap("machamp.png");
al_draw_bitmap(machamp, x1, y1, 0);
}
if (strcmp(pokemon1, "Moltres") == 0) {
ALLEGRO_BITMAP* moltres = nullptr;
moltres = al_load_bitmap("moltres.png");
al_draw_bitmap(moltres, x1, y1, 0);
}
if (strcmp(pokemon1, "Onix") == 0) {
ALLEGRO_BITMAP* onix = nullptr;
onix = al_load_bitmap("onix.png");
al_draw_bitmap(onix, x1, y1, 0);
}
if (strcmp(pokemon1, "Venusaur") == 0) {
ALLEGRO_BITMAP* venusaur = nullptr;
venusaur = al_load_bitmap("venusaur.png");
al_draw_bitmap(venusaur, x1, y1, 0);
}
if (strcmp(pokemon1, "Zapdos") == 0) {
ALLEGRO_BITMAP* zapdos = nullptr;
zapdos = al_load_bitmap("zapdos.png");