how to get the input in orders?

Posted By: jockerob

how to get the input in orders? - 10/25/17 13:28

say that I'm making a action game.
And I'm try to get the player run. I want you to double tap the key(like →→)for the running(of course, the 2nd → have to be hold).

Or maybe I'm making a fighting game. That I have to read player input for a special attack(like ↓→+punch = hadoken, →↓→+ punch = shoyoken). Or in the training stage, the player can see what he had inputed(like showing the input "→↓←→←↓→↑↓→←...").

I think I need a function that reads the player's input in orders(and store them or show them). Then if the input order fits some kind of sequence, the player make a special move.
Posted By: DriftWood

Re: how to get the input in orders? - 10/25/17 19:41

I'd use both timers and a complex "SWITCH" setup.

Not functioning code.
Code:
...
var key_timer =0;

var run_yes = 0; // false
var comboo_1 = 0; // false

while(1)
{

if(key_cur) 
key_timer = 10;
if(key_1) 
key_timer = 5;
if(key_2) 
key_timer = 5;
...Subtract timer here...

switch(key_lastpressed )
{
  case 77:
    if(key_timer >0)
    if(key_cur)
    run_yes =1;
    //... Call run function or code below switch
    break;

  case 2:
    if(key_timer >0)
    if(key_1)
    comboo_1 = 0.5;
    else
    {
    comboo_1 = 0;
    key_timer = 0;
    } 
    break;

  case 3: 
   if(key_timer >0)
    if(key_2)
    comboo_1 = 1;
    //... Call comboo function or code below switch
    else
    {
    comboo_1 = 0;
    key_timer = 0;
    } 
    break;

  default:
    printf("None of them! ");
    break;
}

wait(1);
}



reading ...
http://www.conitec.net/beta/akeyboard.htm
http://www.conitec.net/beta/akey_a.htm
http://www.conitec.net/beta/akey_lastpressed.htm
http://www.conitec.net/beta/switch.htm
http://www.conitec.net/beta/acrt-break.htm

You can also use a time and an array to store last-hit key scan codes. Using a "For" loop you can check the array for patterns of combos each frame.

so like
Code:
......
var key_timer =0;
var key_store[5];
var key_index_max = 4;
var key_index =0;

while(1)
{


if(key_cur) 
key_timer = 10;
if(key_1) 
key_timer = 5;
if(key_2) 
key_timer = 5;
...Subtract timer here...

 switch(key_lastpressed)

switch(key_lastpressed )
{
  case 77:
    if(key_timer > 0)
    {
    for(key_index =0; key_index <= key_index_max; key_index++)
    {
      if(key_store[key_index] == 0)
        {
       key_store[key_index] = 77;
         break;
       
     } 
     }
     else
     {
       for(key_index =0; key_index <= key_index_max; key_index++)
        key_store[key_index] = 0;
      }
    run_yes =1;
    //... Call run function or code below switch
    break;

  case 2:
    ......
    break;

  case 3: 
   .........
    break;

  default:
    printf("None of them! ");
    break;
}

//....... Checking the array
if(key_store[0] !=0) // ?One key was hit
{
  if(key_store[1] !=0)
   {
   if(key_store[0] == 77 && key_store[1] == 77 )
     ///...Call RUN here
    }
}
wait(1);
}



http://www.conitec.net/beta/for.htm
http://www.conitec.net/beta/keys_c.htm

The above code doesn't work and is bugged, but you should get an idea of how you can use it to build a combo system.

Also please check the AUM mags, I'm sure a combo system has been done before.
Posted By: jockerob

Re: how to get the input in orders? - 10/26/17 13:05

Thank you for replying.

I got your idea. A timer that would count down, and use "key_lastpressed" function for the last input.

But there is some problem remaining. what about "&#8600;", that require both "&#8595;"&"&#8594;". And what about holding, say I'm making a guy like GUILE(street fighter).

OK I'll check the AUM for answer or some ider.

Thanks again for the kindheart! wish you happy.
Posted By: Ezzett

Re: how to get the input in orders? - 10/26/17 15:18

That's not a trivial task to do. In my opinion you would need some kind of queue data structure to save an arbitrary number of the last key presses. Therefore, you would wrap each key press to a command structure and store the commands in the queue. Your fighter would need a finite state machine to determine if the last key presses are relevant for the current state he's in.

There was a very old fighting game workshop for A5. I don't know if they used the same ideas but I think the workshop is available on Acknex Unlimited. Maybe you can find some inspiration there.
Posted By: DriftWood

Re: how to get the input in orders? - 10/27/17 20:52

Add a new timer called charge timer - for the charge key. You need to step out of the switch and into IF trees.
Code:
.........
var charge_timer =0;
if( key_a)
 charge_time =5;
...sub charge_timer...

if(key_d && key_lastpressed(--key_a--) && charge_time<=0)
----do attack----



As per double keys, it's not complex,
Code:
if(key_a && key_d && key_timer < 0)
{
 .... do -x- .....
}



If you like give each optional key it's own timer... key_a_timer, key_d_timer, ect + key_a_charge timer.....

Also look at this http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=468925#Post468925 , by the Master @txesmi
© 2024 lite-C Forums