I don't know how to limit player movement, before I was planning to use crank to control the player, and force play move in specific tiles, but I give up on how to use crank to move the player, but still need help with the coding. Here is the code, help me PLZ! And THANKS!
on load do
maxHealth = 6
maxCharge = 6
health = maxHealth
charge = 0
end
on update do
if Player_in_Tramcar==0 then
emit "playerUpdated"
sound "move"
if event.dx==1 then
swap "Right"
elseif event.dx==-1 then
swap "Left"
elseif event.dy==1 then
swap "Down"
elseif event.dy==-1 then
swap "Up"
end
end
if Player_in_Tramcar==1 then
swap "Tramcar_up"
emit "playerUpdated"
end
if charge >= 1 then
if event.dx==1 then
charge -= 1
elseif event.dx==-1 then
charge -= 1
elseif event.dy==1 then
charge -= 1
elseif event.dy==-1 then
charge -= 1
end
if charge == 0 then
// idk how to limit player movement```
end
end
hmm player movement is, by default, only limited but the tiles around them.
I suppose you could swap every tile around the player to be solid tiles whenever charge hits zero. that might be tricky though
what might work is this:
if charge == 0 then
previous_x = event.px
previous_y = event.py
previous_x -= event.dx
previous_y -= event.dy
goto previous_x,previous_y
end
since event.dx and event.dy give you -1, 0, 1 based on how the player moved during an update, this should properly set previous_x and previous_y. goto sends the player to that location. they would technically still move, but the game will move them back before the next frame is shown
this may have an issue that you may need to test: event.dx and event.dy may still have nonzero values if the player ATTEMPTS to move but bumps into a wall. if this is the case, when charge is zero and someone attempts to move into a solid tile, the default pulp behavior and this code will both compensate and the player will end up moving the opposite direction. if that is the case, you can use the solid function to test where these walls are programmatically and adjust the code. see Playdate PulpScript