If you've used my Two-tile-tall player tutorial, you know that it also sets the player's facing-direction and does a little walk animation. It accomplishes this by checking what the player is trying to do in their update
event.
I thought of another thing to do: the animation to show when the player tries to "use" something by interact
ing with it. For instance, a switch:
What I added to the script from my tutorial above is just a check for whether the target tile is a sprite. If so, I show a new player animation:
on update do
// we abstracted the movement calculation into the calculateMove function
// because it needs to be called more than once here
call "calculateMove"
// change player's facing position
targetType = type event.tx, event.ty
// horizontal movement
if event.dx<0 then // if the attempted movement on the X axis was negative
playerDirection = "left" // save this so we can use it
if targetType == "sprite" then
// trying to interact with a sprite
// first show the "use" animation
swap "player use left"
// then after a brief delay, reset back to the static frame
wait 0.3 then
swap "player left"
end
else
// just trying to move
// first show the walk animation…
swap "player walk left"
// then after a brief delay, reset back to the static frame
wait 0.3 then
swap "player left"
end
end
elseif event.dx>0 then
// same basic logic as above
playerDirection = "right"
if targetType == "sprite" then
swap "player use right"
// then after a brief delay, reset back to the static frame
wait 0.3 then
swap "player right"
end
else
swap "player walk right"
wait 0.3 then
swap "player right"
end
end
…
It's tiny, but it makes your Pulp game seem more alive!