rapid button press mini game tutorials?

Started by Reid, Wed 18/07/2007 05:25:28

Previous topic - Next topic

Reid

Hi, I'm looking for a tutorial on how to create a rapid button press mini-game for an AGS game I'm working on.

The idea is that the player must rapidly press a button to simulate struggling to do something in game. If they press the button fast enough, they will be successful. If they are too slow, they will fail. Ideally, while pressing, I can animate characters step by step, press by press to show progress or even animate other things if needed.

If there aren't any tutorials, are there any example games where I can look at how the scripts work? I have some experience with scripting for AGS, but not a ton. My biggest achievement has been taking health away from players if they choose a specific dialog choice.

-Reid

Shane 'ProgZmax' Stevens

#1
One simple way of doing it would be to create a storage variable that increments each time the key is pressed.  You can then compare this value with particular phases of the sequence and easily determine what to do, like:

if(IsKeyPressed(32)) //if you press the space bar
{
  //increment struggle_val
  struggle_val+=1;
}


if(struggle_val >= 10)
{
  //reset struggle_val
  struggle_val=0;

  //increment animation frame
character[0].Frame+=1;

if(character[0].Frame>4)
{
  //if you have reached the 6th frame of the struggle animation do something

}


}




You could further complicate matters by creating a small timer that clears struggle_val after a certain time to make players press the button faster.  For instance:

(this would be in the repeatedly_execute() loop either globally or for the room the action happens in.  You would specify a condition for entering this loop so it doesn't run constantly).

struggle_count+=1;

if(struggle_count>100)
{
   //clear struggle_val

  struggle_val=0;
 
  //clear struggle_count
  struggle_count=0;
}


This should be enough to get you going.

SMF spam blocked by CleanTalk