Skip navigation
elimann
Currently Being Moderated

set spawn points for each sprite?

Apr 14, 2012 7:56 AM

heres my dilema

 

i currently have 5 sprites and 5 different set co ordinates for each one to spawn into with individual behaviour scripts, however i want each sprite to spawn into one of the set co ordinate without more than one of them spawning into the same point.

so eventually each sprite will spawn into a random set co ordinate

 

so something like

 

pRandomStartingLoc = (200,100) (300,100) (400,100) so each sprite spawns into only one set of cordinates without more than one spawning into the same one

 
Replies
  • Currently Being Moderated
    Apr 14, 2012 8:25 AM   in reply to elimann

    You want something like the following:

     

    --  Random Set behavior

     

    property  pSetNum

    property  pMySet

     

    On GetPropertyDescriptionList me

      Props = [:]

      Props[#pSetNum] = [#default:#1, #format:#integer, #Range:[#min:1, #max:5], #comment:"Choose a set."]

     

      return Props

    end GetPropertyDescriptionList

     

     

    on beginSprite me

      Case pSetNum of

        1:  pMySet = [point(200,100), point(300,100), point(400,100)]

        2:  pMySet = [point(200,100), point(300,100), point(400,100)]

        3:  pMySet = [point(200,100), point(300,100), point(400,100)]

        4:  pMySet = [point(200,100), point(300,100), point(400,100)]

        5:  pMySet = [point(200,100), point(300,100), point(400,100)]

      end case

     

      put pMySet

    end beginSprite

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 9:24 AM   in reply to elimann

    Yes you would use one behavior for all five sprites.

     

    You need to modify the code I wrote and add it to your behavior. And, of course each "pMySet" property in the case statement would be set to a different list of points.

     

    The general idea is that if a set of sprites all have the same behavior but some of their properties need to be set to different values, then you use the " GetPropertyDescriptionList()" handler to set those differenct values.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 9:52 AM   in reply to elimann

    The code I posted is Not complete. You need to write the "spawning" code. I only show how to pick a different set of points for each sprite.

     

    If your spawing code continues to not work, post your code so we can see what is not working.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 10:11 AM   in reply to elimann

    I thought perhaps you were using some variation of the code Mister MUX wrote.

     

    Here's a more complete version:

     

    --  Random Set behavior

     

    property  pSetNum

    property  pMySet

    property  pSp

    property  pStartLoc

     

     

    On GetBehaviorDescription me

      return "Sets sprite to a random location based off a predefined set."

    end GetBehaviorDescription

     

     

    On GetPropertyDescriptionList me

      Props = [:]

      Props[#pSetNum] = [#default:#1, #format:#integer, #Range:[#min:1, #max:5], #comment:"Choose a set."]

      return Props

    end GetPropertyDescriptionList

     

     

    on beginSprite me

      pSp = Sprite(me.spriteNum)

     

      -- get my location choice set

      Case pSetNum of

          -- *** Change these value to what you want *****

        1:  pMySet = [point(200,100), point(300,100), point(400,100)] 

        2:  pMySet = [point(100,200), point(500,105)]

        3:  pMySet = [point(50,70), point(478,387)]

        4:  pMySet = [point(400,500), point(623,245)]

        5:  pMySet = [point(600,400), point(284,470)]

      end case

     

      pSp.loc = pMySet[random(pMySet.count)]   -- set my location

      pStartLoc = pSp.loc  -- store current location in case you want to return to it

    end beginSprite

     

     

    on goToStartLoc me

      pSp.loc = pStartLoc

    end

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 10:36 AM   in reply to elimann

    I'm not sure what you want. Is this closer?

     

    --  Random Set behavior

     

    property  pPosNum

    property  pSp

    property  pStartLoc

     

     

    On GetBehaviorDescription me

      return "Sets sprite to a random location based off a predefined set."

    end GetBehaviorDescription

     

     

    On GetPropertyDescriptionList me

      Props = [:]

      Props[#pPosNum] = [#default:#1, #format:#integer, #Range:[#min:1, #max:5], #comment:"Choose a set."]

      return Props

    end GetPropertyDescriptionList

     

     

    on beginSprite me

      pSp = Sprite(me.spriteNum)

      pSp.loc = [point(200,100), point(300,100), point(400,100), point(500,100), point(600,100)][pPosNum]   -- set my location

      pStartLoc = pSp.loc  -- store current location in case you want to return to it

    end beginSprite

     

     

    on goToStartLoc me

      pSp.loc = pStartLoc

    end

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 11:02 AM   in reply to elimann

    Okay fourth time may be the charm.

     

    This behavior contains a Single Locations list that is global to all sprites with this behavior attached. Each sprite picks a random loc from the list and then deletes that value from the list so that no other sprite can use it.

     

    Note: This uses some advanced Lingo, but you should only need to replace the point values in the list of point values.

     

     

    --  Random Set behavior

     

    property  pSp   -- this sprite

    property  pStartLoc  -- this sprites location at beginsprite

     

    -- global/static behavior property

    property  curLocs  -- list of sprite locations used by ALL sprites with this behavior attached

     

     

    on beginSprite me

      -- define our quasi global locations list if it is not defined or is empty

      if me.script.curLocs.voidP OR me.script.curLocs = [] then

        me.script.curLocs = [point(200,100), point(300,100), point(400,100), point(500,100), point(600,100)]  -- Define Sprite Locs Here

      end if

     

      Locs = me.script.curLocs

      pSp = Sprite(me.spriteNum)

      pSp.loc = Locs[random(Locs.count)]   -- set my location to random point from list

      Locs.deleteOne(pSp.loc)  -- remove this Loc from list so that no other sprite can use it.

      pStartLoc = pSp.loc  -- store current location in case you want to return to it

     

      -- debug code. Check message window

      put "Sprite " & me.spriteNum & " is at location " & pSp.loc

    end beginSprite

     

     

    on goToStartLoc me

      pSp.loc = pStartLoc

    end

     

     

    on endSprite me

      me.script.curLocs = void

    end

     

     

    on reset me

      me.endSprite()

      me.beginSprite()

    end

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 11:46 AM   in reply to elimann

    pStartLoc holds the starting location point and you can use that to modify the code, or you can just call the goToStartLoc() handler. As in:

     

    sprite(5).goToStartLoc()

     

    sendAllSprites(#goToStartLoc)

     

     

    Delete the "reset()" handler above. It will not work correctly. I would delete it from the forum but the forum won't let me at the moment.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 18, 2012 6:15 PM   in reply to elimann

    sendAllSprites(#goToStartLoc)

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 6:05 AM   in reply to elimann

    The code I posted works exactly the way you want it to work. Each sprite returns to the random location that was picked on beginSprite. If it does not do that then you perhaps changed some code or have another behavior attached to the sprites that is causing your problem.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points