3 Replies Latest reply on Aug 15, 2007 5:02 AM by James Newton, ACP

    changing direction of sprite

    andy_scot
      hi, does anyone know why this piece of code wont send the sprite in the opposite direction to that it was travelling in before it hits the other sprite??

      property pSprite, pleftBound, prightBound, ptopBound, pbottomBound, pMove, pMove2
      global gvScore, gvlives

      on beginSprite me

      pSprite = sprite(me.spritenum) -- sets pSprite to the sprite of me
      pleftBound = 25 -- sets the left boundary to 50
      prightBound = 750 -- sets the right boundary to 750
      ptopBound = 0
      pbottomBound = 550
      pMove = 5
      pMove2 = 5
      end
      on exitframe me
      pSprite.loch=pSprite.loch+pMove -- moves pSprite by a horizontal increment of pMove

      pSprite.locV=pSprite.locV+pMove2

      if pSprite.locV < ptopBound then
      pMove2 = pMove2*-1
      end if

      if pSprite.locV > pbottomBound then
      pMove2 = pMove2*-1
      end if



      if pSprite.loch > prightBound then -- if pSprite passes the right boundary
      pMove=pMove*-1 -- change direction

      end if

      if pSprite.loch < pleftBound then -- if pSprite passes left boundary
      pMove=pMove*-1 -- change direction

      end if

      if sprite 22 intersects 23 THEN


      pMove2 = pMove*-1



      pMove = pMove2*-1





      pMove=pMove2*-1 -- change direction


      pMove2=pMove*-1 -- change direction

      end if



      if sprite 23 intersects 24 THEN

      gvlives = gvlives - 1
      put gvlives into field "lives"
      if gvlives = 0 then
      go to frame "gameover"

      end if
      end if
      end

      Thanks in advance, andy