3 Replies Latest reply on Aug 11, 2010 1:33 PM by Production Monkey

    Noobie needs help

    GSE1242

      Hi I'm currently creating a break-out style game just for fun.

       

      I have got the ball and paddle working and hit-detection etc but now I am trying to get the game to recognise when all the blocks have been destroyed.

       

      I need a piece of code that asks the system whether sprites 4-38 (the blocks) have all been hit by gBallSpriteNum (the ball).

       

      It then should go to frame 20

       

      I was trying things like

       

      if Sprite ("4-38") isVisible = 0 then

      go to frame 20

      end if

       

      But I am a noob and can't get it to work .

       

      Thanks for any help

       

      The code for hit detection on the blocks to make them invisible is the following:

       

      global gBallSpriteNum

       

      property spriteNum
      property my
      property isVisible
      property pBallSpriteNum

       

      on beginSprite me
        my = sprite(spriteNum)
        isVisible = TRUE
      end

       

      on enterFrame me
        if isVisible then
          if my.intersects(gBallSpriteNum) then
            _movie.sendSprite(gBallSpriteNum, #hit, point(1,-1))
            isVisible = 0
            my.loc = my.loc + 10000
        
          end if
        end if
      end

        • 1. Re: Noobie needs help
          Production Monkey Level 3

          There are many different approaches you could use but the fastest and simplest would be to just keep a count of the number of visble brick sprites.

           

          --  ball behavior

           

          property pVisibleBricks

           

          on beginSprite me

            pVisibleBricks = 35  -- or whatever the count is.

          end

           

          on hit me, aPoint, SpType

            if SpType =  #Brick then

              pVisibleBricks = pVisibleBricks - 1

              if pVisibleBricks = 0 then

                go to frame 20  -- you should use a frame label.

                exit

              end if

            end if

          end hit

           

           

          Then you call "hit" from the brick behavior thus:

           

          sendSprite(gBallSpriteNum, #hit, point(1,-1), #Brick)

          • 2. Re: Noobie needs help
            GSE1242 Level 1

            Hey. thanks for the reply. But when i input it the game just continues to play This is my ball script and brick script:

             

            -- ball script

            global gBallSpriteNum

             


            property spriteNum
            property my
            property pRightBound, pLeftBound, pTopBound, pBottomBound
            property pSpeed
            property pLifeCount
            property pVisibleBricks

             


            on beginsprite me
              pVisibleBricks = 35
              pLifeCount = 0
              my = sprite(spriteNum)
              gBallSpriteNum = spriteNum
              me.mSetBounds()
              me.mStart()
            end

             

            on mSetBounds me
              sr = _player.activeWindow.rect
              pLeftBound   = my.member.regPoint.locH
              pTopBound    = my.member.regPoint.locV
              pRightBound  = sr.width  - (my.width - pLeftBound)
              pBottomBound = sr.height - (my.height - pTopBound)
            end

             

            on mStart me
              -- setting random direction and speed when ball starts.
             
              pSpeed = point(random(10,15) * [-1,1][random(1,2)], random(5,10))
              my.loc = point(200 + random(200), 300)
            end if
            end

             

            on enterFrame me
            tLoc = my.loc + pSpeed

             


            if tLoc.locH > pRightBound OR tLoc.locH < pLeftBound then
            me.hit(point(-1,1))
            exit
            end if

             

            if tLoc.locV < pTopBound then
            me.hit(point(1,-1))
            exit
            end if

             

             

             

            if tLoc.locV > pBottomBound then
            pLifeCount = pLifeCount + 1
            if pLifeCount = 10 then
            go to frame 60
            else
            me.mStart()  
            end if
            exit
            end if

             

            my.loc = tLoc
            end enterFrame

             

            on hit me, ReflectionBias, aPoint, SpType
            pSpeed = pSpeed * ReflectionBias
            if SpType =  #Brick then

             

                pVisibleBricks = pVisibleBricks - 1

             

                if pVisibleBricks = 34 then

             

                  go to frame 30

             

                  exit

             

                end if

             

              end if

             

            end

             

             

             

            -- brick script

             

            global gBallSpriteNum

             

            property spriteNum
            property my
            property isVisible
            property pBallSpriteNum

             

            on beginSprite me
              my = sprite(spriteNum)
              isVisible = TRUE
            end

             

            on enterFrame me
              if isVisible then
                if my.intersects(gBallSpriteNum) then
                  _movie.sendSprite(gBallSpriteNum, #hit, point(1,-1), #Brick)
                  isVisible = 0
                  my.loc = my.loc + 10000
                end if
              end if
            end

            • 3. Re: Noobie needs help
              Production Monkey Level 3

              if pVisibleBricks = 34 then

               

              should be:

               

              if pVisibleBricks = 0 then

               

              And

               

              on hit me, ReflectionBias, aPoint, SpType

               

              should be:

               

              on hit me, ReflectionBias, SpType