4 Replies Latest reply on Jan 13, 2012 7:18 PM by Production Monkey

    Lingo collision detection(intersects).


      Hello guys! I am a newbie at lingo and i have a big problem!!I am desperate!

      First of all, i want to create a 2D game like unblock game but untill now i can't set the intersects between the bricks(actors) and the outline (in the stage i've create this outline beacuse is the room who the bricks are inside..).I want the bricks to stop when they intersect with the outline  .I placed almost 6 bricks and there is only one that must get out of the outline.

      I know that my code must be something like this(maybe) :


      on enterframe me

         if sprite (5).intersects(1) then  --sprite 5 the brick and sprite 1 the outline

                                                     --what i must write here to stop the brick when touches the outine??

          end if


      I have read for Color-based collisions and location-based collision but they were not so understandable to me.. :/

      Please help  meeeeeeeee!!!!!

      Any advice will be helpful!!!!

      Thanx in advance!!


      P.S. Sorry if my english are awful!!


      Greetings from Greece...!!

        • 1. Re: Lingo collision detection(intersects).
          zDreams Level 1

          The following will move sprite(5) to the same location over and over (at the current frame rate of the movie), which will effectively stop it. However, it is still possible for other Lingo, such as the code that actually moves the sprite, to override this, on a separate frame, for example.


          on enterFrame me

             if sprite(5).intersects(1) then  --sprite 5 the brick and sprite 1 the outline

                 sprite(5).loc = sprite(5).loc -- keeps the sprite in the same location

              end if




          The following is a simple way to have a state cancel itself out when a condition is TRUE.


          property pStop


          on enterFrame me

            if pStop = FALSE then

              if sprite(5).intersects(1) then  --sprite 5 the brick and sprite 1 the outline

                 sprite(5).loc = sprite(5).loc -- keeps the sprite in the same location

                 pStop = TRUE

              end if

            end if



          In the above example the instersect() funtion will only work if pStop is false. Once the intersect occurs pStop is true, so nothing else in the handler will execute.



          There are a lot of helpful Lingo movies and behaviors you may download for free here: http://dreamsteep.com


          Go through the downloads section and you will see a lot of example movies to explore and learn from.

          1 person found this helpful
          • 2. Re: Lingo collision detection(intersects).
            josh_chunick Level 1
            1 person found this helpful
            • 3. Re: Lingo collision detection(intersects).
              nikoskas Level 1

              Hey guys thank you for your answers!I tried everything you told me but they don't work for my game .

              Is there any chance to have some other ideas?  Something more simple for the collision detection!


              Thank you!

              • 4. Re: Lingo collision detection(intersects).
                Production Monkey Level 3

                Sounds like you just want to keep the bricks within a bounding rect, which is defined by your outline.


                Here is a minimal behavior script that shows the code for dragging a sprite around the screen while restricting its movement to the inside of a rect. You will have to modify the code for your use.


                For testing purposes the script sets the bounding rect to something a few hundred pixels larger than the sprite it is attached to.



                -- Bounded Sprite


                property  pMe  -- this sprite

                property  pBounds  --  bounding rect that this sprite's movement is contained in

                property  pDragging  -- true/false . Currently dragging this sprite



                on beginSprite me

                  pMe = sprite(me.spriteNum)

                  pBounds = pMe.rect.inflate(100,100)  -- Temporary way to create a bounding box around this sprite for testing.

                  pDragging = false

                end beginSprite



                on mouseDown me

                  pDragging = true -- start dragging this sprite

                  the mouseUpScript = String(pMe) & ".mouseUp()"  -- send mouseUp to this sprite




                on mouseUp me

                  the mouseUpScript = ""  -- stop sending mouseUps to this sprite

                  pDragging = false  -- stop dragging this sprite




                on enterFrame me

                  if Not pDragging then exit  -- exit if not dragging this sprite


                  -- determine new location for this sprite based off the mouse position, but

                  -- keep the sprite contained within pBounds rect.

                  x = min(pBounds.right, max( pBounds.left, _mouse.mouseH))

                  y = min(pBounds.bottom, max( pBounds.top, _mouse.mouseV))


                  -- set new location for this sprite

                  pMe.loc =  point(x,y)

                end enterFrame