17 January 2009

8-Directional Movement (2K3)

This is a simple method for moving in 8 directions, rather than the standard 4 (up, down, left and right). This is not the best method, but it is workable, using the keypad, which means that Numlock must be on.

Knowledge Base

  • Common Events
  • Forks/Branch Conditions
  • Variables


Variables

We'll only need one variable for the movement system, 0001:Dir Move.

Common Events

Open the Database (F9) and create a new Common Event, 8-Dir Movement and set the "Trigger" to "Parallel Process". This means that it will run in the background until one of the movement keys is pressed. Leave the "Switch" blank.

In the "Event Commands" section, place the following commands:

  • First create a "Loop" (Tab 3), into which everything will be placed.
    <>Loop
    <>
    : <>End Loop
  • Next, we'll need to define the "Key Input Processing" (Tab 3), which will be stored in our variable 0001:Dir Move. Make sure the "Wait Until Key Pressed" option is checked and only the "Number Keys 0-9 (10-19)" is checked as well.

    <>Key Input Proc: [0001:Dir Move]

  • This is where things could become rather confusing, but it's not really that hard. Create 8 "Branch Conditions" with the "Else" option checked for each.

    Set the first condition to "Variable 0001:Dir Move, Number Equal To 11 (the numerical value for 1, i.e. down/left).
    <>Branch if Var [0001:Dir Move] is 11
    <>
    : Else Handler
    <>
    : End

    Under the "Branch if" create a "Move Event" (Tab 2) and set the movement to down/left using the "Move Down/Left", setting the "Move Event" to "Hero" (usually selected by default).

    <>Branch if Var [0001:Dir Move] is 11
    <>Move Event: Hero, Move Down/Left
    : Else Handler
    <>
    : End

    Under the "Else Handler", repeat the process, but change the variable number and movement in the "Move Event" command to correspond with the direction (i.e. with the second fork, the "Variable" would be set to 12 and the direction to "Down", but ignoring number 15. Continue all the way up to 19.
  • Finally, in the last "Else Handler" insert a "Break Loop" command (Tab 3).

Complete Code

<>Loop
<>Key Input Proc: [0001:Dir Move]
<>Branch if Var [0001:Dir Move] is 11
<>Move Event: Hero, Move Down/Left
: Else Handler
<>Branch if Var [0001:Dir Move] is 12
<>Move Event: Hero, Move Down
: Else Handler
<>Branch if Var [0001:Dir Move] is 13
<>Move Event: Hero, Move Down/Right
: Else Handler
<>Branch if Var [0001:Dir Move] is 14
<>Move Event: Hero, Move Left
: Else Handler
<>Branch if Var [0001:Dir Move] is 16
<>Move Event: Hero, Move Right
: Else Handler
<>Branch if Var [0001:Dir Move] is 17
<>Move Event: Hero, Move Up/Left
: Else Handler
<>Branch if Var [0001:Dir Move] is 18
<>Move Event: Hero, Move Up
: Else Handler
<>Branch if Var [0001:Dir Move] is 19
<>Move Event: Hero, Move Up/Right
: Else Handler
<>Break Loop
: End
: End
: End
: End
: End
: End
: End
: End
: End Loop

Notes

The downside to this method is that only the default movement keys (up, down, left and right) will repeat if they are held down. The other keys will need to be continuously pressed in order to move in that direction.

0 Comments So Far:

Post a Comment

Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner