4 Replies Latest reply on May 23, 2008 9:51 AM by Chunick

    Basic Coding Help

    m_saade
      Hello,
      i need to know how to ma a sprite move with keyboard controls on a certain sprite only;

      i started making a mini-game where i have a character which i need moving on the picture of the floor, and not moving on tables and chairs... and without continuing to move outside the stage.

      so i thought the best way to do it is to put the moving area of that character in a new sprite, but i didnt know how to do it.

      so i need ur help for giving me the code.
      thanks
        • 1. Basic Coding Help
          Chunick Level 3
          The basic idea is communication between two sprites. Each time the sprite moves it should ask, "Have I collided with another object?" This message can be interpreted in Lingo using a sendAllSprites message. The reason we use this is to broadcast a message out to all sprites that are listening (they contain the necessary code to receive the message). If the moving object has "collided" with another object then that object will respond back to say, "you have collided with me."

          Using the code below will get us started:
          • 2. Re: Basic Coding Help
            m_saade Level 1
            thx, im trying to implement it in my project since there's some new notions in the code i didnt know about.
            • 3. Re: Basic Coding Help
              m_saade Level 1
              hello chunick, there was a problem with the code u gave me:

              on updateMove me
              if keyPressed(123) then
              me.move(point(-1,0)) -- left
              end if

              if keyPressed(124) then
              me.move(point(1,0)) -- right
              end if

              if keyPressed(125) then
              me.move(point(0,1)) -- down
              end if

              if keyPressed(126) then
              me.move(point(0,-1)) -- up
              end if
              end

              i fixed it and it worked, the fixed code is:

              on updateMove me
              if keyPressed(123) then
              me.move(-1,0) -- left
              end if

              if keyPressed(124) then
              me.move(1,0) -- right
              end if

              if keyPressed(125) then
              me.move(0,1) -- down
              end if

              if keyPressed(126) then
              me.move(0,-1) -- up
              end if
              end

              thanks for ur help
              regards
              • 4. Re: Basic Coding Help
                Chunick Level 3
                m_saade,

                good catch! Sorry about the Franken-code... I was surprised I couldn't find the original code I wrote and posted on the DOUG forum and apparently I saved over the original code in my .dir files too with modified code for collision detection which has been a hot topic over at DOUG lately. Anyways, good luck with the project.