Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Coolio on Thu 28/09/2006 12:05:26

Title: moving object with keyboard
Post by: Coolio on Thu 28/09/2006 12:05:26
How would I make it so that I can move an object with the arrow keys and then only return to normal gameplay when the enter key is pressed.
What I want is:
1)place object in room with mouse click (I can do that)
2)be able to move object with arrow keys
3)only return to 'normal' gameplay once enter is pressed

The problem I have is that I can't get it to stay on step 2 until step 3 is fulfilled.
I can get the object to move once in a single direction if I am holding the arrow key down BEFORE I place the object in the room, but I want to be able to move it freely in any direction once it has been placed.
Can this be done.
Title: Re: moving object with keyboard
Post by: Khris on Thu 28/09/2006 14:07:23
Please always post the code you've used.

Step2:
In the repeatedly execute, use
Ã,  if (keymovement) {
Ã,  Ã,  int wt=10;
Ã,  Ã,  Object*o=oBall;Ã,  Ã,  //Ã,  change this
Ã,  Ã,  int c=o.X*o.Y;
Ã,  Ã,  if (IsKeyPressed(372)) o.Y--;
Ã,  Ã,  if (IsKeyPressed(380)) o.Y++;
Ã,  Ã,  if (IsKeyPressed(375)) o.X--;
Ã,  Ã,  if (IsKeyPressed(377)) o.X++;
Ã,  Ã,  if (c!=o.X*o.Y) Wait(wt);
Ã,  }

Step3:
In on_mouse_click and on_keypress, establish the same if-check for all functions you don't want to be accessible
// on mouse click
if (!keymovement) {Ã,  // no key movement
Ã,  //usual click code here
}

// on keypress
if (keycode==13 && keymovement) keymovement=false;
if (!keymovement) {
Ã,  //usual keypress code here
}
Set the global variable keymovement to true as soon as you've placed the object.

(This is code isn't going to work until you've declared, exported and imported the keymovement variable. And it probably needs some refining, too.)
Title: Re: moving object with keyboard
Post by: Coolio on Fri 29/09/2006 02:53:08
Thanks. I'll try it. :)

Edit:
It worked. ;D I had to change a few things to suit my needs, but other than that it worked perfectly.
Thanks for the help. :)