1 /**********************************************************************************
2 * Copyright (c) 2008, 2009 Derek Yu and Mossmouth, LLC
3 * Copyright (c) 2018, Ketmar Dark
5 * This file is part of Spelunky.
7 * You can redistribute and/or modify Spelunky, including its source code, under
8 * the terms of the Spelunky User License.
10 * Spelunky is distributed in the hope that it will be entertaining and useful,
11 * but WITHOUT WARRANTY. Please see the Spelunky User License for more details.
13 * The Spelunky User License should be available in "Game Information", which
14 * can be found in the Resource Explorer, or as an external file called COPYING.
15 * If not, please obtain a new copy of Spelunky from <http://spelunkyworld.com/>
17 **********************************************************************************/
18 // recoded by Ketmar // Invisible Vector
19 class PlayerPawn : MapEnemy;
24 const int hangCountMax = 3;
26 array!PlayerPowerup powerups; // created in initializer
28 int cameraBlockX; // >0: don't center camera
29 int cameraBlockY; // >0: don't center camera
35 const int bubbleTimerMax = 20;
36 int jetpackFlaresTime;
47 bool justdied = true; // so dead body won't spill blood endlessly
55 const int firingMax = 20;
56 const int firingPistolMax = 20;
57 const int firingShotgunMax = 40;
61 int hotkeyPressed = -1;
73 //!!!global.poisonStrength = max(global.poisonStrength-0.5, 1);
75 //string holdItemType = "";
76 //string pickupItemType = "";
78 // this is what we had picked up
79 // picked item will be stored here by bomb/rope/item switcher
82 bool canDropStuff = true;
94 int bombArrowCounter = 80;
103 // the keys that the platform character will use (don't edit)
115 bool jumpButtonReleased; // whether the jump button was released. (Stops the user from pressing the jump button many times to get extra jumps)
118 bool kAttackReleased;
120 const float gravNorm = 1;
121 //float grav = 1; // the gravity
123 const float initialJumpAcc = -2; // relates to how high the character will jump
124 const int jumpTimeTotal = 10; // how long the user must hold the jump button to get the maximum jump height
126 float climbAcc = 0.6; // how fast the character will climb
127 float climbAnimSpeed = 0.4; // relates to how fast the climbing animation should go
128 int climbSndSpeed = 8;
132 // these flags are used to recreate ball and chain when player is moved at a new level
136 const float departLadderXVel = 4; // how fast character should be moving horizontally when he leaves the ladder
137 const float departLadderYVel = -4; // how fast the character should be moving vertically when he leaves the ladder
139 const float frictionRunningX = 0.6; // friction obtained while running
140 const float frictionRunningFastX = 0.98; // friction obtained while holding the shift button for some time while running
141 const float frictionClimbingX = 0.6; // friction obtained while climbing
142 const float frictionClimbingY = 0.6; // friction obtained while climbing
143 const float frictionDuckingX = 0.8; // friction obtained while ducking
144 const float frictionFlyingX = 0.99; // friction obtained while "flying"
146 const float runAnimSpeed = 0.1; // relates to the how fast the running animation should go
148 // hidden variables (don't edit)
149 protected int statePrev;
150 protected int statePrevPrev;
151 protected float gravityIntensity = grav; // this variable describes the current force due to gravity (this variable is altered for variable jumping)
152 protected float jumpTime = jumpTimeTotal; // current time of the jump (0=start of jump, jumpTimeTotal=end of jump)
153 protected int ladderTimer; // relates to whether the character can climb a ladder
154 protected int kLeftPushedSteps;
155 protected int kRightPushedSteps;
157 transient protected bool skipCutscenePressed;
162 //PlayerWeapon actWeapon; // active weapon object
175 // ////////////////////////////////////////////////////////////////////////// //
181 final ItemBall getMyBall () {
182 ItemBall res = myBall;
183 if (res && !res.isInstanceAlive) { res = none; myBall = none; }
188 void spawnBallAndChain (optional bool levelStart) {
190 auto owh = wasHoldingBall;
191 removeBallAndChain();
192 wasHoldingBall = owh;
194 mustBeChained = true;
195 auto ball = getMyBall();
197 if (levelStart) writeln("::: respawning ball; old ball is missing (it is ok)");
198 writeln("creating new ball");
199 ball = ItemBall(level.MakeMapObject(ix, iy, 'oBall'));
201 ball.attachTo(self, levelStart);
202 writeln("ball created");
206 if (levelStart) writeln("::: attaching ball to player");
207 ball.attachTo(self, levelStart);
208 if (wasHoldingBall) {
209 if (levelStart) writeln("::: picking ball");
211 pickedItem.instanceRemove();
214 if (holdItem && holdItem != ball) {
215 holdItem.instanceRemove();
221 if (myBall != ball) FatalError("error in ball management");
222 if (levelStart) writeln("ballpos=(", ball.ix, ",", ball.iy, "); plrpos=(", ix, ",", iy, "); ballalive=", ball.isInstanceAlive);
224 writeln("failed to create a new ball");
225 mustBeChained = false;
227 wasHoldingBall = false;
231 void removeBallAndChain (optional bool temp) {
232 auto ball = getMyBall();
234 writeln("removing ball and chain...", (temp ? " (temporarily)" : ""));
235 wasHoldingBall = (holdItem == ball);
236 writeln(" has ball, holding=", wasHoldingBall);
237 mustBeChained = true;
239 ball.instanceRemove();
243 wasHoldingBall = false;
244 mustBeChained = false;
248 // ////////////////////////////////////////////////////////////////////////// //
249 final PlayerPowerup findPowerup (name id) {
250 foreach (PlayerPowerup pp; powerups) if (pp.id == id) return pp;
255 final bool setPowerupState (name id, bool active) {
256 auto pp = findPowerup(id);
257 if (!pp) return false;
258 return (active ? pp.onActivate() : pp.onDeactivate());
262 final bool togglePowerupState (name id) {
263 auto pp = findPowerup(id);
264 if (!pp) return false;
265 return (pp.active ? pp.onDeactivate() : pp.onActivate());
269 final bool activatePowerup (name id) { return setPowerupState(id, true); }
270 final bool deactivatePowerup (name id) { return setPowerupState(id, false); }
273 final bool isActivePowerup (name id) {
274 auto pp = findPowerup(id);
275 return (pp && pp.active);
279 // ////////////////////////////////////////////////////////////////////////// //
280 override void Destroy () {
281 foreach (PlayerPowerup pp; powerups) delete pp;
286 void unpressAllKeys () {
288 kLeftPressed = false;
289 kLeftReleased = false;
291 kRightPressed = false;
292 kRightReleased = false;
296 kJumpPressed = false;
297 kJumpReleased = false;
299 kAttackPressed = false;
300 kAttackReleased = false;
301 kItemPressed = false;
302 kRopePressed = false;
303 kBombPressed = false;
305 kExitPressed = false;
309 // ////////////////////////////////////////////////////////////////////////// //
310 // called on level start too
316 skipCutscenePressed = false;
317 movementBlocked = false;
318 if (global.plife < 1) global.plife = max(1, global.config.scumStartLife);
323 myGrav = default.myGrav;
327 depth = default.depth;
328 status = default.status;
334 distToNearestLightSource = 999;
336 justdied = default.justdied;
338 if (holdItem isa PlayerWeapon) {
344 blink = default.blink;
345 blinkHidden = default.blinkHidden;
351 level.clearKeysPressRelease();
354 //scrSwitchToPocketItem(forceIfEmpty:false);
358 // ////////////////////////////////////////////////////////////////////////// //
359 bool isExitingSprite () {
360 auto spr = getSprite();
361 return (spr.Name == 'sPExit' || spr.Name == 'sDamselExit' || spr.Name == 'sTunnelExit');
365 // ////////////////////////////////////////////////////////////////////////// //
366 override void playSound (name aname, optional bool unique) {
367 if (unique && global.sndIsPlaying(0, aname)) return;
368 global.playSound(0, 0, 0, aname); // it is local
372 override bool sndIsPlaying (name aname) {
373 return global.sndIsPlaying(0, aname);
377 override void sndStopSound (name aname) {
378 global.sndStopSound(0, aname);
382 // ////////////////////////////////////////////////////////////////////////// //
383 transient ItemDice currDie;
385 void onDieRolled (ItemDice die) {
386 if (!die.forSale) return;
387 // only law-abiding players can play
388 if (global.thiefLevel > 0 || global.murderer) return;
389 if (bet == 0) return;
392 level.forEachObject(delegate bool (MapObject o) {
393 MonsterShopkeeper sc = MonsterShopkeeper(o);
394 if (sc && !sc.dead && !sc.angered) return sc.onDiePlayed(self, currDie);
401 // ////////////////////////////////////////////////////////////////////////// //
402 override bool onExplosionTouch (MapObject xplo) {
403 //writeln("PlayerPawn: on explo touch! ", invincible);
404 if (invincible) return false;
405 if (global.config.scumExplosionHurt) {
406 global.plife -= global.config.explosionDmg;
407 if (!dead && global.plife <= 0 /*&& isRealLevel()*/) {
408 auto xp = MapObjExplosion(xplo);
409 if (xp && xp.suicide) level.addDeath('suicide'); else level.addDeath('explosion');
412 if (global.config.scumExplosionStun) {
418 if (xplo.ix < ix) xVel = global.randOther(4, 6); else xVel = -global.randOther(4, 6);
424 // ////////////////////////////////////////////////////////////////////////// //
425 // start new game when exiting from title, and process other custom exits
426 void scrPlayerExit () {
427 level.playerExited = true;
433 // ////////////////////////////////////////////////////////////////////////// //
434 bool scrHideItemToPocket (optional bool forBombOrRope) {
435 if (!holdItem) return true;
436 if (holdItem isa PlayerWeapon) return false;
437 if (holdItem.forSale) return false;
438 if (!forBombOrRope) {
439 if (holdItem isa ItemBall) return false;
442 // cannot hide armed bomb
443 ItemBomb bomb = ItemBomb(holdItem);
444 if (bomb && bomb.armed) return false;
445 if (bomb || holdItem isa ItemRopeThrow) {
446 holdItem.instanceRemove();
452 if (holdItem isa MapEnemy) return false;
453 //writeln("hiding: '", GetClassName(holdItem.Class), "'");
455 if (pickedItem) FatalError("we are already holding '%n'", GetClassName(pickedItem.Class));
456 pickedItem = holdItem;
458 pickedItem.active = false;
459 pickedItem.visible = false;
460 pickedItem.sellOfferDone = false;
461 if (pickedItem.heldBy) FatalError("oooops (scrHideItemToPocket)");
466 bool scrSwitchToBombs () {
467 if (holdItem isa PlayerWeapon) return false;
469 if (global.bombs < 1) return false;
470 if (ItemBomb(holdItem)) return true;
471 if (!scrHideItemToPocket(forBombOrRope:true)) return false;
473 ItemBomb bomb = ItemBomb(level.MakeMapObject(ix, iy, 'oBomb'));
474 if (!bomb) return false;
475 bomb.setSticky(global.stickyBombsActive);
477 whoaTimer = whoaTimerMax;
482 bool scrSwitchToStickyBombs () {
483 if (holdItem isa PlayerWeapon) return false;
484 if (!global.hasStickyBombs) {
485 global.stickyBombsActive = false;
489 global.stickyBombsActive = !global.stickyBombsActive;
494 bool scrSwitchToRopes () {
495 if (holdItem isa PlayerWeapon) return false;
497 if (global.rope < 1) return false;
498 if (ItemRopeThrow(holdItem)) return true;
499 if (!scrHideItemToPocket(forBombOrRope:true)) return false;
501 ItemRopeThrow rope = ItemRopeThrow(level.MakeMapObject(ix, iy, 'oRopeThrow'));
502 if (!rope) return false;
504 whoaTimer = whoaTimerMax;
509 bool isHoldingBombOrRope () {
511 if (!hit) return false;
512 return (hit isa ItemBomb || hit isa ItemRopeThrow);
516 bool isHoldingBomb () {
518 if (!hit) return false;
519 return (hit isa ItemBomb);
523 bool isHoldingArmedBomb () {
524 auto hit = ItemBomb(holdItem);
525 if (!hit) return false;
530 bool isHoldingRope () {
532 if (!hit) return false;
533 return (hit isa ItemRopeThrow);
537 bool scrSwitchToPocketItem (bool forceIfEmpty) {
538 if (holdItem isa PlayerWeapon) return false;
539 if (holdItem && holdItem.forSale) return false;
541 if (holdItem == pickedItem) {
543 whoaTimer = whoaTimerMax;
544 if (holdItem) holdItem.sellOfferDone = false;
548 if (!forceIfEmpty && !pickedItem) return false;
550 // destroy currently holded item if it is a bomb or a rope
552 // you cannot do it with an armed bomb
553 if (holdItem isa MapEnemy) return false; // cannot hide an enemy
554 ItemBomb bomb = ItemBomb(holdItem);
555 if (bomb && bomb.armed) return false;
556 if (bomb || holdItem isa ItemRopeThrow) {
558 holdItem.instanceRemove();
562 writeln(va("cannot switch to pocket item while carrying '%n' ('%n' is in pocket, why?)", GetClassName(holdItem.Class), GetClassName(pickedItem.Class)));
568 auto oldHold = holdItem;
569 holdItem = pickedItem;
570 pickedItem = oldHold;
571 // all flag management is done in property handler
573 oldHold.active = false;
574 oldHold.visible = false;
575 oldHold.sellOfferDone = false;
577 if (holdItem) holdItem.sellOfferDone = false;
578 whoaTimer = whoaTimerMax;
583 bool scrSwitchToNextItem () {
584 if (holdItem isa PlayerWeapon) return false;
585 if (holdItem && holdItem.forSale) return false;
588 if (ItemBomb(holdItem)) {
589 if (ItemBomb(holdItem).armed) return false; // cannot switch out of armed bomb
590 if (scrSwitchToRopes()) return true;
591 return scrSwitchToPocketItem(forceIfEmpty:true);
595 if (ItemRopeThrow(holdItem)) {
596 if (scrSwitchToPocketItem(forceIfEmpty:true)) return true;
597 if (scrSwitchToBombs()) return true;
598 return scrHideItemToPocket();
601 // either nothing, or normal item
602 bool tryPocket = !!holdItem;
603 if (scrSwitchToBombs()) return true;
604 if (scrSwitchToRopes()) return true;
605 if (holdItem isa ItemBall) return false;
606 if (tryPocket) return scrSwitchToPocketItem(forceIfEmpty:true);
611 // ////////////////////////////////////////////////////////////////////////// //
612 bool scrPickupItem (MapObject obj) {
613 if (holdItem isa PlayerWeapon) return false;
615 if (!obj) return false;
618 if (pickedItem) return false;
619 if (isHoldingArmedBomb()) return false;
620 if (isHoldingBombOrRope()) {
621 if (!scrSwitchToPocketItem(forceIfEmpty:true)) return false;
623 if (holdItem) return false;
626 if (pickedItem) return false;
629 if (obj isa ItemBomb && !ItemBomb(obj).armed) ++global.bombs;
630 else if (obj isa ItemRopeThrow) ++global.rope;
632 whoaTimer = whoaTimerMax;
633 obj.onPickedUp(self);
638 // drop currently held item
639 bool scrDropItem (LostCause cause, optional float xVel, optional float yVel) {
640 if (holdItem isa PlayerWeapon) return false;
642 if (!holdItem) return false;
644 if (!onLoosingHeldItem(cause)) return false;
649 if (!hi.onLostAsHeldItem(self, cause, xVel!optional, yVel!optional)) {
655 if (hi isa ItemRopeThrow) global.rope = max(0, global.rope-1);
656 else if (hi isa ItemBomb && !ItemBomb(hi).armed) global.bombs = max(0, global.bombs-1);
660 scrSwitchToPocketItem(forceIfEmpty:true);
665 // ////////////////////////////////////////////////////////////////////////// //
666 void scrUseThrowIt (MapObject it) {
669 it.onBeforeThrowBy(self);
674 if (dir == Dir.Left) {
675 it.xVel = (it.heavy ? -4+xVel : -8+xVel);
676 //foreach (; 0..8) if (level.isSolidAtPoint(ix-8, iy)) it.shiftX(1);
677 //while (!level.isSolidAtPoint(ix-8, iy)) it.shiftX(1); // prevent getting stuck in wall
678 } else if (dir == Dir.Right) {
679 it.xVel = (it.heavy ? 4+xVel : 8+xVel);
680 //foreach (; 0..8) if (level.isSolidAtPoint(ix+8, iy)) it.shiftX(-1);
681 //while (!level.isSolidAtPoint(ix+8, iy)) it.shiftX(-1); // prevent getting stuck in wall
683 it.yVel = (it.heavy ? (kUp ? -4 : -2) : (kUp ? -9 : -3));
684 if (kDown || scrPlayerIsDucking()) {
685 if (platformCharacterIs(ON_GROUND)) {
692 } else if (!global.hasMitt) {
693 if (dir == Dir.Left) {
694 if (level.isSolidAtPoint(ix-8, iy-10)) {
698 } else if (dir == Dir.Right) {
699 if (level.isSolidAtPoint(ix+8, iy-10)) {
706 if (global.hasMitt && !scrPlayerIsDucking()) {
707 it.xVel += (it.xVel < 0 ? -6 : 6);
708 if (!kUp && !kDown) it.yVel = -0.4;
709 else if (kDown) it.yVel = 6;
713 // prevent getting stuck in a wall
714 if (it.isCollision()) {
715 //foreach (; 0..8) if (level.isSolidAtPoint(ix-8, iy)) it.shiftX(1);
717 if (level.isSolidAtPoint(it.ix-8, it.iy)) it.shiftX(8);
718 } else if (it.xVel > 0) {
719 if (level.isSolidAtPoint(it.ix+8, it.iy)) it.shiftX(-8);
720 } else if (it.isCollision()) {
721 int dx = (it.isCollisionLeft(0) ? 1 : it.isCollisionRight(0) ? -1 : 0);
725 if (!it.isCollision()) break;
731 while (dx > 8 && it.isCollisionLeft(dx)) ++dx;
732 if (dx < 8) it.shiftX(8);
735 while (dx > 8 && it.isCollisionRight(dx)) ++dx;
736 if (dx < 8) it.shiftX(-8);
742 if (it.sprite_index == sBombBag ||
743 it.sprite_index == sBombBox ||
744 it.sprite_index == sRopePile)
748 playSound('sndThrow');
751 auto proj = ItemProjectile(it);
752 if (proj) proj.launchedByPlayer = true;
756 bool scrUseThrowItem () {
757 if (holdItem isa PlayerWeapon) return false;
759 auto hitem = holdItem;
761 if (!hitem) return false;
762 if (!onLoosingHeldItem(LostCause.Unknown)) return false;
767 scrUseThrowIt(hitem);
769 // if we throwing away armed bomb, get previous item back into our hands
771 if (/*ItemBomb(hitem)*/isHoldingBombOrRope()) scrSwitchToPocketItem(forceIfEmpty:false);
777 // ////////////////////////////////////////////////////////////////////////// //
778 bool scrPlayerIsDucking () {
779 if (dead) return false;
780 auto spr = getSprite();
781 //if (!spr) return false;
783 spr.Name == 'sDuckLeft' ||
784 spr.Name == 'sCrawlLeft' ||
785 spr.Name == 'sDamselDuckL' ||
786 spr.Name == 'sDamselCrawlL' ||
787 spr.Name == 'sTunnelDuckL' ||
788 spr.Name == 'sTunnelCrawlL';
793 if (holdItem !isa ItemWeaponBow) return false;
794 sndStopSound('sndBowPull');
795 if (!bowArmed) return false;
796 if (!holdItem.onTryUseItem(self)) return false;
801 void scrUsePutItOnGroundHelper (MapObject it, optional float xVelMult, optional float yVelNew) {
804 if (!specified_xVelMult) xVelMult = 0.4;
805 if (!specified_yVelNew) yVelNew = 0.5;
807 //writeln("putting '", GetClassName(hi.Class), "'");
809 if (dir == Dir.Left) {
810 it.xVel = (it.heavy ? -4 : -8);
811 } else if (dir == Dir.Right) {
812 it.xVel = (it.heavy ? 4 : 8);
820 if (ItemGoldIdol(it)) it.flty = iy;
823 if (it.isCollisionBottom(0) && !it.isCollisionTop(1)) {
831 if (it.isCollisionLeft(0)) {
832 if (it.isCollisionRight(1)) break;
834 } else if (it.isCollisionRight(0)) {
835 if (it.isCollisionLeft(1)) break;
844 // put item which player holds in his hands on the ground if player is ducking
845 // return `true` if item was put
846 bool scrUsePutItemOnGround (optional float xVelMult, optional float yVelNew) {
847 if (holdItem isa PlayerWeapon) return false;
850 if (!hi || !scrPlayerIsDucking()) return false;
852 if (!onLoosingHeldItem(LostCause.Unknown)) return false;
854 //writeln("putting '", GetClassName(hi.Class), "'");
856 if (global.bombs > 0) {
857 auto bomb = ItemBomb(hi);
858 if (bomb && !bomb.armed) global.bombs -= 1;
861 if (global.rope > 0) {
862 auto rope = ItemRopeThrow(hi);
865 rope.falling = false;
875 scrUsePutItOnGroundHelper(hi, xVelMult!optional, yVelNew!optional);
881 bool launchRope (bool goDown, bool doDrop) {
882 if (global.rope < 1) {
884 if (ItemRopeThrow(holdItem)) scrSwitchToPocketItem(forceIfEmpty:false);
890 bool wasHeld = false;
891 ItemRopeThrow rp = ItemRopeThrow(holdItem);
892 int xdelta = (doDrop ? 12 : 16)*(dir == Dir.Left ? -1 : 1);
894 //FIXME: call handler
897 rp.setXY(ix+xdelta, iy);
899 rp = ItemRopeThrow(level.MakeMapObject(ix+xdelta, iy, 'oRopeThrow'));
901 if (rp.heldBy) FatalError("PlayerPawn::launchRope: hold management fucked");
904 //rp.resaleValue = 0;
908 if (platformCharacterIs(ON_GROUND)) rp.startY = iy; // YASM 1.7
920 if (!level.isSolidAtPoint(ix+(doDrop ? 2 : 8), iy)) { //2
921 if (!level.checkTilesInRect(rp.ix-8, rp.iy, 2, 17)) rp.shiftX(-8);
922 else if (!level.checkTilesInRect(rp.ix+7, rp.iy, 2, 17)) rp.shiftX(8);
927 } else if (!level.isSolidAtPoint(ix-(doDrop ? 2 : 8), iy)) { //2
928 if (!level.checkTilesInRect(rp.ix+7, rp.iy, 2, 17)) rp.shiftX(8);
929 else if (!level.checkTilesInRect(rp.ix-8, rp.iy, 2, 17)) rp.shiftX(-8);
936 // cannot launch rope
937 /* was commented in the original
938 if (oPlayer1.facing == 18) {
939 obj = instance_create(oPlayer1.x-4, oPlayer1.y+2, oRopeThrow);
942 obj = instance_create(oPlayer1.x+4, oPlayer1.y+2, oRopeThrow);
947 //writeln("!!! goDown=", goDown, "; doDrop=", doDrop, "; wasHeld=", wasHeld);
950 if (!wasHeld) doDrop = true;
954 if (dir == Dir.Left) rp.xVel = -3.2; else rp.xVel = 3.2;
957 rp.forceFixHoldCoords(self);
959 scrUsePutItOnGroundHelper(rp);
963 if (wasHeld) scrSwitchToPocketItem(forceIfEmpty:false);
965 //writeln("NO DROP!");
969 //rp.resaleValue = 1; //k8:???
973 if (wasHeld) scrSwitchToPocketItem(forceIfEmpty:false);
978 level.MakeMapObject(rp.ix, rp.iy, 'oRopeTop');
985 if (wasHeld) scrSwitchToPocketItem(forceIfEmpty:false);
986 playSound('sndThrow');
991 bool scrLaunchBomb () {
992 if (whipping || global.bombs < 1) return false;
995 ItemBomb bomb = ItemBomb(level.MakeMapObject(ix, iy, 'oBomb'));
996 if (!bomb) return false;
997 bomb.forceFixHoldCoords(self);
998 bomb.setSticky(global.stickyBombsActive);
1000 bomb.resaleValue = 0;
1002 if (kDown || scrPlayerIsDucking()) {
1003 scrUsePutItOnGroundHelper(bomb);
1005 scrUseThrowIt(bomb);
1012 bool scrUseItem () {
1014 if (!it) return false;
1015 //writeln(GetClassName(holdItem.Class));
1017 //auto spr = holdItem.getSprite();
1019 } else if (holdItem.type == "Sceptre") {
1020 if (kDown) scrUsePutItemOnGround(0.4, 0.5);
1021 if (firing == 0 && !scrPlayerIsDucking()) {
1022 if (facing == LEFT) {
1031 obj = instance_create(x+xofs, y+4, oPsychicCreateP);
1032 obj.xVel = xsgn*rand(1, 3);
1033 obj.yVel = -random(2);
1035 obj = instance_create(x+xofs, y-2, oPsychicWaveP);
1037 playSound(global.sndPsychic);
1038 firing = firingPistolMax;
1040 } else if (holdItem.type == "Teleporter II") {
1041 scrUseTeleporter2();
1042 } else if (holdItem.type == "Bow") {
1044 scrUsePutItemOnGround(0.4, 0.5);
1045 } else if (firing == 0 && !scrPlayerIsDucking() && !bowArmed && global.arrows > 0) {
1047 playSound(global.sndBowPull);
1048 } else if (global.arrows <= 0) {
1049 global.message = "I'M OUT OF ARROWS!";
1050 global.message2 = "";
1051 global.messageTimer = 80;
1057 if (whipping) return false;
1060 if (scrPlayerIsDucking()) scrUsePutItemOnGround();
1064 // you cannot throw away shop items, but can throw dices
1065 if (it.forSale && it !isa ItemDice) {
1066 if (!level.isInShop(ix/16, iy/16)) {
1069 // allow throw/use shop items
1074 //if (it.forSale) writeln(":::FORSALE 000: '", GetClassName(it.Class), "'");
1075 if (!it.onTryUseItem(self)) {
1076 //if (it.forSale) writeln(":::FORSALE 001: '", GetClassName(it.Class), "'");
1085 // ////////////////////////////////////////////////////////////////////////// //
1086 // called by characterStepEvent
1087 // help player jump up through one block wide gaps by nudging them to one side so they don't hit their head
1088 void scrJumpHelper () {
1089 int d = 4; // max distance to nudge player
1091 if (!level.checkTilesInRect(x, y-12, 1, 7)) {
1092 if (level.checkTilesInRect(x-5, y-12, 1, 7) &&
1093 level.checkTilesInRect(x+14, y-12, 1, 7))
1095 while (d > 0 && level.checkTilesInRect(x-5, y-12, 1, 7)) { ++x; shiftX(1); --d; }
1096 } else if (level.checkTilesInRect(x+5, y-12, 1, 7) &&
1097 level.checkTilesInRect(x-14, y-12, 1, 7))
1099 while (d > 0 && level.checkTilesInRect(x+5, y-12, 1, 7)) { --x; shiftX(-1); --d; }
1103 if (!collision_line(x, y-6, x, y-12, oSolid, 0, 0)) {
1104 if (collision_line(x-5, y-6, x-5, y-12, oSolid, 0, 0) &&
1105 collision_line(x+14, y-6, x+14, y-12, oSolid, 0, 0))
1107 while (collision_line(x-5, y-6, x-5, y-12, oSolid, 0, 0) && d > 0) {
1112 else if (collision_line(x+5, y-6, x+5, y-12, oSolid, 0, 0) and
1113 collision_line(x-14, y-6, x-14, y-12, oSolid, 0, 0))
1115 while (collision_line(x+5, y-6, x+5, y-12, oSolid, 0, 0) && d > 0) {
1125 // ////////////////////////////////////////////////////////////////////////// //
1127 * Returns whether a GENERAL trait about a character is true.
1128 * Only the platform character should run this script.
1130 * `tp` can be one of the following:
1135 final bool platformCharacterIs (int tp) {
1136 if (tp == ON_GROUND && (status == RUNNING || status == STANDING || status == DUCKING || status == LOOKING_UP)) return true;
1137 if (tp == IN_AIR && (status == JUMPING || status == FALLING)) return true;
1138 if (tp == ON_LADDER && status == CLIMBING) return true;
1143 // ////////////////////////////////////////////////////////////////////////// //
1144 // sets the sprite of the character depending on his/her status
1145 final void characterSprite () {
1146 if (status == STOPPED) {
1147 if (global.isDamsel) setSprite('sDamselLeft');
1148 else if (global.isTunnelMan) setSprite('sTunnelLeft');
1149 else setSprite('sStandLeft');
1154 if (global.isTunnelMan && !stunned && !whipping) {
1156 if (status == STANDING) {
1157 if (!level.isSolidAtPoint(x-2, y+9)) {
1159 setSprite('sTunnelWhoaL');
1161 setSprite('sTunnelLeft');
1164 if (status == RUNNING) {
1165 if (kUp) setSprite('sTunnelLookRunL'); else setSprite('sTunnelRunL');
1167 if (status == DUCKING) {
1168 if (xVel == 0) setSprite('sTunnelDuckL');
1169 else if (fabs(xVel) < 3) setSprite('sTunnelCrawlL');
1170 else setSprite('sTunnelRunL');
1172 if (status == LOOKING_UP) {
1173 if (fabs(xVel) > 0) setSprite('sTunnelRunL'); else setSprite('sTunnelLookL');
1175 if (status == JUMPING) setSprite('sTunnelJumpL');
1176 if (status == FALLING && statePrev == FALLING && statePrevPrev == FALLING) setSprite('sTunnelFallL');
1177 if (status == HANGING) setSprite('sTunnelHangL');
1178 if (pushTimer > 20) setSprite('sTunnelPushL');
1179 if (status == DUCKTOHANG) setSprite('sTunnelDtHL');
1180 if (status == CLIMBING) {
1181 if (level.isRopeAtPoint(x, y)) {
1182 if (kDown) setSprite('sTunnelClimb3'); else setSprite('sTunnelClimb2');
1184 setSprite('sTunnelClimb');
1187 } else if (global.isDamsel && !stunned && !whipping) {
1189 if (status == STANDING) {
1190 if (!level.isSolidAtPoint(x-2, y+9)) {
1192 setSprite('sDamselWhoaL');
1193 /* was commented out in the original
1194 if (holdItem && whoaTimer < 1) {
1195 holdItem.held = false;
1196 if (facing == LEFT) holdItem.xVel = -2; else holdItem.xVel = 2;
1197 if (holdItem.type == "Damsel") playSound('sndDamsel');
1198 if (holdItem.type == pickupItemType) { holdItem = 0; pickupItemType = ""; } else scrSwitchToPocketItem();
1202 setSprite('sDamselLeft');
1205 if (status == RUNNING) {
1206 if (kUp) setSprite('sDamselRunL'); else setSprite('sDamselRunL');
1208 if (status == DUCKING) {
1209 if (xVel == 0) setSprite('sDamselDuckL');
1210 else if (fabs(xVel) < 3) setSprite('sDamselCrawlL');
1211 else setSprite('sDamselRunL');
1213 if (status == LOOKING_UP) {
1214 if (fabs(xVel) > 0) setSprite('sDamselRunL'); else setSprite('sDamselLookL');
1216 if (status == JUMPING) setSprite('sDamselDieLR');
1217 if (status == FALLING && statePrev == FALLING && statePrevPrev == FALLING) setSprite('sDamselFallL');
1218 if (status == HANGING) setSprite('sDamselHangL');
1219 if (pushTimer > 20) setSprite('sDamselPushL');
1220 if (status == DUCKTOHANG) setSprite('sDamselDtHL');
1221 if (status == CLIMBING) {
1222 if (level.isRopeAtPoint(x, y)) {
1223 if (kDown) setSprite('sDamselClimb3'); else setSprite('sDamselClimb2');
1225 setSprite('sDamselClimb');
1228 } else if (!stunned && !whipping) {
1230 if (status == STANDING) {
1231 if (!level.checkTileAtPoint(x-(dir == Dir.Left ? 2 : 0), y+9, &level.cbCollisionForWhoa)) {
1233 setSprite('sWhoaLeft');
1234 /* was commented out in the original
1235 if (holdItem && whoaTimer < 1) {
1236 holdItem.held = false;
1237 if (facing == LEFT) holdItem.xVel = -2; else holdItem.xVel = 2;
1238 if (holdItem.type == "Damsel") playSound('sndDamsel');
1239 if (holdItem.type == pickupItemType) { holdItem = 0; pickupItemType = ""; } else scrSwitchToPocketItem();
1243 setSprite('sStandLeft');
1246 if (status == RUNNING) {
1247 if (kUp) setSprite('sLookRunL'); else setSprite('sRunLeft');
1249 if (status == DUCKING) {
1250 if (xVel == 0) setSprite('sDuckLeft');
1251 else if (fabs(xVel) < 3) setSprite('sCrawlLeft');
1252 else setSprite('sRunLeft');
1254 if (status == LOOKING_UP) {
1255 if (fabs(xVel) > 0) setSprite('sLookRunL'); else setSprite('sLookLeft');
1257 if (status == JUMPING) setSprite('sJumpLeft');
1258 if (status == FALLING && statePrev == FALLING && statePrevPrev == FALLING) setSprite('sFallLeft');
1259 if (status == HANGING) setSprite('sHangLeft');
1260 if (pushTimer > 20) setSprite('sPushLeft');
1261 if (status == CLIMBING) {
1262 if (level.isRopeAtPoint(x, y)) {
1263 if (kDown) setSprite('sClimbUp3'); else setSprite('sClimbUp2');
1265 setSprite('sClimbUp');
1268 if (status == DUCKTOHANG) setSprite('sDuckToHangL');
1274 // ////////////////////////////////////////////////////////////////////////// //
1275 void addScore (int delta) {
1276 if (!level.isNormalLevel()) return;
1278 if (delta == 0) return;
1279 level.stats.addMoney(delta);
1281 level.xmoney += delta;
1282 level.collectCounter = min(100, level.collectCounter+20);
1287 // ////////////////////////////////////////////////////////////////////////// //
1288 // for dead players too
1289 // first, the code will call `onObjectTouched()` for player
1290 // if it returned `false`, the code will call `obj.onTouchedByPlayer()`
1291 // note that player's handler is called *after* its frame thinker,
1292 // but object handler is called *before* frame thinker for the object
1293 // i.e. return `true` to block calling `obj.onTouchedByPlayer()`,
1294 // (but NOT object thinker)
1295 bool onObjectTouched (MapObject obj) {
1297 if (dead || global.plife <= 0) return false; // player may be rendered dead, but not yet transited to dead state
1299 if (obj isa ItemProjectileArrow && holdItem isa ItemWeaponBow && !stunned && global.arrows < 99) {
1300 if (fabs(obj.xVel) < 1 && fabs(obj.yVel) < 1 && !obj.stuck) {
1302 playSound('sndPickup');
1303 obj.instanceRemove();
1309 auto treasure = ItemTreasure(obj);
1310 if (treasure && treasure.canCollect) {
1311 if (treasure.value) addScore(treasure.value);
1312 treasure.onCollected(self); // various other effects
1313 playSound(treasure.soundName);
1314 treasure.instanceRemove();
1319 if (global.hasKapala && obj isa MapObjBlood) {
1320 global.bloodLevel += 1;
1321 level.MakeMapObject(obj.ix, obj.iy, 'oBloodSpark');
1322 obj.instanceRemove();
1324 if (global.bloodLevel > 8) {
1325 global.bloodLevel = 0;
1327 level.MakeMapObject(ix, iy-8, 'oHeart');
1328 playSound('sndKiss');
1331 if (redColor < 55) redColor += 5;
1335 // other objects will take care of themselves
1340 // return `false` to prevent
1341 // holdItem is valid
1342 bool onLoosingHeldItem (LostCause cause) {
1343 if (level.inWinCutscene != 0) return false;
1348 // ////////////////////////////////////////////////////////////////////////// //
1349 // k8: don't even ask me! the following mess is almost straightforward port of the original Derek's code!
1350 private final void closeCape () {
1351 auto pp = PPCape(findPowerup('Cape'));
1352 if (pp) pp.open = false;
1356 private final void switchCape () {
1357 auto pp = PPCape(findPowerup('Cape'));
1358 if (pp) pp.open = !pp.open;
1362 final bool isCapeActiveAndOpen () {
1363 auto pp = PPCape(findPowerup('Cape'));
1364 return (pp && pp.active && pp.open);
1368 final bool isParachuteActive () {
1369 auto pp = findPowerup('Parachute');
1370 return (pp && pp.active);
1374 // ////////////////////////////////////////////////////////////////////////// //
1376 bool checkSkipCutScene () {
1377 if (skipCutscenePressed) {
1378 return level.isKeyReleased(GameConfig::Key.Pay);
1380 skipCutscenePressed = level.isKeyPressed(GameConfig::Key.Pay);
1388 bool forcePlayerControls () {
1389 if (level.inWinCutscene) {
1391 level.winCutscenePlayerControl(self);
1393 } else if (level.inIntroCutscene) {
1395 level.introCutscenePlayerControl(self);
1398 } else if (level.levelKind == GameLevel::LevelKind.Transition) {
1401 if (checkSkipCutScene()) {
1402 level.playerExited = true;
1406 auto door = level.checkTileAtPoint(ix, iy, &level.cbCollisionExitTile);
1408 kExitPressed = true;
1412 if (status == STOPPED) {
1413 if (--transKissTimer > 0) return true;
1418 auto dms = MonsterDamselKiss(level.isObjectAtPoint(ix+8, iy+4, delegate bool (MapObject o) { return (o isa MonsterDamselKiss); }));
1419 if (dms && !dms.kissed) {
1424 transKissTimer = 30;
1429 kRightPressed = true;
1436 // ////////////////////////////////////////////////////////////////////////// //
1437 private final void checkControlKeys (SpriteImage spr) {
1438 if (forcePlayerControls()) {
1439 if (movementBlocked) unpressAllKeys();
1440 if (kLeft) kLeftPushedSteps += 1; else kLeftPushedSteps = 0;
1441 if (kRight) kRightPushedSteps += 1; else kRightPushedSteps = 0;
1445 kLeft = level.isKeyDown(GameConfig::Key.Left);
1446 if (movementBlocked) kLeft = false;
1447 if (kLeft) kLeftPushedSteps += 1; else kLeftPushedSteps = 0;
1448 kLeftPressed = level.isKeyPressed(GameConfig::Key.Left);
1449 kLeftReleased = level.isKeyReleased(GameConfig::Key.Left);
1451 kRight = level.isKeyDown(GameConfig::Key.Right);
1452 if (movementBlocked) kRight = false;
1453 if (kRight) kRightPushedSteps += 1; else kRightPushedSteps = 0;
1454 kRightPressed = level.isKeyPressed(GameConfig::Key.Right);
1455 kRightReleased = level.isKeyReleased(GameConfig::Key.Right);
1457 kUp = level.isKeyDown(GameConfig::Key.Up);
1458 kDown = level.isKeyDown(GameConfig::Key.Down);
1460 kJump = level.isKeyDown(GameConfig::Key.Jump);
1461 kJumpPressed = level.isKeyPressed(GameConfig::Key.Jump);
1462 kJumpReleased = level.isKeyReleased(GameConfig::Key.Jump);
1464 if (movementBlocked) unpressAllKeys();
1468 kJumpPressed = false;
1469 kJumpReleased = false;
1471 } else if (spr && global.isTunnelMan && spr.Name == 'sTunnelAttackL' && !holdItem) {
1473 kJumpPressed = false;
1474 kJumpReleased = false;
1475 cantJump = max(0, cantJump-1);
1478 kAttack = level.isKeyDown(GameConfig::Key.Attack);
1479 kAttackPressed = level.isKeyPressed(GameConfig::Key.Attack);
1480 kAttackReleased = level.isKeyReleased(GameConfig::Key.Attack);
1482 kItemPressed = level.isKeyPressed(GameConfig::Key.Switch);
1483 kRopePressed = level.isKeyPressed(GameConfig::Key.Rope);
1484 kBombPressed = level.isKeyPressed(GameConfig::Key.Bomb);
1486 kPayPressed = level.isKeyPressed(GameConfig::Key.Pay);
1488 if (movementBlocked) unpressAllKeys();
1490 kExitPressed = false;
1491 if (global.config.useDoorWithButton) {
1492 if (kPayPressed) kExitPressed = true;
1494 if (kUp) kExitPressed = true;
1497 if (stunned || dead) {
1499 //level.clearKeysPressRelease();
1504 // ////////////////////////////////////////////////////////////////////////// //
1505 // knock off monkeys that grabbed you
1506 void knockOffMonkeys () {
1507 level.forEachObject(delegate bool (MapObject o) {
1508 auto mk = EnemyMonkey(o);
1509 if (mk && !mk.dead && mk.status == GRAB) {
1510 mk.xVel = global.randOther(0, 1)-global.randOther(0, 1);
1513 mk.vineCounter = 20;
1514 mk.grabCounter = 60;
1521 // ////////////////////////////////////////////////////////////////////////// //
1522 // fix collision with boulder (bug with non-aligned boulder)
1523 void hackBoulderCollision () {
1524 auto bld = level.checkTilesInRect(x0, y0, width, height, delegate bool (MapTile o) { return (o isa ObjBoulder); });
1525 if (bld && fabs(bld.xVel) <= 1) {
1526 writeln("IN BOULDER!");
1529 writeln(" LEFT: dx=", dx);
1530 if (dx <= 2) fltx = x0-dx;
1531 } else if (x1 > bld.x1) {
1533 writeln(" RIGHT: dx=", dx);
1534 if (dx <= 2) fltx = x1-dx;
1540 // ////////////////////////////////////////////////////////////////////////// //
1541 bool checkHangTileDG (MapTile t) { return (t.solid || t.tree); }
1544 void checkPerformHang (bool colLeft, bool colRight) {
1545 if (status == HANGING || platformCharacterIs(ON_GROUND)) return;
1546 if ((kLeft && kRight) || (!kLeft && !kRight)) return;
1547 if (kLeft && !colLeft) {
1549 writeln("checkPerformHang: no left solid");
1553 if (kRight && !colRight) {
1555 writeln("checkPerformHang: no right solid");
1559 if (hangCount != 0) {
1561 writeln("checkPerformHang: hangCount=", hangCount);
1565 if (iy <= 16) return;
1566 int dx = (kLeft ? -9 : 9);
1568 writeln("checkPerformHang: trying to hang at ", dx);
1571 bool doHang = false;
1573 if (global.hasGloves) {
1574 doHang = (yVel > 0 && !!level.checkTilesInRect(ix+dx, iy-6, 1, 2, &checkHangTileDG));
1577 doHang = !!level.checkTilesInRect(ix+dx, iy-6, 1, 2, &level.cbCollisionAnyTree);
1579 writeln(" tree: ", doHang);
1583 doHang = level.checkTilesInRect(ix+dx, iy-6, 1, 2) &&
1584 !level.isSolidAtPoint(ix+dx, iy-9) && !level.isSolidAtPoint(ix, iy+9);
1586 writeln(" solid: ", doHang);
1591 writeln(" solid at dx, -6(1): ", !!level.checkTilesInRect(ix+dx, iy-6, 1, 2));
1592 writeln(" solid at dx, -9(0): ", !!level.isSolidAtPoint(ix+dx, iy-9));
1593 writeln(" solid at 0, +9(0): ", !!level.isSolidAtPoint(ix, iy-9));
1596 doHang = level.checkTilesInRect(ix+dx, iy-6, 1, 2) &&
1597 !level.isSolidAtPoint(ix+dx, iy-10) && !level.isSolidAtPoint(ix, iy+9);
1599 if (!doHang) writeln(" easier hang failed");
1602 if (!level.isSolidAtPoint(ix, iy-9)) {
1603 foreach (int dy; 6..24) {
1604 writeln(" solid at dx:-", dy, "(0): ", !!level.isSolidAtPoint(ix+dx, iy-dy));
1606 writeln(" ix=", ix, "; iy=", iy);
1623 // ////////////////////////////////////////////////////////////////////////// //
1624 final void characterStepEvent () {
1625 if (climbSoundTimer > 0) {
1626 if (--climbSoundTimer == 0) {
1627 playSound(climbSndToggle ? 'sndClimb2' : 'sndClimb1');
1628 climbSndToggle = !climbSndToggle;
1632 auto spr = getSprite();
1633 checkControlKeys(spr);
1635 float xPrev = fltx, yPrev = flty;
1638 // check collisions in various directions
1639 bool colSolidLeft = !!getPushableLeft(1);
1640 bool colSolidRight = !!getPushableRight(1);
1641 bool colLeft = !!isCollisionLeft(1);
1642 bool colRight = !!isCollisionRight(1);
1643 bool colTop = !!isCollisionTop(1);
1644 bool colBot = !!isCollisionBottom(1);
1645 bool colLadder = !!isCollisionLadder();
1646 bool colPlatBot = !!isCollisionBottom(1, &level.cbCollisionPlatform);
1647 bool colPlat = !!isCollision(&level.cbCollisionPlatform);
1648 //bool colWaterTop = !!isCollisionTop(1, &level.cbCollisionWater);
1649 bool colWaterTop = !!level.checkTilesInRect(x0, y0-1, width, 3, &level.cbCollisionWater);
1650 bool colIceBot = !!level.isIceAtPoint(x, y+8);
1652 bool runKey = false;
1653 if (level.isKeyDown(GameConfig::Key.Run)) { runHeld = 100; runKey = true; }
1654 if (level.isKeyDown(GameConfig::Key.Attack) && !whipping) { runHeld += 1; runKey = true; }
1655 if (!runKey || (!kLeft && !kRight)) runHeld = 0;
1657 // allows the character to run left and right
1658 // if state!=DUCKING and state!=LOOKING_UP and state!=CLIMBING
1659 if (status != CLIMBING && status != HANGING) {
1660 if (kLeftReleased && fabs(xVel) < 0.0001) xAcc -= 0.5;
1661 if (kRightReleased && fabs(xVel) < 0.0001) xAcc += 0.5;
1662 if (kLeft && !kRight) {
1664 //xVel = 3; // in orig
1665 if (platformCharacterIs(ON_GROUND) && status != DUCKING) {
1668 //playSound('sndPush', unique:true);
1670 } else if (kLeftPushedSteps > 2 && (dir == Dir.Left || fabs(xVel) < 0.0001)) {
1674 //if (platformCharacterIs(ON_GROUND) && fabs(xVel) > 0 && alarm[3] < 1) alarm[3] = floor(16/-xVel);
1676 if (kRight && !kLeft) {
1677 if (colSolidRight) {
1678 //xVel = 3; // in orig
1679 if (platformCharacterIs(ON_GROUND) && status != DUCKING) {
1682 //playSound('sndPush', unique:true);
1684 } else if ((kRightPushedSteps > 2 || colSolidLeft) && (dir == Dir.Right || fabs(xVel) < 0.0001)) {
1688 //if (platformCharacterIs(ON_GROUND) && fabs(xVel) > 0 && alarm[3] < 1) alarm[3] = floor(16/xVel);
1693 if (status == CLIMBING) {
1697 auto ladder = level.isLadderAtPoint(x, y);
1698 if (ladder) { x = ladder.ix+8; setX(x); }
1699 if (kLeft) dir = Dir.Left; else if (kRight) dir = Dir.Right;
1701 // checks both ladder and laddertop
1702 if (level.isAnyLadderAtPoint(x, y-8)) {
1703 //writeln("LADDER00! old yAcc=", yAcc, "; climbAcc=", climbAcc, "; new yAcc=", yAcc-climbAcc);
1705 if (climbSoundTimer < 1) climbSoundTimer = climbSndSpeed;
1706 //!if (alarm[2] < 1) alarm[2] = climbSndSpeed;
1709 for (int dy = -6; dy > -12; --dy) {
1710 ladder = level.isAnyLadderAtPoint(x, y+dy);
1712 writeln("::: ", dy, ": plrx=", x, "; ladder.xy0=(", ladder.x0, ",", ladder.y0, "); ladder.ixy=(", ladder.ix, ",", ladder.iy, "); wdt=", ladder.width, "; hgt=", ladder.height, "; ladder class=", GetClassName(ladder.Class));
1717 auto grid = level.miscTileGrid;
1718 foreach (MapTile t; grid.inCellPix(48, 96, grid.nextTag(), precise:false)) {
1719 writeln("at 48, 96: ", GetClassName(t.Class), "; pos=(", t.ix, ",", t.iy, ")");
1721 foreach (MapTile t; grid.inCellPix(48, 94, grid.nextTag(), precise:false)) {
1722 writeln("at 48, 94: ", GetClassName(t.Class), "; pos=(", t.ix, ",", t.iy, ")");
1724 foreach (int dy; 90..102) {
1725 ladder = level.isAnyLadderAtPoint(48, dy);
1727 writeln("::: ", dy, ": plrx=", x, "; ladder.xy0=(", ladder.x0, ",", ladder.y0, "); ladder.ixy=(", ladder.ix, ",", ladder.iy, "); wdt=", ladder.width, "; hgt=", ladder.height, "; ladder class=", GetClassName(ladder.Class));
1733 // checks both ladder and laddertop
1734 if (level.isAnyLadderAtPoint(x, y+8)) {
1736 //!if (alarm[2] < 1) alarm[2] = climbSndSpeed;
1737 if (climbSoundTimer < 1) climbSoundTimer = climbSndSpeed;
1741 if (colBot) status = STANDING;
1744 if (kJumpPressed && !whipping) {
1745 if (kLeft) xVel = -departLadderXVel; else if (kRight) xVel = departLadderXVel; else xVel = 0;
1746 //yAcc += departLadderYVel;
1747 //k8: was `0.6`, but with `0.4` we can jump onto the wall above, and with `0.6` we cannot
1748 yAcc = 0.4+departLadderYVel; // YASM 1.8.1 Fix for extra air when jumping off ladders due to increased climb speed option
1750 jumpButtonReleased = false;
1755 if (ladderTimer > 0) ladderTimer -= 1;
1758 if (platformCharacterIs(IN_AIR) && status != HANGING) yAcc += gravityIntensity;
1760 // player has landed
1761 if ((colBot || colPlatBot) && platformCharacterIs(IN_AIR) && yVel >= 0) {
1762 if (!colPlat || colBot) {
1767 playSound('sndLand');
1769 if ((colBot || colPlatBot) && !colPlat) yVel = 0;
1771 // player has just walked off of the edge of a solid
1772 if (colBot == 0 && (!colPlatBot || colPlat) && platformCharacterIs(ON_GROUND)) {
1776 if (global.hasGloves) hangCount = 5;
1780 if (dead || stunned) yVel = -yVel*0.8;
1781 else if (status == JUMPING) yVel = fabs(yVel*0.3);
1784 if ((colLeft && dir == Dir.Left) || (colRight && dir == Dir.Right)) {
1785 if (dead || stunned) xVel = -xVel*0.5; else xVel = 0;
1789 if (kJumpReleased && platformCharacterIs(IN_AIR)) {
1791 } else if (platformCharacterIs(ON_GROUND)) {
1796 MapObject oWeb = none, oBlob = none;
1798 oWeb = level.isObjectAtPoint(x, y, &level.cbIsObjectWeb);
1799 if (!oWeb) oBlob = level.isObjectAtPoint(x, y, &level.cbIsObjectBlob);
1802 bool invokeJumpHelper = false;
1804 if (kJumpPressed && oWeb) {
1805 ItemWeb(oWeb).tear(1);
1806 yAcc += initialJumpAcc*2;
1811 jumpButtonReleased = false;
1815 invokeJumpHelper = true;
1816 } else if (kJumpPressed && oBlob) {
1818 scrCreateBloblets(oBlob.x0+8, oBlob.y0+8, 1);
1819 playSound('sndHit');
1820 yAcc += initialJumpAcc*2;
1824 jumpButtonReleased = false; // k8: was `jumpButtonRelease`
1826 invokeJumpHelper = true;
1827 } else if (kJumpPressed && colWaterTop) {
1828 yAcc += initialJumpAcc*2;
1833 jumpButtonReleased = false;
1837 invokeJumpHelper = true;
1838 } else if (global.hasCape && kJumpPressed && kJumped && platformCharacterIs(IN_AIR)) {
1840 } else if (global.hasJetpack && !swimming && kJump && kJumped && platformCharacterIs(IN_AIR) && jetpackFuel > 0) {
1841 yAcc += initialJumpAcc;
1844 if (jetpackFlaresTime < 1) jetpackFlaresTime = 3;
1845 //!if (alarm[10] < 1) alarm[10] = 3; // jetpack flares
1849 jumpButtonReleased = false;
1853 invokeJumpHelper = true;
1854 } else if (platformCharacterIs(ON_GROUND) && kJumpPressed && fallTimer == 0) {
1855 if (fabs(xVel) > 3 /*xVel > 3 || xVel < -3*/) {
1856 yAcc += initialJumpAcc*2;
1859 yAcc += initialJumpAcc*2;
1861 //scrJumpHelper(); // move to location where player doesn't have to be on ground
1863 if (global.hasJordans) {
1867 } else if (global.hasSpringShoes) {
1874 playSound('sndJump');
1878 // the "state" gets changed to JUMPING later on in the code
1880 // "variable jumping" states
1881 jumpButtonReleased = false;
1883 invokeJumpHelper = true;
1886 if (kJumpPressed && invokeJumpHelper) scrJumpHelper(); // YASM 1.8.1
1888 if (jumpTime < jumpTimeTotal) jumpTime += 1;
1889 // let the character continue to jump
1890 if (!kJump) jumpButtonReleased = true;
1891 if (jumpButtonReleased) jumpTime = jumpTimeTotal;
1893 gravityIntensity = (jumpTime/jumpTimeTotal)*grav;
1895 if (kUp && platformCharacterIs(ON_GROUND) && !colLadder) {
1896 //k8:!!!looking = UP;
1897 if (xVel == 0 && xAcc == 0) status = LOOKING_UP;
1899 //k8:!!!looking = 0;
1902 if (!kUp && status == LOOKING_UP) status = STANDING;
1906 checkPerformHang(colLeft, colRight);
1910 // hang on stuck arrow
1911 if (status == FALLING && hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND) &&
1912 !level.isSolidAtPoint(x, y+12)) // from Spelunky Natural
1914 auto arrow = level.isObjectInRect(ix, iy, 16, 16, delegate bool (MapObject o) {
1917 writeln(" ARROW : (", o.x0, ",", o.y0, ")-(", o.x1, ",", o.y1, "); coll=", o.collidesWith(self));
1918 writeln(" PLAYER: (", x0, ",", y0, ")-(", x1, ",", y1, "); coll=", self.collidesWith(o), "; dy=", iy-o.iy);
1920 if (o.stuck && iy-o.iy >= -6 && iy-o.iy <= -5 && o.collidesWith(self)) {
1921 //writeln(" *** HANG IS POSSIBLE! p5=", !!level.isObjectAtPoint(ix, iy-5, &level.cbIsObjectArrow), "; p6=", !!level.isObjectAtPoint(ix, iy-6, &level.cbIsObjectArrow));
1925 }, castClass:ItemProjectileArrow, precise:false);
1928 // move_snap(1, 8); // was commented out in the original
1934 writeln("TRYING ARROW HANG ALLOWED");
1935 writeln(" Z00: ", !level.isObjectAtPoint(x, y-9, &level.cbIsObjectArrow));
1936 writeln(" Z01: ", !level.isObjectAtPoint(x, y+9, &level.cbIsObjectArrow));
1937 writeln(" Z02: ", !!level.isObjectAtPoint(x, y-5, &level.cbIsObjectArrow));
1938 writeln(" Z03: ", !!level.isObjectAtPoint(x, y-6, &level.cbIsObjectArrow));
1939 level.isObjectInRect(ix, iy, 16, 16, delegate bool (MapObject o) {
1941 writeln(" ARROW : (", o.x0, ",", o.y0, ")-(", o.x1, ",", o.y1, "); coll=", o.collidesWith(self));
1942 writeln(" PLAYER: (", x0, ",", y0, ")-(", x1, ",", y1, "); coll=", self.collidesWith(o), "; dy=", iy-o.iy);
1943 if (iy-o.iy >= -6 && iy-o.iy <= -5 && o.collidesWith(self)) {
1944 writeln(" *** HANG IS POSSIBLE! p5=", !!level.isObjectAtPoint(ix, iy-5, &level.cbIsObjectArrow), "; p6=", !!level.isObjectAtPoint(ix, iy-6, &level.cbIsObjectArrow));
1947 }, castClass:ItemProjectileArrow, precise:false);
1951 // hang on stuck arrow
1952 /*k8: this is not working due to collision issues; see the fixed code above
1953 if (status == FALLING && hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND) &&
1954 !level.isSolidAtPoint(x, y+12) && // from Spelunky Natural
1955 !level.isObjectAtPoint(x, y-9, &level.cbIsObjectArrow) && !level.isObjectAtPoint(x, y+9, &level.cbIsObjectArrow))
1957 //obj = instance_nearest(x, y-5, oArrow);
1958 auto arr0 = level.isObjectAtPoint(x, y-5, &level.cbIsObjectArrow);
1959 auto arr1 = level.isObjectAtPoint(x, y-6, &level.cbIsObjectArrow);
1961 writeln("ARROW HANG!");
1962 // get nearest arrow
1965 arr = (arr0.distanceToPoint(x, y-5) < arr1.distanceToPoint(x, y-5) ? arr0 : arr1);
1967 arr = (arr0 ? arr0 : arr1);
1971 // move_snap(1, 8); // was commented out in the original
1979 /* this was commented in the original
1980 if (hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND) && state == FALLING &&
1981 (collision_point(x, y-5, oTreeBranch, 0, 0) || collision_point(x, y-6, oTreeBranch, 0, 0)) &&
1982 !collision_point(x, y-9, oTreeBranch, 0, 0) && !collision_point(x, y+9, oTreeBranch, 0, 0))
1985 // move_snap(1, 8); // was commented out in the original
1993 if (hangCount > 0) --hangCount;
1995 if (status == HANGING) {
2000 if (global.hasGloves) {
2001 if (hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND)) {
2002 if (kRight && colRight &&
2003 (level.isSolidAtPoint(x+9, y-5) || level.isSolidAtPoint(x+9, y-6)))
2009 } else if (kLeft && colLeft &&
2010 (level.isSolidAtPoint(x-9, y-5) || level.isSolidAtPoint(x-9, y-6)))
2032 yAcc += initialJumpAcc*2;
2033 shiftX(dir == Dir.Right ? -2 : 2);
2036 hangCount = hangCountMax;
2037 if (level.isObjectAtPoint(x, y-5, &level.cbIsObjectArrow) || level.isObjectAtPoint(x, y-6, &level.cbIsObjectArrow)) hangCount /= 2; //Spelunky Natural
2040 if ((dir == Dir.Left && !isCollisionLeft(2)) ||
2041 (dir == Dir.Right && !isCollisionRight(2)))
2052 // pressing down while standing
2053 if (kDown && platformCharacterIs(ON_GROUND) && !whipping) {
2056 } else if (colPlatBot) {
2057 // climb down ladder if possible, else jump down
2060 //ladder = instance_place(x, y+16, oLadder);
2062 // from Spelunky Natural
2064 ladder = collision_line(x-4, y+16, x+4, y+16, oLadder, 0, 0);
2065 if (!ladder) ladder = collision_line(x-4, y+16, x+4, y+16, oLadderTop, 0, 0);
2067 auto ladder = level.checkTilesInRect(x-4, y+16, 9, 1, &level.cbCollisionAnyLadder);
2068 //writeln("DOWN; cpb=", colPlatBot, "; cb=", colBot, "; ladder=", !!ladder);
2071 if (abs(x-(ladder.x0+8)) < 4) {
2085 kJumped = true; // Spelunky Natural
2089 // the character can't move down because there is a solid in the way
2094 if (!kDown && status == DUCKING) {
2099 if (xVel == 0 && xAcc == 0 && status == RUNNING) status = STANDING;
2100 if (xAcc != 0 && status == STANDING) status = RUNNING;
2101 if (yVel < 0 && platformCharacterIs(IN_AIR) && status != HANGING) status = JUMPING;
2102 if (yVel > 0 && platformCharacterIs(IN_AIR) && status != HANGING) status = FALLING;
2103 setCollisionBounds(-5, -6, 5, 8);
2106 bool colPointLadder = !!level.isAnyLadderAtPoint(x, y);
2108 /* this was commented in the original
2109 if ((kUp && platformCharacterIs(IN_AIR) && collision_point(x, y-8, oLadder, 0, 0) && ladderTimer == 0) ||
2110 (kUp && colPointLadder && ladderTimer == 0) ||
2111 (kDown && colPointLadder && ladderTimer == 0 && platformCharacterIs(ON_GROUND) && collision_point(x, y+9, oLadderTop, 0, 0) && xVel == 0))
2114 ladder = instance_place(x, y-8, oLadder);
2115 if (instance_exists(ladder)) {
2116 if (abs(x-(ladder.x0+8)) < 4) {
2119 if (!collision_point(x, y, oLadder, 0, 0) && !collision_point(x, y, oLadderTop, 0, 0)) { y = ladder.iy+14; setY(y); }
2129 // Spelunky Natural - Multiple changes to this big "if" condition
2130 if ((kUp && platformCharacterIs(IN_AIR) && ladderTimer == 0 && level.checkTilesInRect(x-2, y-8, 5, 1, &level.cbCollisionLadder)) ||
2131 (kUp && colPointLadder && ladderTimer == 0) ||
2132 (kDown && colPointLadder && ladderTimer == 0 && platformCharacterIs(ON_GROUND) && xVel == 0 && level.isLadderTopAtPoint(x, y+9)) ||
2133 ((kUp || kDown) && status == HANGING && level.checkTilesInRect(x-2, y, 5, 1, &level.cbCollisionLadder)))
2136 //auto ladder = instance_place(x, y-8, oLadder);
2137 auto ladder = level.isLadderAtPoint(x, y-8);
2139 //writeln("LADDER01! plrx=", x, "; ladder.x0=", ladder.x0, "; ladder.ix=", ladder.ix, "; ladder class=", GetClassName(ladder.Class));
2140 if (abs(x-(ladder.x0+8)) < 4) {
2143 if (!level.isAnyLadderAtPoint(x, y)) { y = ladder.y0+14; setY(y); }
2153 /* this was commented in the original
2154 if (sprite_index == sDuckToHangL || sprite_index == sDamselDtHL) {
2156 if (facing == LEFT && collision_rectangle(x-8, y, x, y+16, oLadder, 0, 0) && !collision_point(x-4, y+16, oSolid, 0, 0)) {
2157 ladder = instance_nearest(x-4, y+16, oLadder);
2158 } else if (facing == RIGHT && collision_rectangle(x, y, x+8, y+16, oLadder, 0, 0) && !collision_point(x+4, y+16, oSolid, 0, 0)) {
2159 ladder = instance_nearest(x+4, y+16, oLadder);
2172 if (colLadder && state == CLIMBING && kJumpPressed && !whipping) {
2173 if (kLeft) xVel = -departLadderXVel; else if (kRight) xVel = departLadderXVel; else xVel = 0;
2174 yAcc += departLadderYVel;
2176 jumpButtonReleased = false;
2182 // calculate horizontal/vertical friction
2183 if (status == CLIMBING) {
2184 xFric = frictionClimbingX;
2185 yFric = frictionClimbingY;
2187 //if (runKey && platformCharacterIs(ON_GROUND) && runHeld >= 10)
2188 if ((runKey && runHeld >= 10) && (platformCharacterIs(ON_GROUND) || global.config.toggleRunAnywhere)) {
2194 xFric = frictionRunningFastX;
2195 } else if (kRight) {
2198 xFric = frictionRunningFastX;
2200 } else if (status == DUCKING) {
2201 if (xVel < 2 && xVel > -2) {
2205 } else if (kLeft && global.config.downToRun) {
2209 xFric = frictionRunningFastX;
2210 } else if (kRight && global.config.downToRun) {
2213 xFric = frictionRunningFastX;
2216 if (xVel < 0.5) xVel = 0;
2222 // decrease the friction when the character is "flying"
2223 if (platformCharacterIs(IN_AIR)) {
2224 if (dead || stunned) xFric = 1.0; else xFric = 0.8;
2226 xFric = frictionRunningX;
2230 /* // ORIGINAL RUN/WALK xVel/xFric code this was commented in the original
2231 if (runKey && platformCharacterIs(ON_GROUND) && runHeld >= 10) {
2236 xFric = frictionRunningFastX;
2237 } else if (kRight) {
2240 xFric = frictionRunningFastX;
2242 } else if (state == DUCKING) {
2243 if (xVel < 2 && xVel > -2) {
2247 } else if (kLeft && global.downToRun) {
2251 xFric = frictionRunningFastX;
2252 } else if (kRight && global.downToRun) {
2255 xFric = frictionRunningFastX;
2258 if (xVel < 0.5) xVel = 0;
2264 // decrease the friction when the character is "flying"
2265 if (platformCharacterIs(IN_AIR)) {
2266 if (dead || stunned) xFric = 1.0; else xFric = 0.8;
2268 xFric = frictionRunningX;
2273 // stuck on web or underwater
2274 if (level.isObjectAtPoint(x, y, &level.cbIsObjectWeb)) {
2278 } else if (level.isObjectAtPoint(x, y, &level.cbIsObjectBlob)) {
2280 //obj = instance_place(x, y, oBlob); this was commented in the original
2281 //xVel += obj.xVel; this was commented in the original
2285 } else if (level.isWaterAtPoint(x, y/*, oWater, -1, -1*/)) {
2287 //if (!runKey && global.toggleRunAnywhere) xFric = frictionRunningX; // YASM 1.8.1 this was commented in the original
2288 if (!platformCharacterIs(ON_GROUND)) xFric = frictionRunningX;
2289 if (status == FALLING && yVel > 0) {
2291 if (global.config.naturalSwim && kUp) yFric = 0.2;
2292 else if (global.config.naturalSwim && kDown) yFric = 0.8;
2294 } else if (!level.isWaterAtPoint(x, y-9/*, oWater, -1, -1*/)) {
2299 if (yVel < -6 && global.config.noDolphin) {
2300 // Spelunky Natural (changed from -4 to -6)
2309 if (colIceBot && status != DUCKING && !global.hasSpikeShoes) {
2315 if (global.config.toggleRunAnywhere) {
2316 if (!kJump && !kDown && !runKey) xVelLimit = 3;
2320 if (platformCharacterIs(ON_GROUND)) {
2321 if (status == RUNNING && kLeft && colLeft) pushTimer += 1;
2322 else if (status == RUNNING && kRight && colRight) pushTimer += 1;
2325 //if (platformCharacterIs(ON_GROUND) && !kJump && !kDown && !runKey) this was commented in the original
2326 if (!kJump && !kDown && !runKey) xVelLimit = 3;
2328 /* this was commented in the original
2330 if (state == DUCKING && fabs(xVel) < 3 && facing == LEFT &&
2331 //collision_point(x, y+9, oSolid, 0, 0) && !collision_point(x-1, y+9, oSolid, 0, 0) && kLeft)
2332 collision_point(x, y+9, oSolid, 0, 0) && !collision_line(x-1, y+9, x-10, y+9, oSolid, 0, 0) && kLeft)
2337 if (kLeft && dir == Dir.Left) dhdir = -1;
2338 else if (kRight && dir == Dir.Right) dhdir = 1;
2340 if (dhdir && status == DUCKING && fabs(xVel) < 3+(dhdir < 0 ? 1 : 0) &&
2341 level.isSolidAtPoint(x, y+9) && !level.checkTilesInRect(x+(dhdir < 0 ? -8 : 1), y+9, 8, 8))
2343 status = DUCKTOHANG;
2345 if (!global.config.scumFlipHold || holdItem.heavy) {
2347 holdItem.heldBy = none;
2348 if (holdItem.objName == 'GoldIdol') holdItem.shiftY(-8);
2350 //else if (holdItem.type == "Block Item") { with (oBlockPreview) instance_destroy(); }
2351 scrDropItem(LostCause.Hang, (dir == Dir.Left ? -1 : 1), -4);
2358 if (status == DUCKTOHANG) {
2359 setXY(xPrev, yPrev);
2369 // parachute and cape
2370 if (!level.inWinCutscene) {
2371 if (isParachuteActive() || isCapeActiveAndOpen()) yFric = 0.5;
2374 if (pushTimer > 100) pushTimer = 100;
2376 // limits the acceleration if it is too extreme
2377 xAcc = fclamp(xAcc, -xAccLimit, xAccLimit);
2378 yAcc = fclamp(yAcc, -yAccLimit, yAccLimit);
2380 // applies the acceleration
2382 if (dead || stunned) yVel += 0.6; else yVel += yAcc;
2384 // nullifies the acceleration
2388 // applies the friction to the velocity, now that the velocity has been calculated
2392 auto oBall = getMyBall();
2393 // apply ball and chain
2395 int distsq = (ix-oBall.ix)*(ix-oBall.ix)+(iy-oBall.iy)*(iy-oBall.iy);
2396 if (distsq >= 24*24) {
2397 if (xVel > 0 && oBall.ix < ix && abs(oBall.ix-ix) > 24) xVel = 0;
2398 if (xVel < 0 && oBall.ix > ix && abs(oBall.ix-ix) > 24) xVel = 0;
2399 if (yVel > 0 && oBall.iy < iy && abs(oBall.iy-iy) > 24) {
2400 if (abs(oBall.ix-ix) < 1) {
2401 //teleportTo(destx:oBall.ix);
2403 prevFltX = oBall.prevFltX;
2405 } else if (oBall.ix < ix && !kRight) {
2406 if (xVel > 0) xVel *= -0.25;
2407 else if (xVel == 0) xVel -= 1;
2408 } else if (oBall.ix > ix && !kLeft) {
2409 if (xVel < 0) xVel *= -0.25;
2410 else if (xVel == 0) xVel += 1;
2415 if (yVel < 0 && oBall.iy > iy && abs(oBall.iy-iy) > 24) yVel = 0;
2419 // apply the limits since the velocity may be too extreme
2420 if (!dead && !stunned) xVel = fclamp(xVel, -xVelLimit, xVelLimit);
2421 yVel = fclamp(yVel, -yVelLimit, yVelLimit);
2423 // approximates the "active" variables
2424 if (fabs(xVel) < 0.0001) xVel = 0;
2425 if (fabs(yVel) < 0.0001) yVel = 0;
2426 if (fabs(xAcc) < 0.0001) xAcc = 0;
2427 if (fabs(yAcc) < 0.0001) yAcc = 0;
2429 bool wasInWall = !!isCollision();
2430 moveRel(xVel, yVel);
2432 // don't go out of level (if we're not in ending sequence)
2433 if (!level.inWinCutscene && !level.inIntroCutscene) {
2434 if (ix < 0) fltx = 0;
2435 else if (ix > level.tilesWidth*16-16) fltx = level.tilesWidth*16-16;
2436 if (iy < 0) flty = 0;
2438 if (!dead) hackBoulderCollision();
2440 if (!wasInWall && isCollision()) {
2441 writeln("** FUUUU (XXX)");
2442 if (isCollisionBottom(0) && !isCollisionBottom(-2)) {
2445 // we can stuck in the wall with this
2446 if (isCollisionLeft(0)) {
2447 writeln("** FUUUU (001: left)");
2448 while (isCollisionLeft(0) && !isCollisionRight(1)) shiftX(1);
2449 } else if (isCollisionRight(0)) {
2450 writeln("** FUUUU (001: right)");
2451 while (isCollisionRight(0) && !isCollisionLeft(1)) shiftX(-1);
2455 if (!dead) hackBoulderCollision();
2457 // move out of wall by 1 px, if possible
2458 if (!dead && isCollision()) {
2459 if (isCollisionBottom(0) && !isCollisionBottom(-1)) flty = iy-1;
2460 if (isCollisionTop(0) && !isCollisionTop(1)) flty = iy+1;
2461 if (isCollisionLeft(0) && !isCollisionLeft(1)) fltx = ix+1;
2462 if (isCollisionRight(0) && !isCollisionRight(-1)) fltx = ix-1;
2465 if (!dead && isCollision()) {
2466 //k8:HACK: try to duck
2467 bool wallDeath = true;
2468 if (platformCharacterIs(ON_GROUND)) {
2469 setCollisionBounds(-5, -6, 5, 8);
2470 auto ohbX = hitboxX, ohbY = hitboxY;
2471 auto ohbW = hitboxW, ohbH = hitboxH;
2472 wallDeath = !!isCollision();
2474 //setCollisionBounds(-8, -6, 8, 8);
2475 hitboxX = ohbX; hitboxY = ohbY;
2476 hitboxW = ohbW; hitboxH = ohbH;
2485 if (isCollision()) {
2486 if (isCollisionLeft(0) && !isCollisionRight(4)) fltx = ix+1;
2487 else if (isCollisionRight(0) && !isCollisionLeft(4)) fltx = ix-1;
2488 else if (isCollisionBottom(0) && !isCollisionTop(4)) flty = iy-1;
2489 else if (isCollisionTop(0) && !isCollisionBottom(4)) flty = iy+1;
2494 if (wallDeath && isCollision()) {
2495 if (!dead) level.addDeath('wall');
2498 writeln("PLAYER KILLED BY WALL");
2499 global.plife = 0; // oops
2505 //writeln("flty=", flty, "; iy=", iy);
2511 // figures out what the sprite index of the character should be
2514 // sets the previous state and the previously previous state
2515 statePrevPrev = statePrev;
2518 // calculates the imageSpeed based on the character's velocity
2519 if (status == RUNNING || status == DUCKING || status == LOOKING_UP) {
2520 if (status == RUNNING || status == LOOKING_UP) imageSpeed = fabs(xVel)*runAnimSpeed+0.1;
2523 if (status == CLIMBING) imageSpeed = sqrt(xVel*xVel+yVel*yVel)*climbAnimSpeed;
2525 if (xVel >= 4 || xVel <= -4) {
2527 if (platformCharacterIs(ON_GROUND)) {
2528 setCollisionBounds(-8, -6, 8, 8);
2530 setCollisionBounds(-5, -6, 5, 8);
2533 setCollisionBounds(-5, -6, 5, 8);
2536 if (whipping) imageSpeed = 1;
2538 if (status == DUCKTOHANG) {
2543 // limit the imageSpeed at 1 so the animation always looks good
2544 if (imageSpeed > 1) imageSpeed = 1;
2546 //if (kItemPressed) writeln("ITEM! dead=", dead, "; stunned=", stunned, "; active=", active);
2547 if (dead || stunned || !active) {
2549 } else if (/*inGame &&*/ kItemPressed && !whipping) {
2551 if (kUp) scrSwitchToStickyBombs(); else scrSwitchToNextItem();
2552 } else if (/*inGame &&*/ kRopePressed && global.rope > 0 && !whipping) {
2553 if (!kDown && colTop) {
2556 launchRope(kDown, doDrop:true);
2558 } else if (/*inGame &&*/ kBombPressed && global.bombs > 0 && !whipping) {
2559 if (holdItem isa ItemWeaponBow && bowArmed) {
2560 if (holdArrow != ARROW_BOMB) {
2561 //writeln("set bow arrows to bomb");
2562 holdArrow = ARROW_BOMB;
2564 //writeln("set bow arrows to normal");
2565 holdArrow = ARROW_NORM;
2574 if (!dead && !stunned && kUp && kAttackPressed) {
2575 auto octr = ItemOpenableContainer(level.isObjectInRect(ix, iy, width, height, delegate bool (MapObject o) {
2576 return (o isa ItemOpenableContainer);
2579 if (octr.openMe()) kAttackPressed = false;
2584 // use weapon / attack
2585 if (!dead && !stunned && kAttackPressed && !holdItem /*&& !pickedItem*/) {
2588 sndStopSound('sndBowPull');
2589 if (status != DUCKING && status != DUCKTOHANG && !whipping && !isExitingSprite()) {
2591 if (global.isTunnelMan) {
2592 if (platformCharacterIs(ON_GROUND) || platformCharacterIs(IN_AIR)) {
2593 setSprite('sTunnelAttackL');
2596 } else if (global.isDamsel) {
2597 setSprite('sDamselAttackL');
2600 setSprite('sAttackLeft');
2603 } else if (kDown && !pickedItem) {
2605 //HACK: always select dice to throw if there are two dices there
2606 MapObject diceToThrow = level.isObjectInRect(x-8, y, 9, 9, delegate bool (MapObject o) {
2607 if (o.spectral || !o.canPickUp) return false;
2608 if (ItemDice(o).isReadyToThrowForBet) return o.collidesWith(self);
2610 }, precise:false, castClass:ItemDice);
2615 obj = level.isObjectInRect(x-8, y, 9, 9, delegate bool (MapObject o) {
2616 if (o.spectral || !o.canPickUp) return false;
2617 if (!o.collidesWith(self)) return false;
2618 return o.onCanBePickedUp(self);
2620 if (o isa MapItem) return (o.active && o.canPickUp && !o.spectral);
2621 if (o isa MapEnemy) return (o.active && o.canPickUp && !o.spectral && (o.dead || o.status >= MapObject::STUNNED || o.meGoldMonkey));
2626 if (!obj && diceToThrow) obj = diceToThrow;
2628 // `canPickUp` is checked in callback
2629 if (/*obj.canPickUp &&*/ true /*k8: do we really need this? !level.isSolidAtPoint(obj.ix+2, obj.iy)*/) {
2630 //pickupItemType = holdItem.type;
2631 //!if (isAshShotgun(holdItem)) pickupItemType = "Boomstick";
2632 //!if (isGoldMonkey(obj) and obj.status < 98) obj.status = 0; // do not play walk animation while held
2634 if (!obj.onTryPickup(self)) {
2635 if (obj.isInstanceAlive) scrPickupItem(obj);
2639 if (holdItem.type == "Bow" and holdItem.new) {
2640 holdItem.new = false;
2642 if (global.arrows > 99) global.arrows = 99;
2648 } else if (!dead && !stunned) {
2649 if (holdItem isa ItemWeaponBow) {
2650 //writeln("BOW! kAttack=", kAttack, "; kAttackPressed=", kAttackPressed, "; bowArmed=", bowArmed, "; bowStrength=", bowStrength, "; holdArrow=", holdArrow);
2651 if (kAttackPressed) {
2652 if (scrPlayerIsDucking()) {
2653 scrUsePutItemOnGround();
2654 } else if (!bowArmed) {
2656 ItemWeaponBow(holdItem).armBow(self);
2660 if (bowArmed && bowStrength < 12) {
2662 //writeln("arming: ", bowStrength);
2664 sndStopSound('sndBowPull');
2667 //writeln(" xxBOW!");
2671 if (!holdArrow) holdArrow = ARROW_NORM;
2673 if (kAttackPressed && holdItem) scrUseItem();
2677 // remove held item offer
2678 if (!level.isInShop(ix/16, iy/16)) {
2679 if (holdItem) holdItem.sellOfferDone = false;
2680 if (pickedItem) pickedItem.sellOfferDone = false;
2684 if (!dead && !stunned && kPayPressed) {
2685 // find nearest shopkeeper
2686 auto sc = MonsterShopkeeper(level.findNearestObject(ix, iy, delegate bool (MapObject o) {
2687 auto sc = MonsterShopkeeper(o);
2688 if (!sc) return false;
2689 //if (needCraps && sc.stype != 'Craps') return false;
2690 if (sc.dead || sc.angered || sc.outlaw) return false;
2691 return sc.canSellItem(self, holdItem);
2693 if (level.isInShop(ix/16, iy/16)) {
2694 // if no shopkeepers found, just use it
2697 holdItem.forSale = false;
2698 holdItem.onTryPickup(self);
2700 } else if (global.thiefLevel == 0 && !global.murderer) {
2701 // only law-abiding players can buy/sell items or play games
2702 if (holdItem) writeln("shop item interaction: ", holdItem.objName, "; cost=", holdItem.cost);
2703 if (sc.doSellItem(self, holdItem)) {
2706 holdItem.forSale = false;
2707 holdItem.onTryPickup(self);
2710 if (holdItem && !holdItem.isInstanceAlive) {
2712 scrSwitchToPocketItem(forceIfEmpty:false); // just in case
2716 // use pickup, if any
2717 if (holdItem isa ItemPickup) {
2718 // make nearest shopkeeper angry (an unlikely situation, but still...)
2719 if (sc && holdItem.forSale) level.scrShopkeeperAnger(GameLevel::SCAnger.ItemStolen);
2720 holdItem.forSale = false;
2721 holdItem.onTryPickup(self);
2723 pickupsAround.clear();
2724 level.isObjectInRect(x0, y0, width, height, delegate bool (MapObject o) {
2725 auto pk = ItemPickup(o);
2726 if (pk && pk.collidesWith(self)) {
2728 foreach (auto opk; pickupsAround) if (opk == pk) { found = true; break; }
2729 if (!found) pickupsAround[$] = pk;
2733 // now try to use all pickups
2734 foreach (ItemPickup pk; pickupsAround) {
2735 if (pk.isInstanceAlive) {
2736 if (sc && pk.forSale) level.scrShopkeeperAnger(GameLevel::SCAnger.ItemStolen);
2738 pk.onTryPickup(self);
2741 pickupsAround.clear();
2747 transient array!ItemPickup pickupsAround;
2750 // ////////////////////////////////////////////////////////////////////////// //
2751 override bool initialize () {
2752 if (!::initialize()) return false;
2754 powerups.length = 0;
2755 powerups[$] = SpawnObject(PPParachute);
2756 powerups[$] = SpawnObject(PPCape);
2758 foreach (PlayerPowerup pp; powerups) pp.owner = self;
2760 if (global.isDamsel) {
2762 desc2 = "An athletic, unfittingly-dressed woman with extremely awkward running form.";
2763 setSprite('sDamselLeft');
2764 } else if (global.isTunnelMan) {
2765 desc = "Tunnel Man";
2766 desc2 = "A miner from the desert. His tools are a cut above the rest.";
2767 setSprite('sTunnelLeft');
2770 desc2 = "A strange little man who spends his time exploring caverns. He wants to be just like Indiana Jones when he grows up.";
2771 setSprite('sStandLeft');
2779 switch (global.config.scumClimbSpeed) {
2782 climbAnimSpeed = 0.4;
2787 climbAnimSpeed = 0.45;
2792 climbAnimSpeed = 0.5;
2797 climbAnimSpeed = 0.5;
2801 climbAcc = 0.6; // how fast the character will climb
2802 climbAnimSpeed = 0.4; // relates to how fast the climbing animation should go
2807 // sets the collision bounds to fit the default sprites (you can edit the arguments of the script)
2808 setCollisionBounds(-5, -5, 5, 8); // setCollisionBounds(-5, -8, 5, 8);
2811 statePrevPrev = statePrev;
2812 gravityIntensity = grav; // this variable describes the current force due to gravity (this variable is altered for variable jumping)
2813 jumpTime = jumpTimeTotal; // current time of the jump (0=start of jump, jumpTimeTotal=end of jump)
2819 // ////////////////////////////////////////////////////////////////////////// //
2820 override void onAnimationLooped () {
2821 auto spr = getSprite();
2822 if (spr.Name == 'sAttackLeft' || spr.Name == 'sDamselAttackL' || spr.Name == 'sTunnelAttackL') {
2824 if (holdItem) holdItem.visible = true;
2825 } else if (spr.Name == 'sDuckToHangL' || spr.Name == 'sDamselDtHL' || spr.Name == 'sTunnelDtHL') {
2835 if (dir == Dir.Left) {
2837 obj = level.isAnyLadderAtPoint(x-8, y);
2840 obj = level.isAnyLadderAtPoint(x+8, y);
2845 } else if (dir == Dir.Left) {
2855 } else if (isExitingSprite()) {
2857 //!global.cleanSolids = true;
2862 void activatePlayerWeapon () {
2864 if (holdItem isa PlayerWeapon) {
2865 auto wep = holdItem;
2867 wep.instanceRemove();
2871 if (global.config.unarmed) return;
2873 if (holdItem isa PlayerWeapon) {
2876 writeln("000: !!!!!!!");
2877 if (holdItem) writeln(" H(", GetClassName(holdItem.Class), "): '", holdItem.objType, "'");
2878 if (pickedItem) writeln(" P(", GetClassName(pickedItem.Class), "): '", pickedItem.objType, "'");
2880 auto wep = holdItem;
2882 wep.instanceRemove();
2887 if (holdItem) return;
2889 auto spr = getSprite();
2890 if (spr.Name != 'sAttackLeft' && spr.Name != 'sDamselAttackL' && spr.Name != 'sTunnelAttackL') return;
2892 if (imageFrame > 4) {
2893 //bool hitEnemy = (PlayerWeapon(holdItem) ? PlayerWeapon(holdItem).hitEnemy : false);
2894 if (global.isTunnelMan || pickedItem isa ItemWeaponMattock) {
2895 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oMattockHit');
2896 if (imageFrame < 7) playSound('sndWhip');
2897 } else if (pickedItem isa ItemWeaponMachete) {
2898 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oSlash');
2899 playSound('sndWhip');
2901 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oWhip');
2902 playSound('sndWhip');
2904 /+ not needed anymore
2906 holdItem.active = true;
2907 //if (PlayerWeapon(holdItem)) PlayerWeapon(holdItem).hitEnemy = hitEnemy;
2910 } else if (imageFrame < 2) {
2911 if (global.isTunnelMan || pickedItem isa ItemWeaponMattock) {
2912 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oMattockPre');
2913 } else if (pickedItem isa ItemWeaponMachete) {
2914 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oMachetePre');
2916 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? 16 : -16), iy, 'oWhipPre');
2918 /+ not needed anymore
2919 if (holdItem) holdItem.active = true;
2925 if (holdItem.type == "Machete") {
2926 obj = instance_create(x-16, y, oSlash);
2927 obj.sprite_index = sSlashLeft;
2928 playSound(global.sndWhip);
2929 } else if (holdItem.type == "Mattock") {
2930 obj = instance_create(x-16, y, oMattockHit);
2931 obj.sprite_index = sMattockHitL;
2932 if (image_index < 7) playSound(global.sndWhip);
2935 if (global.isTunnelMan) {
2936 obj = instance_create(x-16, y, oMattockHit);
2937 obj.sprite_index = sMattockHitL;
2938 if (image_index < 7) playSound(global.sndWhip);
2940 obj = instance_create(x-16, y, oWhip);
2941 if (global.scumWhipUpgrade == 1) obj.sprite_index = sWhipLongLeft; else obj.sprite_index = sWhipLeft;
2942 playSound(global.sndWhip);
2949 //bool webHit = false;
2951 bool doBreakWebsCB (MapObject o) {
2952 if (o isa ItemWeb) {
2955 if (fabs(xVel) > 1) {
2957 if (!o.dying) ItemWeb(o).life -= 5;
2961 if (fabs(yVel) > 1) {
2963 if (!o.dying) ItemWeb(o).life -= 5;
2973 void initiateExitSequence () {
2974 writeln("exit sequence initiated...");
2975 if (global.isDamsel) setSprite('sDamselExit');
2976 else if (global.isTunnelMan) setSprite('sTunnelExit');
2977 else setSprite('sPExit');
2984 /*k8: the following is done in `GameLevel`
2985 if (global.thiefLevel > 0) global.thiefLevel -= 1;
2986 //orig dbg:if (global.currLevel == 1) global.currLevel += firstLevelSkip; else global.currLevel += levelSkip;
2987 global.currLevel += 1;
2989 playSound('sndSteps');
2993 void processLevelExit () {
2994 if (dead || stunned || whipping || level.playerExited) return;
2995 if (!platformCharacterIs(ON_GROUND)) return;
2996 if (isExitingSprite()) return; // just in case
2998 auto hld = holdItem;
2999 if (hld isa PlayerWeapon) return; // oops
3001 //if (!kExitPressed && !hld) return false;
3003 auto door = level.checkTileAtPoint(ix, iy, &level.cbCollisionExitTile);
3004 if (!door || !door.visible) return; // note that `invisible` doors still works
3006 // sell idol, or free damsel
3007 if (hld isa ItemGoldIdol) {
3008 //!if (isRealLevel()) global.idolsConverted += 1;
3009 //not thisglobal.money += hld.value*(global.levelType+1);
3010 ItemGoldIdol(hld).registerConverted();
3011 addScore(hld.value*(global.levelType+1));
3012 //!if (hld.sprite_index == sCrystalSkull) global.skulls += 1; else global.idols += 1;
3013 playSound('sndCoin');
3014 level.MakeMapObject(ix, iy-8, 'oBigCollect');
3016 hld.instanceRemove();
3017 //!with (hld) instance_destroy();
3019 //!pickupItemType = "";
3020 } else if (hld isa MonsterDamsel) {
3022 MonsterDamsel(hld).exitAtDoor(door);
3025 if (!kExitPressed) {
3026 if (!door.invisible) {
3027 string msg = door.getExitMessage();
3028 if (msg.length == 0) {
3029 level.osdMessage(va("PRESS %s TO ENTER.", (global.config.useDoorWithButton ? "$PAY" : "$UP")), -666);
3030 } else if (msg[$-1] != '\n') {
3031 level.osdMessage(va("%s\nPRESS %s TO ENTER.", msg, (global.config.useDoorWithButton ? "$PAY" : "$UP")), -666);
3033 level.osdMessage(msg, -666);
3044 if (isHoldingArmedBomb()) scrUseThrowItem();
3046 if (isHoldingBombOrRope()) scrSwitchToPocketItem(forceIfEmpty:true);
3048 wasHoldingBall = false;
3051 if (hld isa ItemGoldIdol) {
3052 //!if (isRealLevel()) global.idolsConverted += 1;
3053 //not thisglobal.money += hld.value*(global.levelType+1);
3054 ItemGoldIdol(hld).registerConverted();
3055 addScore(hld.value*(global.levelType+1));
3056 //!if (hld.sprite_index == sCrystalSkull) global.skulls += 1; else global.idols += 1;
3057 playSound('sndCoin');
3058 level.MakeMapObject(ix, iy-8, 'oBigCollect');
3060 hld.instanceRemove();
3061 //!with (hld) instance_destroy();
3063 //!pickupItemType = "";
3064 } else if (hld isa MonsterDamsel) {
3066 MonsterDamsel(hld).exitAtDoor(door);
3067 } else if (hld.heavy || hld isa MapEnemy) {
3068 // drop heavy items, characters and enemies (but not ball)
3069 if (hld !isa ItemBall) scrUseThrowItem();
3070 } else if (hld isa ItemBall) {
3072 // other items are carried thru
3073 if (hld.cannotBeCarriedOnNextLevel) {
3075 holdItem = none; // just in case
3077 scrHideItemToPocket();
3080 global.pickupItem = hld.type;
3081 if (isAshShotgun(hld)) global.pickupItem = "Boomstick";
3083 breakPieces = false;
3087 //scrHideItemToPocket();
3093 //door = instance_place(x, y, oExit); // done above
3094 door.snapToExit(self);
3096 initiateExitSequence();
3098 level.playerExitDoor = door;
3102 override bool onFellInWater (MapTile water) {
3103 level.MakeMapObject(ix, iy-8, 'oSplash');
3105 playSound('sndSplash');
3106 myGrav = 0.2; //k8:???
3111 override bool onOutOfWater () {
3118 // ////////////////////////////////////////////////////////////////////////// //
3119 override void thinkFrame () {
3120 // remove whip, etc. when dead
3121 if (dead && holdItem isa PlayerWeapon) {
3124 pw.instanceRemove();
3125 scrSwitchToPocketItem(forceIfEmpty:false);
3128 setPowerupState('Cape', global.hasCape);
3130 foreach (PlayerPowerup pp; powerups) if (pp.active) pp.onPreThink();
3134 if (redToggle) redColor -= 5;
3135 else if (redColor < 20) redColor += 5;
3136 else redToggle = true;
3141 if (dead) justdied = false;
3144 if (invincible > 0) --invincible;
3150 blinkHidden = !blinkHidden;
3153 blinkHidden = false;
3156 auto spr = getSprite();
3159 cameraBlockX = max(0, cameraBlockX-1);
3160 cameraBlockY = max(0, cameraBlockY-1);
3163 if (spr.Name == 'sWhoaLeft' || spr.Name == 'sDamselWhoaL' || spr.Name == 'sTunnelWhoaL') {
3164 if (whoaTimer > 0) {
3166 } else if (holdItem && onLoosingHeldItem(LostCause.Whoa)) {
3169 if (!hi.onLostAsHeldItem(self, LostCause.Whoa)) {
3173 scrSwitchToPocketItem(forceIfEmpty:true);
3177 whoaTimer = whoaTimerMax;
3181 if (firing > 0) firing -= 1;
3184 auto wtile = level.isWaterAtPoint(x, y/*, oWaterSwim, -1, -1*/);
3187 if (onFellInWater(wtile) || !isInstanceAlive) return;
3191 if (onOutOfWater() || !isInstanceAlive) return;
3197 if (global.randOther(1, 5) == 1) level.MakeMapObject(x-8+global.randOther(4, 12), y-8+global.randOther(4, 12), 'oBurn');
3202 if (!dead && level.isLavaAtPoint(x, y+6/*, oLava, 0, 0*/)) {
3203 //!if (isRealLevel()) global.miscDeaths[11] += 1;
3204 level.addDeath('lava');
3205 playSound('sndFlame');
3219 if (global.hasJetpack && platformCharacterIs(ON_GROUND)) {
3223 // fall off bottom of screen
3224 if (!level.inWinCutscene && !level.inIntroCutscene) {
3225 if (!dead && y > level.tilesHeight*16+16) {
3226 //!if (isRealLevel()) global.miscDeaths[10] += 1;
3227 level.addDeath('void');
3228 global.plife = -90; // spill blood
3234 scrDropItem(LostCause.Falloff);
3235 playSound('sndThud'); //???
3236 playSound('sndDie'); //???
3239 if (dead && y > level.tilesHeight*16+16) {
3247 if (/*active*/true) {
3248 if (spr.Name == 'sStunL' || spr.Name == 'sDamselStunL' || spr.Name == 'sTunnelStunL') {
3249 if (stunTimer > 0) {
3253 if (stunTimer < 1) {
3255 canDropStuff = true;
3259 if (!level.inWinCutscene) {
3260 if (isParachuteActive() || isCapeActiveAndOpen()) fallTimer = 0;
3263 // changed to yVel > 1 from yVel > 0
3264 if (yVel > 1 && status != CLIMBING) {
3266 if (fallTimer > 16) wallHurt = 0; // no sense in them taking extra damage from being thrown here
3267 int paraOpenHeight = (global.config.scumSpringShoesReduceFallDamage && (global.hasSpringShoes || global.hasJordans) ? 22 : 14);
3268 //paraOpenHeight = 4;
3269 if (global.hasParachute && !stunned && fallTimer > paraOpenHeight) {
3270 //if (not collision_point(x, y+32, oSolid, 0, 0)) // was commented in the original code
3271 //!*if (not collision_line(x, y+16, x, y+32, oSolid, 0, 0))
3272 if (!level.checkTilesInRect(x, y+16, 1, 17, &level.cbCollisionAnySolid)) {
3274 //!instance_create(x-8, y-16, oParachute);
3276 global.hasParachute = false;
3277 activatePowerup('Parachute');
3278 //writeln("parachute state: ", isParachuteActive());
3281 } else if (fallTimer > 16 && platformCharacterIs(ON_GROUND) &&
3282 !level.checkTilesInRect(x-8, y-8, 17, 17, &level.cbCollisionSpringTrap) /* not onto springtrap */)
3284 // long drop -- player has just landed
3285 bool reducedDamage = (global.config.scumSpringShoesReduceFallDamage && (global.hasSpringShoes || global.hasJordans));
3286 if (reducedDamage && fallTimer <= 24) {
3287 // land without taking damage
3291 if (fallTimer > (reducedDamage ? 72 : 48)) global.plife -= 10*global.config.scumFallDamage;
3292 else if (fallTimer > (reducedDamage ? 48 : 32)) global.plife -= 2*global.config.scumFallDamage;
3293 else global.plife -= 1*global.config.scumFallDamage;
3294 if (global.plife < 1) {
3295 if (!dead) level.addDeath('fall');
3299 if (global.config.scumFallDamage > 0) stunTimer += 60;
3302 auto obj = level.MakeMapObject(x-4, y+6, 'oPoof');
3303 if (obj) obj.xVel = -0.4;
3304 obj = level.MakeMapObject(x+4, y+6, 'oPoof');
3305 if (obj) obj.xVel = 0.4;
3306 playSound('sndThud');
3308 } else if (yVel <= 0) {
3310 if (isParachuteActive()) {
3311 deactivatePowerup('Parachute');
3312 level.MakeMapObject(ix-8, iy-16-8, 'oParaUsed');
3316 // if (stunned) fallTimer = 0; // was commented in the original code
3318 if (swimming && !level.isLavaAtPoint(x, y/*, oLava, 0, 0*/)) {
3320 if (bubbleTimer > 0) {
3323 if (level.isWaterAtPoint(x, (y&~0x0f)-8)) level.MakeMapObject(x, y-4, 'oBubble');
3324 bubbleTimer = bubbleTimerMax;
3327 bubbleTimer = bubbleTimerMax;
3330 //TODO: k8: move spear checking to spear handler
3331 if (!isExitingSprite()) {
3332 auto spear = MapObjectSpearsBase(level.isObjectInRect(ix-6, iy-6, 13, 14, delegate bool (MapObject o) {
3333 auto tt = MapObjectSpearsBase(o);
3334 if (!tt) return false;
3335 return tt.isHitFrame;
3340 global.plife -= global.config.spearDmg; // 4
3341 if (!dead && global.plife <= 0 /*and isRealLevel()*/) level.addDeath('spear');
3342 xVel = global.randOther(4, 6)*(spear.isLeft ? -1 : 1);
3351 if (status != DUCKTOHANG && !stunned && !dead && !isExitingSprite()) {
3353 characterStepEvent();
3355 if (status != DUCKING && status != DUCKTOHANG) status = STANDING;
3356 checkControlKeys(getSprite());
3360 // if (dead or stunned)
3361 if (dead || stunned) {
3363 if (holdItem isa ItemWeaponBow && bowArmed) scrFireBow();
3364 scrDropItem(dead ? LostCause.Dead : LostCause.Stunned, xVel, -3);
3367 yVel += (bounced ? 1.0 : 0.6);
3369 if (isCollisionTop(1) && yVel < 0) yVel = -yVel*0.8;
3370 if (isCollisionLeft(1) || isCollisionRight(1)) xVel = -xVel*0.5;
3372 bool collisionbottomcheck = !!isCollisionBottom(1);
3373 if (collisionbottomcheck || isCollisionBottom(1, &level.cbCollisionPlatform)) {
3375 if (collisionbottomcheck) {
3376 if (yVel > 2.5) yVel = -yVel*0.5; else yVel = 0;
3378 // after falling onto a platform don't take extra damage after recovering from stunning
3381 /* was commented in the original code
3382 if (isCollisionBottom(1)) {
3383 if (yVel > 2.5) yVel = -yVel*0.5; else yVel = 0;
3390 if (fabs(xVel) < 0.1) xVel = 0;
3391 else if (fabs(xVel) != 0 && level.isIceAtPoint(x, y+16)) xVel *= 0.8;
3392 else if (fabs(xVel) != 0) xVel *= 0.3;
3398 //level.forEachObjectInRect(ix, iy, width, height, &doBreakWebsCB);
3400 // apply the limits since the velocity may be too extreme
3402 xVel = fclamp(xVel, -xVelLimit, xVelLimit);
3403 yVel = fclamp(yVel, -yVelLimit, yVelLimit);
3405 moveRel(xVel, yVel);
3409 // fix sprites, spawn blood from spikes
3410 if (isParachuteActive()) {
3411 deactivatePowerup('Parachute');
3412 level.MakeMapObject(ix-8, iy-16-8, 'oParaUsed');
3417 //!with (oWhip) instance_destroy();
3420 if (global.isDamsel) {
3422 if (dead) setSprite('sDamselDieL');
3423 else if (stunned) setSprite('sDamselStunL');
3424 } else if (bounced) {
3425 if (yVel < 0) setSprite('sDamselBounceL'); else setSprite('sDamselFallL');
3427 if (xVel < 0) setSprite('sDamselDieLL'); else setSprite('sDamselDieLR');
3429 } else if (global.isTunnelMan) {
3431 if (dead) setSprite('sTunnelDieL');
3432 else if (stunned) setSprite('sTunnelStunL');
3433 } else if (bounced) {
3434 if (yVel < 0) setSprite('sTunnelLBounce'); else setSprite('sTunnelFallL');
3436 if (xVel < 0) setSprite('sTunnelDieLL'); else setSprite('sTunnelDieLR');
3440 if (dead) setSprite('sDieL');
3441 else if (stunned) setSprite('sStunL');
3442 } else if (bounced) {
3443 if (yVel < 0) setSprite('sDieLBounce'); else setSprite('sDieLFall');
3445 if (xVel < 0) setSprite('sDieLL'); else setSprite('sDieLR');
3452 auto colobj = isCollisionRight(1);
3453 if (!colobj) colobj = isCollisionLeft(1);
3454 if (!colobj) colobj = isCollisionBottom(1);
3457 scrCreateBlood(colobj.x0, colobj.y0, 3);
3459 if (!dead && global.plife <= 0 /*&& isRealLevel()*/) {
3461 writeln("thrown to death by '", thrownBy, "'");
3462 level.addDeath(thrownBy);
3466 if (wallHurt <= 0) thrownBy = '';
3467 playSound('sndHurt'); //???
3471 colobj = isCollisionBottom(1);
3472 if (colobj && !bounced) {
3474 scrCreateBlood(colobj.x0, colobj.y0, 2);
3477 if (!dead && global.plife <= 0 /*and isRealLevel()*/) {
3479 writeln("thrown to death by '", thrownBy, "'");
3480 level.addDeath(thrownBy);
3484 if (wallHurt <= 0) thrownBy = '';
3489 bool kPay = level.isKeyDown(GameConfig::Key.Pay);
3491 // gnounc's quick look
3492 if (!kRight && !kLeft && (platformCharacterIs(ON_GROUND) || status == HANGING)) {
3493 if (kDown) { if (viewCount <= 6) viewCount += 3; else viewOffset += 6; }
3494 else if (kUp) { if (viewCount <= 6) viewCount += 3; else viewOffset -= 6; }
3500 // default look up/down with delay if pay button not held
3501 if (!kRight && !kLeft && (platformCharacterIs(ON_GROUND) || status == HANGING)) {
3502 if (kDown) { if (viewCount <= 30) viewCount += 1; else viewOffset += 4; }
3503 else if (kUp) { if (viewCount <= 30) viewCount += 1; else viewOffset -= 4; }
3510 if (viewCount == 0 && viewOffset) viewOffset = (viewOffset < 0 ? min(0, viewOffset+8) : max(0, viewOffset-8));
3511 viewOffset = clamp(viewOffset, -16*6, 16*6);
3513 if (!dead) activatePlayerWeapon();
3515 if (!dead) processLevelExit();
3518 if (global.plife < -99 && visible && justdied) spillBlood();
3520 if (global.plife < 1) {
3524 // spikes, and other shit
3525 if (global.plife >= -99 && visible && !isExitingSprite()) {
3526 auto colSpikes = level.checkTilesInRect(x-4, y-4, 9, 13, &level.cbCollisionSpikes);
3528 if (colSpikes && dead) {
3530 if (!level.isSolidAtPoint(x, y+9)) { shiftY(0.02); y = iy; } //0.05;
3531 //else myGrav = 0.6;
3536 if (colSpikes && yVel > 0 && (fallTimer > 3 || stunned)) { // originally fallTimer > 4
3538 // spikes will always instant-kill in Moon room
3539 /*if (isRoom("rMoon")) global.plife -= 99; else*/ global.plife -= global.config.scumSpikeDamage;
3540 if (/*isRealLevel() &&*/ global.plife <= 0) level.addDeath('spike');
3541 if (global.plife > 0) playSound('sndHurt');
3547 colSpikes.makeBloody();
3549 //else if (not dead) myGrav = 0.6;
3554 if (visible && (status >= STUNNED || stunned || dead || status == DUCKING)) {
3556 checkAndPerformSacrifice(out onAltar);
3557 // block looking down if we're trying to sacrifire ourselves
3558 if (onAltar) viewCount = max(0, viewCount-1);
3560 sacCount = default.sacCount;
3564 if (dead && global.hasAnkh) {
3565 writeln("*** ACTIVATED ANKH");
3566 global.hasAnkh = false;
3568 int newLife = (global.isTunnelMan ? global.config.scumTMLife : global.config.scumStartLife);
3569 global.plife = max(global.plife, newLife);
3570 level.osdMessage("THE ANKH SHATTERS!\nYOU HAVE BEEN REVIVED!", 4);
3572 auto moai = level.forEachTile(delegate bool (MapTile t) { return (t.objType == 'oMoai'); });
3574 level.forEachTile(delegate bool (MapTile t) {
3575 if (t.objType == 'oMoaiInside') {
3576 teleportTo(t.ix+8, t.iy+8);
3581 //teleportTo(moai.ix+16+8, moai.iy+16+8);
3583 if (level.allEnters.length) {
3584 teleportTo(level.allEnters[0].ix+8, level.allEnters[0].iy-8);
3587 level.centerViewAtPlayer();
3588 auto ball = getMyBall();
3589 if (ball) ball.teleportToPrisoner();
3602 //alarm[8] = 60; // this starts music; but we don't need it, 'cause we won't stop the music on player death
3603 playSound('sndTeleport');
3607 if (dead) level.stats.gameOver();
3610 if (status == DUCKTOHANG) {
3612 if (spr.Name != 'sDuckToHangL' && spr.Name != 'sDamselDtHL' && spr.Name != 'sTunnelDtHL') status = STANDING;
3615 foreach (PlayerPowerup pp; powerups) if (pp.active) pp.onPostThink();
3617 if (jetpackFlaresTime > 0) {
3618 if (--jetpackFlaresTime == 0) {
3619 auto obj = level.MakeMapObject(ix+global.randOther(0, 3)-global.randOther(0, 3), iy+global.randOther(0, 3)-global.randOther(0, 3), 'oFlareSpark');
3621 obj.yVel = global.randOther(1, 3);
3622 obj.xVel = global.randOther(0, 3)-global.randOther(0, 3);
3624 playSound('sndJetpack');
3630 // ////////////////////////////////////////////////////////////////////////// //
3631 void drawPrePrePowerupWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
3632 // so ducking player will have it's cape correctly rendered
3633 foreach (PlayerPowerup pp; powerups) {
3634 if (pp.active) pp.prePreDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3639 override void drawWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
3640 //if (heldBy) return; // owner will take care of this
3641 if (blinkHidden) return;
3643 bool renderJetpackBack = false;
3644 if (global.hasJetpack) {
3646 if ((status == CLIMBING || isExitingSprite()) && !whipping) {
3648 renderJetpackBack = true;
3651 getInterpCoords(currFrameDelta, scale, out xi, out yi);
3654 if (dir == Dir.Right) {
3655 spr = level.sprStore['sJetpackRight'];
3658 spr = level.sprStore['sJetpackLeft'];
3662 auto spf = spr.frames[0];
3663 if (spf && spf.width > 0 && spf.height > 0) spf.tex.blitAt(xi-xpos-spf.xofs*scale, yi-ypos-spf.yofs*scale, scale);
3668 bool ducking = (status == DUCKING);
3669 foreach (PlayerPowerup pp; powerups) {
3670 if (pp.active) pp.preDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3673 auto oldColor = Video.color;
3674 if (redColor > 0) Video.color = clamp(200+redColor, 0, 255)<<16;
3675 ::drawWithOfs(xpos, ypos, scale, currFrameDelta);
3676 Video.color = oldColor;
3678 if (renderJetpackBack) {
3680 getInterpCoords(currFrameDelta, scale, out xi, out yi);
3681 SpriteImage spr = level.sprStore['sJetpackBack'];
3683 auto spf = spr.frames[0];
3684 if (spf && spf.width > 0 && spf.height > 0) spf.tex.blitAt(xi-xpos-spf.xofs*scale, yi-ypos-spf.yofs*scale, scale);
3688 foreach (PlayerPowerup pp; powerups) if (pp.active) pp.postDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3692 void lastDrawWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
3693 foreach (PlayerPowerup pp; powerups) {
3694 if (pp.active) pp.lastDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3701 objType = 'oPlayer';
3704 desc2 = "A strange little man who spends his time exploring caverns. He wants to be just like Indiana Jones when he grows up.";
3706 negateMirrorXOfs = true;
3708 status = FALLING; // the character state, must be one of the following: STANDING, RUNNING, DUCKING, LOOKING_UP, CLIMBING, JUMPING, or FALLING
3718 //thrownBy = ""; // "Yeti", "Hawkman", or "Shopkeeper" for stat tracking deaths by being thrown
3721 //whoaTimerMax = 30;
3722 distToNearestLightSource = 999;
3732 frictionFactor = 0.3;
3734 xVelLimit = 16; // limits the xVel: default 15
3735 yVelLimit = 10; // limits the yVel
3736 xAccLimit = 9; // limits the xAcc
3737 yAccLimit = 6; // limits the yAcc
3738 runAcc = 3; // the running acceleration
3745 //lightRadius = 96; //???