We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey im gonna try to create a sliding puzzle. So a game where i have a grid of some sort, and square pieces on top that can be moved around the grid. But only in the up,down,left,right directions. Ive already created something similar by using a 2d array which stores the state of every cell in the grid. so if i change the value of a specific entry in the array it reflects on the grid by drawing a rectangle there. however using this method, if i move the rectangle it just jumps from one position to the next, if that makes sense. it doesn't animate from say left to right instead it just jumps left, seeing as im just making the entry at the current position 0 and then putting the entry in a different position in the array.
Would using object be better in this situation or can i work away around it with the arrays?
i hope this makes sense...
Answers
1st of all, arrays are objects too! Any datatype which doesn't belong to the 8 primitive types are reference types! ;)
2nd, your issue doesn't have anything to do w/ data structures. Like you said, you wanna animate a transition.
That is, from a previous state to the new current state.
You have to create a method which that makes the sliding effect.
While at the same time, refuse user input while the animation takes place!
yeah, stick with the 2D-grid
this 2D array contains objects (cell)
when making a move just draw the animation above the grid. You don't have to use the grid data for it. Remember that the animation and the data don't need to be the same or connected.
ok thanks guys i think i understand what youve mentioned. ill try it out now, ill see how it goes. Also can you point me in the right direction how i would go about loading an image and then splitting it into say 9 or 16 pieces, that are then all seperate images? i havent worked much with images so far. thanks
when you load the image you can make a double for-loop that fills your 2D-grid with the tiles according to the sections of the image
http://www.processing.org/reference/PImage_get_.html
I've got an online example. It's still a lil' buggy. But at least it's a start: 8-X
http://studio.processingtogether.com/sp/pad/export/ro.9$MTikWt80-9w/latest
aight ill try that later thanks Chrisir. GoToLoop thats cool, i had a brief look at it but im busy this weekend with study for a uni test ill have a closer look how you did that during the week. thanks anyway.
Finally got some time to do this. This is what i ended up with after a bit. could be improved but works really well in the moment so i dont see the need. could use a proper start screen of something like that though, tell me what you think or if i could improve it anywhere.
The IntList seems kinda un-necessary i think, but i didnt know if there was anything like the shuffle function i used on the IntList, that i could use on the PImage array.
The sort() method is an attractive addition for the new Processing's data structures. :D
Although regular arrays got their own sort() function too among Processing's API: :-j
http://processing.org/reference/sort_.html
not sure exactly what you mean, sorry. The reference says that sort() function is only for the other array types not PImage arrays. And also how would that help me get a shuffled order like i did in the code i posted with the use of the shuffled intlist? I guess the way i did it in the above code works fine but just seemed like it could be done more elegantly
Oh! My mistake. I've mixed up sort() & shuffle(). L8 at night now! X_X
only 3:30pm where i am ;)
i think ill just leave it as is atm. zank u though