User Tag List

Results 1 to 3 of 3

Thread: flow control?

  1. #1
    No Products Registered

    Join Date
    Oct 2008
    Location
    Germany
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    flow control?

    Hi there,

    I know this question must have been asked a zillion times, but the search function didn't give me any useful advice on how to do this. So I'm asking AGAIN:

    Is there a way to execute a loop (repeat, while, for etc.) inside an event? I need that for slope detection in a platformer since I want to avoid using too many detectors. I wrote the following algorithm in c/pseudo code to illustrate what I am planning to do:

    Code:
    Slope detection:
    
    I am using fast loops to move the player one pixel at a time.
    When the player overlaps with the background we have to check
    if there is a free position available that is no more than X
    pixels (three, for instance) above the current position,
    which _should_ be done with a loop:
    
    Example:
    ###
    ####            # = Background
    #####           P = Player
    #####  P
    #######P
    ##################################
    Now, when the player moves one pixel to the left, the
    following code will be executed:
    
    ------------------------------------------------------
    
        if (player overlaps with obstacle)
        {
          if (player is moving left) 
          {     
            int x = player.leftX;
            int backwards = +1;
          }
          elseif (player is moving right)
          { 
            int x = player.rightx;
            int backwards = -1;
          }
          
          for (int i = 1; i <= 3; ++i) 
          // repeat the following block three times and increase i by 1 each cycle:
          {
            if (getObjectAtPosition(x, player.lowerY + i) is not an obstacle)
            {
              player.Y += i; // slope found, move player up
              return true;
            }      
          } //for
          
          // no slope, player goes back where he came from
          player.x += backwards; 
          return false;
        } //if
      } //if
    Can this be done with mmf2? I don't care if it's dirty, as long as it's reliable and can be used for players and enemies as well. If you have any good ideas about this, please let me know.

    Thanks in advance,
    lincore

  2. #2
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: flow control?

    Yes, the Fastloop feature is what you should use here. When a loop is started, the events with the condition "On loop 'xxx'" as their first condition are executed the number of times you specify, before the event list continues and the frame is next redrawn.

    For your example, you would start the loop (let's call it PushUp) three times, in which you would have:

    On loop "PushUp"
    + The pixel at X, Y Bottom from Player is not an obstacle
    -> Move player up
    -> Stop loop "PushUp"

    It's probably easier, though, to restructure the FOR loop you have there so that it's a function in itself, as this is more easily translatable into event form.

  3. #3
    No Products Registered

    Join Date
    Oct 2008
    Location
    Germany
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: flow control?

    Thank you David for your advice (and that tutorial on custom platform movement). My fast loop powered slope detection kinda works, though there are some odd "stuck in the wall" bugs. Nothing too serious, I assume.

    Looks like a good time to take a break.
    Goodnight,
    lincore

Similar Threads

  1. Pyroclastic Flow
    By Maveritchell in forum Released Games & Apps in Flash
    Replies: 0
    Last Post: 6th May 2013, 09:35 PM
  2. need help about traffic flow
    By webwolf in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 26th March 2012, 06:48 AM
  3. Budget Flow
    By Jeff in forum iOS Released Games & Apps
    Replies: 0
    Last Post: 31st October 2011, 02:40 PM
  4. Making time flow
    By DisneyBoy in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 1st March 2010, 01:32 PM
  5. Flow control issues
    By Fisholith in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 9th November 2007, 04:38 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
  •