Button Sequences, Combos & Logic


(Brian Marwa) #1

So its been a day since I began fiddling with FlashPunk and have been following a tutorial about how to make a horizontal shooter.

Now I want to add dash effect for my ship. I specifically would like for the user to tap a key twice in the direction they want to zoom.

But what is the logic? Should I change my timing form elapsed to fixed?

I’ve tried adding a counter for specific buttons to see if a button can be pressed consecutively but that is not working well.

I think this will be an important topic for those who want to make fighting games to add combos and what not. Any ideas?


(Zachary Lewis) #2

Fighting games use frame-based inputs. I’d recommend doing the same thing.

When writing controls that feel “right,” it’s a lot of specific code and trial-and-error testing. To implement a dash, I’d approach it the following way.

  • If the user pressed forward, start a counter.
  • If the user presses anything other than forward or the timer hits n frames, continue standard operation.
  • If the user presses forward and the counter hasn’t reached n frames, perform a dash.

(Brian Marwa) #3

You see I have tried the counter and your specifications made it a lot easier for me. The issue that I bump into now is that I can dash right when I push right twice. So I can dash now but I cannot move normally to the right.

I tried the timing technique but I struggled and stuck to a counter. Is that good or bad?

So I’ll get cracking on that and keep you posted. I’m still learning the logical programming stuff so thank you for bearing with me. I will work on

I really want to add an image for you to see but here is the essential code: rcounter = 0; {

		/*///////////////////// NORMAL MOVEMENT */
		if (Input.check("right")) 
		{ 
			x += movement * FP.elapsed; 
			rcounter == 0; 
		}
		if (Input.check("left")) 
		{ 
			x -= movement * FP.elapsed; 
			rcounter == 0; 
		} 
		if (Input.check("up")) 
		{ 
			y -= movement * FP.elapsed; 
			rcounter == 0; 
		} 
		if (Input.check("down")) 
		{ 
			y += movement * FP.elapsed; 
			rcounter == 0; 
		}
		/*//////////////////// NORMAL MOVEMENT */
		
		/*///////////////////DASH CODE*/ 

}

I set the movement buttons to move normally with addition to setting rcounter back to zero so that, what I thought, would allow me to move normally to the right but it still counts a check as a press.(Which I understand because technically a check looks for pressed every frame) 

sigh but I will forge on. I feel like I’m getting close!!


(Abel Toy) #4

Well, you wrote rcounter == 0. That’s a comparison. It’s just checking if rcounteris 0. What you need to do instead is set rcounter to 0, which can be done using rcounter = 0.


(Brian Marwa) #5

Thank You so much AbelToy that helped a lot. It was such a simple thing I had to change.

So now I just need to figure out a way to have controls that “feel” right as Zachary said. Now I am using variable time instead of fixed time. Is this a big deal?

I am working on implementing a timer so that if a button is pushed twice in n amount of time then a dash will occur. It’s gonna take some time…I’ll post an update when I’m done.


(Zachary Lewis) #6

Using variable time, you’ll probably want a counter that looks something like this:

var timer:Number = 0;

public function update():void
{
  // Sample timer that resets after two seconds.
  if (timer < 2)
  {
    timer += FP.elapsed;
  }
  else
  {
    /* Since the timestep is variable, setting back to zero will 
     * cause the timer to always be slightly incorrect. By
     * subtracting two seconds from the timer instead, the small
     * variations will be corrected.
     */

    timer -= 2;

    FP.console.log("Bing bong! Timer is reset.");
  }
}