A simple Playdate game that demonstrates restricting the player's movement to the horizontal or vertical axis in the Pulp tile-based game engine.
The approach used here has four parts:
- We store the "real" player location in two globals,
player_x
andplayer_y
- We only update
player_x
when motion is allowed in the horizontal direction, and only updateplayer_y
when motion is allowed in the vertical direction. - Because the Pulp framework will automatically update the player's position, we have to immediately correct it back to
player_x
,player_y
usinggoto
. - Because an
update
even will be generated following thegoto
, we also have to suppress the update handler in that case. To do this, we set another global,goto_triggered
, before executing thegoto
, and then, in the handler, whengoto_triggered
is set, we do nothing except cleargoto_triggered
.
None of the built-in solid object collision detection works when we do the above, so we also have to add our own checks for what the player is allowed to pass through. As you'll see in the game (and code!), this also opened the door ahem for some additional features.