Spelunky is © 2008, 2009 Derek Yu and Mossmouth, LLC, and is used under the [Spelunky User License v1.1b](https://spelunky.ai/LICENSE.txt). spelunky.ai is an unofficial fan project, not affiliated with or endorsed by Mossmouth. The game and its assets may not be sold.

Music by George Buzinkai and Jonathan Perry; sound effects made in SFXR. From Spelunky Classic 1.1, © 2008, 2009 Derek Yu and Mossmouth, LLC.

# The Shopkeeper's one-step patrol

From the spelunky.ai wiki: <https://spelunky.ai/wiki/shopkeeper-patrol-one-step>. Verified against the spelunky.ai port [v0.1.11](https://github.com/851-labs/spelunky/releases/tag/v0.1.11) on 28 October 2026.

The Shopkeeper's one-step patrol is a quirk of Spelunky Classic in which a patrolling Shopkeeper's every walk ends on its first step, so he shuffles about.

| Quirk     |                                                                                                                                                                                                                  |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Status    | GML + Oracle                                                                                                                                                                                                     |
| Where     | [`objects/oShopkeeper/step.gml:283-336`](https://spelunky.ai/wiki/source/objects/oShopkeeper/step#L283-L336)                                                                                                     |
| Pinned by | `fidelity/replays/enemy-shopkeeper-patrol-one-step.txt`                                                                                                                                                          |
| Row       | [docs/quirks.md §1, Bugs and leftovers in the 1.1 source](https://github.com/851-labs/spelunky/blob/main/docs/quirks.md#1-bugs-and-leftovers-in-the-11-source): “A patrolling Shopkeeper's walk lasts one step.” |

A [Shopkeeper](https://spelunky.ai/wiki/shopkeeper) waiting for a thief is on patrol: he stands, walks a little way, and stands again.
The test that ends his walk is the one an Alien turns at a ledge by, without its half that looks for a floor
ahead, so out in the open no walk lasts more than a step: he shuffles rather than walks.

## What happens

A Shopkeeper on patrol in open ground sets off walking, but his walk's check for a wall ahead sends him back to
patrolling on the very next step. He coasts about 10 pixels to a stop, waits, and shuffles again, every second or so[^1].

**Clip: A patrolling Shopkeeper's walk lasts one step.** A Shopkeeper on patrol in open ground sets off walking, but his walk's check for a wall ahead sends him back to patrolling on the very next step. He coasts a few pixels to a stop, waits, and shuffles again, every second or so. ([video](https://spelunky.ai/wiki/media/clips/quirks/shopkeeper-patrol-one-step/clip.mp4))

## Why

On patrol, a Shopkeeper counts down 20 to 50 steps on the ground, then sets off walking a random way[^2]. His walk goes back to patrolling when there's no solid
beside his head, a pixel to his left or right:

```gml objects/oShopkeeper/step.gml:309-328
    if (facing == LEFT)
    {
        if (not collision_point(x-1, y, oSolid, -1, -1))
        {
            status = PATROL;
            counter = rand(20,50);
            xVel = 0;
        }
        xVel = -1.5;
    }
    else
    {
        if (not collision_point(x+16, y, oSolid, -1, -1))
        {
            status = PATROL;
            counter = rand(20,50);
            xVel = 0;
        }
        xVel = 1.5;
    }
```

[`objects/oShopkeeper/step.gml:309-328`](https://spelunky.ai/wiki/source/objects/oShopkeeper/step#L309-L328), from `spelunky.gmk`, Spelunky Classic 1.1's source, © 2008, 2009 Derek Yu and Mossmouth, LLC ([Spelunky User License v1.1b](https://spelunky.ai/LICENSE.txt)).

The same lines in the [Alien](https://spelunky.ai/wiki/alien)'s and the [Mantrap](https://spelunky.ai/wiki/mantrap)'s walks also test the floor in front,
`y+16`, where they turn at a ledge[^3][^4]. Without it, in open ground nothing is beside his head, so every
walk ends on its first step. That step still sets `xVel` to 1.5 after the test, and his friction takes 0.1 a step
off it, so he coasts to a halt over about ten steps[^5][^6].

## Reproducing it

Steal from a shop, or kill a Shopkeeper, and go on to the next level: the Shopkeeper at its exit shuffles in
place[^7], and so does a shop's Shopkeeper there, who patrols rather
than stands[^8]. The level editor's `!` is a Shopkeeper on patrol[^9], and the replay of the clip's staged scene, on a custom level,
puts one in a flat room. In 300 steps he sets off ten times, and every walk lasts one step; after one, his speed
is 1.4, and it's gone ten steps later[^10]. A
thief's next level shows the same[^11].

## In the port

The spelunky.ai port reproduces it exactly: it's in docs/quirks.md's list of the 1.1 source's bugs[^6], and the oracle's fingerprint of the replay pins every walk. No option turns it off.

## FAQ

### Why does the Shopkeeper shuffle back and forth at the exit?

A [Shopkeeper](https://spelunky.ai/wiki/shopkeeper) on patrol stops walking wherever there's no wall beside his head. The same test in an Alien's walk also needs no floor ahead, so it turns only at a ledge; the Shopkeeper's has no such half, so in open ground every walk ends on its first step, and he coasts about 10 pixels to a halt.

### When does a Shopkeeper patrol?

On the levels after a theft, or after the player has killed a Shopkeeper: one waits at the exit, and a shop's Shopkeeper patrols rather than stands. The level editor's Shopkeeper patrols too.

### Do other monsters' walks stop like this?

No. The [Alien](https://spelunky.ai/wiki/alien)'s and the [Mantrap](https://spelunky.ai/wiki/mantrap)'s walks have the same test with the floor ahead added, and turn only at a ledge.

## See also

- **Related:** [Shopkeeper](https://spelunky.ai/wiki/shopkeeper)

## References

[^1]: Clip quirks/shopkeeper-patrol-one-step

[^2]: [`objects/oShopkeeper/step.gml:283-298`](https://spelunky.ai/wiki/source/objects/oShopkeeper/step#L283-L298)

[^3]: [`objects/oAlien/step.gml:49-58`](https://spelunky.ai/wiki/source/objects/oAlien/step#L49-L58)

[^4]: [`objects/oManTrap/step.gml:60-69`](https://spelunky.ai/wiki/source/objects/oManTrap/step#L60-L69)

[^5]: [`objects/oShopkeeper/step.gml:531-533`](https://spelunky.ai/wiki/source/objects/oShopkeeper/step#L531-L533)

[^6]: Quirk 1 (docs/quirks.md)

[^7]: [`scripts/scrInitLevel.gml:245-255`](https://spelunky.ai/wiki/source/scripts/scrInitLevel#L245-L255)

[^8]: [`objects/oShopkeeper/step.gml:121-124`](https://spelunky.ai/wiki/source/objects/oShopkeeper/step#L121-L124)

[^9]: [`scripts/scrCreateTileObj.gml:151-155`](https://spelunky.ai/wiki/source/scripts/scrCreateTileObj#L151-L155)

[^10]: Replay `fidelity/replays/enemy-shopkeeper-patrol-one-step.txt`

[^11]: Replay `fidelity/replays/shop-seed-3-thief-next-level.txt`

### Source code

- [`objects/oShopkeeper/step.gml`](https://spelunky.ai/wiki/source/objects/oShopkeeper/step)
- [`scripts/scrInitLevel.gml`](https://spelunky.ai/wiki/source/scripts/scrInitLevel)
- [`scripts/scrCreateTileObj.gml`](https://spelunky.ai/wiki/source/scripts/scrCreateTileObj)
