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;
170 // ////////////////////////////////////////////////////////////////////////// //
176 final ItemBall getMyBall () {
177 ItemBall res = myBall;
178 if (res && !res.isInstanceAlive) { res = none; myBall = none; }
183 void spawnBallAndChain (optional bool levelStart) {
185 auto owh = wasHoldingBall;
186 removeBallAndChain();
187 wasHoldingBall = owh;
189 mustBeChained = true;
190 auto ball = getMyBall();
192 if (levelStart) writeln("::: respawning ball; old ball is missing (it is ok)");
193 writeln("creating new ball");
194 ball = ItemBall(level.MakeMapObject(ix, iy, 'oBall'));
196 ball.attachTo(self, levelStart);
197 writeln("ball created");
201 if (levelStart) writeln("::: attaching ball to player");
202 ball.attachTo(self, levelStart);
203 if (wasHoldingBall) {
204 if (levelStart) writeln("::: picking ball");
206 pickedItem.instanceRemove();
209 if (holdItem && holdItem != ball) {
210 holdItem.instanceRemove();
216 if (myBall != ball) FatalError("error in ball management");
217 if (levelStart) writeln("ballpos=(", ball.ix, ",", ball.iy, "); plrpos=(", ix, ",", iy, "); ballalive=", ball.isInstanceAlive);
219 writeln("failed to create a new ball");
220 mustBeChained = false;
222 wasHoldingBall = false;
226 void removeBallAndChain (optional bool temp) {
227 auto ball = getMyBall();
229 writeln("removing ball and chain...", (temp ? " (temporarily)" : ""));
230 wasHoldingBall = (holdItem == ball);
231 writeln(" has ball, holding=", wasHoldingBall);
232 mustBeChained = true;
234 ball.instanceRemove();
238 wasHoldingBall = false;
239 mustBeChained = false;
243 // ////////////////////////////////////////////////////////////////////////// //
244 final PlayerPowerup findPowerup (name id) {
245 foreach (PlayerPowerup pp; powerups) if (pp.id == id) return pp;
250 final bool setPowerupState (name id, bool active) {
251 auto pp = findPowerup(id);
252 if (!pp) return false;
253 return (active ? pp.onActivate() : pp.onDeactivate());
257 final bool togglePowerupState (name id) {
258 auto pp = findPowerup(id);
259 if (!pp) return false;
260 return (pp.active ? pp.onDeactivate() : pp.onActivate());
264 final bool activatePowerup (name id) { return setPowerupState(id, true); }
265 final bool deactivatePowerup (name id) { return setPowerupState(id, false); }
268 final bool isActivePowerup (name id) {
269 auto pp = findPowerup(id);
270 return (pp && pp.active);
274 // ////////////////////////////////////////////////////////////////////////// //
275 override void Destroy () {
276 foreach (PlayerPowerup pp; powerups) delete pp;
281 void unpressAllKeys () {
283 kLeftPressed = false;
284 kLeftReleased = false;
286 kRightPressed = false;
287 kRightReleased = false;
291 kJumpPressed = false;
292 kJumpReleased = false;
294 kAttackPressed = false;
295 kAttackReleased = false;
296 kItemPressed = false;
297 kRopePressed = false;
298 kBombPressed = false;
300 kExitPressed = false;
304 void removeActivatedPlayerWeapon () {
306 if (holdItem isa PlayerWeapon) {
310 if (pickedItem) scrSwitchToPocketItem(forceIfEmpty:false);
315 // ////////////////////////////////////////////////////////////////////////// //
316 // called on level start too
322 skipCutscenePressed = false;
323 movementBlocked = false;
324 if (global.plife < 1) global.plife = max(1, global.config.scumStartLife);
329 myGrav = default.myGrav;
333 depth = default.depth;
334 status = default.status;
340 distToNearestLightSource = 999;
342 justdied = default.justdied;
343 removeActivatedPlayerWeapon();
345 blink = default.blink;
346 blinkHidden = default.blinkHidden;
352 level.clearKeysPressRelease();
355 //scrSwitchToPocketItem(forceIfEmpty:false);
359 // ////////////////////////////////////////////////////////////////////////// //
360 bool isExitingSprite () {
361 auto spr = getSprite();
362 return (spr.Name == 'sPExit' || spr.Name == 'sDamselExit' || spr.Name == 'sTunnelExit');
366 // ////////////////////////////////////////////////////////////////////////// //
367 override void playSound (name aname, optional bool unique) {
368 if (unique && global.sndIsPlaying(0, aname)) return;
369 global.playSound(0, 0, 0, aname); // it is local
373 override bool sndIsPlaying (name aname) {
374 return global.sndIsPlaying(0, aname);
378 override void sndStopSound (name aname) {
379 global.sndStopSound(0, aname);
383 // ////////////////////////////////////////////////////////////////////////// //
384 transient ItemDice currDie;
386 void onDieRolled (ItemDice die) {
387 if (!die.forSale) return;
388 // only law-abiding players can play
389 if (global.thiefLevel > 0 || global.murderer) return;
390 if (bet == 0) return;
393 level.forEachObject(delegate bool (MapObject o) {
394 MonsterShopkeeper sc = MonsterShopkeeper(o);
395 if (sc && !sc.dead && !sc.angered) return sc.onDiePlayed(self, currDie);
402 // ////////////////////////////////////////////////////////////////////////// //
403 override bool onExplosionTouch (MapObject xplo) {
404 //writeln("PlayerPawn: on explo touch! ", invincible);
405 if (invincible) return false;
406 if (global.config.scumExplosionHurt) {
407 global.plife -= global.config.explosionDmg;
408 if (!dead && global.plife <= 0 /*&& isRealLevel()*/) {
409 auto xp = MapObjExplosion(xplo);
410 if (xp && xp.suicide) level.addDeath('suicide'); else level.addDeath('explosion');
413 if (global.config.scumExplosionStun) {
419 if (xplo.ix < ix) xVel = global.randOther(4, 6); else xVel = -global.randOther(4, 6);
425 // ////////////////////////////////////////////////////////////////////////// //
426 // start new game when exiting from title, and process other custom exits
427 void scrPlayerExit () {
428 level.playerExited = true;
434 // ////////////////////////////////////////////////////////////////////////// //
435 bool scrHideItemToPocket (optional bool forBombOrRope) {
436 if (!holdItem) return true;
437 if (holdItem isa PlayerWeapon) return false;
438 if (holdItem.forSale) return false;
439 if (!forBombOrRope) {
440 if (holdItem isa ItemBall) return false;
443 // cannot hide armed bomb
444 ItemBomb bomb = ItemBomb(holdItem);
445 if (bomb && bomb.armed) return false;
446 if (bomb || holdItem isa ItemRopeThrow) {
447 holdItem.instanceRemove();
453 if (holdItem isa MapEnemy) return false;
454 //writeln("hiding: '", GetClassName(holdItem.Class), "'");
456 if (pickedItem) FatalError("we are already holding '%n'", GetClassName(pickedItem.Class));
457 pickedItem = holdItem;
459 pickedItem.active = false;
460 pickedItem.visible = false;
461 pickedItem.sellOfferDone = false;
462 if (pickedItem.heldBy) FatalError("oooops (scrHideItemToPocket)");
467 bool scrSwitchToBombs () {
468 if (holdItem isa PlayerWeapon) return false;
470 if (global.bombs < 1) return false;
471 if (ItemBomb(holdItem)) return true;
472 if (!scrHideItemToPocket(forBombOrRope:true)) return false;
474 ItemBomb bomb = ItemBomb(level.MakeMapObject(ix, iy, 'oBomb'));
475 if (!bomb) return false;
476 bomb.setSticky(global.stickyBombsActive);
478 whoaTimer = whoaTimerMax;
483 bool scrSwitchToStickyBombs () {
484 if (holdItem isa PlayerWeapon) return false;
485 if (!global.hasStickyBombs) {
486 global.stickyBombsActive = false;
490 global.stickyBombsActive = !global.stickyBombsActive;
495 bool scrSwitchToRopes () {
496 if (holdItem isa PlayerWeapon) return false;
498 if (global.rope < 1) return false;
499 if (ItemRopeThrow(holdItem)) return true;
500 if (!scrHideItemToPocket(forBombOrRope:true)) return false;
502 ItemRopeThrow rope = ItemRopeThrow(level.MakeMapObject(ix, iy, 'oRopeThrow'));
503 if (!rope) return false;
505 whoaTimer = whoaTimerMax;
510 bool isHoldingBombOrRope () {
512 if (!hit) return false;
513 return (hit isa ItemBomb || hit isa ItemRopeThrow);
517 bool isHoldingBomb () {
519 if (!hit) return false;
520 return (hit isa ItemBomb);
524 bool isHoldingArmedBomb () {
525 auto hit = ItemBomb(holdItem);
526 if (!hit) return false;
531 bool isHoldingRope () {
533 if (!hit) return false;
534 return (hit isa ItemRopeThrow);
538 bool scrSwitchToPocketItem (bool forceIfEmpty) {
539 if (holdItem isa PlayerWeapon) return false;
540 if (holdItem && holdItem.forSale) return false;
542 if (holdItem == pickedItem) {
544 whoaTimer = whoaTimerMax;
545 if (holdItem) holdItem.sellOfferDone = false;
549 if (!forceIfEmpty && !pickedItem) return false;
551 // destroy currently holded item if it is a bomb or a rope
553 // you cannot do it with an armed bomb
554 if (holdItem isa MapEnemy) return false; // cannot hide an enemy
555 ItemBomb bomb = ItemBomb(holdItem);
556 if (bomb && bomb.armed) return false;
557 if (bomb || holdItem isa ItemRopeThrow) {
559 holdItem.instanceRemove();
563 writeln(va("cannot switch to pocket item while carrying '%n' ('%n' is in pocket, why?)", GetClassName(holdItem.Class), GetClassName(pickedItem.Class)));
569 auto oldHold = holdItem;
570 holdItem = pickedItem;
571 pickedItem = oldHold;
572 // all flag management is done in property handler
574 oldHold.active = false;
575 oldHold.visible = false;
576 oldHold.sellOfferDone = false;
578 if (holdItem) holdItem.sellOfferDone = false;
579 whoaTimer = whoaTimerMax;
584 bool scrSwitchToNextItem () {
585 if (holdItem isa PlayerWeapon) return false;
586 if (holdItem && holdItem.forSale) return false;
589 if (ItemBomb(holdItem)) {
590 if (ItemBomb(holdItem).armed) return false; // cannot switch out of armed bomb
591 if (scrSwitchToRopes()) return true;
592 return scrSwitchToPocketItem(forceIfEmpty:true);
596 if (ItemRopeThrow(holdItem)) {
597 if (scrSwitchToPocketItem(forceIfEmpty:true)) return true;
598 if (scrSwitchToBombs()) return true;
599 return scrHideItemToPocket();
602 // either nothing, or normal item
603 bool tryPocket = !!holdItem;
604 if (scrSwitchToBombs()) return true;
605 if (scrSwitchToRopes()) return true;
606 if (holdItem isa ItemBall) return false;
607 if (tryPocket) return scrSwitchToPocketItem(forceIfEmpty:true);
612 // ////////////////////////////////////////////////////////////////////////// //
613 bool scrPickupItem (MapObject obj) {
614 if (holdItem isa PlayerWeapon) return false;
616 if (!obj) return false;
619 if (pickedItem) return false;
620 if (isHoldingArmedBomb()) return false;
621 if (isHoldingBombOrRope()) {
622 if (!scrSwitchToPocketItem(forceIfEmpty:true)) return false;
624 if (holdItem) return false;
627 if (pickedItem) return false;
630 if (obj isa ItemBomb && !ItemBomb(obj).armed) ++global.bombs;
631 else if (obj isa ItemRopeThrow) ++global.rope;
633 whoaTimer = whoaTimerMax;
634 obj.onPickedUp(self);
639 // ////////////////////////////////////////////////////////////////////////// //
640 //transient MapObject itck;
641 void unstuckDroppedObject (MapObject it) {
642 if (!it || !it.isInstanceAlive || it.width < 1 || it.height < 1) return;
644 if (it isa MapEnemy) {
645 it.ix = ix+(dir == Dir.Left ? -8 : -4);
649 // prevent getting stuck in a wall
650 writeln("???STUCK: (", it.objType, "), hitbox=(", it.hitboxX, ",", it.hitboxY, ")-(", it.hitboxW, "x", it.hitboxH, ")");
651 auto ospec = it.spectral;
653 if (!it.isCollision()) { it.spectral = ospec; return; }
654 writeln("***STUCK! (", it.objType, ")");
656 auto ox = it.ix, oy = it.iy;
659 if (!it.isCollision()) { it.spectral = ospec; it.saveInterpData(); it.updateGrid(); return; }
662 level.checkTilesInRect(it.x0, it.y0, width, height, delegate bool (MapTile t) {
664 writeln("mypos=(", itck.x0, ",", itck.y0, ")-(", itck.x1, ",", itck.y1, "); tpos=(", t.x0, ",", t.y0, ")-(", t.x1, ",", t.y1, ")");
670 foreach (int dy; 0..16) {
672 int dx = (dir == Dir.Left ? 1 : -1);
673 writeln(" only horizontal; dir=", dx);
675 foreach (auto step; 1..16) {
677 if (!it.isCollision()) { writeln(" OK at dx=", dx); break; }
679 if (!it.isCollision()) { writeln(" OK at dx=-", dx); break; }
681 if (!it.isCollision()) break;
682 if (it.isCollisionBottom(0)) {
683 writeln(" slide up");
685 } else if (it.isCollisionTop(0)) {
686 writeln(" slide down");
690 if (it.isCollision()) {
691 writeln(" CANNOT UNSTUCK!");
695 writeln(" MOVED BY (", it.ix-ox, ",", it.iy-oy, ")");
696 if (it.isCollision()) FatalError("FUCK?!");
704 // ////////////////////////////////////////////////////////////////////////// //
705 // drop currently held item
706 bool scrDropItem (LostCause cause, optional float xVel, optional float yVel) {
707 if (holdItem isa PlayerWeapon) return false;
709 if (!holdItem) return false;
711 if (!onLoosingHeldItem(cause)) return false;
716 if (!hi.onLostAsHeldItem(self, cause, xVel!optional, yVel!optional)) {
722 if (hi isa ItemRopeThrow) global.rope = max(0, global.rope-1);
723 else if (hi isa ItemBomb && !ItemBomb(hi).armed) global.bombs = max(0, global.bombs-1);
727 unstuckDroppedObject(hi);
729 scrSwitchToPocketItem(forceIfEmpty:true);
734 // ////////////////////////////////////////////////////////////////////////// //
735 void scrUseThrowIt (MapObject it) {
738 it.onBeforeThrowBy(self);
743 if (dir == Dir.Left) {
744 it.xVel = (it.heavy ? -4+xVel : -8+xVel);
745 //foreach (; 0..8) if (level.isSolidAtPoint(ix-8, iy)) it.shiftX(1);
746 //while (!level.isSolidAtPoint(ix-8, iy)) it.shiftX(1); // prevent getting stuck in wall
747 } else if (dir == Dir.Right) {
748 it.xVel = (it.heavy ? 4+xVel : 8+xVel);
749 //foreach (; 0..8) if (level.isSolidAtPoint(ix+8, iy)) it.shiftX(-1);
750 //while (!level.isSolidAtPoint(ix+8, iy)) it.shiftX(-1); // prevent getting stuck in wall
752 it.yVel = (it.heavy ? (kUp ? -4 : -2) : (kUp ? -9 : -3));
753 if (kDown || scrPlayerIsDucking()) {
754 if (platformCharacterIs(ON_GROUND)) {
761 } else if (!global.hasMitt) {
762 if (dir == Dir.Left) {
763 if (level.isSolidAtPoint(ix-8, iy-10)) {
767 } else if (dir == Dir.Right) {
768 if (level.isSolidAtPoint(ix+8, iy-10)) {
775 if (global.hasMitt && !scrPlayerIsDucking()) {
776 it.xVel += (it.xVel < 0 ? -6 : 6);
777 if (!kUp && !kDown) it.yVel = -0.4;
778 else if (kDown) it.yVel = 6;
782 //unstuckDroppedObject(it);
783 if (it.isCollision()) {
785 if (level.isSolidAtPoint(it.ix-8, it.iy)) it.shiftX(8);
786 } else if (it.xVel > 0) {
787 if (level.isSolidAtPoint(it.ix+8, it.iy)) it.shiftX(-8);
788 } else if (it.isCollision()) {
789 int dx = (it.isCollisionLeft(0) ? 1 : it.isCollisionRight(0) ? -1 : 0);
793 if (!it.isCollision()) break;
800 if (it.sprite_index == sBombBag ||
801 it.sprite_index == sBombBox ||
802 it.sprite_index == sRopePile)
806 playSound('sndThrow');
809 auto proj = ItemProjectile(it);
810 if (proj) proj.launchedByPlayer = true;
814 bool scrUseThrowItem () {
815 if (holdItem isa PlayerWeapon) return false;
817 auto hitem = holdItem;
819 if (!hitem) return false;
820 if (!onLoosingHeldItem(LostCause.Unknown)) return false;
825 scrUseThrowIt(hitem);
827 // if we throwing away armed bomb, get previous item back into our hands
830 if (/*ItemBomb(hitem)*/isHoldingBombOrRope()) scrSwitchToPocketItem(forceIfEmpty:false);
832 if (!holdItem) scrSwitchToPocketItem(forceIfEmpty:false);
838 // ////////////////////////////////////////////////////////////////////////// //
839 bool scrPlayerIsDucking () {
840 if (dead) return false;
841 auto spr = getSprite();
842 //if (!spr) return false;
844 spr.Name == 'sDuckLeft' ||
845 spr.Name == 'sCrawlLeft' ||
846 spr.Name == 'sDamselDuckL' ||
847 spr.Name == 'sDamselCrawlL' ||
848 spr.Name == 'sTunnelDuckL' ||
849 spr.Name == 'sTunnelCrawlL';
854 if (holdItem !isa ItemWeaponBow) return false;
855 sndStopSound('sndBowPull');
856 if (!bowArmed) return false;
857 if (!holdItem.onTryUseItem(self)) return false;
862 void scrUsePutItOnGroundHelper (MapObject it, optional float xVelMult, optional float yVelNew) {
865 if (!specified_xVelMult) xVelMult = 0.4;
866 if (!specified_yVelNew) yVelNew = 0.5;
868 //writeln("putting '", GetClassName(hi.Class), "'");
870 if (dir == Dir.Left) {
871 it.xVel = (it.heavy ? -4 : -8);
872 } else if (dir == Dir.Right) {
873 it.xVel = (it.heavy ? 4 : 8);
881 if (ItemGoldIdol(it)) it.flty = iy;
885 if (it.isCollisionBottom(0) && !it.isCollisionTop(1)) {
893 if (it.isCollisionLeft(0)) {
894 if (it.isCollisionRight(1)) break;
896 } else if (it.isCollisionRight(0)) {
897 if (it.isCollisionLeft(1)) break;
905 unstuckDroppedObject(it);
909 // put item which player holds in his hands on the ground if player is ducking
910 // return `true` if item was put
911 bool scrUsePutItemOnGround (optional float xVelMult, optional float yVelNew) {
912 if (holdItem isa PlayerWeapon) return false;
915 if (!hi || !scrPlayerIsDucking()) return false;
917 if (!onLoosingHeldItem(LostCause.Unknown)) return false;
919 //writeln("putting '", GetClassName(hi.Class), "'");
921 if (global.bombs > 0) {
922 auto bomb = ItemBomb(hi);
923 if (bomb && !bomb.armed) global.bombs -= 1;
926 if (global.rope > 0) {
927 auto rope = ItemRopeThrow(hi);
930 rope.falling = false;
940 scrUsePutItOnGroundHelper(hi, xVelMult!optional, yVelNew!optional);
946 bool launchRope (bool goDown, bool doDrop) {
947 if (global.rope < 1) {
949 if (ItemRopeThrow(holdItem)) scrSwitchToPocketItem(forceIfEmpty:false);
955 bool wasHeld = false;
956 ItemRopeThrow rp = ItemRopeThrow(holdItem);
957 int xdelta = (doDrop ? 12 : 16)*(dir == Dir.Left ? -1 : 1);
959 //FIXME: call handler
962 rp.setXY(ix+xdelta, iy);
964 rp = ItemRopeThrow(level.MakeMapObject(ix+xdelta, iy, 'oRopeThrow'));
966 if (rp.heldBy) FatalError("PlayerPawn::launchRope: hold management fucked");
969 //rp.resaleValue = 0;
973 if (platformCharacterIs(ON_GROUND)) rp.startY = iy; // YASM 1.7
985 if (!level.isSolidAtPoint(ix+(doDrop ? 2 : 8), iy)) { //2
986 if (!level.checkTilesInRect(rp.ix-8, rp.iy, 2, 17)) rp.shiftX(-8);
987 else if (!level.checkTilesInRect(rp.ix+7, rp.iy, 2, 17)) rp.shiftX(8);
992 } else if (!level.isSolidAtPoint(ix-(doDrop ? 2 : 8), iy)) { //2
993 if (!level.checkTilesInRect(rp.ix+7, rp.iy, 2, 17)) rp.shiftX(8);
994 else if (!level.checkTilesInRect(rp.ix-8, rp.iy, 2, 17)) rp.shiftX(-8);
1001 // cannot launch rope
1002 /* was commented in the original
1003 if (oPlayer1.facing == 18) {
1004 obj = instance_create(oPlayer1.x-4, oPlayer1.y+2, oRopeThrow);
1007 obj = instance_create(oPlayer1.x+4, oPlayer1.y+2, oRopeThrow);
1012 //writeln("!!! goDown=", goDown, "; doDrop=", doDrop, "; wasHeld=", wasHeld);
1015 if (!wasHeld) doDrop = true;
1019 if (dir == Dir.Left) rp.xVel = -3.2; else rp.xVel = 3.2;
1022 rp.forceFixHoldCoords(self);
1024 scrUsePutItOnGroundHelper(rp);
1028 if (wasHeld) scrSwitchToPocketItem(forceIfEmpty:false);
1030 //writeln("NO DROP!");
1034 //rp.resaleValue = 1; //k8:???
1037 rp.instanceRemove();
1038 if (wasHeld) scrSwitchToPocketItem(forceIfEmpty:false);
1043 level.MakeMapObject(rp.ix, rp.iy, 'oRopeTop');
1050 if (wasHeld) scrSwitchToPocketItem(forceIfEmpty:false);
1051 playSound('sndThrow');
1056 bool scrLaunchBomb () {
1057 if (whipping || global.bombs < 1) return false;
1060 ItemBomb bomb = ItemBomb(level.MakeMapObject(ix, iy, 'oBomb'));
1061 if (!bomb) return false;
1062 bomb.forceFixHoldCoords(self);
1063 bomb.setSticky(global.stickyBombsActive);
1065 bomb.resaleValue = 0;
1067 if (kDown || scrPlayerIsDucking()) {
1068 scrUsePutItOnGroundHelper(bomb);
1070 scrUseThrowIt(bomb);
1077 bool scrUseItem () {
1079 if (!it) return false;
1080 //writeln(GetClassName(holdItem.Class));
1082 //auto spr = holdItem.getSprite();
1084 } else if (holdItem.type == "Sceptre") {
1085 if (kDown) scrUsePutItemOnGround(0.4, 0.5);
1086 if (firing == 0 && !scrPlayerIsDucking()) {
1087 if (facing == LEFT) {
1096 obj = instance_create(x+xofs, y+4, oPsychicCreateP);
1097 obj.xVel = xsgn*rand(1, 3);
1098 obj.yVel = -random(2);
1100 obj = instance_create(x+xofs, y-2, oPsychicWaveP);
1102 playSound(global.sndPsychic);
1103 firing = firingPistolMax;
1105 } else if (holdItem.type == "Teleporter II") {
1106 scrUseTeleporter2();
1107 } else if (holdItem.type == "Bow") {
1109 scrUsePutItemOnGround(0.4, 0.5);
1110 } else if (firing == 0 && !scrPlayerIsDucking() && !bowArmed && global.arrows > 0) {
1112 playSound(global.sndBowPull);
1113 } else if (global.arrows <= 0) {
1114 global.message = "I'M OUT OF ARROWS!";
1115 global.message2 = "";
1116 global.messageTimer = 80;
1122 if (whipping) return false;
1125 if (scrPlayerIsDucking()) scrUsePutItemOnGround();
1129 // you cannot throw away shop items, but can throw dices
1130 if (it.forSale && it !isa ItemDice) {
1131 if (!level.isInShop(ix/16, iy/16)) {
1134 // allow throw/use shop items
1139 //if (it.forSale) writeln(":::FORSALE 000: '", GetClassName(it.Class), "'");
1140 if (!it.onTryUseItem(self)) {
1141 //if (it.forSale) writeln(":::FORSALE 001: '", GetClassName(it.Class), "'");
1150 // ////////////////////////////////////////////////////////////////////////// //
1151 // called by characterStepEvent
1152 // help player jump up through one block wide gaps by nudging them to one side so they don't hit their head
1153 void scrJumpHelper () {
1154 int d = 4; // max distance to nudge player
1156 if (!level.checkTilesInRect(x, y-12, 1, 7)) {
1157 if (level.checkTilesInRect(x-5, y-12, 1, 7) &&
1158 level.checkTilesInRect(x+14, y-12, 1, 7))
1160 while (d > 0 && level.checkTilesInRect(x-5, y-12, 1, 7)) { ++x; shiftX(1); --d; }
1161 } else if (level.checkTilesInRect(x+5, y-12, 1, 7) &&
1162 level.checkTilesInRect(x-14, y-12, 1, 7))
1164 while (d > 0 && level.checkTilesInRect(x+5, y-12, 1, 7)) { --x; shiftX(-1); --d; }
1168 if (!collision_line(x, y-6, x, y-12, oSolid, 0, 0)) {
1169 if (collision_line(x-5, y-6, x-5, y-12, oSolid, 0, 0) &&
1170 collision_line(x+14, y-6, x+14, y-12, oSolid, 0, 0))
1172 while (collision_line(x-5, y-6, x-5, y-12, oSolid, 0, 0) && d > 0) {
1177 else if (collision_line(x+5, y-6, x+5, y-12, oSolid, 0, 0) and
1178 collision_line(x-14, y-6, x-14, y-12, oSolid, 0, 0))
1180 while (collision_line(x+5, y-6, x+5, y-12, oSolid, 0, 0) && d > 0) {
1190 // ////////////////////////////////////////////////////////////////////////// //
1192 * Returns whether a GENERAL trait about a character is true.
1193 * Only the platform character should run this script.
1195 * `tp` can be one of the following:
1200 final bool platformCharacterIs (int tp) {
1201 if (tp == ON_GROUND && (status == RUNNING || status == STANDING || status == DUCKING || status == LOOKING_UP)) return true;
1202 if (tp == IN_AIR && (status == JUMPING || status == FALLING)) return true;
1203 if (tp == ON_LADDER && status == CLIMBING) return true;
1208 // ////////////////////////////////////////////////////////////////////////// //
1209 // sets the sprite of the character depending on his/her status
1210 final void characterSprite () {
1211 if (status == STOPPED) {
1212 if (global.isDamsel) setSprite('sDamselLeft');
1213 else if (global.isTunnelMan) setSprite('sTunnelLeft');
1214 else setSprite('sStandLeft');
1219 if (global.isTunnelMan && !stunned && !whipping) {
1221 if (status == STANDING) {
1222 if (!level.isSolidAtPoint(x-2, y+9)) {
1224 setSprite('sTunnelWhoaL');
1226 setSprite('sTunnelLeft');
1229 if (status == RUNNING) {
1230 if (kUp) setSprite('sTunnelLookRunL'); else setSprite('sTunnelRunL');
1232 if (status == DUCKING) {
1233 if (xVel == 0) setSprite('sTunnelDuckL');
1234 else if (fabs(xVel) < 3) setSprite('sTunnelCrawlL');
1235 else setSprite('sTunnelRunL');
1237 if (status == LOOKING_UP) {
1238 if (fabs(xVel) > 0) setSprite('sTunnelRunL'); else setSprite('sTunnelLookL');
1240 if (status == JUMPING) setSprite('sTunnelJumpL');
1241 if (status == FALLING && statePrev == FALLING && statePrevPrev == FALLING) setSprite('sTunnelFallL');
1242 if (status == HANGING) setSprite('sTunnelHangL');
1243 if (pushTimer > 20) setSprite('sTunnelPushL');
1244 if (status == DUCKTOHANG) setSprite('sTunnelDtHL');
1245 if (status == CLIMBING) {
1246 if (level.isRopeAtPoint(x, y)) {
1247 if (kDown) setSprite('sTunnelClimb3'); else setSprite('sTunnelClimb2');
1249 setSprite('sTunnelClimb');
1252 } else if (global.isDamsel && !stunned && !whipping) {
1254 if (status == STANDING) {
1255 if (!level.isSolidAtPoint(x-2, y+9)) {
1257 setSprite('sDamselWhoaL');
1258 /* was commented out in the original
1259 if (holdItem && whoaTimer < 1) {
1260 holdItem.held = false;
1261 if (facing == LEFT) holdItem.xVel = -2; else holdItem.xVel = 2;
1262 if (holdItem.type == "Damsel") playSound('sndDamsel');
1263 if (holdItem.type == pickupItemType) { holdItem = 0; pickupItemType = ""; } else scrSwitchToPocketItem();
1267 setSprite('sDamselLeft');
1270 if (status == RUNNING) {
1271 if (kUp) setSprite('sDamselRunL'); else setSprite('sDamselRunL');
1273 if (status == DUCKING) {
1274 if (xVel == 0) setSprite('sDamselDuckL');
1275 else if (fabs(xVel) < 3) setSprite('sDamselCrawlL');
1276 else setSprite('sDamselRunL');
1278 if (status == LOOKING_UP) {
1279 if (fabs(xVel) > 0) setSprite('sDamselRunL'); else setSprite('sDamselLookL');
1281 if (status == JUMPING) setSprite('sDamselDieLR');
1282 if (status == FALLING && statePrev == FALLING && statePrevPrev == FALLING) setSprite('sDamselFallL');
1283 if (status == HANGING) setSprite('sDamselHangL');
1284 if (pushTimer > 20) setSprite('sDamselPushL');
1285 if (status == DUCKTOHANG) setSprite('sDamselDtHL');
1286 if (status == CLIMBING) {
1287 if (level.isRopeAtPoint(x, y)) {
1288 if (kDown) setSprite('sDamselClimb3'); else setSprite('sDamselClimb2');
1290 setSprite('sDamselClimb');
1293 } else if (!stunned && !whipping) {
1295 if (status == STANDING) {
1296 if (!level.checkTileAtPoint(x-(dir == Dir.Left ? 2 : 0), y+9, &level.cbCollisionForWhoa)) {
1298 setSprite('sWhoaLeft');
1299 /* was commented out in the original
1300 if (holdItem && whoaTimer < 1) {
1301 holdItem.held = false;
1302 if (facing == LEFT) holdItem.xVel = -2; else holdItem.xVel = 2;
1303 if (holdItem.type == "Damsel") playSound('sndDamsel');
1304 if (holdItem.type == pickupItemType) { holdItem = 0; pickupItemType = ""; } else scrSwitchToPocketItem();
1308 setSprite('sStandLeft');
1311 if (status == RUNNING) {
1312 if (kUp) setSprite('sLookRunL'); else setSprite('sRunLeft');
1314 if (status == DUCKING) {
1315 if (xVel == 0) setSprite('sDuckLeft');
1316 else if (fabs(xVel) < 3) setSprite('sCrawlLeft');
1317 else setSprite('sRunLeft');
1319 if (status == LOOKING_UP) {
1320 if (fabs(xVel) > 0) setSprite('sLookRunL'); else setSprite('sLookLeft');
1322 if (status == JUMPING) setSprite('sJumpLeft');
1323 if (status == FALLING && statePrev == FALLING && statePrevPrev == FALLING) setSprite('sFallLeft');
1324 if (status == HANGING) setSprite('sHangLeft');
1325 if (pushTimer > 20) setSprite('sPushLeft');
1326 if (status == CLIMBING) {
1327 if (level.isRopeAtPoint(x, y)) {
1328 if (kDown) setSprite('sClimbUp3'); else setSprite('sClimbUp2');
1330 setSprite('sClimbUp');
1333 if (status == DUCKTOHANG) setSprite('sDuckToHangL');
1339 // ////////////////////////////////////////////////////////////////////////// //
1340 void addScore (int delta) {
1341 if (!level.isNormalLevel()) return;
1343 if (delta == 0) return;
1344 level.stats.addMoney(delta);
1346 level.xmoney += delta;
1347 level.collectCounter = min(100, level.collectCounter+20);
1352 // ////////////////////////////////////////////////////////////////////////// //
1353 // for dead players too
1354 // first, the code will call `onObjectTouched()` for player
1355 // if it returned `false`, the code will call `obj.onTouchedByPlayer()`
1356 // note that player's handler is called *after* its frame thinker,
1357 // but object handler is called *before* frame thinker for the object
1358 // i.e. return `true` to block calling `obj.onTouchedByPlayer()`,
1359 // (but NOT object thinker)
1360 bool onObjectTouched (MapObject obj) {
1362 if (dead || global.plife <= 0) return false; // player may be rendered dead, but not yet transited to dead state
1364 if (obj isa ItemProjectileArrow && holdItem isa ItemWeaponBow && !stunned && global.arrows < 99) {
1365 if (fabs(obj.xVel) < 1 && fabs(obj.yVel) < 1 && !obj.stuck) {
1367 playSound('sndPickup');
1368 obj.instanceRemove();
1374 auto treasure = ItemTreasure(obj);
1375 if (treasure && treasure.canCollect) {
1376 if (treasure.value) addScore(treasure.value);
1377 treasure.onCollected(self); // various other effects
1378 playSound(treasure.soundName);
1379 treasure.instanceRemove();
1384 if (global.hasKapala && obj isa MapObjBlood) {
1385 global.bloodLevel += 1;
1386 level.MakeMapObject(obj.ix, obj.iy, 'oBloodSpark');
1387 obj.instanceRemove();
1389 if (global.bloodLevel > 8) {
1390 global.bloodLevel = 0;
1392 level.MakeMapObject(ix, iy-8, 'oHeart');
1393 playSound('sndKiss');
1396 if (redColor < 55) redColor += 5;
1400 // other objects will take care of themselves
1405 // return `false` to prevent
1406 // holdItem is valid
1407 bool onLoosingHeldItem (LostCause cause) {
1408 if (level.inWinCutscene != 0) return false;
1413 // ////////////////////////////////////////////////////////////////////////// //
1414 // k8: don't even ask me! the following mess is almost straightforward port of the original Derek's code!
1415 private final void closeCape () {
1416 auto pp = PPCape(findPowerup('Cape'));
1417 if (pp) pp.open = false;
1421 private final void switchCape () {
1422 auto pp = PPCape(findPowerup('Cape'));
1423 if (pp) pp.open = !pp.open;
1427 final bool isCapeActiveAndOpen () {
1428 auto pp = PPCape(findPowerup('Cape'));
1429 return (pp && pp.active && pp.open);
1433 final bool isParachuteActive () {
1434 auto pp = findPowerup('Parachute');
1435 return (pp && pp.active);
1439 // ////////////////////////////////////////////////////////////////////////// //
1441 bool checkSkipCutScene () {
1442 if (skipCutscenePressed) {
1443 return level.isKeyReleased(GameConfig::Key.Pay);
1445 skipCutscenePressed = level.isKeyPressed(GameConfig::Key.Pay);
1453 bool forcePlayerControls () {
1454 if (level.inWinCutscene) {
1456 level.winCutscenePlayerControl(self);
1458 } else if (level.inIntroCutscene) {
1460 level.introCutscenePlayerControl(self);
1463 } else if (level.levelKind == GameLevel::LevelKind.Transition) {
1466 if (checkSkipCutScene()) {
1467 level.playerExited = true;
1471 auto door = level.checkTileAtPoint(ix, iy, &level.cbCollisionExitTile);
1473 kExitPressed = true;
1477 if (status == STOPPED) {
1478 if (--transKissTimer > 0) return true;
1483 auto dms = MonsterDamselKiss(level.isObjectAtPoint(ix+8, iy+4, delegate bool (MapObject o) { return (o isa MonsterDamselKiss); }));
1484 if (dms && !dms.kissed) {
1489 transKissTimer = 30;
1494 kRightPressed = true;
1501 // ////////////////////////////////////////////////////////////////////////// //
1502 private final void checkControlKeys (SpriteImage spr) {
1503 if (forcePlayerControls()) {
1504 if (movementBlocked) unpressAllKeys();
1505 if (kLeft) kLeftPushedSteps += 1; else kLeftPushedSteps = 0;
1506 if (kRight) kRightPushedSteps += 1; else kRightPushedSteps = 0;
1510 kLeft = level.isKeyDown(GameConfig::Key.Left);
1511 if (movementBlocked) kLeft = false;
1512 if (kLeft) kLeftPushedSteps += 1; else kLeftPushedSteps = 0;
1513 kLeftPressed = level.isKeyPressed(GameConfig::Key.Left);
1514 kLeftReleased = level.isKeyReleased(GameConfig::Key.Left);
1516 kRight = level.isKeyDown(GameConfig::Key.Right);
1517 if (movementBlocked) kRight = false;
1518 if (kRight) kRightPushedSteps += 1; else kRightPushedSteps = 0;
1519 kRightPressed = level.isKeyPressed(GameConfig::Key.Right);
1520 kRightReleased = level.isKeyReleased(GameConfig::Key.Right);
1522 kUp = level.isKeyDown(GameConfig::Key.Up);
1523 kDown = level.isKeyDown(GameConfig::Key.Down);
1525 kJump = level.isKeyDown(GameConfig::Key.Jump);
1526 kJumpPressed = level.isKeyPressed(GameConfig::Key.Jump);
1527 kJumpReleased = level.isKeyReleased(GameConfig::Key.Jump);
1529 if (movementBlocked) unpressAllKeys();
1533 kJumpPressed = false;
1534 kJumpReleased = false;
1536 } else if (spr && global.isTunnelMan && spr.Name == 'sTunnelAttackL' && !holdItem) {
1538 kJumpPressed = false;
1539 kJumpReleased = false;
1540 cantJump = max(0, cantJump-1);
1543 kAttack = level.isKeyDown(GameConfig::Key.Attack);
1544 kAttackPressed = level.isKeyPressed(GameConfig::Key.Attack);
1545 kAttackReleased = level.isKeyReleased(GameConfig::Key.Attack);
1547 kItemPressed = level.isKeyPressed(GameConfig::Key.Switch);
1548 kRopePressed = level.isKeyPressed(GameConfig::Key.Rope);
1549 kBombPressed = level.isKeyPressed(GameConfig::Key.Bomb);
1551 kPayPressed = level.isKeyPressed(GameConfig::Key.Pay);
1553 if (movementBlocked) unpressAllKeys();
1555 kExitPressed = false;
1556 if (global.config.useDoorWithButton) {
1557 if (kPayPressed) kExitPressed = true;
1559 if (kUp) kExitPressed = true;
1562 if (stunned || dead) {
1564 //level.clearKeysPressRelease();
1569 // ////////////////////////////////////////////////////////////////////////// //
1570 // knock off monkeys that grabbed you
1571 void knockOffMonkeys () {
1572 level.forEachObject(delegate bool (MapObject o) {
1573 auto mk = EnemyMonkey(o);
1574 if (mk && !mk.dead && mk.status == GRAB) {
1575 mk.xVel = global.randOther(0, 1)-global.randOther(0, 1);
1578 mk.vineCounter = 20;
1579 mk.grabCounter = 60;
1586 // ////////////////////////////////////////////////////////////////////////// //
1587 // fix collision with boulder (bug with non-aligned boulder)
1588 void hackBoulderCollision () {
1589 auto bld = level.checkTilesInRect(x0, y0, width, height, delegate bool (MapTile o) { return (o isa ObjBoulder); });
1590 if (bld && fabs(bld.xVel) <= 1) {
1591 writeln("IN BOULDER!");
1594 writeln(" LEFT: dx=", dx);
1595 if (dx <= 2) fltx = x0-dx;
1596 } else if (x1 > bld.x1) {
1598 writeln(" RIGHT: dx=", dx);
1599 if (dx <= 2) fltx = x1-dx;
1605 // ////////////////////////////////////////////////////////////////////////// //
1606 bool checkHangTileDG (MapTile t) { return (t.solid || t.tree); }
1609 void checkPerformHang (bool colLeft, bool colRight) {
1610 if (status == HANGING || platformCharacterIs(ON_GROUND)) return;
1611 if ((kLeft && kRight) || (!kLeft && !kRight)) return;
1612 if (kLeft && !colLeft) {
1614 writeln("checkPerformHang: no left solid");
1618 if (kRight && !colRight) {
1620 writeln("checkPerformHang: no right solid");
1624 if (hangCount != 0) {
1626 writeln("checkPerformHang: hangCount=", hangCount);
1630 if (iy <= 16) return;
1631 int dx = (kLeft ? -9 : 9);
1633 writeln("checkPerformHang: trying to hang at ", dx);
1636 bool doHang = false;
1638 if (global.hasGloves) {
1639 doHang = (yVel > 0 && !!level.checkTilesInRect(ix+dx, iy-6, 1, 2, &checkHangTileDG));
1642 doHang = !!level.checkTilesInRect(ix+dx, iy-6, 1, 2, &level.cbCollisionAnyTree);
1644 writeln(" tree: ", doHang);
1648 doHang = level.checkTilesInRect(ix+dx, iy-6, 1, 2) &&
1649 !level.isSolidAtPoint(ix+dx, iy-9) && !level.isSolidAtPoint(ix, iy+9);
1651 writeln(" solid: ", doHang);
1656 writeln(" solid at dx, -6(1): ", !!level.checkTilesInRect(ix+dx, iy-6, 1, 2));
1657 writeln(" solid at dx, -9(0): ", !!level.isSolidAtPoint(ix+dx, iy-9));
1658 writeln(" solid at 0, +9(0): ", !!level.isSolidAtPoint(ix, iy-9));
1661 doHang = level.checkTilesInRect(ix+dx, iy-6, 1, 2) &&
1662 !level.isSolidAtPoint(ix+dx, iy-10) && !level.isSolidAtPoint(ix, iy+9);
1664 if (!doHang) writeln(" easier hang failed");
1667 if (!level.isSolidAtPoint(ix, iy-9)) {
1668 foreach (int dy; 6..24) {
1669 writeln(" solid at dx:-", dy, "(0): ", !!level.isSolidAtPoint(ix+dx, iy-dy));
1671 writeln(" ix=", ix, "; iy=", iy);
1688 // ////////////////////////////////////////////////////////////////////////// //
1689 final void characterStepEvent () {
1690 if (climbSoundTimer > 0) {
1691 if (--climbSoundTimer == 0) {
1692 playSound(climbSndToggle ? 'sndClimb2' : 'sndClimb1');
1693 climbSndToggle = !climbSndToggle;
1697 auto spr = getSprite();
1698 checkControlKeys(spr);
1700 float xPrev = fltx, yPrev = flty;
1703 // check collisions in various directions
1704 bool colSolidLeft = !!getPushableLeft(1);
1705 bool colSolidRight = !!getPushableRight(1);
1706 bool colLeft = !!isCollisionLeft(1);
1707 bool colRight = !!isCollisionRight(1);
1708 bool colTop = !!isCollisionTop(1);
1709 bool colBot = !!isCollisionBottom(1);
1710 bool colLadder = !!isCollisionLadder();
1711 bool colPlatBot = !!isCollisionBottom(1, &level.cbCollisionPlatform);
1712 bool colPlat = !!isCollision(&level.cbCollisionPlatform);
1713 //bool colWaterTop = !!isCollisionTop(1, &level.cbCollisionWater);
1714 bool colWaterTop = !!level.checkTilesInRect(x0, y0-1, width, 3, &level.cbCollisionWater);
1715 bool colIceBot = !!level.isIceAtPoint(x, y+8);
1717 bool runKey = false;
1718 if (level.isKeyDown(GameConfig::Key.Run)) { runHeld = 100; runKey = true; }
1719 if (level.isKeyDown(GameConfig::Key.Attack) && !whipping) { runHeld += 1; runKey = true; }
1720 if (!runKey || (!kLeft && !kRight)) runHeld = 0;
1722 // allows the character to run left and right
1723 // if state!=DUCKING and state!=LOOKING_UP and state!=CLIMBING
1724 if (status != CLIMBING && status != HANGING) {
1725 if (kLeftReleased && fabs(xVel) < 0.0001) xAcc -= 0.5;
1726 if (kRightReleased && fabs(xVel) < 0.0001) xAcc += 0.5;
1727 if (kLeft && !kRight) {
1729 //xVel = 3; // in orig
1730 if (platformCharacterIs(ON_GROUND) && status != DUCKING) {
1733 //playSound('sndPush', unique:true);
1735 } else if (kLeftPushedSteps > 2 && (dir == Dir.Left || fabs(xVel) < 0.0001)) {
1739 //if (platformCharacterIs(ON_GROUND) && fabs(xVel) > 0 && alarm[3] < 1) alarm[3] = floor(16/-xVel);
1741 if (kRight && !kLeft) {
1742 if (colSolidRight) {
1743 //xVel = 3; // in orig
1744 if (platformCharacterIs(ON_GROUND) && status != DUCKING) {
1747 //playSound('sndPush', unique:true);
1749 } else if ((kRightPushedSteps > 2 || colSolidLeft) && (dir == Dir.Right || fabs(xVel) < 0.0001)) {
1753 //if (platformCharacterIs(ON_GROUND) && fabs(xVel) > 0 && alarm[3] < 1) alarm[3] = floor(16/xVel);
1758 if (status == CLIMBING) {
1762 auto ladder = level.isLadderAtPoint(x, y);
1763 if (ladder) { x = ladder.ix+8; setX(x); }
1764 if (kLeft) dir = Dir.Left; else if (kRight) dir = Dir.Right;
1766 // checks both ladder and laddertop
1767 if (level.isAnyLadderAtPoint(x, y-8)) {
1768 //writeln("LADDER00! old yAcc=", yAcc, "; climbAcc=", climbAcc, "; new yAcc=", yAcc-climbAcc);
1770 if (climbSoundTimer < 1) climbSoundTimer = climbSndSpeed;
1771 //!if (alarm[2] < 1) alarm[2] = climbSndSpeed;
1774 for (int dy = -6; dy > -12; --dy) {
1775 ladder = level.isAnyLadderAtPoint(x, y+dy);
1777 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));
1782 auto grid = level.miscTileGrid;
1783 foreach (MapTile t; grid.inCellPix(48, 96, grid.nextTag(), precise:false)) {
1784 writeln("at 48, 96: ", GetClassName(t.Class), "; pos=(", t.ix, ",", t.iy, ")");
1786 foreach (MapTile t; grid.inCellPix(48, 94, grid.nextTag(), precise:false)) {
1787 writeln("at 48, 94: ", GetClassName(t.Class), "; pos=(", t.ix, ",", t.iy, ")");
1789 foreach (int dy; 90..102) {
1790 ladder = level.isAnyLadderAtPoint(48, dy);
1792 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));
1798 // checks both ladder and laddertop
1799 if (level.isAnyLadderAtPoint(x, y+8)) {
1801 //!if (alarm[2] < 1) alarm[2] = climbSndSpeed;
1802 if (climbSoundTimer < 1) climbSoundTimer = climbSndSpeed;
1806 if (colBot) status = STANDING;
1809 if (kJumpPressed && !whipping) {
1810 if (kLeft) xVel = -departLadderXVel; else if (kRight) xVel = departLadderXVel; else xVel = 0;
1811 //yAcc += departLadderYVel;
1812 //k8: was `0.6`, but with `0.4` we can jump onto the wall above, and with `0.6` we cannot
1813 yAcc = 0.4+departLadderYVel; // YASM 1.8.1 Fix for extra air when jumping off ladders due to increased climb speed option
1815 jumpButtonReleased = false;
1820 if (ladderTimer > 0) ladderTimer -= 1;
1823 if (platformCharacterIs(IN_AIR) && status != HANGING) yAcc += gravityIntensity;
1825 // player has landed
1826 if ((colBot || colPlatBot) && platformCharacterIs(IN_AIR) && yVel >= 0) {
1827 if (!colPlat || colBot) {
1832 playSound('sndLand');
1834 if ((colBot || colPlatBot) && !colPlat) yVel = 0;
1836 // player has just walked off of the edge of a solid
1837 if (colBot == 0 && (!colPlatBot || colPlat) && platformCharacterIs(ON_GROUND)) {
1841 if (global.hasGloves) hangCount = 5;
1845 if (dead || stunned) yVel = -yVel*0.8;
1846 else if (status == JUMPING) yVel = fabs(yVel*0.3);
1849 if ((colLeft && dir == Dir.Left) || (colRight && dir == Dir.Right)) {
1850 if (dead || stunned) xVel = -xVel*0.5; else xVel = 0;
1854 if (kJumpReleased && platformCharacterIs(IN_AIR)) {
1856 } else if (platformCharacterIs(ON_GROUND)) {
1861 MapObject oWeb = none, oBlob = none;
1863 oWeb = level.isObjectAtPoint(x, y, &level.cbIsObjectWeb);
1864 if (!oWeb) oBlob = level.isObjectAtPoint(x, y, &level.cbIsObjectBlob);
1867 bool invokeJumpHelper = false;
1869 if (kJumpPressed && oWeb) {
1870 ItemWeb(oWeb).tear(1);
1871 yAcc += initialJumpAcc*2;
1876 jumpButtonReleased = false;
1880 invokeJumpHelper = true;
1881 } else if (kJumpPressed && oBlob) {
1883 scrCreateBloblets(oBlob.x0+8, oBlob.y0+8, 1);
1884 playSound('sndHit');
1885 yAcc += initialJumpAcc*2;
1889 jumpButtonReleased = false; // k8: was `jumpButtonRelease`
1891 invokeJumpHelper = true;
1892 } else if (kJumpPressed && colWaterTop) {
1893 yAcc += initialJumpAcc*2;
1898 jumpButtonReleased = false;
1902 invokeJumpHelper = true;
1903 } else if (global.hasCape && kJumpPressed && kJumped && platformCharacterIs(IN_AIR)) {
1905 } else if (global.hasJetpack && !swimming && kJump && kJumped && platformCharacterIs(IN_AIR) && jetpackFuel > 0) {
1906 yAcc += initialJumpAcc;
1909 if (jetpackFlaresTime < 1) jetpackFlaresTime = 3;
1910 //!if (alarm[10] < 1) alarm[10] = 3; // jetpack flares
1914 jumpButtonReleased = false;
1918 invokeJumpHelper = true;
1919 } else if (platformCharacterIs(ON_GROUND) && kJumpPressed && fallTimer == 0) {
1920 if (fabs(xVel) > 3 /*xVel > 3 || xVel < -3*/) {
1921 yAcc += initialJumpAcc*2;
1924 yAcc += initialJumpAcc*2;
1926 //scrJumpHelper(); // move to location where player doesn't have to be on ground
1928 if (global.hasJordans) {
1932 } else if (global.hasSpringShoes) {
1939 playSound('sndJump');
1943 // the "state" gets changed to JUMPING later on in the code
1945 // "variable jumping" states
1946 jumpButtonReleased = false;
1948 invokeJumpHelper = true;
1951 if (kJumpPressed && invokeJumpHelper) scrJumpHelper(); // YASM 1.8.1
1953 if (jumpTime < jumpTimeTotal) jumpTime += 1;
1954 // let the character continue to jump
1955 if (!kJump) jumpButtonReleased = true;
1956 if (jumpButtonReleased) jumpTime = jumpTimeTotal;
1958 gravityIntensity = (jumpTime/jumpTimeTotal)*grav;
1960 if (kUp && platformCharacterIs(ON_GROUND) && !colLadder) {
1961 //k8:!!!looking = UP;
1962 if (xVel == 0 && xAcc == 0) status = LOOKING_UP;
1964 //k8:!!!looking = 0;
1967 if (!kUp && status == LOOKING_UP) status = STANDING;
1971 checkPerformHang(colLeft, colRight);
1975 // hang on stuck arrow
1976 if (status == FALLING && hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND) &&
1977 !level.isSolidAtPoint(x, y+12)) // from Spelunky Natural
1979 auto arrow = level.isObjectInRect(ix, iy, 16, 16, delegate bool (MapObject o) {
1982 writeln(" ARROW : (", o.x0, ",", o.y0, ")-(", o.x1, ",", o.y1, "); coll=", o.collidesWith(self));
1983 writeln(" PLAYER: (", x0, ",", y0, ")-(", x1, ",", y1, "); coll=", self.collidesWith(o), "; dy=", iy-o.iy);
1985 if (o.stuck && iy-o.iy >= -6 && iy-o.iy <= -5 && o.collidesWith(self)) {
1986 //writeln(" *** HANG IS POSSIBLE! p5=", !!level.isObjectAtPoint(ix, iy-5, &level.cbIsObjectArrow), "; p6=", !!level.isObjectAtPoint(ix, iy-6, &level.cbIsObjectArrow));
1990 }, castClass:ItemProjectileArrow, precise:false);
1993 // move_snap(1, 8); // was commented out in the original
1999 writeln("TRYING ARROW HANG ALLOWED");
2000 writeln(" Z00: ", !level.isObjectAtPoint(x, y-9, &level.cbIsObjectArrow));
2001 writeln(" Z01: ", !level.isObjectAtPoint(x, y+9, &level.cbIsObjectArrow));
2002 writeln(" Z02: ", !!level.isObjectAtPoint(x, y-5, &level.cbIsObjectArrow));
2003 writeln(" Z03: ", !!level.isObjectAtPoint(x, y-6, &level.cbIsObjectArrow));
2004 level.isObjectInRect(ix, iy, 16, 16, delegate bool (MapObject o) {
2006 writeln(" ARROW : (", o.x0, ",", o.y0, ")-(", o.x1, ",", o.y1, "); coll=", o.collidesWith(self));
2007 writeln(" PLAYER: (", x0, ",", y0, ")-(", x1, ",", y1, "); coll=", self.collidesWith(o), "; dy=", iy-o.iy);
2008 if (iy-o.iy >= -6 && iy-o.iy <= -5 && o.collidesWith(self)) {
2009 writeln(" *** HANG IS POSSIBLE! p5=", !!level.isObjectAtPoint(ix, iy-5, &level.cbIsObjectArrow), "; p6=", !!level.isObjectAtPoint(ix, iy-6, &level.cbIsObjectArrow));
2012 }, castClass:ItemProjectileArrow, precise:false);
2016 // hang on stuck arrow
2017 /*k8: this is not working due to collision issues; see the fixed code above
2018 if (status == FALLING && hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND) &&
2019 !level.isSolidAtPoint(x, y+12) && // from Spelunky Natural
2020 !level.isObjectAtPoint(x, y-9, &level.cbIsObjectArrow) && !level.isObjectAtPoint(x, y+9, &level.cbIsObjectArrow))
2022 //obj = instance_nearest(x, y-5, oArrow);
2023 auto arr0 = level.isObjectAtPoint(x, y-5, &level.cbIsObjectArrow);
2024 auto arr1 = level.isObjectAtPoint(x, y-6, &level.cbIsObjectArrow);
2026 writeln("ARROW HANG!");
2027 // get nearest arrow
2030 arr = (arr0.distanceToPoint(x, y-5) < arr1.distanceToPoint(x, y-5) ? arr0 : arr1);
2032 arr = (arr0 ? arr0 : arr1);
2036 // move_snap(1, 8); // was commented out in the original
2044 /* this was commented in the original
2045 if (hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND) && state == FALLING &&
2046 (collision_point(x, y-5, oTreeBranch, 0, 0) || collision_point(x, y-6, oTreeBranch, 0, 0)) &&
2047 !collision_point(x, y-9, oTreeBranch, 0, 0) && !collision_point(x, y+9, oTreeBranch, 0, 0))
2050 // move_snap(1, 8); // was commented out in the original
2058 if (hangCount > 0) --hangCount;
2060 if (status == HANGING) {
2065 if (global.hasGloves) {
2066 if (hangCount == 0 && y > 16 && !platformCharacterIs(ON_GROUND)) {
2067 if (kRight && colRight &&
2068 (level.isSolidAtPoint(x+9, y-5) || level.isSolidAtPoint(x+9, y-6)))
2074 } else if (kLeft && colLeft &&
2075 (level.isSolidAtPoint(x-9, y-5) || level.isSolidAtPoint(x-9, y-6)))
2097 yAcc += initialJumpAcc*2;
2098 shiftX(dir == Dir.Right ? -2 : 2);
2101 hangCount = hangCountMax;
2102 if (level.isObjectAtPoint(x, y-5, &level.cbIsObjectArrow) || level.isObjectAtPoint(x, y-6, &level.cbIsObjectArrow)) hangCount /= 2; //Spelunky Natural
2105 if ((dir == Dir.Left && !isCollisionLeft(2)) ||
2106 (dir == Dir.Right && !isCollisionRight(2)))
2117 // pressing down while standing
2118 if (kDown && platformCharacterIs(ON_GROUND) && !whipping) {
2121 } else if (colPlatBot) {
2122 // climb down ladder if possible, else jump down
2125 //ladder = instance_place(x, y+16, oLadder);
2127 // from Spelunky Natural
2129 ladder = collision_line(x-4, y+16, x+4, y+16, oLadder, 0, 0);
2130 if (!ladder) ladder = collision_line(x-4, y+16, x+4, y+16, oLadderTop, 0, 0);
2132 auto ladder = level.checkTilesInRect(x-4, y+16, 9, 1, &level.cbCollisionAnyLadder);
2133 //writeln("DOWN; cpb=", colPlatBot, "; cb=", colBot, "; ladder=", !!ladder);
2136 if (abs(x-(ladder.x0+8)) < 4) {
2150 kJumped = true; // Spelunky Natural
2154 // the character can't move down because there is a solid in the way
2159 if (!kDown && status == DUCKING) {
2164 if (xVel == 0 && xAcc == 0 && status == RUNNING) status = STANDING;
2165 if (xAcc != 0 && status == STANDING) status = RUNNING;
2166 if (yVel < 0 && platformCharacterIs(IN_AIR) && status != HANGING) status = JUMPING;
2167 if (yVel > 0 && platformCharacterIs(IN_AIR) && status != HANGING) status = FALLING;
2168 setCollisionBounds(-5, -6, 5, 8);
2171 bool colPointLadder = !!level.isAnyLadderAtPoint(x, y);
2173 /* this was commented in the original
2174 if ((kUp && platformCharacterIs(IN_AIR) && collision_point(x, y-8, oLadder, 0, 0) && ladderTimer == 0) ||
2175 (kUp && colPointLadder && ladderTimer == 0) ||
2176 (kDown && colPointLadder && ladderTimer == 0 && platformCharacterIs(ON_GROUND) && collision_point(x, y+9, oLadderTop, 0, 0) && xVel == 0))
2179 ladder = instance_place(x, y-8, oLadder);
2180 if (instance_exists(ladder)) {
2181 if (abs(x-(ladder.x0+8)) < 4) {
2184 if (!collision_point(x, y, oLadder, 0, 0) && !collision_point(x, y, oLadderTop, 0, 0)) { y = ladder.iy+14; setY(y); }
2194 // Spelunky Natural - Multiple changes to this big "if" condition
2195 if ((kUp && platformCharacterIs(IN_AIR) && ladderTimer == 0 && level.checkTilesInRect(x-2, y-8, 5, 1, &level.cbCollisionLadder)) ||
2196 (kUp && colPointLadder && ladderTimer == 0) ||
2197 (kDown && colPointLadder && ladderTimer == 0 && platformCharacterIs(ON_GROUND) && xVel == 0 && level.isLadderTopAtPoint(x, y+9)) ||
2198 ((kUp || kDown) && status == HANGING && level.checkTilesInRect(x-2, y, 5, 1, &level.cbCollisionLadder)))
2201 //auto ladder = instance_place(x, y-8, oLadder);
2202 auto ladder = level.isLadderAtPoint(x, y-8);
2204 //writeln("LADDER01! plrx=", x, "; ladder.x0=", ladder.x0, "; ladder.ix=", ladder.ix, "; ladder class=", GetClassName(ladder.Class));
2205 if (abs(x-(ladder.x0+8)) < 4) {
2208 if (!level.isAnyLadderAtPoint(x, y)) { y = ladder.y0+14; setY(y); }
2218 /* this was commented in the original
2219 if (sprite_index == sDuckToHangL || sprite_index == sDamselDtHL) {
2221 if (facing == LEFT && collision_rectangle(x-8, y, x, y+16, oLadder, 0, 0) && !collision_point(x-4, y+16, oSolid, 0, 0)) {
2222 ladder = instance_nearest(x-4, y+16, oLadder);
2223 } else if (facing == RIGHT && collision_rectangle(x, y, x+8, y+16, oLadder, 0, 0) && !collision_point(x+4, y+16, oSolid, 0, 0)) {
2224 ladder = instance_nearest(x+4, y+16, oLadder);
2237 if (colLadder && state == CLIMBING && kJumpPressed && !whipping) {
2238 if (kLeft) xVel = -departLadderXVel; else if (kRight) xVel = departLadderXVel; else xVel = 0;
2239 yAcc += departLadderYVel;
2241 jumpButtonReleased = false;
2247 // calculate horizontal/vertical friction
2248 if (status == CLIMBING) {
2249 xFric = frictionClimbingX;
2250 yFric = frictionClimbingY;
2252 //if (runKey && platformCharacterIs(ON_GROUND) && runHeld >= 10)
2253 if ((runKey && runHeld >= 10) && (platformCharacterIs(ON_GROUND) || global.config.toggleRunAnywhere)) {
2259 xFric = frictionRunningFastX;
2260 } else if (kRight) {
2263 xFric = frictionRunningFastX;
2265 } else if (status == DUCKING) {
2266 if (xVel < 2 && xVel > -2) {
2270 } else if (kLeft && global.config.downToRun) {
2274 xFric = frictionRunningFastX;
2275 } else if (kRight && global.config.downToRun) {
2278 xFric = frictionRunningFastX;
2281 if (xVel < 0.5) xVel = 0;
2287 // decrease the friction when the character is "flying"
2288 if (platformCharacterIs(IN_AIR)) {
2289 if (dead || stunned) xFric = 1.0; else xFric = 0.8;
2291 xFric = frictionRunningX;
2295 /* // ORIGINAL RUN/WALK xVel/xFric code this was commented in the original
2296 if (runKey && platformCharacterIs(ON_GROUND) && runHeld >= 10) {
2301 xFric = frictionRunningFastX;
2302 } else if (kRight) {
2305 xFric = frictionRunningFastX;
2307 } else if (state == DUCKING) {
2308 if (xVel < 2 && xVel > -2) {
2312 } else if (kLeft && global.downToRun) {
2316 xFric = frictionRunningFastX;
2317 } else if (kRight && global.downToRun) {
2320 xFric = frictionRunningFastX;
2323 if (xVel < 0.5) xVel = 0;
2329 // decrease the friction when the character is "flying"
2330 if (platformCharacterIs(IN_AIR)) {
2331 if (dead || stunned) xFric = 1.0; else xFric = 0.8;
2333 xFric = frictionRunningX;
2338 // stuck on web or underwater
2339 if (level.isObjectAtPoint(x, y, &level.cbIsObjectWeb)) {
2343 } else if (level.isObjectAtPoint(x, y, &level.cbIsObjectBlob)) {
2345 //obj = instance_place(x, y, oBlob); this was commented in the original
2346 //xVel += obj.xVel; this was commented in the original
2350 } else if (level.isWaterAtPoint(x, y/*, oWater, -1, -1*/)) {
2352 //if (!runKey && global.toggleRunAnywhere) xFric = frictionRunningX; // YASM 1.8.1 this was commented in the original
2353 if (!platformCharacterIs(ON_GROUND)) xFric = frictionRunningX;
2354 if (status == FALLING && yVel > 0) {
2356 if (global.config.naturalSwim && kUp) yFric = 0.2;
2357 else if (global.config.naturalSwim && kDown) yFric = 0.8;
2359 } else if (!level.isWaterAtPoint(x, y-9/*, oWater, -1, -1*/)) {
2364 if (yVel < -6 && global.config.noDolphin) {
2365 // Spelunky Natural (changed from -4 to -6)
2374 if (colIceBot && status != DUCKING && !global.hasSpikeShoes) {
2380 if (global.config.toggleRunAnywhere) {
2381 if (!kJump && !kDown && !runKey) xVelLimit = 3;
2385 if (platformCharacterIs(ON_GROUND)) {
2386 if (status == RUNNING && kLeft && colLeft) pushTimer += 1;
2387 else if (status == RUNNING && kRight && colRight) pushTimer += 1;
2390 //if (platformCharacterIs(ON_GROUND) && !kJump && !kDown && !runKey) this was commented in the original
2391 if (!kJump && !kDown && !runKey) xVelLimit = 3;
2393 /* this was commented in the original
2395 if (state == DUCKING && fabs(xVel) < 3 && facing == LEFT &&
2396 //collision_point(x, y+9, oSolid, 0, 0) && !collision_point(x-1, y+9, oSolid, 0, 0) && kLeft)
2397 collision_point(x, y+9, oSolid, 0, 0) && !collision_line(x-1, y+9, x-10, y+9, oSolid, 0, 0) && kLeft)
2402 if (kLeft && dir == Dir.Left) dhdir = -1;
2403 else if (kRight && dir == Dir.Right) dhdir = 1;
2405 if (dhdir && status == DUCKING && fabs(xVel) < 3+(dhdir < 0 ? 1 : 0) &&
2406 level.isSolidAtPoint(x, y+9) && !level.checkTilesInRect(x+(dhdir < 0 ? -8 : 1), y+9, 8, 8))
2408 status = DUCKTOHANG;
2410 if (!global.config.scumFlipHold || holdItem.heavy) {
2412 holdItem.heldBy = none;
2413 if (holdItem.objName == 'GoldIdol') holdItem.shiftY(-8);
2415 //else if (holdItem.type == "Block Item") { with (oBlockPreview) instance_destroy(); }
2416 scrDropItem(LostCause.Hang, (dir == Dir.Left ? -1 : 1), -4);
2423 if (status == DUCKTOHANG) {
2424 setXY(xPrev, yPrev);
2434 // parachute and cape
2435 if (!level.inWinCutscene) {
2436 if (isParachuteActive() || isCapeActiveAndOpen()) yFric = 0.5;
2439 if (pushTimer > 100) pushTimer = 100;
2441 // limits the acceleration if it is too extreme
2442 xAcc = fclamp(xAcc, -xAccLimit, xAccLimit);
2443 yAcc = fclamp(yAcc, -yAccLimit, yAccLimit);
2445 // applies the acceleration
2447 if (dead || stunned) yVel += 0.6; else yVel += yAcc;
2449 // nullifies the acceleration
2453 // applies the friction to the velocity, now that the velocity has been calculated
2457 auto oBall = getMyBall();
2458 // apply ball and chain
2460 int distsq = (ix-oBall.ix)*(ix-oBall.ix)+(iy-oBall.iy)*(iy-oBall.iy);
2461 if (distsq >= 24*24) {
2462 if (xVel > 0 && oBall.ix < ix && abs(oBall.ix-ix) > 24) xVel = 0;
2463 if (xVel < 0 && oBall.ix > ix && abs(oBall.ix-ix) > 24) xVel = 0;
2464 if (yVel > 0 && oBall.iy < iy && abs(oBall.iy-iy) > 24) {
2465 if (abs(oBall.ix-ix) < 1) {
2466 //teleportTo(destx:oBall.ix);
2468 prevFltX = oBall.prevFltX;
2470 } else if (oBall.ix < ix && !kRight) {
2471 if (xVel > 0) xVel *= -0.25;
2472 else if (xVel == 0) xVel -= 1;
2473 } else if (oBall.ix > ix && !kLeft) {
2474 if (xVel < 0) xVel *= -0.25;
2475 else if (xVel == 0) xVel += 1;
2480 if (yVel < 0 && oBall.iy > iy && abs(oBall.iy-iy) > 24) yVel = 0;
2484 // apply the limits since the velocity may be too extreme
2485 if (!dead && !stunned) xVel = fclamp(xVel, -xVelLimit, xVelLimit);
2486 yVel = fclamp(yVel, -yVelLimit, yVelLimit);
2488 // approximates the "active" variables
2489 if (fabs(xVel) < 0.0001) xVel = 0;
2490 if (fabs(yVel) < 0.0001) yVel = 0;
2491 if (fabs(xAcc) < 0.0001) xAcc = 0;
2492 if (fabs(yAcc) < 0.0001) yAcc = 0;
2494 bool wasInWall = !!isCollision();
2495 moveRel(xVel, yVel);
2497 // don't go out of level (if we're not in ending sequence)
2498 if (!level.inWinCutscene && !level.inIntroCutscene) {
2499 if (ix < 0) fltx = 0;
2500 else if (ix > level.tilesWidth*16-16) fltx = level.tilesWidth*16-16;
2501 if (iy < 0) flty = 0;
2503 if (!dead) hackBoulderCollision();
2505 if (!wasInWall && isCollision()) {
2506 writeln("** FUUUU (XXX)");
2507 if (isCollisionBottom(0) && !isCollisionBottom(-2)) {
2510 // we can stuck in the wall with this
2511 if (isCollisionLeft(0)) {
2512 writeln("** FUUUU (001: left)");
2513 while (isCollisionLeft(0) && !isCollisionRight(1)) shiftX(1);
2514 } else if (isCollisionRight(0)) {
2515 writeln("** FUUUU (001: right)");
2516 while (isCollisionRight(0) && !isCollisionLeft(1)) shiftX(-1);
2520 if (!dead) hackBoulderCollision();
2522 // move out of wall by 1 px, if possible
2523 if (!dead && isCollision()) {
2524 if (isCollisionBottom(0) && !isCollisionBottom(-1)) flty = iy-1;
2525 if (isCollisionTop(0) && !isCollisionTop(1)) flty = iy+1;
2526 if (isCollisionLeft(0) && !isCollisionLeft(1)) fltx = ix+1;
2527 if (isCollisionRight(0) && !isCollisionRight(-1)) fltx = ix-1;
2530 if (!dead && isCollision()) {
2531 //k8:HACK: try to duck
2532 bool wallDeath = true;
2533 if (platformCharacterIs(ON_GROUND)) {
2534 setCollisionBounds(-5, -6, 5, 8);
2535 auto ohbX = hitboxX, ohbY = hitboxY;
2536 auto ohbW = hitboxW, ohbH = hitboxH;
2537 wallDeath = !!isCollision();
2539 //setCollisionBounds(-8, -6, 8, 8);
2540 hitboxX = ohbX; hitboxY = ohbY;
2541 hitboxW = ohbW; hitboxH = ohbH;
2550 if (isCollision()) {
2551 if (isCollisionLeft(0) && !isCollisionRight(4)) fltx = ix+1;
2552 else if (isCollisionRight(0) && !isCollisionLeft(4)) fltx = ix-1;
2553 else if (isCollisionBottom(0) && !isCollisionTop(4)) flty = iy-1;
2554 else if (isCollisionTop(0) && !isCollisionBottom(4)) flty = iy+1;
2559 if (wallDeath && isCollision()) {
2560 if (!dead) level.addDeath('wall');
2563 writeln("PLAYER KILLED BY WALL");
2564 global.plife = 0; // oops
2570 //writeln("flty=", flty, "; iy=", iy);
2576 // figures out what the sprite index of the character should be
2579 // sets the previous state and the previously previous state
2580 statePrevPrev = statePrev;
2583 // calculates the imageSpeed based on the character's velocity
2584 if (status == RUNNING || status == DUCKING || status == LOOKING_UP) {
2585 if (status == RUNNING || status == LOOKING_UP) imageSpeed = fabs(xVel)*runAnimSpeed+0.1;
2588 if (status == CLIMBING) imageSpeed = sqrt(xVel*xVel+yVel*yVel)*climbAnimSpeed;
2590 if (xVel >= 4 || xVel <= -4) {
2592 if (platformCharacterIs(ON_GROUND)) {
2593 setCollisionBounds(-8, -6, 8, 8);
2595 setCollisionBounds(-5, -6, 5, 8);
2598 setCollisionBounds(-5, -6, 5, 8);
2601 if (whipping) imageSpeed = 1;
2603 if (status == DUCKTOHANG) {
2608 // limit the imageSpeed at 1 so the animation always looks good
2609 if (imageSpeed > 1) imageSpeed = 1;
2611 //if (kItemPressed) writeln("ITEM! dead=", dead, "; stunned=", stunned, "; active=", active);
2612 if (dead || stunned || !active) {
2614 } else if (/*inGame &&*/ kItemPressed && !whipping) {
2616 if (kUp) scrSwitchToStickyBombs(); else scrSwitchToNextItem();
2617 } else if (/*inGame &&*/ kRopePressed && global.rope > 0 && !whipping) {
2618 if (!kDown && colTop) {
2621 launchRope(kDown, doDrop:true);
2623 } else if (/*inGame &&*/ kBombPressed && global.bombs > 0 && !whipping) {
2624 if (holdItem isa ItemWeaponBow && bowArmed) {
2625 if (holdArrow != ARROW_BOMB) {
2626 //writeln("set bow arrows to bomb");
2627 holdArrow = ARROW_BOMB;
2629 //writeln("set bow arrows to normal");
2630 holdArrow = ARROW_NORM;
2639 if (!dead && !stunned && kUp && kAttackPressed) {
2640 auto octr = ItemOpenableContainer(level.isObjectInRect(ix, iy, width, height, delegate bool (MapObject o) {
2641 return (o isa ItemOpenableContainer);
2644 if (octr.openMe()) kAttackPressed = false;
2649 // use weapon / attack
2650 if (!dead && !stunned && kAttackPressed && !holdItem /*&& !pickedItem*/) {
2653 sndStopSound('sndBowPull');
2654 if (!global.config.unarmed && status != DUCKING && status != DUCKTOHANG && !whipping && !isExitingSprite()) {
2656 if (global.isTunnelMan) {
2657 if (platformCharacterIs(ON_GROUND) || platformCharacterIs(IN_AIR)) {
2658 setSprite('sTunnelAttackL');
2661 } else if (global.isDamsel) {
2662 setSprite('sDamselAttackL');
2665 setSprite('sAttackLeft');
2668 } else if (kDown && !pickedItem) {
2670 //HACK: always select dice to throw if there are two dices there
2671 MapObject diceToThrow = level.isObjectInRect(x-8, y, 9, 9, delegate bool (MapObject o) {
2672 if (o.spectral || !o.canPickUp) return false;
2673 if (ItemDice(o).isReadyToThrowForBet) return o.collidesWith(self);
2675 }, precise:false, castClass:ItemDice);
2680 obj = level.isObjectInRect(x-8, y, 9, 9, delegate bool (MapObject o) {
2681 if (o.spectral || !o.canPickUp) return false;
2682 if (!o.collidesWith(self)) return false;
2683 return o.onCanBePickedUp(self);
2685 if (o isa MapItem) return (o.active && o.canPickUp && !o.spectral);
2686 if (o isa MapEnemy) return (o.active && o.canPickUp && !o.spectral && (o.dead || o.status >= MapObject::STUNNED || o.meGoldMonkey));
2691 if (!obj && diceToThrow) obj = diceToThrow;
2693 // `canPickUp` is checked in callback
2694 if (/*obj.canPickUp &&*/ true /*k8: do we really need this? !level.isSolidAtPoint(obj.ix+2, obj.iy)*/) {
2695 //pickupItemType = holdItem.type;
2696 //!if (isAshShotgun(holdItem)) pickupItemType = "Boomstick";
2697 //!if (isGoldMonkey(obj) and obj.status < 98) obj.status = 0; // do not play walk animation while held
2699 if (!obj.onTryPickup(self)) {
2700 if (obj.isInstanceAlive) scrPickupItem(obj);
2704 if (holdItem.type == "Bow" and holdItem.new) {
2705 holdItem.new = false;
2707 if (global.arrows > 99) global.arrows = 99;
2713 } else if (!dead && !stunned) {
2714 if (holdItem isa ItemWeaponBow) {
2715 //writeln("BOW! kAttack=", kAttack, "; kAttackPressed=", kAttackPressed, "; bowArmed=", bowArmed, "; bowStrength=", bowStrength, "; holdArrow=", holdArrow);
2716 if (kAttackPressed) {
2717 if (scrPlayerIsDucking()) {
2718 scrUsePutItemOnGround();
2719 } else if (!bowArmed) {
2721 ItemWeaponBow(holdItem).armBow(self);
2725 if (bowArmed && bowStrength < 12) {
2727 //writeln("arming: ", bowStrength);
2729 sndStopSound('sndBowPull');
2732 //writeln(" xxBOW!");
2736 if (!holdArrow) holdArrow = ARROW_NORM;
2738 if (kAttackPressed && holdItem) scrUseItem();
2742 // remove held item offer
2743 if (!level.isInShop(ix/16, iy/16)) {
2744 if (holdItem) holdItem.sellOfferDone = false;
2745 if (pickedItem) pickedItem.sellOfferDone = false;
2749 if (!dead && !stunned && kPayPressed) {
2750 // find nearest shopkeeper
2751 auto sc = MonsterShopkeeper(level.findNearestObject(ix, iy, delegate bool (MapObject o) {
2752 auto sc = MonsterShopkeeper(o);
2753 if (!sc) return false;
2754 //if (needCraps && sc.stype != 'Craps') return false;
2755 if (sc.dead || sc.angered || sc.outlaw) return false;
2756 return sc.canSellItem(self, holdItem);
2758 if (level.isInShop(ix/16, iy/16)) {
2759 // if no shopkeepers found, just use it
2762 holdItem.forSale = false;
2763 holdItem.onTryPickup(self);
2765 } else if (global.thiefLevel == 0 && !global.murderer) {
2766 // only law-abiding players can buy/sell items or play games
2767 if (holdItem) writeln("shop item interaction: ", holdItem.objName, "; cost=", holdItem.cost);
2768 if (sc.doSellItem(self, holdItem)) {
2771 holdItem.forSale = false;
2772 holdItem.onTryPickup(self);
2775 if (holdItem && !holdItem.isInstanceAlive) {
2777 scrSwitchToPocketItem(forceIfEmpty:false); // just in case
2781 // use pickup, if any
2782 if (holdItem isa ItemPickup) {
2783 // make nearest shopkeeper angry (an unlikely situation, but still...)
2784 if (sc && holdItem.forSale) level.scrShopkeeperAnger(GameLevel::SCAnger.ItemStolen);
2785 holdItem.forSale = false;
2786 holdItem.onTryPickup(self);
2788 pickupsAround.clear();
2789 level.isObjectInRect(x0, y0, width, height, delegate bool (MapObject o) {
2790 auto pk = ItemPickup(o);
2791 if (pk && pk.collidesWith(self)) {
2793 foreach (auto opk; pickupsAround) if (opk == pk) { found = true; break; }
2794 if (!found) pickupsAround[$] = pk;
2798 // now try to use all pickups
2799 foreach (ItemPickup pk; pickupsAround) {
2800 if (pk.isInstanceAlive) {
2801 if (sc && pk.forSale) level.scrShopkeeperAnger(GameLevel::SCAnger.ItemStolen);
2803 pk.onTryPickup(self);
2806 pickupsAround.clear();
2812 transient array!ItemPickup pickupsAround;
2815 // ////////////////////////////////////////////////////////////////////////// //
2816 override bool initialize () {
2817 if (!::initialize()) return false;
2819 powerups.length = 0;
2820 powerups[$] = SpawnObject(PPParachute);
2821 powerups[$] = SpawnObject(PPCape);
2823 foreach (PlayerPowerup pp; powerups) pp.owner = self;
2825 if (global.isDamsel) {
2827 desc2 = "An athletic, unfittingly-dressed woman with extremely awkward running form.";
2828 setSprite('sDamselLeft');
2829 } else if (global.isTunnelMan) {
2830 desc = "Tunnel Man";
2831 desc2 = "A miner from the desert. His tools are a cut above the rest.";
2832 setSprite('sTunnelLeft');
2835 desc2 = "A strange little man who spends his time exploring caverns. He wants to be just like Indiana Jones when he grows up.";
2836 setSprite('sStandLeft');
2844 switch (global.config.scumClimbSpeed) {
2847 climbAnimSpeed = 0.4;
2852 climbAnimSpeed = 0.45;
2857 climbAnimSpeed = 0.5;
2862 climbAnimSpeed = 0.5;
2866 climbAcc = 0.6; // how fast the character will climb
2867 climbAnimSpeed = 0.4; // relates to how fast the climbing animation should go
2872 // sets the collision bounds to fit the default sprites (you can edit the arguments of the script)
2873 setCollisionBounds(-5, -5, 5, 8); // setCollisionBounds(-5, -8, 5, 8);
2876 statePrevPrev = statePrev;
2877 gravityIntensity = grav; // this variable describes the current force due to gravity (this variable is altered for variable jumping)
2878 jumpTime = jumpTimeTotal; // current time of the jump (0=start of jump, jumpTimeTotal=end of jump)
2884 // ////////////////////////////////////////////////////////////////////////// //
2885 override void onAnimationLooped () {
2886 auto spr = getSprite();
2887 if (spr.Name == 'sAttackLeft' || spr.Name == 'sDamselAttackL' || spr.Name == 'sTunnelAttackL') {
2888 removeActivatedPlayerWeapon();
2889 } else if (spr.Name == 'sDuckToHangL' || spr.Name == 'sDamselDtHL' || spr.Name == 'sTunnelDtHL') {
2899 if (dir == Dir.Left) {
2901 obj = level.isAnyLadderAtPoint(x-8, y);
2904 obj = level.isAnyLadderAtPoint(x+8, y);
2909 } else if (dir == Dir.Left) {
2919 } else if (isExitingSprite()) {
2921 //!global.cleanSolids = true;
2926 void activatePlayerWeapon () {
2928 if (holdItem isa PlayerWeapon) {
2929 auto wep = holdItem;
2931 wep.instanceRemove();
2936 if (holdItem isa PlayerWeapon) {
2938 removeActivatedPlayerWeapon();
2945 auto spr = getSprite();
2946 if (spr.Name != 'sAttackLeft' && spr.Name != 'sDamselAttackL' && spr.Name != 'sTunnelAttackL') {
2947 writeln("PLR ATTACK DONE; holdItem=", (holdItem ? GetClassName(holdItem.Class) : '<none>'), "; frm=", imageFrame);
2949 writeln("PLR ATTACK; holdItem=", (holdItem ? GetClassName(holdItem.Class) : '<none>'), "; frm=", imageFrame);
2954 if (global.config.unarmed && !holdItem) return; // no whip when unarmed
2956 auto spr = getSprite();
2957 if (spr.Name != 'sAttackLeft' && spr.Name != 'sDamselAttackL' && spr.Name != 'sTunnelAttackL') {
2958 //writeln("PLR ATTACK DONE; holdItem=", (holdItem ? GetClassName(holdItem.Class) : '<none>'), "; frm=", imageFrame);
2961 //writeln("PLR ATTACK; holdItem=", (holdItem ? GetClassName(holdItem.Class) : '<none>'), "; frm=", imageFrame);
2963 if (imageFrame > 4) {
2964 //bool hitEnemy = (PlayerWeapon(holdItem) ? PlayerWeapon(holdItem).hitEnemy : false);
2965 if (global.isTunnelMan || pickedItem isa ItemWeaponMattock) {
2966 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oMattockHit');
2967 if (imageFrame < 7) playSound('sndWhip');
2968 } else if (pickedItem isa ItemWeaponMachete) {
2969 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oSlash');
2970 playSound('sndWhip');
2972 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oWhip');
2973 playSound('sndWhip');
2975 } else if (imageFrame < 2) {
2976 if (global.isTunnelMan || pickedItem isa ItemWeaponMattock) {
2977 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oMattockPre');
2978 } else if (pickedItem isa ItemWeaponMachete) {
2979 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? -16 : 16), iy, 'oMachetePre');
2981 holdItem = level.MakeMapObject(ix+(dir == Dir.Left ? 16 : -16), iy, 'oWhipPre');
2987 //bool webHit = false;
2989 bool doBreakWebsCB (MapObject o) {
2990 if (o isa ItemWeb) {
2993 if (fabs(xVel) > 1) {
2995 if (!o.dying) ItemWeb(o).life -= 5;
2999 if (fabs(yVel) > 1) {
3001 if (!o.dying) ItemWeb(o).life -= 5;
3011 void initiateExitSequence () {
3012 writeln("exit sequence initiated...");
3013 if (global.isDamsel) setSprite('sDamselExit');
3014 else if (global.isTunnelMan) setSprite('sTunnelExit');
3015 else setSprite('sPExit');
3022 /*k8: the following is done in `GameLevel`
3023 if (global.thiefLevel > 0) global.thiefLevel -= 1;
3024 //orig dbg:if (global.currLevel == 1) global.currLevel += firstLevelSkip; else global.currLevel += levelSkip;
3025 global.currLevel += 1;
3027 playSound('sndSteps');
3031 void processLevelExit () {
3032 if (dead || stunned || whipping || level.playerExited) return;
3033 if (!platformCharacterIs(ON_GROUND)) return;
3034 if (isExitingSprite()) return; // just in case
3036 auto hld = holdItem;
3037 if (hld isa PlayerWeapon) return; // oops
3039 //if (!kExitPressed && !hld) return false;
3041 auto door = level.checkTileAtPoint(ix, iy, &level.cbCollisionExitTile);
3042 if (!door || !door.visible) return; // note that `invisible` doors still works
3044 // sell idol, or free damsel
3045 if (hld isa ItemGoldIdol) {
3046 //!if (isRealLevel()) global.idolsConverted += 1;
3047 //not thisglobal.money += hld.value*(global.levelType+1);
3048 ItemGoldIdol(hld).registerConverted();
3049 addScore(hld.value*(global.levelType+1));
3050 //!if (hld.sprite_index == sCrystalSkull) global.skulls += 1; else global.idols += 1;
3051 playSound('sndCoin');
3052 level.MakeMapObject(ix, iy-8, 'oBigCollect');
3054 hld.instanceRemove();
3055 //!with (hld) instance_destroy();
3057 //!pickupItemType = "";
3058 } else if (hld isa MonsterDamsel) {
3060 MonsterDamsel(hld).exitAtDoor(door);
3063 if (!kExitPressed) {
3064 if (!door.invisible) {
3065 string msg = door.getExitMessage();
3066 if (msg.length == 0) {
3067 level.osdMessage(va("PRESS %s TO ENTER.", (global.config.useDoorWithButton ? "$PAY" : "$UP")), -666);
3068 } else if (msg[$-1] != '\n') {
3069 level.osdMessage(va("%s\nPRESS %s TO ENTER.", msg, (global.config.useDoorWithButton ? "$PAY" : "$UP")), -666);
3071 level.osdMessage(msg, -666);
3082 if (isHoldingArmedBomb()) scrUseThrowItem();
3084 if (isHoldingBombOrRope()) scrSwitchToPocketItem(forceIfEmpty:true);
3086 wasHoldingBall = false;
3089 if (hld isa ItemGoldIdol) {
3090 //!if (isRealLevel()) global.idolsConverted += 1;
3091 //not thisglobal.money += hld.value*(global.levelType+1);
3092 ItemGoldIdol(hld).registerConverted();
3093 addScore(hld.value*(global.levelType+1));
3094 //!if (hld.sprite_index == sCrystalSkull) global.skulls += 1; else global.idols += 1;
3095 playSound('sndCoin');
3096 level.MakeMapObject(ix, iy-8, 'oBigCollect');
3098 hld.instanceRemove();
3099 //!with (hld) instance_destroy();
3101 //!pickupItemType = "";
3102 } else if (hld isa MonsterDamsel) {
3104 MonsterDamsel(hld).exitAtDoor(door);
3105 } else if (hld.heavy || hld isa MapEnemy) {
3106 // drop heavy items, characters and enemies (but not ball)
3107 if (hld !isa ItemBall) scrUseThrowItem();
3108 } else if (hld isa ItemBall) {
3110 // other items are carried thru
3111 if (hld.cannotBeCarriedOnNextLevel) {
3113 holdItem = none; // just in case
3115 scrHideItemToPocket();
3118 global.pickupItem = hld.type;
3119 if (isAshShotgun(hld)) global.pickupItem = "Boomstick";
3121 breakPieces = false;
3125 //scrHideItemToPocket();
3131 //door = instance_place(x, y, oExit); // done above
3132 door.snapToExit(self);
3134 initiateExitSequence();
3136 level.playerExitDoor = door;
3140 override bool onFellInWater (MapTile water) {
3141 level.MakeMapObject(ix, iy-8, 'oSplash');
3143 playSound('sndSplash');
3144 myGrav = 0.2; //k8:???
3149 override bool onOutOfWater () {
3156 // ////////////////////////////////////////////////////////////////////////// //
3157 override void thinkFrame () {
3159 // remove whip, etc. when dead
3160 if (dead && holdItem isa PlayerWeapon) {
3161 removeActivatedPlayerWeapon();
3164 setPowerupState('Cape', global.hasCape);
3166 foreach (PlayerPowerup pp; powerups) if (pp.active) pp.onPreThink();
3170 if (redToggle) redColor -= 5;
3171 else if (redColor < 20) redColor += 5;
3172 else redToggle = true;
3177 if (dead) justdied = false;
3180 if (invincible > 0) --invincible;
3186 blinkHidden = !blinkHidden;
3189 blinkHidden = false;
3192 auto spr = getSprite();
3195 if (level.lg && level.isInShop(x/16, y/16)) {
3196 shopType = level.lg.roomShopType(x/16, y/16);
3201 cameraBlockX = max(0, cameraBlockX-1);
3202 cameraBlockY = max(0, cameraBlockY-1);
3205 if (spr.Name == 'sWhoaLeft' || spr.Name == 'sDamselWhoaL' || spr.Name == 'sTunnelWhoaL') {
3206 if (whoaTimer > 0) {
3208 } else if (holdItem && onLoosingHeldItem(LostCause.Whoa)) {
3211 if (!hi.onLostAsHeldItem(self, LostCause.Whoa)) {
3215 scrSwitchToPocketItem(forceIfEmpty:true);
3219 whoaTimer = whoaTimerMax;
3223 if (firing > 0) firing -= 1;
3226 auto wtile = level.isWaterAtPoint(x, y/*, oWaterSwim, -1, -1*/);
3229 if (onFellInWater(wtile) || !isInstanceAlive) return;
3233 if (onOutOfWater() || !isInstanceAlive) return;
3239 if (global.randOther(1, 5) == 1) level.MakeMapObject(x-8+global.randOther(4, 12), y-8+global.randOther(4, 12), 'oBurn');
3244 if (!dead && level.isLavaAtPoint(x, y+6/*, oLava, 0, 0*/)) {
3245 //!if (isRealLevel()) global.miscDeaths[11] += 1;
3246 level.addDeath('lava');
3247 playSound('sndFlame');
3261 if (global.hasJetpack && platformCharacterIs(ON_GROUND)) {
3265 // fall off bottom of screen
3266 if (!level.inWinCutscene && !level.inIntroCutscene) {
3267 if (!dead && y > level.tilesHeight*16+16) {
3268 //!if (isRealLevel()) global.miscDeaths[10] += 1;
3269 level.addDeath('void');
3270 global.plife = -90; // spill blood
3276 scrDropItem(LostCause.Falloff);
3277 playSound('sndThud'); //???
3278 playSound('sndDie'); //???
3281 if (dead && y > level.tilesHeight*16+16) {
3289 if (/*active*/true) {
3290 if (spr.Name == 'sStunL' || spr.Name == 'sDamselStunL' || spr.Name == 'sTunnelStunL') {
3291 if (stunTimer > 0) {
3295 if (stunTimer < 1) {
3297 canDropStuff = true;
3301 if (!level.inWinCutscene) {
3302 if (isParachuteActive() || isCapeActiveAndOpen()) fallTimer = 0;
3305 // changed to yVel > 1 from yVel > 0
3306 if (yVel > 1 && status != CLIMBING) {
3308 if (fallTimer > 16) wallHurt = 0; // no sense in them taking extra damage from being thrown here
3309 int paraOpenHeight = (global.config.scumSpringShoesReduceFallDamage && (global.hasSpringShoes || global.hasJordans) ? 22 : 14);
3310 //paraOpenHeight = 4;
3311 if (global.hasParachute && !stunned && fallTimer > paraOpenHeight) {
3312 //if (not collision_point(x, y+32, oSolid, 0, 0)) // was commented in the original code
3313 //!*if (not collision_line(x, y+16, x, y+32, oSolid, 0, 0))
3314 if (!level.checkTilesInRect(x, y+16, 1, 17, &level.cbCollisionAnySolid)) {
3316 //!instance_create(x-8, y-16, oParachute);
3318 global.hasParachute = false;
3319 activatePowerup('Parachute');
3320 //writeln("parachute state: ", isParachuteActive());
3323 } else if (fallTimer > 16 && platformCharacterIs(ON_GROUND) &&
3324 !level.checkTilesInRect(x-8, y-8, 17, 17, &level.cbCollisionSpringTrap) /* not onto springtrap */)
3326 // long drop -- player has just landed
3327 bool reducedDamage = (global.config.scumSpringShoesReduceFallDamage && (global.hasSpringShoes || global.hasJordans));
3328 if (reducedDamage && fallTimer <= 24) {
3329 // land without taking damage
3333 if (fallTimer > (reducedDamage ? 72 : 48)) global.plife -= 10*global.config.scumFallDamage;
3334 else if (fallTimer > (reducedDamage ? 48 : 32)) global.plife -= 2*global.config.scumFallDamage;
3335 else global.plife -= 1*global.config.scumFallDamage;
3336 if (global.plife < 1) {
3337 if (!dead) level.addDeath('fall');
3341 if (global.config.scumFallDamage > 0) stunTimer += 60;
3344 auto obj = level.MakeMapObject(x-4, y+6, 'oPoof');
3345 if (obj) obj.xVel = -0.4;
3346 obj = level.MakeMapObject(x+4, y+6, 'oPoof');
3347 if (obj) obj.xVel = 0.4;
3348 playSound('sndThud');
3350 } else if (yVel <= 0) {
3352 if (isParachuteActive()) {
3353 deactivatePowerup('Parachute');
3354 level.MakeMapObject(ix-8, iy-16-8, 'oParaUsed');
3358 // if (stunned) fallTimer = 0; // was commented in the original code
3360 if (swimming && !level.isLavaAtPoint(x, y/*, oLava, 0, 0*/)) {
3362 if (bubbleTimer > 0) {
3365 if (level.isWaterAtPoint(x, (y&~0x0f)-8)) level.MakeMapObject(x, y-4, 'oBubble');
3366 bubbleTimer = bubbleTimerMax;
3369 bubbleTimer = bubbleTimerMax;
3372 //TODO: k8: move spear checking to spear handler
3373 if (!isExitingSprite()) {
3374 auto spear = MapObjectSpearsBase(level.isObjectInRect(ix-6, iy-6, 13, 14, delegate bool (MapObject o) {
3375 auto tt = MapObjectSpearsBase(o);
3376 if (!tt) return false;
3377 return tt.isHitFrame;
3382 global.plife -= global.config.spearDmg; // 4
3383 if (!dead && global.plife <= 0 /*and isRealLevel()*/) level.addDeath('spear');
3384 xVel = global.randOther(4, 6)*(spear.isLeft ? -1 : 1);
3393 if (status != DUCKTOHANG && !stunned && !dead && !isExitingSprite()) {
3395 characterStepEvent();
3397 if (status != DUCKING && status != DUCKTOHANG) status = STANDING;
3398 checkControlKeys(getSprite());
3402 // if (dead or stunned)
3403 if (dead || stunned) {
3405 if (holdItem isa ItemWeaponBow && bowArmed) scrFireBow();
3406 scrDropItem(dead ? LostCause.Dead : LostCause.Stunned, xVel, -3);
3409 yVel += (bounced ? 1.0 : 0.6);
3411 if (isCollisionTop(1) && yVel < 0) yVel = -yVel*0.8;
3412 if (isCollisionLeft(1) || isCollisionRight(1)) xVel = -xVel*0.5;
3414 bool collisionbottomcheck = !!isCollisionBottom(1);
3415 if (collisionbottomcheck || isCollisionBottom(1, &level.cbCollisionPlatform)) {
3417 if (collisionbottomcheck) {
3418 if (yVel > 2.5) yVel = -yVel*0.5; else yVel = 0;
3420 // after falling onto a platform don't take extra damage after recovering from stunning
3423 /* was commented in the original code
3424 if (isCollisionBottom(1)) {
3425 if (yVel > 2.5) yVel = -yVel*0.5; else yVel = 0;
3432 if (fabs(xVel) < 0.1) xVel = 0;
3433 else if (fabs(xVel) != 0 && level.isIceAtPoint(x, y+16)) xVel *= 0.8;
3434 else if (fabs(xVel) != 0) xVel *= 0.3;
3440 //level.forEachObjectInRect(ix, iy, width, height, &doBreakWebsCB);
3442 // apply the limits since the velocity may be too extreme
3444 xVel = fclamp(xVel, -xVelLimit, xVelLimit);
3445 yVel = fclamp(yVel, -yVelLimit, yVelLimit);
3447 moveRel(xVel, yVel);
3451 // fix sprites, spawn blood from spikes
3452 if (isParachuteActive()) {
3453 deactivatePowerup('Parachute');
3454 level.MakeMapObject(ix-8, iy-16-8, 'oParaUsed');
3458 removeActivatedPlayerWeapon();
3460 //!with (oWhip) instance_destroy();
3463 if (global.isDamsel) {
3465 if (dead) setSprite('sDamselDieL');
3466 else if (stunned) setSprite('sDamselStunL');
3467 } else if (bounced) {
3468 if (yVel < 0) setSprite('sDamselBounceL'); else setSprite('sDamselFallL');
3470 if (xVel < 0) setSprite('sDamselDieLL'); else setSprite('sDamselDieLR');
3472 } else if (global.isTunnelMan) {
3474 if (dead) setSprite('sTunnelDieL');
3475 else if (stunned) setSprite('sTunnelStunL');
3476 } else if (bounced) {
3477 if (yVel < 0) setSprite('sTunnelLBounce'); else setSprite('sTunnelFallL');
3479 if (xVel < 0) setSprite('sTunnelDieLL'); else setSprite('sTunnelDieLR');
3483 if (dead) setSprite('sDieL');
3484 else if (stunned) setSprite('sStunL');
3485 } else if (bounced) {
3486 if (yVel < 0) setSprite('sDieLBounce'); else setSprite('sDieLFall');
3488 if (xVel < 0) setSprite('sDieLL'); else setSprite('sDieLR');
3495 auto colobj = isCollisionRight(1);
3496 if (!colobj) colobj = isCollisionLeft(1);
3497 if (!colobj) colobj = isCollisionBottom(1);
3500 scrCreateBlood(colobj.x0, colobj.y0, 3);
3502 if (!dead && global.plife <= 0 /*&& isRealLevel()*/) {
3504 writeln("thrown to death by '", thrownBy, "'");
3505 level.addDeath(thrownBy);
3509 if (wallHurt <= 0) thrownBy = '';
3510 playSound('sndHurt'); //???
3514 colobj = isCollisionBottom(1);
3515 if (colobj && !bounced) {
3517 scrCreateBlood(colobj.x0, colobj.y0, 2);
3520 if (!dead && global.plife <= 0 /*and isRealLevel()*/) {
3522 writeln("thrown to death by '", thrownBy, "'");
3523 level.addDeath(thrownBy);
3527 if (wallHurt <= 0) thrownBy = '';
3532 bool kPay = level.isKeyDown(GameConfig::Key.Pay);
3534 // gnounc's quick look
3535 if (!kRight && !kLeft && (platformCharacterIs(ON_GROUND) || status == HANGING)) {
3536 if (kDown) { if (viewCount <= 6) viewCount += 3; else viewOffset += 6; }
3537 else if (kUp) { if (viewCount <= 6) viewCount += 3; else viewOffset -= 6; }
3543 // default look up/down with delay if pay button not held
3544 if (!kRight && !kLeft && (platformCharacterIs(ON_GROUND) || status == HANGING)) {
3545 if (kDown) { if (viewCount <= 30) viewCount += 1; else viewOffset += 4; }
3546 else if (kUp) { if (viewCount <= 30) viewCount += 1; else viewOffset -= 4; }
3553 if (viewCount == 0 && viewOffset) viewOffset = (viewOffset < 0 ? min(0, viewOffset+8) : max(0, viewOffset-8));
3554 viewOffset = clamp(viewOffset, -16*6, 16*6);
3556 if (!dead) activatePlayerWeapon();
3558 if (!dead) processLevelExit();
3561 if (global.plife < -99 && visible && justdied) spillBlood();
3563 if (global.plife < 1) {
3567 // spikes, and other shit
3568 if (global.plife >= -99 && visible && !isExitingSprite()) {
3569 auto colSpikes = level.checkTilesInRect(x-4, y-4, 9, 13, &level.cbCollisionSpikes);
3571 if (colSpikes && dead) {
3573 if (!level.isSolidAtPoint(x, y+9)) { shiftY(0.02); y = iy; } //0.05;
3574 //else myGrav = 0.6;
3579 if (colSpikes && yVel > 0 && (fallTimer > 3 || stunned)) { // originally fallTimer > 4
3581 // spikes will always instant-kill in Moon room
3582 /*if (isRoom("rMoon")) global.plife -= 99; else*/ global.plife -= global.config.scumSpikeDamage;
3583 if (/*isRealLevel() &&*/ global.plife <= 0) level.addDeath('spike');
3584 if (global.plife > 0) playSound('sndHurt');
3590 colSpikes.makeBloody();
3592 //else if (not dead) myGrav = 0.6;
3597 if (visible && (status >= STUNNED || stunned || dead || status == DUCKING)) {
3599 checkAndPerformSacrifice(out onAltar);
3600 // block looking down if we're trying to sacrifire ourselves
3601 if (onAltar) viewCount = max(0, viewCount-1);
3603 sacCount = default.sacCount;
3607 if (dead && global.hasAnkh) {
3608 writeln("*** ACTIVATED ANKH");
3609 global.hasAnkh = false;
3611 int newLife = (global.isTunnelMan ? global.config.scumTMLife : global.config.scumStartLife);
3612 global.plife = max(global.plife, newLife);
3613 level.osdMessage("THE ANKH SHATTERS!\nYOU HAVE BEEN REVIVED!", 4);
3615 auto moai = level.forEachTile(delegate bool (MapTile t) { return (t.objType == 'oMoai'); });
3617 level.forEachTile(delegate bool (MapTile t) {
3618 if (t.objType == 'oMoaiInside') {
3619 teleportTo(t.ix+8, t.iy+8);
3624 //teleportTo(moai.ix+16+8, moai.iy+16+8);
3626 if (level.allEnters.length) {
3627 teleportTo(level.allEnters[0].ix+8, level.allEnters[0].iy-8);
3630 level.centerViewAtPlayer();
3631 auto ball = getMyBall();
3632 if (ball) ball.teleportToPrisoner();
3645 //alarm[8] = 60; // this starts music; but we don't need it, 'cause we won't stop the music on player death
3646 playSound('sndTeleport');
3650 if (dead) level.stats.gameOver();
3653 if (status == DUCKTOHANG) {
3655 if (spr.Name != 'sDuckToHangL' && spr.Name != 'sDamselDtHL' && spr.Name != 'sTunnelDtHL') status = STANDING;
3658 foreach (PlayerPowerup pp; powerups) if (pp.active) pp.onPostThink();
3660 if (jetpackFlaresTime > 0) {
3661 if (--jetpackFlaresTime == 0) {
3662 auto obj = level.MakeMapObject(ix+global.randOther(0, 3)-global.randOther(0, 3), iy+global.randOther(0, 3)-global.randOther(0, 3), 'oFlareSpark');
3664 obj.yVel = global.randOther(1, 3);
3665 obj.xVel = global.randOther(0, 3)-global.randOther(0, 3);
3667 playSound('sndJetpack');
3673 // ////////////////////////////////////////////////////////////////////////// //
3674 void drawPrePrePowerupWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
3675 // so ducking player will have it's cape correctly rendered
3676 foreach (PlayerPowerup pp; powerups) {
3677 if (pp.active) pp.prePreDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3682 override void drawWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
3683 //if (heldBy) return; // owner will take care of this
3684 if (blinkHidden) return;
3686 bool renderJetpackBack = false;
3687 if (global.hasJetpack) {
3689 if ((status == CLIMBING || isExitingSprite()) && !whipping) {
3691 renderJetpackBack = true;
3694 getInterpCoords(currFrameDelta, scale, out xi, out yi);
3697 if (dir == Dir.Right) {
3698 spr = level.sprStore['sJetpackRight'];
3701 spr = level.sprStore['sJetpackLeft'];
3705 auto spf = spr.frames[0];
3706 if (spf && spf.width > 0 && spf.height > 0) spf.tex.blitAt(xi-xpos-spf.xofs*scale, yi-ypos-spf.yofs*scale, scale);
3711 bool ducking = (status == DUCKING);
3712 foreach (PlayerPowerup pp; powerups) {
3713 if (pp.active) pp.preDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3716 auto oldColor = Video.color;
3717 if (redColor > 0) Video.color = clamp(200+redColor, 0, 255)<<16;
3718 ::drawWithOfs(xpos, ypos, scale, currFrameDelta);
3719 Video.color = oldColor;
3721 if (renderJetpackBack) {
3723 getInterpCoords(currFrameDelta, scale, out xi, out yi);
3724 SpriteImage spr = level.sprStore['sJetpackBack'];
3726 auto spf = spr.frames[0];
3727 if (spf && spf.width > 0 && spf.height > 0) spf.tex.blitAt(xi-xpos-spf.xofs*scale, yi-ypos-spf.yofs*scale, scale);
3731 foreach (PlayerPowerup pp; powerups) if (pp.active) pp.postDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3735 void lastDrawWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
3736 foreach (PlayerPowerup pp; powerups) {
3737 if (pp.active) pp.lastDrawWithOfs(xpos, ypos, scale, currFrameDelta);
3744 objType = 'oPlayer';
3747 desc2 = "A strange little man who spends his time exploring caverns. He wants to be just like Indiana Jones when he grows up.";
3749 negateMirrorXOfs = true;
3751 status = FALLING; // the character state, must be one of the following: STANDING, RUNNING, DUCKING, LOOKING_UP, CLIMBING, JUMPING, or FALLING
3761 //thrownBy = ""; // "Yeti", "Hawkman", or "Shopkeeper" for stat tracking deaths by being thrown
3764 //whoaTimerMax = 30;
3765 distToNearestLightSource = 999;
3775 frictionFactor = 0.3;
3777 xVelLimit = 16; // limits the xVel: default 15
3778 yVelLimit = 10; // limits the yVel
3779 xAccLimit = 9; // limits the xAcc
3780 yAccLimit = 6; // limits the yAcc
3781 runAcc = 3; // the running acceleration
3788 //lightRadius = 96; //???