summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-08-09 19:29:42 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2020-08-09 19:29:42 -0400
commit325913a35173b80804e9428b17f2855edae63f91 (patch)
tree2fffc10609656d99770ed4d9cec53c8a9b9921ac
parent568d3a2854ea94b811272f7e27ddf2764159e3e5 (diff)
Disable jumping over ledges onto obstacle tiles or NPCs
-rw-r--r--Disable-jumping-over-ledges-onto-obstacle-tiles-or-NPCs.md43
-rw-r--r--Tutorials.md1
2 files changed, 44 insertions, 0 deletions
diff --git a/Disable-jumping-over-ledges-onto-obstacle-tiles-or-NPCs.md b/Disable-jumping-over-ledges-onto-obstacle-tiles-or-NPCs.md
new file mode 100644
index 0000000..20bd6da
--- /dev/null
+++ b/Disable-jumping-over-ledges-onto-obstacle-tiles-or-NPCs.md
@@ -0,0 +1,43 @@
+Ledges are always placed in maps so that you can safely jump over them, without landing on an obstacle tile (like a building, tree, or water) or an NPC. It's a common mistake for beginners to misplace ledges so that you might jump onto an obstacle and get stuck. But if for some reason you want to design your map that way, you can add a check in the ledge-hopping code to only jump when it's safe to do so.
+
+Edit `DoPlayerMovement` in [engine/overworld/player_movement.asm](../blob/master/engine/overworld/player_movement.asm):
+
+```diff
++; d = x coordinate of tile across the ledge
++ ld a, [wPlayerStandingMapX]
++ ld d, a
++ ld a, [wWalkingX]
++ add a
++ add d
++ ld d, a
++; e = y coordinate of tile across the ledge
++ ld a, [wPlayerStandingMapY]
++ ld e, a
++ ld a, [wWalkingY]
++ add a
++ add e
++ ld e, a
++; make sure the tile across the ledge is walkable
++ push de
++ call GetCoordTile
++ call .CheckWalkable
++ pop de
++ jr c, .DontJump
++; make sure there's no NPC across the ledge
++ xor a
++ ldh [hMapObjectIndexBuffer], a
++ farcall IsNPCAtCoord
++ jr c, .DontJump
+
+ ld de, SFX_JUMP_OVER_LEDGE
+ call PlaySFX
+ ld a, STEP_LEDGE
+ call .DoStep
+ ld a, PLAYERMOVEMENT_JUMP
+ scf
+ ret
+
+ .DontJump:
+ xor a
+ ret
+```
diff --git a/Tutorials.md b/Tutorials.md
index ef40cd1..a879d52 100644
--- a/Tutorials.md
+++ b/Tutorials.md
@@ -128,6 +128,7 @@ Tutorials may use diff syntax to show edits:
- [Level cap](Level-cap)
- [Customizable Pokédex Color](Customizable-Pokédex-Color)
- [Wall-to-wall carpeting in your room](Wall-to-wall-carpeting-in-your-room)
+- [Disable jumping over ledges onto obstacle tiles or NPCs](Disable-jumping-over-ledges-onto-obstacle-tiles-or-NPCs)
- [Add more music that changes at night](Add-more-music-that-changes-at-night)