Need help with a game board piece interacting with the side of the board
2 views (last 30 days)
Show older comments
my board piece will be dropping down the board and for every space it moves down there is a chance it will hit a peg. each peg will have a random integer value witch will cause it to move left or right x positions for every space it moves down, the problem is I don't know how to implement a part of the script to reverse the movement of the piece after it collides with the wall (edge of the matrix/board) Thanks in advance
3 Comments
Star Strider
on 12 Mar 2014
Edited: Star Strider
on 12 Mar 2014
With all the other deflectors, the piece has a probability of moving + (right) or - (left) with a given velocity. If it encounters the left wall, it can only move right, and with the right wall it can only move left. If the ‘board’ is an M row (depth) by N column (width) matrix, then it seems to me that you need to test to see if a given trajectory will result in a column position either <=1 or >=N, reset the position to 1 or N and compute the new velocity and displacement, similarly to any other deflector. You have to take into account the number of positions the piece will move after having hit the previous deflector, determine how many positions it had to move to reach the wall, and have it reflect the remaining distance left (for the right wall) or right (for the left wall).
I didn’t see what the properties of the walls were. This might be important if the position has it stopping at a wall (column position =1 or =N), which seems to me to be possible. What energy does the wall give it in that situation?
Salaheddin Hosseinzadeh
on 12 Mar 2014
I don't get a lot of clues from your explanation unfortunately, the most complex game I made was to aim with mouse while you had to read a number appeared for a glimpse somewhere on the screen. I just had to take care of the number not to overlap the bullseye or any of them getting out of the boundaries of the figure, then figure out whether the player clicked on the bullseye and if yes ask them to enter the disappeared number, easy, just testing your attention, lol! I would like to help you with this, but I don't really get what do you want to do! Share your files if you want and I'll do my best to help.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!