ID:317304   Feb 19 2012, 2:18 am Keywords: diagonal, movement, native, pixel (See the best response by Kaiochao.) How exactly do I implement it so whenever I am pressing the Up arrow key, and then press down the right arrow key as well, I go northeast? It seems I can only go up, down, left, and right. I can go , diagonal if I use a numpad and press 9, 7, 1, and 3. Can anyone help?
 <-> Feb 19 2012, 2:38 am If you want to implement it yourself, one of the solutions in this thread should work. Forum_Account's Pixel Movement library will also handle this for you (he also posted in the above thread)
 <-> Feb 19 2012, 4:25 am (Edited on Feb 19 2012, 4:49 am) Best response Forum_account's Pixel Movement library uses his Keyboard library. If you don't want to use his Pixel Movement library, you can just as easily use his Keyboard library. You'll probably also want some kind of loop, so you could either use Deadron's EventLoop or my extremely simple loop library. I also find myself using my ProcLib library for some things. A simple way I've come up with (influenced a tiny bit by F_a and made extremely simple by use of libraries): controls var up = "w" down = "s" right = "d" left = "a"mob var controls/controls Login() ..() controls = new start_ticking() // this is from my loop library // this is called every tick after start_ticking() is called tick()/* In the Keyboard library, if a key is currently pressed, client.keys[key] == 1 (0 otherwise) This allows you to simply subtract to get an offset: Holding right and up: (1 - 0, 1 - 0) = (1, 1) Holding up and down: (0 - 0, 1 - 1) = (0, 0) Holding left and up: (0 - 1, 1 - 0) = (-1, 1) Theoretically, holding up, down, left, and right: (1 - 1, 1 - 1) = (0, 0)*/ // This is from ProcLib var d = kAngle.offset2dir( client.keys[controls.up] - client.keys[controls.down], client.keys[controls.right] - client.keys[controls.left])/* offset2dir(dx, dy) does exactly this: . = 0 if(dy) if(dy > 0) . |= NORTH else . |= SOUTH if(dx) if(dx > 0) . |= EAST else . |= WEST It simply returns a BYOND-direction when given an offset. (0, 1) = NORTH, (7, 0) == EAST, (-3, -9) == SOUTHWEST, etc.*/ // Now that you have a direction, you can move that way. // I do more complicated things here myself, but you can probably do this: step(src, d) // Also, be sure to set step_size if you're using that.