8 Way Movement!?

  • 17 years ago

    I'm having problems with the following code. I've got a movement system in the making, and I'm trying to have 8 way movement, I've succesfully managed 4 way, (left, right, up, down) but I'm having very big problems having the diagonal movement. I've tried the following code, it doesn't return any debug errors, however, the character only moves right under all circumstances. Can anbody see what I'm doing wrong? Any suggestions?


    Code:
    onClipEvent(keyDown) {
       var dir;
       var goleft;
       var goright;
       var godown;
       var goup;
       
       goup = false;
       godown = false;
       goright = false;
       goleft = false;
       
       if (Key.isDown(Key.UP)) {
           goup = true;
       }
       if (Key.isDown(Key.DOWN)) {
           godown = true;
       }
       if (Key.isDown(Key.LEFT)) {
           goleft = true;
       }
       if (Key.isDown(Key.RIGHT)) {
           goright = true;
       } else {
           dir = null;
           goup = false;
           godown = false;
           goright = false;
           goleft = false;
       }
       
       if (goup = true) {
           dir = "up";
               if (goleft = true) {
                   dir = "upleft";
               }
               if (goright = true) {
                   dir = "upright";
               }
       }
       if (godown = true) {
           dir = "down";
               if (goleft = true) {
                   dir = "downleft";
               }
               if (goright = true) {
                   dir = "downright";
               }
       }
       if (goleft = true) {
           dir = "left";
       }
       if (goright = true) {
           dir = "right";
       }
       
       _parent.walk(dir);
       updateAfterEvent();
    }

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++ : Where friends have access to your private members.” - Gavin Russell Baker