Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-19-2009, 01:59 PM   #1
thebangzats
Registered User
 
Join Date: May 2009
Posts: 4
Arrow Actionscripting a Fighting Game (multiple questions)

I'm currently working on a simple fighting game on Flash CS3, coded with Actionscript 2.0

I have the basic setup done, just need to make a few more features, including more playable characters, move combos, and a Mortal Kombat style fatality. What I've already done is a simple one round game, with just 4 moves, low kick, high kick, low punch, high punch, jump kick, jump punch, and guard.

---

Problem #1: Move Combos
The combos are not complicated, just pressing two keys at the same time (e.g. instead of just a low kick, pressing low kick and high kick simultaneously will activate a certain combo, instead of just low kicking or high kicking)

Here's a snippet of code:
Code:
	if (!jump1 && this.punch == 0 && !dead1 && !Key.isDown(87)) {
		if (Key.isDown(85)) {
			this.gotoAndPlay("punch1");
		}
		if (Key.isDown(79)) {
			this.gotoAndPlay("punch2");
		}
		if (Key.isDown(73)) {
			this.gotoAndPlay("kick1");
		}
		if (Key.isDown(74)) {
			this.gotoAndPlay("kick2");
		}
	}
	if (this.punch == 0 && jump1) {
		if (Key.isDown(85) or Key.isDown(79)) {
			this.gotoAndPlay("jumppunch");
		}
		if (Key.isDown(73) or Key.isDown(74)) {
			this.gotoAndPlay("jumpkick");
		}
	}
If a certain key is pressed, it will play an animation of the assigned action, but how do I make it so if two keys are pressed at the same time, it will play an altogether different animation?

Problem #2: A Mortal Kombat style, finishing Fatality
I thought I had this down before, I made a code where a certain key (reserved for the Fatality move) can only be pressed when the opponentís health reaches a certain level, e.g. :
Code:
 if ((health2<=10) && Key.isDown(85)) {
			this.gotoAndPlay("fatality");
		}
So, if the opponentís (in this case, player 2)ís health is not below 10, the fatality key canít be pressed, so a fatality cannot be performed until the opponentís health is below 10

The problem is, what if both players use a fatality at the same time? It would cause chaos, so if by chance both player 1 and player 2 can do a fatality to each other (bothís health below 10), how do we prevent player 2 from activating a fatality when player 1 activated his fatality first (and vice versa)?

---

Help will be greatly appreciated, and if there isn't enough code to set an example, I can send you the actual .fla file of the prototype (not in english though), just tell me if you need it

Thanks in advance ^^
thebangzats is offline   Reply With Quote
Old 05-19-2009, 02:10 PM   #2
wibily
Member
 
Join Date: May 2009
Posts: 39
Default

with regard to the first problem, i'll suggest a few nested if loops ie
Code:
if(Key.isDown(79) || Key.isDown(85)){
   if(Key.isDown(79) && Key.isDown(85)){
      //combo move
   }
   else if (Key.isDown(79){
      //79 move
   }
   else if (Key.isDown(85)){
      //85 move
   }
}
problem 2:
the chance that they BOTH do a fataility at the same time is very very rare but hey, if i were you i would just do something like this:

assuming we have player1 with health1 and player2 with health2
Code:
var:Boolean gameEnd = false;
.
.
.
.
if (health1 < 10 && Key.IsDown(fatality_key)){
   this.gotoAndPlay("fatality");
   gameEnd = true;
   //probably more game ending code here
}
if (gameEnd == false && (health2 < 10 && Key.IsDown(fatlity_key2))){
   this.gotoAndPlay("fatality");
   //end game code here
}
so if they BOTH do a fatality at the same time...palyer1 wins and the game ends so the second player's fatality isn't executed.
wibily is offline   Reply With Quote
Old 05-19-2009, 08:37 PM   #3
runawayprisoner
ActionScripted
 
Join Date: Nov 2008
Posts: 94
Default

Quote:
Originally Posted by thebangzats View Post
Problem #1: Move Combos

Code:
	if (!jump1 && this.punch == 0 && !dead1 && !Key.isDown(87)) {
		if (Key.isDown(85)) {
			this.gotoAndPlay("punch1");
		}
		if (Key.isDown(79)) {
			this.gotoAndPlay("punch2");
		}
		if (Key.isDown(73)) {
			this.gotoAndPlay("kick1");
		}
		if (Key.isDown(74)) {
			this.gotoAndPlay("kick2");
		}
	}
	if (this.punch == 0 && jump1) {
		if (Key.isDown(85) or Key.isDown(79)) {
			this.gotoAndPlay("jumppunch");
		}
		if (Key.isDown(73) or Key.isDown(74)) {
			this.gotoAndPlay("jumpkick");
		}
	}
If a certain key is pressed, it will play an animation of the assigned action, but how do I make it so if two keys are pressed at the same time, it will play an altogether different animation?
Use a boolean value for each key presses:

Code:
if(key.isDown(73)){
    lkick = true;
}
if(key.isDown(74)){
    hkick = true;
}
Then check them at run-time:

Code:
if(lkick && hkick){
    // Do whatever
}
else if(lkick) {
    // Do whatever
}

//...
Basically like the above but use boolean values instead to avoid overheads.

Also check for the combo keys before the single keys.

Quote:
Problem #2: A Mortal Kombat style, finishing Fatality
Mmm...

Quote:
if(!fatality && ((health1 < 10 && key.isDown(fatal)) || (health2 < 10 && key.isDown(fatal))){
// play animation
fatality = true;
}
That should do.
runawayprisoner is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fighting Game with AS 2.0 Tutorials. bhograj Gaming and Game Development 1 02-14-2009 09:11 PM
[AS3] use mouse to choose multiple objects by surrounding them in game stevor Gaming and Game Development 1 08-12-2008 07:47 AM
Another Game questions, might be useful for gamers. Mutty Gaming and Game Development 1 08-11-2002 05:12 AM
flash game, complex questions :( rabsterb Gaming and Game Development 2 06-17-2001 10:05 AM
A survey with 24 multiple choice questions... jpstaub ActionScript 1.0 (and below) 3 04-14-2001 09:46 AM


All times are GMT. The time now is 11:28 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.