Pulp how-to: player "sidescroller" animation

Based on Neven's two-tile-tall-player tutorial https://devforum.play.date/t/pulp-how-to-two-tile-tall-player/1716 I built a small sidescrolling animation. I confined player movement to one horizontal line of tiles.

scrolling

Scripting: Instead of adding a "playerHead" like Neven I added trailing animation tiles for walking in and out of a tile. Somehow I could not use "draw" for painting the tile next to the player (like Neven does for the playerHead). I had to use "tell". So what happens is:

  • player tile moves to the next position
  • both the new and old player position get one-cycle animation tiles.
  • animation shows player walking out of the "old" player position and into the new one

In principle this player-animation configuration should also work with four directions. Would need additional animated tiles for up-down though :D.

On the bottom of this post I added the main script, which is used in the player tile. The script is commented. Additional scripts are found within "resting" background tiles, which will play their respective animation tiles when the player moves. Oh, and there's also a "gun draw" mechanic to the player animation.

Among many things to be improved these two are the most obvious:

  1. The script should ignore the movement input while the animation is running. can probably be solved with "wait"?
  2. The script should ignore movement when bumping into the map's boundaries. Can be done with "bump".

Here's the demo :slight_smile: 2D Scrolling Test 1.zip (6.2 KB)

Thank you Neven!

Script for player tile

// animate player while moving
// based on neven's how-to: two tile-tall-player
on enter do
// calling "calculateMove" like in two-tall-player script,
// but i don't know if really needed here.
// setting player direction to look downwards,
// "stance"=1 -> player's arms out
call "calculateMove"
playerDirection = "down"
stance = 0
end

on calculateMove do
// copying coordinates for player main tile to x,y variables
playerHeadX = event.px
playerHeadY = event.py
end

on update do
// emitting event for triggering background scrolling
emit "calculate_Scrolling"
// calling calculateMove
call "calculateMove"
// movement to the left
if event.dx<0 then // if the attempted movement on the X axis was negative
playerHeadX += 1
playerDirection = "left" // save this so we can use it
stance = 0
// play the walk animation (once and then swap) for the "trailing" tile…
tell playerHeadX,playerHeadY to
play "pl_walkbehind_left" then
swap "emptytile"
end
end
// ...and for the tile of player's new position
play "pl_walkleft" then
swap "pl_lookleft"
end
// movement to the right
elseif event.dx>0 then // if the attempted movement on the X axis was positive
playerHeadX -= 1
playerDirection = "right"
stance = 0
tell playerHeadX,playerHeadY to
play "pl_walkbehind_right" then
swap "emptytile"
end
end
play "pl_walkright" then
swap "pl_lookright"
end
end

// vertical movement, no walk animation here, only directional change
if event.dy<0 then
	playerDirection = "up"
	stance = 0
	swap "pl_lookup"
end

if event.dy>0 then
	playerDirection = "down"
	stance = 0
	swap "pl_lookdown"
end

end

// player's "shoot animation", followed by arms staying out
on confirm do
stance = 1
play "pl_stance{playerDirection}_shoot" then
swap "pl_stance{playerDirection}_hold"
end
end

// activate or deactivate player's stance depending on current stance:
// Player retracts arms, but only if arms are out! Otherwise he puts them up.
on cancel do
if stance==1 then
stance = 0
play "pl_stance{playerDirection}_lose" then
swap "pl_look{playerDirection}"
end
else
stance = 1
play "pl_stance{playerDirection}_take" then
swap "pl_stance{playerDirection}_hold"
end
end
end

3 Likes