2 Replies Latest reply on Dec 18, 2011 12:38 PM by kitty07271

    randomize code

    kitty07271 Level 1

      need a little help: i want to make my own version of "The Shell Game".. can anyone tell me how can i randomize the paths of the shells? ps: i'm new to lingo

        • 1. Re: randomize code
          Production Monkey Level 3

          Here is the code for a behavior that moves a sprite around the stage randomly. 

           

          --  Random Movement Behavior

           

          Property  pMe

          Property  pVelocity

          Property  pRightBounds

          Property  pBottomBounds

           

           

          on new me, thisSprite

            pMe = thisSprite

            xVel = random(1,6) * [-1,1][random(1,2)]

            yVel = random(1,6) * [-1,1][random(1,2)]

            pVelocity = point(xVel, yVel)

            pRightBounds = _movie.stage.rect.width

            pBottomBounds = _movie.stage.rect.height

            return me

          end new

           

           

          on beginSprite me

            if pMe.voidP then pMe = sprite(me.spriteNum)

          end beginSprite

           

           

          on enterFrame me

            if pMe.left < 0 then  pVelocity = pVelocity * point(-1,1)

            if pMe.right > pRightBounds then pVelocity = pVelocity * point(-1,1)

            if pMe.top < 0 then pVelocity = pVelocity * point(1,-1)

            if pMe.bottom > pBottomBounds then  pVelocity = pVelocity *  point(1,-1)

            pMe.loc = pMe.loc + pVelocity

          end enterFrame

           

          ----------------------------------------------------

           

           

          Is this what you are looking for? 

          1 person found this helpful
          • 2. Re: randomize code
            kitty07271 Level 1

            ok.. can i ask you how can i speed up things?i spotted the space for the random movement..