9 Allow Jumping Over Ledges with Acro Bike
voloved edited this page 2024-08-15 18:24:39 -04:00

By Devolov

Goal: To allow the player to jump over both sides of a ledge with the Acro Bike. Collision check prevents the player from jumping into impassable terrain or objects.

joop

In event_object_movement.c, add the following Includes:

#include "constants/mauville_old_man.h"
#include "constants/trainer_types.h"
#include "constants/union_room.h"
+#include "constants/metatile_behaviors.h"
+#include "bike.h"

Then, in GetLedgeJumpDirection, make the following change:

u8 GetLedgeJumpDirection(s16 x, s16 y, u8 direction)
{
    static bool8 (*const ledgeBehaviorFuncs[])(u8) = {
        [DIR_SOUTH - 1] = MetatileBehavior_IsJumpSouth,
        [DIR_NORTH - 1] = MetatileBehavior_IsJumpNorth,
        [DIR_WEST - 1]  = MetatileBehavior_IsJumpWest,
        [DIR_EAST - 1]  = MetatileBehavior_IsJumpEast,
    };

    u8 behavior;
    u8 index = direction;
+   struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId];

    if (index == DIR_NONE)
        return DIR_NONE;
    else if (index > DIR_EAST)
        index -= DIR_EAST;

    index--;
    behavior = MapGridGetMetatileBehaviorAt(x, y);

    if (ledgeBehaviorFuncs[index](behavior) == TRUE)
        return index + 1;

+   if (gPlayerAvatar.acroBikeState == ACRO_STATE_BUNNY_HOP &&
+       MB_JUMP_EAST <= behavior && behavior <= MB_JUMP_SOUTH)
+   {
+       MoveCoords(direction, &x, &y);
+       if (GetCollisionAtCoords(playerObjEvent, x, y, direction) == COLLISION_NONE)
+           return index + 1;
+   }
+
    return DIR_NONE;
}