-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathMap.cpp
More file actions
2359 lines (2149 loc) · 66 KB
/
Map.cpp
File metadata and controls
2359 lines (2149 loc) · 66 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
#define MAP_DEFINITION
#include "Map.h"
#include "Alloc.h"
#include "Constants.h"
#include "CustomLevels.h"
#include "Entity.h"
#include "Game.h"
#include "GlitchrunnerMode.h"
#include "Graphics.h"
#include "Localization.h"
#include "MakeAndPlay.h"
#include "Maths.h"
#include "Music.h"
#include "Script.h"
#include "Unused.h"
#include "UtilityClass.h"
mapclass::mapclass(void)
{
//Start here!
colstatedelay = 0;
colsuperstate = 0;
spikeleveltop = 0;
spikelevelbottom = 0;
oldspikeleveltop = 0;
oldspikelevelbottom = 0;
warpx = false;
warpy = false;
extrarow = 0;
showteleporters = false;
showtargets = false;
showtrinkets = false;
finalmode = false;
finalstretch = false;
cursorstate = 0;
cursordelay = 0;
towermode = false;
cameraseekframe = 0;
resumedelay = 0;
final_colormode = false;
final_colorframe = 0;
final_colorframedelay = 0;
final_mapcol = 0;
final_aniframe = 0;
final_aniframedelay = 0;
custommode=false;
custommodeforreal=false;
customshowmm=true;
revealmap = true;
rcol = 0;
//This needs to be in map instead!
invincibility = false;
//We create a blank map
SDL_memset(contents, 0, sizeof(contents));
SDL_memset(roomdeaths, 0, sizeof(roomdeaths));
SDL_memset(roomdeathsfinal, 0, sizeof(roomdeathsfinal));
resetmap();
setroomname("");
hiddenname = "";
roomname_special = false;
specialroomnames.clear();
roomnameset = false;
tileset = 0;
initmapdata();
ypos = 0;
oldypos = 0;
background = 0;
cameramode = 0;
cameraseek = 0;
minitowermode = false;
roomtexton = false;
nexttowercolour_set = false;
currentregion = 0;
SDL_zeroa(region);
}
static char roomname_static[SCREEN_WIDTH_CHARS];
static char* roomname_heap;
void mapclass::destroy(void)
{
VVV_free(roomname_heap);
}
//Areamap starts at 100,100 and extends 20x20
const int mapclass::areamap[] = {
1,2,2,2,2,2,2,2,0,3,0,0,0,4,4,4,4,4,4,4,
1,2,2,2,2,2,2,0,0,3,0,0,0,0,4,4,4,4,4,4,
0,1,0,0,2,0,0,0,0,3,0,0,0,0,4,4,4,4,4,4,
0,0,0,0,2,0,0,0,0,3,0,0,5,5,5,5,4,4,4,4,
0,0,2,2,2,0,0,0,0,3,11,11,5,5,5,5,0,0,0,0,
0,0,0,0,0,0,0,0,0,3,5,5,5,5,5,5,0,0,0,0,
0,0,0,0,0,0,0,0,0,3,5,5,5,5,5,5,5,0,0,0,
0,0,0,0,0,0,0,0,0,3,5,5,5,5,5,5,5,5,5,0,
0,0,0,0,0,0,0,0,0,3,0,0,0,5,5,5,5,5,5,0,
0,0,0,0,0,0,0,0,11,3,0,0,0,5,5,5,5,5,5,0,
0,0,0,0,0,0,0,0,0,3,0,0,0,5,5,5,5,5,5,0,
0,0,0,0,0,0,0,0,0,3,0,5,5,5,5,5,5,5,5,0,
0,0,0,0,0,0,0,0,0,3,0,5,5,5,5,5,5,0,5,0,
0,0,0,0,0,0,0,0,0,3,0,5,5,5,5,5,5,0,5,0,
0,0,0,0,0,0,0,0,0,3,0,5,5,0,0,0,0,0,5,0,
0,0,0,0,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,
0,0,2,2,2,2,2,2,0,3,0,0,0,0,0,0,0,0,0,0,
0,2,2,2,2,2,2,2,0,3,0,0,0,0,0,0,0,0,0,0,
2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,
2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,
};
int mapclass::getwidth(void)
{
if (custommode)
{
return cl.mapwidth;
}
return 20;
}
int mapclass::getheight(void)
{
if (custommode)
{
return cl.mapheight;
}
return 20;
}
int mapclass::intpol(int a, int b, float c)
{
return static_cast<int>(a + ((b - a) * c));
}
void mapclass::setteleporter(int x, int y)
{
if (x < 0 || x >= getwidth() || y < 0 || y >= getheight())
{
return;
}
SDL_Point temp;
temp.x = x;
temp.y = y;
teleporters.push_back(temp);
}
void mapclass::settrinket(int x, int y)
{
if (x < 0 || x >= getwidth() || y < 0 || y >= getheight())
{
return;
}
SDL_Point temp;
temp.x = x;
temp.y = y;
shinytrinkets.push_back(temp);
}
void mapclass::setroomname(const char* name)
{
VVV_free(roomname_heap);
const size_t size = SDL_strlcpy(
roomname_static, name, sizeof(roomname_static)
) + 1;
roomname = roomname_static;
if (size > sizeof(roomname_static))
{
roomname_heap = SDL_strdup(name);
if (roomname_heap != NULL)
{
roomname = roomname_heap;
}
}
}
void mapclass::resetmap(void)
{
//clear the explored area of the map
SDL_memset(explored, 0, sizeof(explored));
}
void mapclass::fullmap(void)
{
//mark the whole map as explored
SDL_memset(explored, 1, sizeof(explored));
}
void mapclass::updateroomnames(void)
{
if (roomnameset)
{
return;
}
const int rx = game.roomx;
const int ry = game.roomy;
for (int i = specialroomnames.size() - 1; i >= 0; i--)
{
Roomname* roomname = &specialroomnames[i];
if (rx == roomname->x && ry == roomname->y && (roomname->flag == -1 || (INBOUNDS_ARR(roomname->flag, obj.flags) && obj.flags[roomname->flag])))
{
roomname_special = true;
if (roomname->type == RoomnameType_STATIC)
{
setroomname(roomname->text[0].c_str());
}
if (roomname->type == RoomnameType_GLITCH)
{
roomname->delay--;
if (roomname->delay <= 0)
{
roomname->progress = (roomname->progress + 1) % 2;
roomname->delay = 5;
if (roomname->progress == 0)
{
roomname->delay = 25 + (int) (fRandom() * 10);
}
}
setroomname(roomname->text[roomname->progress].c_str());
}
if (roomname->type == RoomnameType_TRANSFORM)
{
roomname->delay--;
if (roomname->delay <= 0)
{
roomname->progress++;
roomname->delay = 2;
if ((size_t) roomname->progress >= roomname->text.size())
{
roomname->progress = roomname->loop ? 0 : roomname->text.size() - 1;
}
}
setroomname(roomname->text[roomname->progress].c_str());
}
break;
}
}
}
void mapclass::initmapdata(void)
{
if (custommode)
{
initcustommapdata();
return;
}
teleporters.clear();
shinytrinkets.clear();
//Set up static map information like teleporters and shiny trinkets.
setteleporter(0, 0);
setteleporter(0, 16);
setteleporter(2, 4);
setteleporter(2, 11);
setteleporter(7, 9);
setteleporter(7, 15);
setteleporter(8, 11);
setteleporter(10, 5);
setteleporter(11, 4);
setteleporter(13, 2);
setteleporter(13, 8);
setteleporter(14, 19);
setteleporter(15, 0);
setteleporter(17, 12);
setteleporter(17, 17);
setteleporter(18, 1);
setteleporter(18, 7);
settrinket(14, 4);
settrinket(13, 6);
settrinket(11, 12);
settrinket(15, 12);
settrinket(14, 11);
settrinket(18, 14);
settrinket(11, 7);
settrinket(9, 2);
settrinket(9, 16);
settrinket(2, 18);
settrinket(7, 18);
settrinket(6, 1);
settrinket(17, 3);
settrinket(10, 19);
settrinket(5, 15);
settrinket(1, 10);
settrinket(3, 2);
settrinket(10, 8);
//Special room names
specialroomnames.clear();
{
static const char* lines[] = {
"Television Newsvel",
"TelevisvonvNewsvel",
"TvlvvvsvonvNevsvel",
"vvvvvvsvovvNe svel",
"vhv vvv'vvovv vevl",
"vhv V v'Cvovv vewv",
"vhe 9 v'Cvovv vewv",
"vhe 9 v'Cvovv Newv",
"The 9 O'Cvovk Newv",
"The 9 O'Clock News"
};
roomnamechange(45, 51, lines, SDL_arraysize(lines));
}
{
static const char* lines[] = {
"Vwitvhed",
"vVwivcvedv",
"vvvwMvcvMdvv",
"DvvvwMvfvvMdvvv",
"Dvav Mvfvr Mdvvvv",
"Diav M for Mdrver",
"Dial M for Murder"
};
roomnamechange(46, 51, lines, SDL_arraysize(lines));
}
{
static const char* lines[] = {
"Gvnsmove",
"Gvnvmovevv",
"Gunvmove1vv6",
"Vunsmoke 19v6",
"Gunsmoke 1966"
};
roomnamechange(47, 51, lines, SDL_arraysize(lines));
}
{
static const char* lines[] = {
"Please envoy theve repeats",
"Plse envoy tse rvpvas",
"Plse envoy tse rvpvas",
"Vl envoy te rvevs",
"Vv evo tv vevs",
"Iv vhv Mvrvivs",
"In the Margins"
};
roomnamechange(50, 53, lines, SDL_arraysize(lines));
}
{
static const char* lines[] = {
"Try Viggling the Antenna",
"TryJivglvng theAvtevna",
"Tvvivglvng thAvtvvv",
"Vvvgglvnv tvnvva",
"Vvavvnvs vvtv",
"Veavvn's Gvte",
"Heaven's Gate"
};
roomnamechange(50, 54, lines, SDL_arraysize(lines));
}
roomnameglitch(42, 51, "Rear Window", "Rear Vindow");
roomnameglitch(48, 51, "On the Waterfront", "On the Vaterfront");
roomnameglitch(49, 51, "The Untouchables", "The Untouchavles");
}
void mapclass::roomnameglitch(int x, int y, const char* name, const char* text)
{
Roomname roomname;
roomname.x = x;
roomname.y = y;
roomname.type = RoomnameType_GLITCH;
roomname.flag = -1;
roomname.loop = false;
roomname.progress = 1;
roomname.delay = -1;
roomname.text.push_back(name);
roomname.text.push_back(text);
specialroomnames.push_back(roomname);
}
void mapclass::roomnamechange(const int x, const int y, const char** lines, const size_t size)
{
Roomname roomname;
roomname.x = x;
roomname.y = y;
roomname.type = RoomnameType_TRANSFORM;
roomname.flag = 72; // Flag 72 is synced with finalstretch
roomname.loop = false;
roomname.progress = 0;
roomname.delay = 2;
roomname.text.insert(roomname.text.end(), lines, lines + size);
specialroomnames.push_back(roomname);
}
void mapclass::initcustommapdata(void)
{
shinytrinkets.clear();
for (size_t i = 0; i < customentities.size(); i++)
{
const CustomEntity& ent = customentities[i];
if (ent.t != 9)
{
continue;
}
settrinket(ent.rx, ent.ry);
}
}
int mapclass::finalat(int x, int y)
{
//return the tile index of the final stretch tiles offset by the colour difference
const int tile = contents[TILE_IDX(x, y)];
if (tile == 740)
{
//Special case: animated tiles
if (final_mapcol == 1)
{
int offset;
if (game.noflashingmode)
{
offset = 0;
}
else
{
offset = int(fRandom() * 11) * 40;
}
return 737 + offset;
}
else
{
int offset;
if (game.noflashingmode)
{
offset = 0;
}
else
{
offset = final_aniframe * 40;
}
return tile - (final_mapcol * 3) + offset;
}
}
else if (tile >= 80)
{
return tile - (final_mapcol * 3);
}
else
{
return tile;
}
}
int mapclass::maptiletoenemycol(int t)
{
//returns the colour index for enemies that matches the map colour t
switch(t)
{
case 0:
return EntityColour_ENEMY_CYAN;
break;
case 1:
return EntityColour_ENEMY_RED;
break;
case 2:
return EntityColour_ENEMY_PINK;
break;
case 3:
return EntityColour_ENEMY_BLUE;
break;
case 4:
return EntityColour_ENEMY_YELLOW;
break;
case 5:
return EntityColour_ENEMY_GREEN;
break;
case 6:
return EntityColour_ENEMY_GRAY;
break;
}
return EntityColour_ENEMY_CYAN;
}
void mapclass::changefinalcol(int t)
{
//change the map to colour t - for the game's final stretch.
//First up, the tiles. This is just a setting:
final_mapcol = t;
const int temp = 6 - t;
//Next, entities
for (size_t i = 0; i < obj.entities.size(); i++)
{
if (obj.entities[i].type == EntityType_MOVING)
{
if (obj.entities[i].animate == 10 || obj.entities[i].animate == 11) //treadmill
{
if(temp<3)
{
obj.entities[i].tile = 907 + (temp * 80);
}
else
{
obj.entities[i].tile = 911 + ((temp-3) * 80);
}
if(obj.entities[i].animate == 10) obj.entities[i].tile += 40;
}
else if (obj.entities[i].isplatform)
{
obj.entities[i].tile = 915+(temp*40);
}
else //just an enemy
{
obj.entities[i].colour = maptiletoenemycol(temp);
}
}
else if (obj.entities[i].type == EntityType_DISAPPEARING_PLATFORM)
{
obj.entities[i].tile = 915+(temp*40);
}
}
}
void mapclass::setcol(TowerBG& bg_obj, const int r1, const int g1, const int b1 , const int r2, const int g2, const int b2, const int c)
{
bg_obj.r = intpol(r1, r2, c / 5);
bg_obj.g = intpol(g1, g2, c / 5);
bg_obj.b = intpol(b1, b2, c / 5);
}
void mapclass::updatebgobj(TowerBG& bg_obj)
{
const int check = bg_obj.colstate % 5; //current state of phase
const int cmode = (bg_obj.colstate - check) / 5; // current colour transition;
switch(cmode)
{
case 0:
setcol(bg_obj, 255, 93, 107, 255, 255, 93, check);
break;
case 1:
setcol(bg_obj, 255, 255, 93, 159, 255, 93, check);
break;
case 2:
setcol(bg_obj, 159, 255, 93, 93, 245, 255, check);
break;
case 3:
setcol(bg_obj, 93, 245, 255, 177, 93, 255, check);
break;
case 4:
setcol(bg_obj, 177, 93, 255, 255, 93, 255, check);
break;
case 5:
setcol(bg_obj, 255, 93, 255, 255, 93, 107, check);
break;
}
bg_obj.tdrawback = true;
}
void mapclass::setbgobjlerp(TowerBG& bg_obj)
{
bg_obj.bypos = ypos / 2;
bg_obj.bscroll = (ypos - oldypos) / 2;
}
void mapclass::updatetowerglow(TowerBG& bg_obj)
{
if (colstatedelay <= 0 || colsuperstate > 0)
{
if (colsuperstate > 0) bg_obj.colstate--;
bg_obj.colstate++;
if (bg_obj.colstate >= 30) bg_obj.colstate = 0;
const int check = bg_obj.colstate % 5;
updatebgobj(bg_obj);
if (check == 0)
{
colstatedelay = 45;
}
else
{
colstatedelay = 0;
}
if (colsuperstate > 0) colstatedelay = 0;
}
else
{
colstatedelay--;
}
}
void mapclass::nexttowercolour(void)
{
/* Prevent cycling title BG more than once per frame. */
if (nexttowercolour_set)
{
return;
}
nexttowercolour_set = true;
graphics.titlebg.colstate+=5;
if (graphics.titlebg.colstate >= 30) graphics.titlebg.colstate = 0;
updatebgobj(graphics.titlebg);
}
void mapclass::settowercolour(int t)
{
graphics.titlebg.colstate=t*5;
if (graphics.titlebg.colstate >= 30) graphics.titlebg.colstate = 0;
updatebgobj(graphics.titlebg);
}
bool mapclass::towerspikecollide(int x, int y)
{
if (tower.at(x,y,0)>= 6 && tower.at(x,y,0) <= 11) return true;
return false;
}
bool mapclass::collide(int x, int y, const bool invincible)
{
if (towermode)
{
if (tower.at(x, y, 0) >= 12 && tower.at(x, y, 0) <= 27) return true;
if (invincible)
{
if (tower.at(x, y, 0) >= 6 && tower.at(x, y, 0) <= 11) return true;
}
}
else if (tileset == 2)
{
int tile;
if (y == -1) return collide(x, y + 1, invincible);
if (y == 29+extrarow) return collide(x, y - 1, invincible);
if (x == -1) return collide(x + 1, y, invincible);
if (x == 40) return collide(x - 1, y, invincible);
if (x < 0 || y < 0 || x >= 40 || y >= 29 + extrarow) return false;
tile = contents[TILE_IDX(x, y)];
if (tile >= 12 && tile <= 27) return true;
if (invincible)
{
if (tile >= 6 && tile <= 11) return true;
}
}
else
{
int tile;
if (y == -1) return collide(x, y + 1, invincible);
if (y == 29+extrarow) return collide(x, y - 1, invincible);
if (x == -1) return collide(x + 1, y, invincible);
if (x == 40) return collide(x - 1, y, invincible);
if (x < 0 || y < 0 || x >= 40 || y >= 29+extrarow) return false;
tile = contents[TILE_IDX(x, y)];
if (tile == 1) return true;
if (tileset==0 && tile == 59) return true;
if (tile>= 80 && tile < 680) return true;
if (tile == 740 && tileset==1) return true;
if (invincible)
{
if (tile>= 6 && tile <= 9) return true;
if (tile>= 49 && tile <= 50) return true;
if (tileset == 1)
{
if (tile>= 49 && tile < 80) return true;
}
}
}
return false;
}
void mapclass::settile(int xp, int yp, int t)
{
if (xp >= 0 && xp < 40 && yp >= 0 && yp < 29+extrarow)
{
contents[TILE_IDX(xp, yp)] = t;
}
}
int mapclass::area(int _rx, int _ry)
{
//THIS IS THE BUG
if (finalmode)
{
return 6;
}
else
{
int lookup = (_rx - 100) + ((_ry - 100) * 20);
if(_rx-100>=0 && _rx-100<20 && _ry-100>=0 && _ry-100<20){
return areamap[lookup];
}
else
{
return 6;
}
}
}
bool mapclass::isexplored(const int rx, const int ry)
{
const int roomnum = rx + ry*20;
if (INBOUNDS_ARR(roomnum, explored))
{
return explored[roomnum];
}
return false;
}
void mapclass::setexplored(const int rx, const int ry, const bool status)
{
const int roomnum = rx + ry*20;
if (INBOUNDS_ARR(roomnum, explored))
{
explored[roomnum] = status;
}
}
void mapclass::exploretower(void)
{
for (int i = 0; i < 20; i++)
{
setexplored(9, i, true);
}
}
void mapclass::hideship(void)
{
//remove the ship from the explored areas
setexplored(2, 10, false);
setexplored(3, 10, false);
setexplored(4, 10, false);
setexplored(2, 11, false);
setexplored(3, 11, false);
setexplored(4, 11, false);
}
void mapclass::showship(void)
{
//show the ship in the explored areas
setexplored(2, 10, true);
setexplored(3, 10, true);
setexplored(4, 10, true);
setexplored(2, 11, true);
setexplored(3, 11, true);
setexplored(4, 11, true);
}
void mapclass::resetplayer(void)
{
resetplayer(false);
}
void mapclass::resetplayer(const bool player_died)
{
bool was_in_tower = towermode;
game.deathseq = -1;
if (game.roomx != game.saverx || game.roomy != game.savery)
{
gotoroom(game.saverx, game.savery);
twoframedelayfix();
}
int i = obj.getplayer();
if(INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].vx = 0;
obj.entities[i].vy = 0;
obj.entities[i].ax = 0;
obj.entities[i].ay = 0;
obj.entities[i].xp = game.savex;
obj.entities[i].yp = game.savey;
//Fix conveyor death loop glitch
obj.entities[i].newxp = obj.entities[i].xp;
obj.entities[i].newyp = obj.entities[i].yp;
obj.entities[i].dir = game.savedir;
obj.entities[i].colour = game.savecolour;
if (player_died)
{
game.lifeseq = 10;
obj.entities[i].invis = true;
}
else
{
obj.entities[i].invis = false;
}
if (!GlitchrunnerMode_less_than_or_equal(Glitchrunner2_2))
{
obj.entities[i].size = 0;
obj.entities[i].cx = 6;
obj.entities[i].cy = 2;
obj.entities[i].w = 12;
obj.entities[i].h = 21;
}
// If we entered a tower as part of respawn, reposition camera
if (!was_in_tower && towermode)
{
ypos = obj.entities[i].yp - 120;
if (ypos < 0)
{
ypos = 0;
}
oldypos = ypos;
setbgobjlerp(graphics.towerbg);
}
}
if (game.state == 0 && !script.running && game.completestop)
{
/* Looks like a collection dialogue was interrupted.
* Undo its effects! */
game.advancetext = false;
graphics.showcutscenebars = false;
if (music.currentsong > -1)
{
music.fadeMusicVolumeIn(3000);
}
}
game.scmhurt = false; //Just in case the supercrewmate is fucking this up!
if (game.supercrewmate)
{
if (game.roomx == game.scmprogress + 41)
{
game.scmprogress = game.roomx - 41;
}
else
{
game.scmprogress = game.roomx - 40;
}
}
}
void mapclass::warpto(int rx, int ry , int t, int tx, int ty)
{
gotoroom(rx, ry);
game.teleport = false;
if (INBOUNDS_VEC(t, obj.entities))
{
obj.entities[t].xp = tx * 8;
obj.entities[t].yp = (ty * 8) - obj.entities[t].h;
obj.entities[t].lerpoldxp = obj.entities[t].xp;
obj.entities[t].lerpoldyp = obj.entities[t].yp;
}
game.gravitycontrol = 0;
}
void mapclass::gotoroom(int rx, int ry)
{
int roomchangedir;
std::vector<entclass> linecrosskludge;
//First, destroy the current room
obj.removeallblocks();
game.activetele = false;
game.readytotele = 0;
game.oldreadytotele = 0;
//Ok, let's save the position of all lines on the screen
for (size_t i = 0; i < obj.entities.size(); i++)
{
if (obj.entities[i].type == EntityType_HORIZONTAL_GRAVITY_LINE)
{
//It's a horizontal line
if (obj.entities[i].xp <= 0 || (obj.entities[i].xp + obj.entities[i].w) >= 312)
{
//it's on a screen edge
obj.copylinecross(linecrosskludge, i);
}
}
}
/* Disable all entities in the room, and deallocate any unnecessary entity slots. */
/* However don't disable player entities, but do preserve holes between them (if any). */
bool player_found = false;
for (int i = obj.entities.size() - 1; i >= 0; --i)
{
/* Iterate in reverse order to prevent unnecessary indice shifting */
if (obj.entities[i].rule == 0)
{
player_found = true;
continue;
}
if (!player_found)
{
obj.entities.erase(obj.entities.begin() + i);
}
else
{
obj.disableentity(i);
}
}
if (rx < game.roomx)
{
roomchangedir = 0;
}
else
{
roomchangedir = 1;
}
if (finalmode)
{
//Ok, what way are we moving?
game.roomx = rx;
game.roomy = ry;
if (game.roomy < 10)
{
game.roomy = 11;
}
if(game.roomx>=41 && game.roomy>=48 && game.roomx<61 && game.roomy<68 )
{
game.currentroomdeaths = roomdeathsfinal[game.roomx - 41 + (20 * (game.roomy - 48))];
}
else
{
game.currentroomdeaths = 0;
}
//Final level for time trial
if (game.intimetrial && game.roomx == 46 && game.roomy == 54)
{
music.niceplay(Music_PREDESTINEDFATEREMIX);
}
}
else if (custommode)
{
game.roomx = rx;
game.roomy = ry;
if (game.roomx < 100) game.roomx = 100 + cl.mapwidth-1;
if (game.roomy < 100) game.roomy = 100 + cl.mapheight-1;
if (game.roomx > 100 + cl.mapwidth-1) game.roomx = 100;
if (game.roomy > 100 + cl.mapheight-1) game.roomy = 100;
}
else
{
game.roomx = rx;
game.roomy = ry;
if (game.roomx < 100) game.roomx = 119;
if (game.roomy < 100) game.roomy = 119;
if (game.roomx > 119) game.roomx = 100;
if (game.roomy > 119) game.roomy = 100;
game.currentroomdeaths = roomdeaths[game.roomx - 100 + (20 * (game.roomy - 100))];
//Alright, change music depending on where we are:
music.changemusicarea(game.roomx - 100, game.roomy - 100);
}
loadlevel(game.roomx, game.roomy);
//Do we need to reload the background?
bool redrawbg = game.roomx != game.prevroomx || game.roomy != game.prevroomy;
if (redrawbg)
{
graphics.backgrounddrawn = false; //Used for background caching speedup
}
graphics.foregrounddrawn = false; //Used for background caching speedup