# The player idle animation
image player0:
"sprites/player/idleFrame1.png"
pause 0.1
"sprites/player/idleFrame2.png"
pause 0.1
"sprites/player/idleFrame3.png"
pause 0.1
"sprites/player/idleFrame4.png"
pause 0.1
repeat
# The player animation when moving up.
image player1:
"sprites/player/upFrame1.png"
pause 0.1
"sprites/player/upFrame2.png"
pause 0.1
"sprites/player/upFrame3.png"
pause 0.1
"sprites/player/upFrame4.png"
pause 0.1
repeat
init python:
# Make the animation move.
def movePlayer():
# Proceed only if the player is moving.
if playerMove == 0: return
# Update the coordinate of the player, accordingly to its destination.
# If you intend to let it move to more than one cell, you'll have to adapt
# this part since it's designed for straight and diagonal moves only.
if store.playerX < store.destX:
store.playerX += 1
elif store.playerX > store.destX:
store.playerX -= 1
if store.playerY < store.destY:
store.playerY += 1
elif store.playerY > store.destY:
store.playerY -= 1
# When the player reach its destination...
if store.playerX == store.destX and store.playerY == store.destY:
# return to the idle animation.
store.playerMove = 0
# Coordinate for the player sprite.
default playerX = 0
default playerY = 0
# Direction for the player movement.
# 0 - idle, 1 - up, 2 - up/right, ... 8 - up/left
default playerMove = 0
# Coordinate of the player destination.
default destX = 0
default destY = 0
screen map():
[display the map the way you want]
# One destination cell as demonstration
imagebutton:
idle "cell1.png"
# When clicked, define the player destination, and indicate in what direction he's moving.
action [ SetVariable( "destX", 10 ), SetVariable( "destY", 10 ), SetVariable( "playerMove", 4 ) ]
# Display the animation corresponding to the actual player move ;
# "player0" when static, "player1" when moving up, etc. And place
# this animation at the actual coordinate where the player is expected
# to be.
add "player{}".format( playerMove ) pos( playerX, playerY )
# Add a timer that will be triggered every 0.5 second.
timer 0.5:
repeat True
# Each time the time is triggered it will call the /movePlayer/ function.
# It could also be done directly with a complex combination of /If/ and /SetScreenVariable/,
# But there's no reason and it would be slower.
action Function( movePlayer )