Discuss Scratch

thechrisare
New to Scratch
6 posts

Help moving pieces on a board

Hi all,

I am in the process of making a very simple game, kind of like a board game. I have most of it working correctly, but am having issues with moving the player pieces

As you'll see, the board is a z shape. One piece starts at the far left in space 1. The other starts at the far right in space 23. I need both pieces to have the ability of moving forwards and backwards along the board, one space at a time.

To set this up, I used a tutorial I found on Youtube's technique for moving pieces on a snakes and ladders game, whereby I made a list of corresponding to each square on the board and the direction the piece should move when on that square. I made a second list of the directions in reverse, to move the pieces the other way. I then have If/Then/ blocks determining which direction the piece will need to move, and then the pieces are set in motion.

This method has worked perfectly for the pieces moving in their natural direction i.e. the piece that starts at the left end of the board can move perfectly along the track in the right direction. However, when they need to move the other way, it doesn't work correctly. They move almost correctly, but they do things like go a step too far and end up off the board, or they stop in the wrong place.

I've spent several hours trying to figure this out but for the life of me cant get it. I'd really appreciate if someone would take a look to see if they can spot what might be causing the issue. As I'm very new to programming and copied the method for moving the pieces, it's very possible that the logic I applied in order to reverse them does not make sense.

You will only need to look at the code for either car sprite, no need to look at both.

Project here
https://scratch.mit.edu/projects/193256432/#player

Edit - there are other glitchy/unfinished parts of the code, please don't worry about these as I know what I'm doing with them.

Last edited by thechrisare (Dec. 15, 2017 13:37:49)

deck26
Scratcher
1000+ posts

Help moving pieces on a board

I couldn't replicate the problem but do feel you're overcomplicating. There are only two directions really - numbers increasing or decreasing. If you use lists to record the x,y positions of each square you can easily go from one square to another. If you want the cars to face the right direction another list could handle that - set the direction for when the car is going up the range of numbers and use the opposite direction if the car is going the other way.
thechrisare
New to Scratch
6 posts

Help moving pieces on a board

Thank you very much for the answer deck26. I have spent a couple hours this morning breaking down how to apply your suggestion and I'm finally getting there. I'm going to start rebuilding the game from scratch with this method and anticipate it being much easier this time round. Cheers
deck26
Scratcher
1000+ posts

Help moving pieces on a board

thechrisare wrote:

Thank you very much for the answer deck26. I have spent a couple hours this morning breaking down how to apply your suggestion and I'm finally getting there. I'm going to start rebuilding the game from scratch with this method and anticipate it being much easier this time round. Cheers
Glad to have helped.

Powered by DjangoBB