-
Notifications
You must be signed in to change notification settings - Fork 36
/
player.cpp
1670 lines (1415 loc) · 40.7 KB
/
player.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 "nx.h"
#include "inventory.h"
#include "playerstats.fdh"
#include "player.fdh"
Player *player = NULL;
static void InitWeapon(int wpn, int l1, int l2, int l3, int maxammo=0);
bool pinputs[INPUT_COUNT];
bool lastpinputs[INPUT_COUNT];
void PInitFirstTime()
{
player->dir = RIGHT;
player->hp = player->maxHealth = 3;
player->nxflags |= NXFLAG_FOLLOW_SLOPE;
player->ninventory = 0;
memset(player->weapons, 0, sizeof(player->weapons));
InitWeapon(WPN_POLARSTAR, 10, 20, 10);
InitWeapon(WPN_MGUN, 30, 40, 10, 100);
InitWeapon(WPN_MISSILE, 10, 20, 10, 10);
InitWeapon(WPN_FIREBALL, 10, 20, 20);
InitWeapon(WPN_BLADE, 15, 18, 0);
InitWeapon(WPN_BUBBLER, 10, 20, 5);
InitWeapon(WPN_SUPER_MISSILE, 30, 60, 10, 10);
InitWeapon(WPN_SNAKE, 30, 40, 16);
InitWeapon(WPN_SPUR, 40, 60, 200);
InitWeapon(WPN_NEMESIS, 1, 1, 0);
player->weapons[WPN_MGUN].SetFireRate(6, 6, 6);
player->weapons[WPN_MGUN].SetRechargeRate(5, 5, 5);
player->weapons[WPN_BUBBLER].SetFireRate(0, 7, 7);
player->weapons[WPN_BUBBLER].SetRechargeRate(20, 1, 1);
player->curWeapon = WPN_NONE;
if (player->XPText) delete player->XPText;
player->XPText = new FloatText(SPR_WHITENUMBERS);
// initialize player repel points
PInitRepel();
}
static void InitWeapon(int wpn, int l1, int l2, int l3, int maxammo)
{
player->weapons[wpn].max_xp[0] = l1;
player->weapons[wpn].max_xp[1] = l2;
player->weapons[wpn].max_xp[2] = l3;
player->weapons[wpn].maxammo = maxammo;
}
void InitPlayer(void)
{
player->lookaway = false;
player->walking = false;
player->dead = false;
player->drowned = false;
player->disabled = false;
player->hurt_time = 0;
player->hurt_flash_state = 0;
player->water_shield_frame = 0;
player->movementmode = MOVEMODE_NORMAL;
player->inputs_locked_lasttime = true;
player->booststate = BOOST_OFF;
player->lastbooststate = BOOST_OFF;
player->boosterfuel = BOOSTER_FUEL_QTY;
player->xinertia = 0;
player->yinertia = 0;
player->riding = NULL;
player->lastriding = NULL;
player->cannotride = NULL;
player->DamageText->Reset();
player->XPText->Reset();
statusbar.xpflashcount = 0;
PResetWeapons();
PSelectSprite();
// this prevents a splash if we start underwater, and prevents us
// from drowning immediately since our air isn't yet set up
player->touchattr = TA_WATER;
player->airleft = 1000;
player->airshowtimer = 0;
}
Player::~Player()
{
if (XPText)
{
delete XPText;
XPText = NULL;
}
}
/*
void c------------------------------() {}
*/
void HandlePlayer(void)
{
// freeze player for the split-second between <TRA to a new map and the
// start of the on-entry script for that map. (Fixes: player could shoot during
// end sequence if he holds key down).
if (game.switchstage.mapno != -1)
return;
PUpdateInput();
if (!player->dead)
{
PHandleAttributes(); // handle special tile attributes
PHandleSolidMushyObjects(); // handle objects like bugs marked "solid / mushy"
PDoWeapons(); // p_arms.cpp
PDoHurtFlash();
switch((inputs[DEBUG_MOVE_KEY] && settings->enable_debug_keys) ? MOVEMODE_DEBUG : \
player->movementmode)
{
case MOVEMODE_NORMAL:
{
PDoBooster();
PDoBoosterEnd();
PDoWalking();
PDoLooking();
PDoJumping();
PDoFalling();
PSelectFrame();
}
break;
case MOVEMODE_ZEROG: // Ironhead battle/UNI 1
{
PHandleZeroG();
}
break;
case MOVEMODE_DEBUG:
{
player->xinertia = player->yinertia = 0;
player->blockl = player->blockr = player->blockd = player->blocku = 0;
if (inputs[DOWNKEY]) player->y += 0x1000;
if (inputs[UPKEY]) player->y -= 0x1000;
if (inputs[LEFTKEY]) { player->x -= 0x1000; player->dir = LEFT; }
if (inputs[RIGHTKEY]) { player->x += 0x1000; player->dir = RIGHT; }
map_scroll_jump(player->x, player->y);
player->frame = 2;
}
break;
default:
{
player->xinertia = player->yinertia = 0;
}
break;
}
// handle some special features, like damage and bouncy, of
// 100% solid objects such as moving blocks. It's put at the end
// so that we can see the desired inertia of the player before
// it's canceled out by any block points that are set. That way
// we can tell if the player is trying to move into it.
PHandleSolidBrickObjects();
}
// apply inertia
PDoPhysics();
// thud sound when land on some objects
if (player->riding && !player->lastriding &&
(player->riding->nxflags & NXFLAG_THUD_ON_RIDING))
{
sound(SND_THUD);
}
}
// player aftermove routine
void HandlePlayer_am(void)
{
//debug("xinertia: %s", strhex(player->xinertia));
//debug("yinertia: %s", strhex(player->yinertia));
//debug("booststate: %d", player->booststate);
//debug("y: %d", player->y>>CSF);
//debug("riding %x", player->riding);
//debug("block: %d%d%d%d", player->blockl, player->blockr, player->blocku, player->blockd);
// if player is riding some sort of platform apply it's inertia to him
if (player->riding)
{
player->apply_xinertia(player->riding->xinertia);
player->apply_yinertia(player->riding->yinertia);
}
// keep player out of blocks "SMB1 style"
PDoRepel();
// handle landing and bonking head
if (player->blockd && player->yinertia > 0)
{
if (player->yinertia > 0x400 && !player->hide)
sound(SND_THUD);
player->yinertia = 0;
player->jumping = 0;
}
else if (player->blocku && player->yinertia < 0)
{
// he behaves a bit differently when bonking his head on a
// solid-brick object vs. bonking his head on the map.
// bonk-head star effect
if (player->yinertia < -0x200 && !player->hide && \
player->blocku == BLOCKED_MAP)
{
sound(SND_BONK_HEAD);
effect(player->CenterX(), player->y, EFFECT_BONKPLUS);
}
// bounces off ceiling with booster 0.8
if (player->booststate == BOOST_08)
{
player->yinertia = 0x200;
}
else if (player->bopped_object && player->bopped_object->yinertia != 0)
{
// no clear yinertia when bop head on OBJ_BLOCK_MOVEV in labyrinth.
}
else
{
player->yinertia = 0;
}
player->jumping = false;
}
player->lastwalking = player->walking;
player->lastriding = player->riding;
player->inputs_locked_lasttime = player->inputs_locked;
memcpy(lastpinputs, pinputs, sizeof(lastpinputs));
}
/*
void c------------------------------() {}
*/
void PDoPhysics(void)
{
if (player->xinertia > 0x5ff) player->xinertia = 0x5ff;
if (player->xinertia < -0x5ff) player->xinertia = -0x5ff;
if (player->yinertia > 0x5ff) player->yinertia = 0x5ff;
if (player->yinertia < -0x5ff) player->yinertia = -0x5ff;
if (player->blockd && player->yinertia > 0)
player->yinertia = 0;
player->apply_yinertia(player->yinertia);
// if xinertia is less than the decel speed then maintain the value but don't actually
// move anything. It seems a bit odd...but that's the best I can figure to make it
// behave like the original.
if (player->xinertia > player->decelspeed || player->xinertia < -player->decelspeed)
{
player->apply_xinertia(player->xinertia);
}
}
void PUpdateInput(void)
{
int i;
if (player->inputs_locked || player->disabled)
{
memset(pinputs, 0, sizeof(pinputs));
}
else
{
memcpy(pinputs, inputs, sizeof(pinputs));
// prevent jumping/shooting when leaving a messagebox
if (player->inputs_locked_lasttime)
{
for(i=0;i<INPUT_COUNT;i++)
lastpinputs[i] |= pinputs[i];
}
// allow entering inventory
if (justpushed(INVENTORYKEY))
{
if (!game.frozen && !player->dead && GetCurrentScript() == -1)
{
game.setmode(GM_INVENTORY);
}
}
// Map System
if (justpushed(MAPSYSTEMKEY) && (FindInventory(ITEM_MAP_SYSTEM) != -1))
{
if (!game.frozen && !player->dead && GetCurrentScript() == -1)
{
if (fade.getstate() == FS_NO_FADE && game.switchstage.mapno == -1)
{
game.setmode(GM_MAP_SYSTEM, game.mode);
}
}
}
}
}
// handles tile attributes of tiles player is touching
void PHandleAttributes(void)
{
static const Point pattrpoints[] = { {8, 8}, {8, 14} };
static const Point hurt_bottom_attrpoint = {8, 7};
unsigned int attr;
int tile;
// get attributes of tiles player it touching.
// first, we'll check the top pattrpoint alone; this is the point at
// which you go underwater, when that point is lower than the water level.
// ** There is a spot in Labyrinth W just after the Shop where the positioning
// of this point is a minor element in the gameplay, and so it must be set
// correctly. If set too high you will not be underwater after climbing up the
// small slope and you can just jump over the wall that you shouldn't be able to.
attr = player->GetAttributes(&pattrpoints[0], 1, &tile);
// water handler -- water uses only the top pattrpoint
if (attr & TA_WATER)
{
// check if we just entered the water
if (!(player->touchattr & TA_WATER))
{
// splash on entering water quick enough
if ((player->yinertia > 0x200 && !player->blockd) || \
(player->xinertia < -0x200 || player->xinertia > 0x200))
{
int x = player->CenterX();
int y = player->CenterY();
int splashtype = !(player->touchattr & TA_HURTS_PLAYER) ? \
OBJ_WATER_DROPLET : OBJ_LAVA_DROPLET;
for(int i=0;i<8;i++)
{
Object *o = CreateObject(x + (random(-8, 8) << CSF), y, splashtype);
o->xinertia = random(-0x200, 0x200) + player->xinertia;
o->yinertia = random(-0x200, 0x80) - (player->yinertia >> 1);
}
sound(SND_SPLASH);
}
}
// setup physics constants for water
player->walkspeed = 0x196;
player->fallspeed = 0x2ff;
player->fallaccel = 0x28;
player->jumpfallaccel = 0x10;
player->walkaccel = 0x2a;
player->jumpwalkaccel = 0x10;
player->decelspeed = 0x19;
// was set at 0x280 but I believe that makes it impossible to clear one of the long
// spike jumps in River
player->jumpvelocity = 0x2c0;
// decrement air left
if (player->equipmask & EQUIP_AIRTANK)
{
player->airleft = 1000;
player->airshowtimer = 0;
}
else
{
player->airshowtimer = 60;
if (!player->drowned)
{
if (!player->inputs_locked) player->airleft--;
if (player->airleft <= 0 && !game.debug.god)
{ // player drowned
// if flag 4000 is set, then we do not drown, but are in the Almond
// level after Core battle, and should instead execute script 1100.
if (game.flags[4000])
{ // "your senses dim and the world grows dark"
StartScript(1100);
}
else
{ // nope sorry buddy, no such luck this time
Object *o = CreateObject(player->x, player->y, OBJ_NULL);
o->sprite = SPR_PDROWNED;
o->dir = player->dir;
killplayer(SCRIPT_DROWNED);
}
player->drowned = 1;
}
}
}
}
else
{
// setup normal physics constants
player->walkspeed = 0x32c;////0x030e;
player->fallspeed = 0x5ff;
player->fallaccel = 0x50;
player->jumpfallaccel = 0x20;
player->walkaccel = 0x55;
player->jumpwalkaccel = 0x20;
player->decelspeed = 0x33;
player->jumpvelocity = 0x500;
// reset air supply
player->airleft = 1000;
if (player->airshowtimer) player->airshowtimer--;
}
// add in the bottom pattrpoint, but don't let it set the "water" bit.
// only the top pattrpoint can set "water".
attr |= (player->GetAttributes(&pattrpoints[1], 1, &tile) & ~TA_WATER);
// If the tile has "hurt" bit, we recheck it with the the different bottom attrpoint.
// This fixes bottom spikes in water level, last cave... Standart bottom attrpoint
// allows intersection with spike only for 1 pixel, but origianl game allows 8 pixels
// of safe intersection.
if (attr & TA_HURTS_PLAYER)
{
attr &= ~TA_HURTS_PLAYER;
attr |= (player->GetAttributes(&hurt_bottom_attrpoint, 1, &tile) & ~TA_WATER);
}
if (attr & TA_HURTS_PLAYER)
hurtplayer(10);
// water current/wind:
// for water currents--get the sum total of several points on the player to see
// all the directions he's getting blown around at (support multiple directions)
DoWaterCurrents();
player->touchattr = attr;
}
// handes player being blown around by water currents
void DoWaterCurrents(void)
{
static Point currentpoints[] = { {7, 8},
{1, 2}, {1, 8}, {1, 14},
{7, 2}, {7, 14},
{15,2}, {15, 8}, {15, 14} };
int i;
static const int current_dir[] = { LEFTMASK, UPMASK, RIGHTMASK, DOWNMASK };
uint8_t currentmask;
int tile;
// check each point in currentpoints[] for a water current, and if found,
// add it to the list of directions we're being blown
currentmask = 0;
for(i=0;i<9;i++)
{
//DebugCrosshair(player->x+(currentpoints[i].x<<CSF),player->y+(currentpoints[i].y<<CSF), 255,0,0);
if (player->GetAttributes(¤tpoints[i], 1, &tile) & TA_CURRENT)
{
currentmask |= current_dir[tilecode[tile] & 3];
}
// if the center point (the first one) has no current, then don't
// bother checking the rest. as during 90% of the game you are NOT underwater.
if (!currentmask) return;
}
// these constants are very critical for Waterway to work properly.
// please be careful with them.
if (currentmask & LEFTMASK) player->xinertia -= 0x88;
if (currentmask & RIGHTMASK) player->xinertia += 0x88;
if (currentmask & UPMASK) player->yinertia -= 0x80;
if (currentmask & DOWNMASK) player->yinertia += 0x50;
}
void PDoWalking(void)
{
int walk_accel;
int limit;
walk_accel = (player->blockd) ? player->walkaccel : player->jumpwalkaccel;
// walking/moving
if (pinputs[LEFTKEY] || pinputs[RIGHTKEY])
{
// we check both without an else so that both keys down=turn right & walk in place
if (pinputs[LEFTKEY])
{
player->walking = true;
player->dir = LEFT;
if (player->xinertia > -player->walkspeed)
{
player->xinertia -= walk_accel;
if (player->xinertia < -player->walkspeed)
player->xinertia = -player->walkspeed;
}
}
if (pinputs[RIGHTKEY])
{
player->walking = true;
player->dir = RIGHT;
if (player->xinertia < player->walkspeed)
{
player->xinertia += walk_accel;
if (player->xinertia > player->walkspeed)
player->xinertia = player->walkspeed;
}
}
if (player->walking && !player->lastwalking)
player->walkanimframe = 1;
}
else
{
player->walking = false;
player->walkanimframe = 0;
player->walkanimtimer = 0;
// tap sound when stopped walking
if (player->lastwalking && player->blockd)
sound(SND_PLAYER_WALK);
}
// deceleration
if (player->blockd && player->yinertia >= 0)
{ // deceleration on ground...
// always move towards zero at decelspeed
if (player->xinertia > 0)
{
if (player->blockr && !pinputs[RIGHTKEY])
{
player->xinertia = 0;
}
else if (player->xinertia > player->decelspeed)
{
player->xinertia -= player->decelspeed;
}
else
{
player->xinertia = 0;
}
}
else if (player->xinertia < 0)
{
if (player->blockl && !pinputs[LEFTKEY])
{
player->xinertia = 0;
}
else if (player->xinertia < -player->decelspeed)
{
player->xinertia += player->decelspeed;
}
else
{
player->xinertia = 0;
}
}
}
else // deceleration in air...
{
// implements 2 things
// 1) if player partially hits a brick while in air, his inertia is lesser after he passes it
// 2) but, if he's trying to turn around, let him! don't "stick" him to it just because
// of a high inertia when he hit it
if (player->blockr)
{
limit = (player->dir == RIGHT) ? 0x180 : 0;
if (player->xinertia > limit) player->xinertia = limit;
}
if (player->blockl)
{
limit = (player->dir == LEFT) ? -0x180 : 0;
if (player->xinertia < limit) player->xinertia = limit;
}
}
}
void PDoFalling(void)
{
if (player->disabled)
return;
if (player->booststate)
return;
if (game.curmap == STAGE_KINGS_TABLE && \
fade.getstate() == FS_FADING)
return;
// needed to be able to see the falling blocks during
// good-ending Helicopter cutscene (otherwise your
// invisible character falls and the blocks spawn too low).
if (player->hide)
{
player->xinertia = 0;
player->yinertia = 0;
return;
}
// use jump gravity as long as Jump Key is down and we're moving up,
// regardless of whether a jump was ever actually initiated.
// this is for the fans that blow up--you can push JUMP to climb higher.
if (player->yinertia < 0 && pinputs[JUMPKEY])
{ // use jump gravity
if (player->yinertia < player->fallspeed)
{
player->yinertia += player->jumpfallaccel;
if (player->yinertia > player->fallspeed) player->yinertia = player->fallspeed;
}
}
else
{ // use normal gravity
if (player->yinertia < player->fallspeed)
{
player->yinertia += player->fallaccel;
if (player->yinertia > player->fallspeed) player->yinertia = player->fallspeed;
}
// if we no longer qualify for jump gravity then the jump is over
player->jumping = 0;
}
}
void PDoJumping(void)
{
// jumping
if (pinputs[JUMPKEY] && !lastpinputs[JUMPKEY])
{
if (player->blockd)
{
if (!player->jumping)
{
player->jumping = true;
player->yinertia -= player->jumpvelocity;
sound(SND_PLAYER_JUMP);
}
}
else if ((player->equipmask & (EQUIP_BOOSTER08 | EQUIP_BOOSTER20)))
{
PStartBooster();
}
}
}
void PDoLooking(void)
{
int lookscroll_want;
int i, key;
// looking/aiming up and down
player->look = lookscroll_want = 0;
if (pinputs[DOWNKEY])
{
if (!player->blockd)
{
player->look = DOWN;
}
else if (!lastpinputs[DOWNKEY])
{ // activating scripts/talking to NPC's
if (!player->walking && !player->lookaway && \
!pinputs[JUMPKEY] && !pinputs[FIREKEY])
{
if (!inputs[DEBUG_MOVE_KEY] || !settings->enable_debug_keys)
{
player->lookaway = true;
player->xinertia = 0;
PTryActivateScript();
}
}
}
// can still scroll screen down while standing, even though
// it doesn't show any different frame.
lookscroll_want = DOWN;
}
if (pinputs[UPKEY])
{
player->look = lookscroll_want = UP;
}
// when looking, pause a second to be sure they really want to do it
// before triggering any real screen scrolling
if (player->lookscroll != lookscroll_want)
{
if (player->lookscroll_timer >= 4 || !lookscroll_want)
{
player->lookscroll = lookscroll_want;
}
else
{
player->lookscroll_timer++;
}
}
else
{
player->lookscroll_timer = 0;
}
// deactivation of lookaway
if (player->lookaway)
{
// keys which deactivate lookaway when you are facing away from player
static const signed char actionkeys[] = \
{ LEFTKEY, RIGHTKEY, UPKEY, JUMPKEY, FIREKEY, -1 };
// stop looking away if any keys are pushed
for(i=0;;i++)
{
key = actionkeys[i];
if (key == -1) break;
if (pinputs[key])
{
player->lookaway = false;
break;
}
}
if (!player->blockd)
player->lookaway = false;
}
}
/*
void c------------------------------() {}
*/
// called when the player has just turned on the booster
void PStartBooster(void)
{
if (player->boosterfuel <= 0)
return;
// booster 2.0 lets you pick a direction and tacks inertia
// solid in that direction when first activated
if ((player->equipmask & EQUIP_BOOSTER20))
{
// default boost direction if no key is pressed
player->booststate = BOOST_UP;
// in order of precedence
if (inputs[LEFTKEY] || inputs[RIGHTKEY])
player->booststate = BOOST_HOZ;
if (inputs[DOWNKEY])
player->booststate = BOOST_DOWN;
if (inputs[UPKEY])
player->booststate = BOOST_UP;
// set initial inertia full on
if (player->booststate == BOOST_UP || player->booststate == BOOST_DOWN)
player->xinertia = 0;
switch(player->booststate)
{
case BOOST_UP:
player->yinertia = -0x5ff;
break;
case BOOST_DOWN:
player->yinertia = 0x5ff;
break;
case BOOST_HOZ:
{
player->yinertia = 0;
if (inputs[LEFTKEY])
player->xinertia = -0x5ff;
else
player->xinertia = 0x5ff;
}
break;
}
}
else
{
player->booststate = BOOST_08;
// help it overcome gravity
if (player->yinertia > 0x100)
player->yinertia >>= 1;
}
PBoosterSmokePuff();
}
// called every tick to run the booster
void PDoBooster(void)
{
/*static const char *statedesc[] = { "OFF", "UP", "DN", "HOZ", "0.8" };
debug("fuel: %d", player->boosterfuel);
debug("booststate: %s", statedesc[player->booststate]);
debug("xinertia: %d", player->xinertia);
debug("yinertia: %d", player->yinertia);*/
if (!(player->equipmask & (EQUIP_BOOSTER08 | EQUIP_BOOSTER20)))
{
player->booststate = BOOST_OFF;
return;
}
if (!pinputs[JUMPKEY])
{
player->booststate = BOOST_OFF;
if (player->blockd)
player->boosterfuel = BOOSTER_FUEL_QTY;
return;
}
if (!player->booststate)
return;
// player seems to want it active...check the fuel
if (player->boosterfuel <= 0)
{
player->booststate = BOOST_OFF;
return;
}
else
{
player->boosterfuel--;
}
// ok so then, booster is active right now
bool sputtering = false;
switch(player->booststate)
{
case BOOST_HOZ:
{
if ((player->dir == LEFT && player->blockl) || \
(player->dir == RIGHT && player->blockr))
{
player->yinertia = -0x100;
}
// this probably isn't the right way to do this, but this
// bit makes the hurt-hop work if you get hit during a sideways boost
//if (player->hitwhileboosting)
// player->yinertia = -0x400;
if (player->dir == LEFT) player->xinertia -= 0x20;
if (player->dir == RIGHT) player->xinertia += 0x20;
}
break;
case BOOST_UP:
{
player->yinertia -= 0x20;
}
break;
case BOOST_DOWN:
{
player->yinertia += 0x20;
}
break;
case BOOST_08:
{
// top speed and sputtering
if (player->yinertia < -0x400)
{
player->yinertia += 0x20;
sputtering = true; // no sound/smoke this frame
}
else
{
player->yinertia -= 0x20;
}
}
break;
}
// don't land if we booster through a one-tile high corridor,
// but do land if we're, well, landing on something (yinertia not negative).
// must be done after booster inertia applied to work properly.
// for 1) there's a place in the village next to Mahin that is good for testing this,
// for 2) the gaps in outer wall by the little house.
if (player->blockd)
{
if (player->yinertia < 0)
player->blockd = false;
else
{
player->booststate = BOOST_OFF;
return;
}
}
// smoke and sound effects
if ((player->boosterfuel % 3) == 1 && !sputtering)
{
PBoosterSmokePuff();
}
}
// called every tick just after PDoBooster returns.
// tones down player's inertia a bit once the Booster 2.0 stops firing
void PDoBoosterEnd()
{
// put here to be sure it catches all the different ways the Booster can get turned off
//if (!player->booststate)
//player->hitwhileboosting = false;
if (player->booststate != player->lastbooststate)
{
if (player->booststate == BOOST_OFF && (player->equipmask & EQUIP_BOOSTER20))
{
switch(player->lastbooststate)
{
case BOOST_HOZ:
player->xinertia >>= 1;
break;
case BOOST_UP:
player->yinertia >>= 1;
break;
}
}
}
// in the original touching a slope while boosting horizontally
// disables the booster. In that case, we don't want to half the xinertia,
// which is why it's here.
//if (player->booststate == BOOST_HOZ && CheckStandOnSlope(player))
//player->booststate = BOOST_OFF;
player->lastbooststate = player->booststate;
}
// spawn a Booster smoke puff
void PBoosterSmokePuff()
{
// these are the directions the SMOKE is traveling, not the player
// RT LT UP DN
static const int smoke_xoffs[] = { 10, 4, 7, 7 };
static const int smoke_yoffs[] = { 10, 10, 0, 14 };
int smokedir;
switch(player->booststate)
{
case BOOST_HOZ: smokedir = (player->dir ^ 1); break;
case BOOST_UP: smokedir = DOWN; break;
case BOOST_DOWN:smokedir = UP; break;
case BOOST_08: smokedir = DOWN; break;
default: return;
}
int x = player->x + (smoke_xoffs[smokedir] << CSF);
int y = player->y + (smoke_yoffs[smokedir] << CSF);
Caret *smoke = effect(x, y, EFFECT_SMOKETRAIL_SLOW);
smoke->MoveAtDir(smokedir, 0x200);
sound(SND_BOOSTER);
}
/*
void c------------------------------() {}
*/