User Tag List

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 30

Thread: Creating an Undo Command for Sokoban

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Simflare's Avatar
    Join Date
    Oct 2013
    Location
    Australia
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating an Undo Command for Sokoban

    Hey guys

    I am creating a sokoban type game and I am trying to work out a way to create an undo command. I would like to be able to have infinite 'Undo's, just like in my puzzle script games.

    In my head I can think of the logic. The positions of various objects need to be stored somewhere, probably an array. But I am not very good with loops or arrays - I've never really used either much. So the hardest thing will be not only working out how to do 'Undo' for a single object, but how to do it for multiple objects.

    I have attached the MFA that contains the logic of what I'm working on. Can someone please help me achieve the following:

    1. An Undo command for each level
    2. Make it so that every time you press 'Z', it reverses the last move you did, moving the player and anything the player moved back 1 turn
    3. Make it so that multiple objects can be automatically stored and 'Undone' so that I could add as many instances of the crates as I like, and they can all respond to 'Undo'
    4. Please explain to me the process so that I can do it again myself in the future. I'm not so good at understanding examples, I need a bit of an explanation
    5. Please explain how you used any loops, arrays or processes


    Here is the file: SokobanUndoTest.mfa

    Please let me know if I can explain things any clearer.

    Thank you in advance for your time and help
    Simflare

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's one way of doing it. You will need to use loops and an array.

    Make a 3D array with X dimension the number of grid cells your level is wide, Y dimension the number of grid cells high, and Z dimension the max number of Undo levels you want to have.

    Every time a move is made, before you actually do the move, loop through all movable objects (you could probably use a "for each" loop here). Record the type of object in the following array index: ( X/gridsize, Y/gridsize, NumUndos). Now add 1 to NumUndos. In this way, you're recording the state of the entire level for each move the player makes.

    Now --- when it comes to actually doing the undo, your best bet is going to be just destroying every moveable object onscreen. Sub 1 to NumUndos. Start a fastloop "RespawnX" and run it the number of times your level is wide. On loop "RespawnX", start a fastloop "RespawnY" and run it the number of times your level is high. Then detect the cell type at ( loopindex("RespawnX"), loopindex("RespawnY"), NumUndos ) in your array, and spawn an object based on that type, thus reconstructing the level how it once was.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module

    Join Date
    Feb 2014
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about a very simpler approach: Just restart the level.

    I've seen a very well made games like yours they just give an option to restart the level if you are stuck.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Simflare's Avatar
    Join Date
    Oct 2013
    Location
    Australia
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Click n Create. Your suggestion of restarting the level is a very practical solution. It is something I've considered, however the problem is that if you just accidentally move one space too many or make a very simple mistake and have to redo the whole puzzle, that could be very annoying. It's very easy to move one block too many by accident.

    Having said that, it's got me thinking that perhaps I don't need unlimited undo's but perhaps only a few, like say 5 or 10. And then beyond that, the person has to restart. 5 or 10 undo's will be easier to program than unlimited.

    Ultimate Walrus, your suggestion sounds good, except I have no experience with doing those sorts of loops and arrays. Particularly the loops. Do you know of any good 'for each loop' tutorials that might help me?

  5. #5
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    662
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Here is a brief example explaining how to fill an area using nested loops:
    https://www.dropbox.com/s/tdm7hsz8rk...oops2.mfa?dl=0

    Just think of loops like a 0 based value adding up: If you run a loop 20 times, it will increment by 1 starting from 0, until it reaches the final number (19 instead of 20 - because loops are 0 based) and ends. This can be taken advantage of to position objects by multiplying a value (in this case the tile width/height) by the current loop index.

    Assuming your frame is 640 pixels wide and your tile is 32 pixels wide, you would be running 20 loops to fill the frame on the X axis. A tile created during loop index 0 would be at frame x coordinate 0 (32*0 =0) and a tile created during loop index 19 would be at frame x coordinate 608 (32*19 =608).

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Oct 2007
    Location
    UK
    Posts
    306
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Instead of having an 'undo', why not have a reverse movement where the player grabs the box and moves it back to its original position, like here: https://www.dropbox.com/s/rufigpb0pp...ly1.3.exe?dl=0

    Note: The above was programmed for android(still needs a lot of work), but the first level is playable on windows. Press the cream/yellow button on the right to toggle reverse.

  7. #7
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,736
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Caesar. I would be nice to have some kind of code for the first level, instead of an exe that is nice to look at.

    Thanks,
    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Oct 2007
    Location
    UK
    Posts
    306
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Nivram, I intended on releasing the game when, or if, it's completed - so didn't want to be handing the code out just yet. I only uploaded it as example of what I meant(using a reverse button). Simflare's version is coded very different from mine and looks far more efficient. If I have the time, I'll study his version and try adding a reverse button - although I'm sure he'd be capable of doing that looking at his code.

  9. #9
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,736
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response Caesar and I can relate to that.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    ineke's Avatar
    Join Date
    Jan 2011
    Location
    Netherlands / Spain
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Maybe someone has an example?

    Ineke

Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. Sokoban (Flash Game)
    By warlords in forum Released Games & Apps in Flash
    Replies: 0
    Last Post: 14th January 2014, 10:32 AM
  2. Undo bug
    By Skyhunter in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 3rd October 2012, 05:30 PM
  3. Undo Bug: resizing objects doesn`t undo
    By Tiles in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 3rd March 2007, 10:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •