I would like to know how to move a player’s pawn on a board game. Move is determined through a number variable.
I made a picture to illustrate. For example the player’s pawn is on the square number 1. The dice shows 3, so the variable = +3 and pawn has to move of 3 squares.
The question is how does it go from 1 to 2, then to 3 and finally to the square 4?
Another linked question. The pawn only passes through squares 2 and 3 without stopping. So the actions associated with these squares will not be executed. But if it stops there another time, these actions will be executed. How to do? Ideas?
Add a string object variable on the square object, to indicate where the next square is, and give it one of 4 values - “Left”, “Right”, “Up” and “Down”.
When you move the player from a square, read this variable of that square, and move the player piece accordingly.
It depends on how you move the player. I would look at moving a square at a time, and with each move decreasing the variable that holds the dice roll. If the dice roll is greater then 0, move the player. And if it reaches 0, execute the action of that square.
I understand the idea but i can’t realize it and I meet several problems. Please have a look on my code & screenshots.
case_initiale : initial square
case_arrivee : arrival square
deplacement_restant : remaining movement
deplacement : moving
I think it’s even simpler than I had put earlier. Using your square object - the square the playing piece is on has the variable “prochaine”. Simply find the position of the square that has an id the current square’s prochaine value, and move to it.
Here’s what it look like :
The squares are still what you’ve got. The star has it’s origin moved to the centre, and has variables :
Please, how do I to retrieve the following values:
-the initial square before each roll/move? it would be substitued by the one of the following movement
-the arrival id, for each roll (is there a better way than Star.Variable(SquareId)?)
-the squares the pawn has been through for each move
-number of turns: whether the pawn only passes through square 1 or stops there= +1 turn
Since I added platform behavior to squares and platformer object behavior to the pawn, the pawn moves anormally, inside the board and even outside the screen. I don’t know how to make video to show you.
That changes things completely. The solution I gave is for a top-down view, as if you’re looking down onto the board. Platform behaviour is for a side-on view, and applies gravity (usually down the screen) onto the platform character.
So unless you are looking to change the style of game, remove the platform and platform object behaviours.
No You’ll need to click on the spanner icon for the variable, and change it to an array (second option, then choose array when you click on the spanner icon)