PDA

View Full Version : Great tutorial; two attacks?



inkwellmagickit
September 8th, 2008, 11:01 PM
Hello all,

In trying to get a better handle on Actionscript, I've been looking at various tutorials on creating a fighting game. Most tutorials are rather uninformative/poorly written, but there is one that seems to work quite well:

http://www.gotoandplay.it/_articles/2006/06/beatemup.php

I'm having one large problem, however - I can't make my protagonist do more than one attack. For instance, I would like to have the character throw a punch when hitting control, and a kick while hitting shift. But based on the way the code is set up, it seems that I can only have one attack as specified in the tutorial; everything else I try simply causes the character to freeze on the first frame of attack #2.

So, experienced Actionscriptors, would anyone have an idea of what I should do? I realize the answer is probably obvious, but as a novice, I'd appreciate a detailed answer. Thanks very much in advance!

bluemagica
September 9th, 2008, 11:22 AM
well from the looks of that code, it is already made for both punch and kick! If you understand that tutorial, then you should have no problem doing what you are asking! So dont copy paste it, try and understand it! And if you cant understand, ask!

inkwellmagickit
September 9th, 2008, 12:37 PM
Thank you for your time looking at my post. However, I don't think you quite understand what I'm asking for.

This tutorial covers how to do two attacks based on the same button. That is, you can either hit control, or control and down. In effect, control is almost a modifier button, as all attacks that spring from this must start with control. Now, if I want to add another attack to a completely independent button (example: I'd like to have him punch with control, but kick with shift), that's where things get sticky... literally; the character simply freezes on the first frame of the other attack animation.
Where I think things are getting thrown off is that the first line of the attack code essentially states that control makes attack = true; if I try to duplicate the code to, say, make shift cause attack to equal true as well, that's where the trouble begins. Interestingly, if the code repeated so that you have control and shift do the same set of attacks, everything works fine.
So, long story short, I in fact do not understand what's going on here. I've read the tutorial several times, tried code variations forwards & backwards... nothing. So, would anyone be able to help? I hope my dilemma is a bit more clear now. Thanks!

bluemagica
September 9th, 2008, 01:15 PM
in that tutorial ctrl is a modifier key, infact it is showing you how to do combos! But leave that aside for now, you are asking how to do different attacks on different keypress, so assuming your attack keys are different from your movement keys, just do :

if(Key.isDown(Key.SHIFT) && keydown==false)
{
player_mc.gotoAndStop("punch");
}
else if(Key.isDown......
............
..............




The main thing is the if else ladder you use here! I will advice you to make a flochart or tree diagram to understand the flow! It is really simple!

Charleh
September 9th, 2008, 02:00 PM
I'd scrap this tut, to be honest it's not bad but the code is within MCs and frankly after you get going a bit you'll find that the code gets too difficult to manage. You might want to consider looking at this small demo I did of a beat em up. It's got combos and jumping etc and depth movement (not just side to side/platform).

http://www.kirupa.com/forum/showthread.php?t=272699&highlight=double+dragon

There's the thread - the code is included (get the last uploaded file that's the most recent). I've not done much with it, and you could use bitmap rendering instead of MCs which would be quicker - but this is what I had so far.