-
Notifications
You must be signed in to change notification settings - Fork 19
/
game.cpp
2227 lines (1843 loc) · 76 KB
/
game.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
#include <cstring>
#include <cstdlib>
#include "game.h"
#include <fstream>
#include <iostream>
#include <algorithm>
#ifdef PSP
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdebug.h>
#endif
#ifdef ANDROID
#include <android/log.h>
#endif
#include "timerlib.h"
extern timerLib timer;
#include <math.h>
#include "graphicslib.h"
extern graphicsLib graphLib;
#include "soundlib.h"
extern soundLib soundManager;
#include "inputlib.h"
extern inputLib input;
extern std::string GAMENAME;
#include "graphic/option_picker.h"
#include "file/format.h"
#include "defines.h"
#include "file/file_io.h"
#include "file/fio_strings.h"
#include "strings_map.h"
extern CURRENT_FILE_FORMAT::st_save game_save;
extern CURRENT_FILE_FORMAT::file_io fio;
extern struct CURRENT_FILE_FORMAT::st_checkpoint checkpoint;
extern bool run_game;
extern string FILEPATH;
extern CURRENT_FILE_FORMAT::file_game game_data;
extern CURRENT_FILE_FORMAT::file_stage stage_data;
extern bool GAME_FLAGS[FLAG_COUNT];
extern bool leave_game;
extern FREEZE_EFFECT_TYPES freeze_weapon_effect;
extern std::map<Uint8, Uint8> game_scenes_map;
#include "aux_tools/fps_control.h"
extern fps_control fps_manager;
#define DEATH_ANIMATION_DELAY 120
// ********************************************************************************************** //
// class constructor //
// ********************************************************************************************** //
game::game() : loaded_stage(-1, NULL), _show_boss_hp(false), player1(0)
{
is_game_started = false;
currentStage = INTRO_STAGE;
_frame_duration = 1000/80; // each frame must use this share of time
invencible_old_value = false;
_dark_mode = false;
SharedData::get_instance()->is_showing_boss_intro = false;
current_save_slot = 0;
show_fps_enabled = false;
map_interstage_points.push_back(st_position(11, 27));
map_interstage_points.push_back(st_position(54, 31));
map_interstage_points.push_back(st_position(105, 27));
map_interstage_points.push_back(st_position(160, 70));
map_interstage_points.push_back(st_position(198, 7));
map_interstage_points.push_back(st_position(288, 26));
map_interstage_points.push_back(st_position(265, 92));
map_interstage_points.push_back(st_position(161, 121));
map_interstage_points.push_back(st_position(78, 120));
map_interstage_points.push_back(st_position(41, 174));
map_interstage_points.push_back(st_position(120, 204));
map_interstage_points.push_back(st_position(201, 205));
map_interstage_points.push_back(st_position(203, 170));
map_interstage_points.push_back(st_position(282, 171));
}
// ********************************************************************************************** //
// class destructor //
// ********************************************************************************************** //
game::~game()
{
}
// ********************************************************************************************** //
// initializar game, can't be on constructor because it needs other objects (circular) //
// ********************************************************************************************** //
void game::initGame()
{
player1.initialize();
loaded_stage = stage(currentStage, &player1);
player1.initFrames();
player1.set_is_player(true);
player1.reset_hp();
config_manager.set_player_ref(&player1);
invencible_old_value = GAME_FLAGS[FLAG_INVENCIBLE];
fps_manager.initialize();
#if defined(DINGUX) || defined(PLAYSTATION2) || defined (PSP)
fps_manager.set_frameskip(5);
#endif
is_game_started = true;
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
void game::show_game(bool can_characters_move, bool can_scroll_stage)
{
if (leave_game == true) {
exit_game();
}
if (player1.is_teleporting() == false) { // ignore input while player is teleporting because it caused some issues
input.read_input();
}
if (config_manager.execute_ingame_menu()) { // game is paused
return;
}
if (SharedData::get_instance()->leave_stage_request == true) {
SharedData::get_instance()->leave_stage_request = false;
leave_stage();
input.clean();
}
bool must_skip_frame = fps_manager.must_skip_frame();
if (test_teleport(&player1)) {
return;
}
if (timer.is_paused() == false) {
if (can_scroll_stage == true) {
update_stage_scrolling();
}
loaded_stage.move_objects();
}
if (_dark_mode == false && !must_skip_frame) {
loaded_stage.show_stage();
}
if (can_characters_move == true) {
player1.execute();
loaded_stage.move_npcs();
}
/// @TODO - move this to the player, so we don't need to check every single loop
if (player1.is_dead() == true) {
restart_stage();
return;
}
if (!must_skip_frame) {
if (_dark_mode == false) {
player1.show();
loaded_stage.show_above_objects();
loaded_stage.showAbove();
} else {
graphLib.blank_screen();
}
if (loaded_stage.get_current_map_gfx_mode() == SCREEN_GFX_MODE_OVERLAY) {
draw_lib.show_gfx();
}
// draw HUD
draw_lib.show_hud(player1.get_current_hp(), 1, player1.get_selected_weapon(), player1.get_selected_weapon_value());
draw_lib.show_weapon_tooltip();
}
if (show_fps_enabled == true) {
fps_manager.fps_count();
}
fps_manager.limit();
/*
// REMOVED BECAUSE IT IS NOT USER FRIENDLY //
if (fps_manager.get_failed_min_fps() == true) {
if (game_config.graphics_performance_mode == PERFORMANCE_MODE_HIGH) {
game_config.graphics_performance_mode = PERFORMANCE_MODE_NORMAL;
} else if (game_config.graphics_performance_mode == PERFORMANCE_MODE_NORMAL) {
game_config.graphics_performance_mode = PERFORMANCE_MODE_LOW;
}
fps_manager.reset_failed_min_fps();
}
*/
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
Uint8 game::getMapPointLock(struct st_position pos)
{
return loaded_stage.getMapPointLock(pos);
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
st_float_position game::checkScrolling()
{
st_float_position move;
st_float_position mapScroll = loaded_stage.getMapScrolling();
st_float_position p1Pos(player1.getPosition().x, player1.getPosition().y);
move.x += (p1Pos.x - mapScroll.x) - RES_W/2;
if (mapScroll.x + move.x < 0 || mapScroll.x + move.x > MAP_W*TILESIZE) {
move.x = 0;
}
return move;
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
void game::start_stage()
{
_show_boss_hp = false;
input.clean();
loaded_stage.reset_current_map();
/// @TODO - this must be on a single method in soundlib
player1.set_position(st_position(RES_W/2 - player1.get_hitbox().h/2, -TILESIZE));
soundManager.stop_music();
soundManager.load_stage_music(stage_data.bgmusic_filename);
loaded_stage.reload_stage();
player1.cancel_slide();
player1.reset_jump();
player1.clean_projectiles();
player1.set_direction(ANIM_DIRECTION_RIGHT);
player1.refill_weapons();
player1.reset_hp();
loaded_stage.show_stage();
loaded_stage.showAbove();
//draw_lib.update_screen();
draw_lib.fade_in_screen(0, 0, 0, 1000);
game_unpause();
soundManager.play_music();
for (int i=0; i<AUTOSCROLL_START_DELAY_FRAMES; i++) { // extra delay to show dialogs
input.read_input();
input.clean_confirm_button();
loaded_stage.show_stage();
loaded_stage.showAbove();
draw_lib.update_screen();
timer.delay(20);
}
loaded_stage.add_autoscroll_delay();
show_player_teleport(PLAYER_INITIAL_X_POS, -1);
show_game(false, false);
// reset timers for objects
loaded_stage.reset_objects_timers();
}
void game::set_player_position_teleport_in(int initial_pos_x, int initial_pos_y)
{
int first_unlocked_from_bottom = loaded_stage.get_current_map()->get_first_lock_on_bottom(initial_pos_x, initial_pos_y, player1.get_size().width, player1.get_size().height);
player1.set_position(st_position(initial_pos_x, (first_unlocked_from_bottom+1)*TILESIZE-player1.get_size().height));
player1.char_update_real_position();
player1.set_animation_type(ANIM_TYPE_TELEPORT);
player1.set_animation_frame(0);
}
void game::show_player_teleport(int pos_x, int pos_y)
{
// find ground for player
set_player_position_teleport_in(pos_x, pos_y);
unsigned long end_time = timer.getTimer() + 1500;
while (timer.getTimer() < end_time) {
if (player1.animation_has_restarted()) {
player1.set_animation_frame(1);
player1.set_animation_has_restarted(false);
}
loaded_stage.show_stage();
player1.show();
loaded_stage.showAbove();
draw_lib.update_screen();
timer.delay(20);
}
player1.set_animation_frame(2);
loaded_stage.show_stage();
player1.show();
loaded_stage.showAbove();
draw_lib.update_screen();
timer.delay(20);
show_ready();
// force stand to avoid gravity not doing it for any reason
player1.set_animation_type(ANIM_TYPE_STAND);
loaded_stage.show_stage();
player1.show();
loaded_stage.showAbove();
draw_lib.update_screen();
timer.delay(20);
}
void game::show_ready()
{
draw_lib.show_ready();
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
void game::restart_stage()
{
soundManager.stop_music();
input.clean_all();
if (checkpoint.x < TILESIZE*4) {
checkpoint.x = TILESIZE*4;
}
// remove any used teleporter
draw_lib.fade_out_screen(0, 0, 0, 500);
player1.set_teleporter(-1);
_player_teleporter.active = false;
remove_all_projectiles();
remove_players_slide();
_show_boss_hp = false;
input.clean();
loaded_stage.reset_current_map();
// TODO - this must be on a single method in soundlib
player1.clean_projectiles();
player1.set_animation_type(ANIM_TYPE_TELEPORT);
player1.reset_hp();
player1.reset_jump();
player1.cancel_slide();
loaded_stage.reset_stage_maps();
game_unpause();
loaded_stage.show_stage();
loaded_stage.showAbove();
graphLib.set_screen_adjust(st_position(0, 0));
draw_lib.update_screen();
// if was on stage-boss, mneeds to reload music
soundManager.load_stage_music(stage_data.bgmusic_filename);
soundManager.play_music();
if (checkpoint.y == -1) { // did not reached any checkpoint, use the calculated value from stage start
// find teleport stop point
show_player_teleport(PLAYER_INITIAL_X_POS, -1);
} else {
show_player_teleport(checkpoint.x, checkpoint.y);
}
while (player1.get_anim_type() == ANIM_TYPE_TELEPORT) {
input.clean_all();
show_game(true, false);
draw_lib.update_screen();
}
for (int i=0; i<AUTOSCROLL_START_DELAY_FRAMES; i++) { // extra delay to teleport without moving screen
input.clean_all();
show_game(false, false);
draw_lib.update_screen();
timer.delay(20);
}
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
bool game::show_game_intro()
{
show_notice();
#ifdef BETA_VERSION
show_beta_version_warning();
#endif
currentStage = INTRO_STAGE;
scenes.preloadScenes();
scenes.game_scenes_show_unbeaten_intro();
scenes.main_screen();
initGame();
currentStage = scenes.pick_stage(INTRO_STAGE);
loaded_stage = stage(currentStage, &player1);
// show boss intro with stars, if needed
soundManager.stop_music();
scenes.boss_intro(currentStage);
start_stage();
return true;
}
void game::show_beta_version_warning()
{
graphLib.blank_screen();
draw_lib.update_screen();
input.clean();
timer.delay(100);
graphLib.draw_centered_text(30, "-- BETA VERSION WARNING --", graphLib.gameScreen, st_color(255, 130, 0));
graphLib.draw_centered_text(60, "THIS IS A TEST VERSION OF ROCKBOT,");
graphLib.draw_centered_text(75, "IT DOES CONTAIN ERRORS AND IS NOT");
graphLib.draw_centered_text(90, "COMPLETE MISSING SOME FEATURES.");
graphLib.draw_centered_text(120, "SOFTWARE IS PROVIDED \"AS IS\"");
graphLib.draw_centered_text(135, "WITHOUT WARRANTY OF ANY KIND,");
graphLib.draw_centered_text(150, "EXPRESS OR IMPLIED FROM AUTHOR.");
graphLib.draw_centered_text(170, "REPORT ANY FOUND ISSUES TO");
graphLib.draw_centered_text(185, "[email protected]");
graphLib.draw_centered_text(210, "PRESS A BUTTON OR KEY TO CONTINUE.");
draw_lib.update_screen();
input.wait_keypress();
}
void game::show_free_version_warning()
{
graphLib.blank_screen();
draw_lib.update_screen();
input.clean();
timer.delay(100);
graphLib.draw_centered_text(10, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning_title), graphLib.gameScreen, st_color(255, 130, 0));
graphLib.draw_centered_text(30, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning1));
graphLib.draw_centered_text(45, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning2));
graphLib.draw_centered_text(60, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning3));
graphLib.draw_centered_text(75, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning4));
graphLib.draw_centered_text(90, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning5));
graphLib.draw_centered_text(105, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning6));
graphLib.draw_centered_text(130, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning7));
graphLib.draw_centered_text(145, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning8));
graphLib.draw_centered_text(160, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning9));
graphLib.draw_centered_text(175, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning10));
graphLib.draw_centered_text(205, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning11));
graphLib.draw_centered_text(220, strings_map::get_instance()->get_ingame_string(string_press_key_or_button));
draw_lib.update_screen();
input.wait_keypress();
}
void game::show_notice()
{
graphLib.blank_screen();
draw_lib.update_screen();
graphicsLib_gSurface upperland_surface;
graphLib.surfaceFromFile(GAMEPATH + "/shared/images/upperland.png", &upperland_surface);
graphicsLib_gSurface jmd_surface;
graphLib.surfaceFromFile(GAMEPATH + "/shared/images/jmd_logo.png", &jmd_surface);
graphicsLib_gSurface boberatu_surface;
graphLib.surfaceFromFile(GAMEPATH + "/shared/images/boberatu.png", &boberatu_surface);
st_position upperland_logo_pos(RES_W/2 - (upperland_surface.width/6)/2, 40);
graphLib.draw_centered_text(upperland_logo_pos.y + upperland_surface.height + 2, strings_map::get_instance()->get_ingame_string(string_intro_upperland_studios), graphLib.gameScreen, st_color(199, 215, 255));
graphLib.copyArea(st_rectangle(0, 0, boberatu_surface.width, boberatu_surface.height), st_position(20, 100), &boberatu_surface, &graphLib.gameScreen);
graphLib.copyArea(st_rectangle(0, 0, jmd_surface.width, jmd_surface.height), st_position(RES_W-jmd_surface.width-20, 100), &jmd_surface, &graphLib.gameScreen);
graphLib.draw_text(190, upperland_logo_pos.y + upperland_surface.height + 75, "JMD AMIGA MUSIC", st_color(199, 215, 255));
graphLib.draw_centered_text(upperland_logo_pos.y + upperland_surface.height + 135, strings_map::get_instance()->get_ingame_string(string_intro_presents), graphLib.gameScreen, st_color(199, 215, 255));
graphLib.copyArea(st_rectangle(0, 0, upperland_surface.width/6, upperland_surface.height), upperland_logo_pos, &upperland_surface, &graphLib.gameScreen);
graphLib.draw_centered_text(210, "HTTPS://TWITTER.COM/BOBERATU");
graphLib.draw_centered_text(220, "HTTPS://JMDAMIGAMUSIC.BANDCAMP.COM");
graphLib.draw_centered_text(230, "HTTPS://ROCKBOT.UPPERLAND.NET");
draw_lib.update_screen();
input.clean_and_wait_scape_time(400);
for (int i=1; i<6; i++) {
graphLib.copyArea(st_rectangle((upperland_surface.width/6)*i, 0, upperland_surface.width/6, upperland_surface.height), upperland_logo_pos, &upperland_surface, &graphLib.gameScreen);
draw_lib.update_screen();
input.wait_scape_time(30);
}
graphLib.copyArea(st_rectangle(0, 0, upperland_surface.width/6, upperland_surface.height), upperland_logo_pos, &upperland_surface, &graphLib.gameScreen);
draw_lib.update_screen();
input.clean_and_wait_scape_time(3200);
graphLib.blank_screen();
/*
graphLib.draw_centered_text(10, strings_map::get_instance()->get_ingame_string(string_intro_engine1, current_language), graphLib.gameScreen, st_color(199, 215, 255));
graphLib.draw_centered_text(30, strings_map::get_instance()->get_ingame_string(string_intro_engine2, current_language));
graphLib.draw_centered_text(50, strings_map::get_instance()->get_ingame_string(string_intro_engine3, current_language));
graphLib.draw_centered_text(70, strings_map::get_instance()->get_ingame_string(string_intro_engine4, current_language));
graphLib.draw_centered_text(90, strings_map::get_instance()->get_ingame_string(string_intro_engine5, current_language));
graphLib.draw_centered_text(110, strings_map::get_instance()->get_ingame_string(string_intro_engine6, current_language));
graphLib.draw_centered_text(130, strings_map::get_instance()->get_ingame_string(string_intro_engine7, current_language));
graphLib.draw_centered_text(150, strings_map::get_instance()->get_ingame_string(string_intro_engine8, current_language));
graphLib.draw_centered_text(170, strings_map::get_instance()->get_ingame_string(string_intro_engine9, current_language));
graphLib.draw_centered_text(190, strings_map::get_instance()->get_ingame_string(string_intro_engine10, current_language));
graphLib.draw_centered_text(210, strings_map::get_instance()->get_ingame_string(string_intro_engine11, current_language));
draw_lib.update_screen();
timer.delay(10000);
graphLib.blank_screen();
graphLib.draw_centered_text(10, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning_title, current_language), graphLib.gameScreen, st_color(199, 215, 255));
graphLib.draw_centered_text(30, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning1, current_language));
graphLib.draw_centered_text(50, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning2, current_language));
graphLib.draw_centered_text(70, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning3, current_language));
graphLib.draw_centered_text(90, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning4, current_language));
graphLib.draw_centered_text(110, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning5, current_language));
graphLib.draw_centered_text(130, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning6, current_language));
graphLib.draw_centered_text(150, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning7, current_language));
graphLib.draw_centered_text(170, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning8, current_language));
graphLib.draw_centered_text(200, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning9, current_language));
graphLib.draw_centered_text(220, strings_map::get_instance()->get_ingame_string(string_intro_demo_warning10, current_language));
draw_lib.update_screen();
timer.delay(10000);
graphLib.blank_screen();
*/
}
void game::show_in_memorian()
{
graphLib.blank_screen();
draw_lib.update_screen();
graphLib.draw_centered_text(60, "IN MEMORIAN TO MY OLD BROTHER");
graphLib.draw_centered_text(100, "IVAN FIEDORUK");
graphLib.draw_centered_text(120, "AUGUST, 27, 1973 - MAY, 16, 2018");
graphLib.draw_centered_text(160, "CREATOR OF APEBOT");
graphLib.draw_centered_text(180, "REST IN PEACE");
draw_lib.fade_in_screen(0, 0, 0, 2000);
draw_lib.update_screen();
timer.delay(4000);
draw_lib.fade_out_screen(0, 0, 0, 2000);
}
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
bool game::test_teleport(classPlayer *test_player) {
if (player1.get_anim_type() == ANIM_TYPE_TELEPORT) {
return false;
}
int currentMap = loaded_stage.get_current_map_number();
int temp_x, temp_y;
int temp_map_n=0;
int player_x = 0;
int transition_type = 0;
int i=0;
bool MUST_TELEPORT = false;
int teleporter_dist = 0;
int link_type = -1;
int j = 0;
for (j=0; j<STAGE_MAX_LINKS; j++) {
if (stage_data.links[j].id_map_origin == -1 || stage_data.links[j].id_map_destiny == -1) {
continue;
}
if (stage_data.links[j].id_map_origin != -1) {
// @TODO: replace CASTLE1_STAGE5 by a flag that indicates last level
if (currentStage == CASTLE1_STAGE5 && _last_stage_used_teleporters.find(i) != _last_stage_used_teleporters.end()) {
i++;
continue;
}
if (stage_data.links[j].id_map_origin == currentMap) {
temp_x = stage_data.links[j].pos_origin.x;
temp_y = stage_data.links[j].pos_origin.y;
temp_map_n = stage_data.links[j].id_map_destiny;
player_x = stage_data.links[j].pos_destiny.x;
if (stage_data.links[j].pos_origin.y > stage_data.links[j].pos_destiny.y) {
transition_type = TRANSITION_TOP_TO_BOTTOM;
} else if (stage_data.links[j].pos_origin.y < stage_data.links[j].pos_destiny.y) {
transition_type = TRANSITION_BOTTOM_TO_TOP;
}
MUST_TELEPORT = check_player_is_on_teleport(test_player, currentMap, temp_x, temp_y, j, transition_type, i, teleporter_dist, player_x, link_type);
}
if (MUST_TELEPORT == false && stage_data.links[j].id_map_destiny == currentMap && stage_data.links[j].bidirecional == true) {
temp_x = stage_data.links[j].pos_destiny.x;
temp_y = stage_data.links[j].pos_destiny.y;
temp_map_n = stage_data.links[j].id_map_origin;
player_x = stage_data.links[j].pos_origin.x;
if (stage_data.links[j].pos_origin.y < stage_data.links[j].pos_destiny.y) {
transition_type = TRANSITION_TOP_TO_BOTTOM;
} else if (stage_data.links[j].pos_origin.y > stage_data.links[j].pos_destiny.y) {
transition_type = TRANSITION_BOTTOM_TO_TOP;
}
MUST_TELEPORT = check_player_is_on_teleport(test_player, currentMap, temp_x, temp_y, j, transition_type, i, teleporter_dist, player_x, link_type);
}
if (MUST_TELEPORT == false) {
i++;
continue;
} else {
break;
}
}
i++;
}
if (!MUST_TELEPORT) {
return false;
}
game_pause();
graphLib.set_screen_adjust(st_position(0, 0));
remove_all_projectiles();
reset_beam_objects(); // beam/ray objects must be reset when changing maps
// must move the map, so that the dest position in screen is equal to player_real_pos_x
int new_map_pos_x;
new_map_pos_x = loaded_stage.getMapScrolling().x - teleporter_dist;
if (new_map_pos_x < 0) {
new_map_pos_x = 0;
} else if (new_map_pos_x > MAP_W*TILESIZE) {
new_map_pos_x = MAP_W*TILESIZE;
}
int diff_h=6;
/*
if (test_player->get_size().width > 30) {
diff_h = abs((float)test_player->get_size().width-30);
}
*/
new_map_pos_x -= diff_h +2;
if (is_link_teleporter(stage_data.links[j].type) == true) {
draw_lib.fade_out_screen(0, 0, 0, 300);
graphLib.blank_screen();
draw_lib.update_screen();
timer.delay(500);
int calc_pos_x = ((int)stage_data.links[j].pos_destiny.x * TILESIZE) - TILESIZE*2;
if (link_type == LINK_TELEPORT_LEFT_LOCK) {
new_map_pos_x = loaded_stage.get_first_lock_on_left(calc_pos_x/TILESIZE) - TILESIZE;
} else if (link_type == LINK_TELEPORT_RIGHT_LOCK) {
new_map_pos_x = loaded_stage.get_first_lock_on_right(calc_pos_x/TILESIZE);
} else {
new_map_pos_x = calc_pos_x;
}
} else {
transition_screen(transition_type, temp_map_n, new_map_pos_x, test_player);
}
remove_temp_objects();
st_float_position bg1_pos = loaded_stage.get_current_map()->get_bg_scroll();
std::string current_bg_filename = std::string(GameMediator::get_instance()->map_data[loaded_stage.get_current_map_number()].backgrounds[0].filename);
std::string new_bg_filename = std::string(GameMediator::get_instance()->map_data[temp_map_n].backgrounds[0].filename);
set_current_map(temp_map_n);
if (is_link_teleporter(stage_data.links[j].type) == true) {
int left_wall_lock = loaded_stage.get_first_lock_on_left(stage_data.links[j].pos_destiny.x);
int diff = RES_W/2 - player1.get_size().width;
if (left_wall_lock <= new_map_pos_x-diff) { // if no wall on left in near-screen, move scroll to center
new_map_pos_x -= diff;
}
//loaded_stage.set_scrolling(st_float_position(new_scroll_pos, loaded_stage.getMapScrolling().y));
loaded_stage.set_scrolling(st_float_position(new_map_pos_x, loaded_stage.getMapScrolling().y));
loaded_stage.get_current_map()->reset_scrolled();
if (link_type == LINK_FADE_TELEPORT) {
test_player->set_position(st_position(stage_data.links[j].pos_destiny.x*TILESIZE, stage_data.links[j].pos_destiny.y*TILESIZE));
test_player->char_update_real_position();
test_player->set_animation_type(ANIM_TYPE_JUMP);
show_game(false, true);
timer.delay(50);
draw_lib.fade_in_screen(0, 0, 0, 1000);
} else {
test_player->set_position(st_position(stage_data.links[j].pos_destiny.x*TILESIZE, stage_data.links[j].pos_destiny.y*TILESIZE));
test_player->set_animation_type(ANIM_TYPE_JUMP);
test_player->char_update_real_position();
}
} else {
loaded_stage.set_scrolling(st_float_position(new_map_pos_x, loaded_stage.getMapScrolling().y));
if (current_bg_filename == new_bg_filename) {
loaded_stage.get_current_map()->set_bg_scroll(bg1_pos);
} else {
loaded_stage.get_current_map()->set_bg_scroll(0);
}
test_player->set_position(st_position(abs((float)test_player->get_real_position().x+new_map_pos_x), test_player->getPosition().y));
test_player->char_update_real_position();
loaded_stage.get_current_map()->reset_scrolled();
}
timer.delay(100);
game_unpause();
draw_lib.update_screen();
return true;
}
bool game::check_player_is_on_teleport(classPlayer *test_player, int currentMap, int temp_x, int temp_y, int link_n, int transition_type, int &teleport_count, int &teleporter_dist, int &player_x, int &link_type)
{
int lim1 = temp_x * TILESIZE;
int lim2 = temp_x * TILESIZE + stage_data.links[link_n].size * TILESIZE;
int lim3 = (temp_y)*TILESIZE + (TILESIZE*0.5);
int lim4 = ((temp_y)*TILESIZE) + TILESIZE;
int px = test_player->getPosition().x + (test_player->get_size().width*0.5);
int py = test_player->getPosition().y + (test_player->get_size().height*0.5) + (test_player->get_size().height*0.25);
// if teleporter is out of screen, ignore it
st_float_position scroll = loaded_stage.getMapScrolling();
int min = scroll.x - RES_W/2;
int max = scroll.x + RES_W*1.5;
if (abs(px) < min || abs(px) > max) {
return false;
}
int lim3_before = lim3;
int add_lim3 = TILESIZE * 1.7;
// give extra pixels in the END-Y, if top to bottom ot bottom to top
if (is_link_teleporter(stage_data.links[link_n].type) == false) {
if (transition_type == TRANSITION_TOP_TO_BOTTOM) {
lim4 += TILESIZE * 1.5;
lim3 += TILESIZE * 0.5;
} else if (transition_type == TRANSITION_BOTTOM_TO_TOP) {
int add_lim3 = TILESIZE * 1.7;
lim3 -= TILESIZE * 1.7;
}
}
if ((px >= lim1 && px <= lim2) && ((py > lim3 && py < lim4))) {
if (test_player->get_teleporter() == -1) {
// avoid using same teleporter to return
if ((is_link_teleporter(stage_data.links[link_n].type) == true) && teleport_count == _player_teleporter.teleporter_n) {
teleport_count++;
// TODO: return false in structure
return false;
}
// for transition up/down, only execute if player is partially out of screen
if (is_link_teleporter(stage_data.links[link_n].type) == false && (transition_type == TRANSITION_TOP_TO_BOTTOM || transition_type == TRANSITION_BOTTOM_TO_TOP)) {
short int p_posy = test_player->getPosition().y;
if (p_posy > 0 && p_posy+test_player->get_size().height < RES_H-4) {
teleport_count++;
// TODO: return false in structure
return false;
}
}
teleporter_dist = lim1 - player_x*TILESIZE - 8;
if (is_link_teleporter(stage_data.links[link_n].type) == false) {
test_player->set_teleporter(teleport_count);
}
link_type = stage_data.links[link_n].type;
return true;
}
// only clean teleport when player is out of the teleporter
} else {
if (teleport_count == test_player->get_teleporter()) {
if (currentStage != CASTLE1_STAGE5 || currentMap != 2) { // only clean link if not teleporter nor is on final stage/map
test_player->set_teleporter(-1);
}
}
}
return false;
}
bool game::is_link_teleporter(int type)
{
if (type == LINK_TELEPORTER || type == LINK_TELEPORT_LEFT_LOCK || type == LINK_TELEPORT_RIGHT_LOCK || type == LINK_FADE_TELEPORT) {
return true;
}
return false;
}
void game::set_current_map(int temp_map_n)
{
loaded_stage.set_current_map(temp_map_n);
loaded_stage.reset_current_map_objects();
}
Uint8 game::get_current_map()
{
return loaded_stage.get_current_map_n();;
}
void game::map_present_boss(bool show_dialog, bool is_static_boss, bool is_stage_boss)
{
SharedData::get_instance()->is_showing_boss_intro = true;
soundManager.stop_music();
soundManager.unload_music();
// 1. keep showing game screen until player reaches ground
player1.clear_move_commands();
bool loop_run = true;
unsigned long limit_time = timer.getTimer() + 3000;
while (loop_run == true) {
loaded_stage.show_stage();
player1.charMove();
int anim_type = player1.get_anim_type();
if (player1.hit_ground() == true && anim_type == ANIM_TYPE_STAND) {
loop_run = false;
}
if (timer.getTimer() > limit_time) {
loop_run = false;
}
player1.show();
loaded_stage.showAbove();
timer.delay(8);
draw_lib.update_screen();
}
// 2. blink screen
graphLib.blink_screen(255, 255, 255);
// 3. move boss from top to ground
classnpc* boss_ref = loaded_stage.get_near_boss();
if (boss_ref == NULL) {
std::cout << "GAME::map_present_boss - no boss found" << std::endl;
return;
}
if (boss_ref != NULL) {
if (is_static_boss == false) {
loop_run = true;
unsigned long limit_time = timer.getTimer() + 3000;
while (loop_run == true) {
if (loaded_stage.boss_hit_ground(boss_ref) == true) {
loop_run = false;
show_stage(0, false);
} else {
show_stage(0, true);
}
if (timer.getTimer() > limit_time) {
loop_run = false;
}
if (show_fps_enabled == true) {
fps_manager.fps_count();
}
fps_manager.limit();
}
}
}
// 4. show boss intro sprites animation
loop_run = true;
limit_time = timer.getTimer() + 3000;
while (loop_run == true) {
if (loaded_stage.boss_show_intro_sprites(boss_ref) == true) { // done playing the intro
if (boss_ref->get_can_fly() == true) {
boss_ref->set_animation_type(ANIM_TYPE_WALK_AIR);
} else {
boss_ref->set_animation_type(ANIM_TYPE_STAND);
}
loop_run = false;
show_stage(0, false);
} else { // still running the intro animation
show_stage(0, true);
}
if (timer.getTimer() > limit_time) {
if (boss_ref->get_can_fly() == true) {
boss_ref->set_animation_type(ANIM_TYPE_WALK_AIR);
} else {
boss_ref->set_animation_type(ANIM_TYPE_STAND);
}
loop_run = false;
}
if (show_fps_enabled == true) {
fps_manager.fps_count();
}
fps_manager.limit();
}
// TODO: add a delay here
if (is_stage_boss) {
input.clean_all();
// 5. show boss dialog
dialogs boss_dialog;
boss_dialog.show_boss_dialog(loaded_stage.get_number());
}
show_stage(8, false);
if (boss_ref->is_final_game_boss()) {
soundManager.stop_music();
soundManager.load_music(game_data.final_boss_music_filename);
soundManager.play_music();
} else {
soundManager.play_boss_music();
}
timer.delay(100);
_show_boss_hp = true;
SharedData::get_instance()->is_showing_boss_intro = false;
}
object* game::get_player_platform()
{
return player1.get_platform();
}
void game::check_player_return_teleport()
{
remove_all_projectiles();
remove_players_slide();
if (is_player_on_teleporter() == true) {
finish_player_teleporter();
}
}
bool game::must_show_boss_hp()
{
// check boss in on extended-screen and alive
return (_show_boss_hp && loaded_stage.get_current_map()->is_boss_on_extended_screen());
}
void game::reset_stage_maps()
{
loaded_stage.reset_stage_maps();
}
// ********************************************************************************************** //
// remove the projectiles from the list of all players and npcs //
// ********************************************************************************************** //
void game::remove_all_projectiles()
{
player1.clean_projectiles();
loaded_stage.get_current_map()->clean_map_npcs_projectiles();