Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Hollister Man on Thu 18/12/2003 19:08:12

Title: Walking with arrow keys held down
Post by: Hollister Man on Thu 18/12/2003 19:08:12
Is there a known way to script the arrow kets to move EGO in the direction of the key press, and then stop when it is released, instead of the default way it works?
Title: Re:Continous Walking
Post by: a-v-o on Thu 18/12/2003 22:01:39
Description:
The player can use keys 1-9 on the numeric keypad or the corresponding arrow keys to control the movement of the player character (pc). The pc moves as long as the key is pressed and stops moving when the key is released.

===>>> GLOBAL SCRIPT <<<===

// ------ keyboard control ------

#define DIR_DISTANCE     10000

#define DIR_DOWN_LEFT  1
#define DIR_DOWN       2
#define DIR_DOWN_RIGHT 3
#define DIR_LEFT       4
#define DIR_STOP       5
#define DIR_RIGHT      6
#define DIR_UP_LEFT    7
#define DIR_UP         8
#define DIR_UP_RIGHT   9

int PrevDirection;

function game_start()
{
 // called when the game starts, before the first room is loaded

 // ------ keyboard control ------
 PrevDirection = DIR_STOP;
}

function repeatedly_execute()
{
 // put anything you want to happen every game cycle here

 // --- keyboard control ---
 int CharId, Direction, dx, dy;

   // neue Richtung ermitteln
        if ((IsKeyPressed (371) > 0) || (IsKeyPressed (55) > 0)) Direction = DIR_UP_LEFT;    // 7 Home (numeric pad)
   else if ((IsKeyPressed (372) > 0) || (IsKeyPressed (56) > 0)) Direction = DIR_UP;         // 8 Up arrow
   else if ((IsKeyPressed (373) > 0) || (IsKeyPressed (57) > 0)) Direction = DIR_UP_RIGHT;   // 9 PgUp (numeric pad)
   else if ((IsKeyPressed (375) > 0) || (IsKeyPressed (52) > 0)) Direction = DIR_LEFT;       // 4 Left arrow
   else if ((IsKeyPressed (376) > 0) || (IsKeyPressed (53) > 0)) Direction = DIR_STOP;       // 5 Stop (numeric pad)
   else if ((IsKeyPressed (377) > 0) || (IsKeyPressed (54) > 0)) Direction = DIR_RIGHT;      // 6 Right arrow
   else if ((IsKeyPressed (379) > 0) || (IsKeyPressed (49) > 0)) Direction = DIR_DOWN_LEFT;  // 1 End (numeric pad)
   else if ((IsKeyPressed (380) > 0) || (IsKeyPressed (50) > 0)) Direction = DIR_DOWN;       // 2 Down arrow
   else if ((IsKeyPressed (381) > 0) || (IsKeyPressed (51) > 0)) Direction = DIR_DOWN_RIGHT; // 3 PgDn (numeric pad)
   else Direction = DIR_STOP;
   // Vergleich mit aktueller Richtung
   if (PrevDirection != Direction)
   {
     PrevDirection = Direction;
     CharId = GetPlayerCharacter ();
     if (Direction == DIR_STOP)              { StopMoving (CharId);                    }  // 5 Stop (numeric pad)
     else
     {
            if (Direction == DIR_UP_LEFT)    { dx = -DIR_DISTANCE; dy = -DIR_DISTANCE; }  // 7 Home (numeric pad)
       else if (Direction == DIR_UP)         { dx = 0;             dy = -DIR_DISTANCE; }  // 8 Up arrow
       else if (Direction == DIR_UP_RIGHT)   { dx = DIR_DISTANCE;  dy = -DIR_DISTANCE; }  // 9 PgUp (numeric pad)
       else if (Direction == DIR_LEFT)       { dx = -DIR_DISTANCE; dy = 0;             }  // 4 Left arrow
       else if (Direction == DIR_RIGHT)      { dx = DIR_DISTANCE;  dy = 0;             }  // 6 Right arrow
       else if (Direction == DIR_DOWN_LEFT)  { dx = -DIR_DISTANCE; dy = DIR_DISTANCE;  }  // 1 End (numeric pad)
       else if (Direction == DIR_DOWN)       { dx = 0;             dy = DIR_DISTANCE;  }  // 2 Down arrow
       else if (Direction == DIR_DOWN_RIGHT) { dx = DIR_DISTANCE;  dy = DIR_DISTANCE;  }  // 3 PgDn (numeric pad)
       MoveCharacterStraight (CharId, character [CharId].x + dx, character [CharId].y + dy);
     }
   }
}
Title: Re:Continous Walking
Post by: Hollister Man on Thu 18/12/2003 22:57:34
1: I am going to post this in the Tech Archive, if you don't mind.
2: Will this carry over to the non-numeric arrows?
3: Is that German in the comments?

Thank you, thank you, thank you, thank you.   :D

What happened to the site?
Title: Re:Walking with arrow keys held down
Post by: a-v-o on Sat 20/12/2003 17:54:57
1. Please do so.
2. You can use either non-numeric arrows, NumPad-arrows (NumLock off) or NumPad-Numbers (NumLock on).
3. Yes, it's german:

// neue Richtung ermitteln
// get new direction

// Vergleich mit aktueller Richtung
// compare with current direction

a problem with the hard disc in my server.