chanman
|
first off, get your mind out of the gutter =P
ok, I made a pic of a finger that points to what you are selecting.
i have 3 selections:
Continue
New Game
Exit
When I press the up or down button, the finger moves really fast. How do I made it so it only moves one position up or down. Is there a when to wait till you let up on the button before you can press it again?
Posted on 2004-05-14 04:04:23 (last edited on 2004-05-14 04:07:11)
|
el_desconocido
|
Quick and dirty method:
Just before you have the code move the finger, add:
while(up) updatecontrols();
This will force the game to wait for the person to release the button before actually moving the arrow. Same with down.
Slicker, more complicated method, allowing update of screen, animations, etc within a loop:
int up_is_pressed = 0; // declare before loop
if(up) up_is_pressed = 1;
if(!up && up_is_pressed)
{
up_is_pressed = 0;
// code to move arrow here
}
El
Posted on 2004-05-14 04:21:11
|
geronimo
|
i reckon you need to keep track of how long the direction key was pressed:
NewDirection=0;
if(key[SCAN_UP])
{
if(!UpIsPressed)
{
UpIsPressed=1;
NewDirection=DIR_UP;
}
}
else UpIsPressed=0;
if(key[SCAN_DOWN])
{
if(!DownIsPressed)
{
DownIsPressed=1;
NewDirection=DIR_DOWN;
}
}
else DownIsPressed=0;
if(NewDirection==OldDirection)
DirectionTime=DirectionTime | 1;
else
DirectionTime=0;
// later that night...
if(!DirectionTime) Move.
Posted on 2004-05-14 04:21:16
|
chanman
|
cool, thanks. I used El Desconocido's since It only needed two extra variables. I will try out geronimo's when I stop being lazy. I just needed to get it to work for now.
Posted on 2004-05-14 05:29:01
|
RageCage
|
you shouldent need anything more than your statement and resetting the variable.
if(key[SCAN_UP]){
key[SCAN_UP]=0;
}
thats it. if your doing a menu you might wanna look into this though:
switch(lastpressed){
case SCAN_UP: //code for pressing up
case SCAN_DOWN: //code for pressing down
case SCAN_ENTER: //code for pressing enter
}
//and somewhere at the end of your loop you need to put...
lastpressed=0;
//note: never put it at the beginning of the loop =p
Posted on 2004-05-14 12:38:40
|
mcgrue
|
Must... finish... documentation...
That way, everyone will know about things like Unpress();
Unpress( 0 ); //halts b1-b4
Unpress( 1 ); //halts b1
Unpress( 2 ); //halts b2
Unpress( 3 ); //halts b3
Unpress( 4 ); //halts b4
Unpress( 5 ); //halts up
Unpress( 6 ); //halts down
Unpress( 7 ); //halts left
Unpress( 8 ); //halts right
so your control code would look like:
if( up ) {
menu_pointer--;
Unpress( 5 );
} else if( down ) {
menu_pointer++;
Unpress( 6 );
}
Or something like that.
Posted on 2004-05-14 12:52:35
|
RageCage
|
unpress seems more trouble than its worth. I'd much rather refer to the actual keys than b1-4, but I guess thats just me.
is there really any advantage to unpress over setting a key[] to 0?
Posted on 2004-05-14 13:40:10
|
resident
|
Yup. Using buttons and Unpress means the player will be able to use a joystick and the keyboard interchangeably, plus it's easier than keeping track of scancodes manually.
Posted on 2004-05-14 16:32:02
|
RageCage
|
ahh, but I cant help but comment that keeping track of scan codes is just as easy if not easier than keeping track of b1-4 since you can just type SCAN_ENTER rather than b2 or something.
Posted on 2004-05-14 16:36:38
|
chanman
|
can I use unpress(down) instead of unpress(6)?
Posted on 2004-05-14 19:02:43
|
vecna
|
you could make a #define.
#define B_DOWN 6 or something.
I may put in builtin defines for that later, but I'd probably reserve DOWN for the facing number codes, which are different. Sigh.
But yeah, for things like menus I would highly suggest you use up/down/left/right and b1-b4 rather than directly looking at the key[] array so that people can use a joystick interchangably.
Posted on 2004-05-14 19:07:26
|
resident
|
I do believe that B1 - B4 may be user redefineable at some point in the future. (any comments Vecna? :D) I'm inclined that the best way to think of it is as a virtual controller for the entirely hypothetical VERGE console system.
Let me give you an example of how this is nice. Lets imagine you are playing a real, commercial game with a joypad, and then hit a menu system, hardcoded only to accept keyboard input, forcing you to put down the pad, and press buttons on the keyboard, before picking up their pad again.
How long do you think it would take you to track down the programmer of such a game, and how would you kill them? For a relatively minimal amount of effort on your own part, you can stop such a fate befalling you by utilising unpress();
Basically, it means that the game is playable - at the users whim - by either keyboard or DirectX supported controller. Anything that makes your game easier to use and play should probably be applauded and encouraged.
FYI, by default, B1 is return, B2 is alt, B3 is escape and B4 is space on the keyboard. Exactly what they map to on your controller is pretty much dependent on your controller. They seem to map fine onto my adaptorized GC pad tho.
Posted on 2004-05-15 10:18:39 (last edited on 2004-05-15 10:32:08)
|
Zip
|
Just to join the code posting frenzy, this is mine for moving up in a choice box:
if (up=1)
{
if (gl_current != 255)
{
if (player[gl_current].opt_cur == 0) player[gl_current].opt_cur = 3;
else player[gl_current].opt_cur--;
ChoiceBox();
}
unpress(5);
}
unpress() is ceratinly an easy method, and doesn't break your game loop, like while() solutions will.
Zip
Posted on 2004-05-15 16:52:21
|
RageCage
|
out of curiousity, how many people actually use controllers on computers?
Posted on 2004-05-15 19:12:01
|
vecna
|
I do. console-style games are meant to be played with console-style controllers!
Posted on 2004-05-15 20:01:21
|
mcgrue
|
...What, you don't have the delete button on your views?
Hrm, odd.
(Also, I use controllers with verge games all the time! Nothing better!)
Posted on 2004-05-15 20:37:31 (last edited on 2004-05-15 20:38:07)
|
resident
|
As you can probably tell from my previous post, I do too. When they don't actively REQUIRE me to use the keyboard.
Posted on 2004-05-15 22:11:58
|
chanman
|
I do too
Posted on 2004-05-15 23:47:25 (last edited on 2004-05-15 23:48:20)
|
geronimo
|
*raises hand*
You're gonna be kinda challenged to get really good at Tetris Attack Remix with a keyboard, heh
Posted on 2004-05-16 07:21:32
|
RageCage
|
wow, I was under the impression controllers were obsolete =p
Posted on 2004-05-17 12:40:44
|