|
-
DOT-INVADER
here's the source code of the combos used in my fighting game
ok, here's the code i used for the combos in my fighting game... too bad it's not a .fla file, but in the last version of super crossover fighter (not online) i had a very strange "bug" (not with the combo system though)...
so here it is, and i hope some expert coders will improve it, why not, mmmhh? ^^
(sure it can be simpler or shorter! ^^)
Code:
// array that will check and record the last key pressed
LastKeyPressed = new Array();
// function that handle the LastKeyPressed array
function SortKeyPressed() {
// only the last 8 keys are recorded
if (LastKeyPressed.length<8) {
// there cannot be two same keys recorded consecutively
if (CurrentKeyPressed != LastKeyPressed[(LastKeyPressed.length)-1]) {
LastKeyPressed.push(CurrentKeyPressed);
}
} else {
LastKeyPressed.shift();
}
}
// which key is pressed right now?
var CurrentKeyPressed;
// function that give a name to the keys pressed
function ComboHandler_enterFrame() {
if (key.isdown(UpArrow)) {
if (key.isdown(RightDirection)) {
CurrentKeyPressed = "up+right";
SortKeyPressed();
} else if (key.isdown(LeftDirection)) {
CurrentKeyPressed = "up+left";
SortKeyPressed();
} else {
CurrentKeyPressed = "up";
SortKeyPressed();
}
} else if (key.isdown(DownArrow)) {
if (key.isdown(RightDirection)) {
CurrentKeyPressed = "down+right";
SortKeyPressed();
} else if (key.isdown(LeftDirection)) {
CurrentKeyPressed = "down+left";
SortKeyPressed();
} else {
CurrentKeyPressed = "down";
SortKeyPressed();
}
} else if (key.isdown(RightDirection)) {
if (key.isdown(UpArrow)) {
CurrentKeyPressed = "up+right";
SortKeyPressed();
} else if (key.isdown(DownArrow)) {
CurrentKeyPressed = "down+right";
SortKeyPressed();
} else {
CurrentKeyPressed = "right";
SortKeyPressed();
}
} else if (key.isdown(LeftDirection)) {
if (key.isdown(UpArrow)) {
CurrentKeyPressed = "up+left";
SortKeyPressed();
} else if (key.isdown(DownArrow)) {
CurrentKeyPressed = "down+left";
SortKeyPressed();
} else {
CurrentKeyPressed = "left";
SortKeyPressed();
}
}
// combo's timer
timer = 0;
if (LastKeyPressed.length>0) {
timer++;
} else {
timer = 0;
}
if (timer>=34) {
timer = 0;
LastKeyPressed.shift();
}
// variable that involve three keys combos (down, down+forward, forward)
ComboCheckerThree = LastKeyPressed[LastKeyPressed.length-3]+LastKeyPressed[LastKeyPressed.length-2]+LastKeyPressed[LastKeyPressed.length-1];
}
then, each time you hit a punch or kick key (under key.Down event), the combo combination is checked. if it's corresponding to a combination you specified, then the special attack is launched. if not, normal action.
sure, it can really be simpler. but it works very well for me, try it here:
http://www.marmotte.levillage.org/ga...r_fighter.html
1,2,3,4 are the punches/kicks
Last edited by marmotte; 12-03-2002 at 04:36 PM.
-
-
Senior Member
what does MP and MK stand for? How do you hit?
-
DOT-INVADER
sorry...
1 = MP (medium punch)
2 = SP (strong punch)
3 = MK (medium kick)
4 = SK (strong kick)
throw: forward+MP when you hit the opponent
-
Free Stock Photos
that looks awesome man...
-
Couldn't you replace all of those "SortKeyPressed();" functions from the if statements in ComboHandler_enterFrame() to just one line at the end of them all?
Great game marmotte, can't believe how smooth that is!
-
Marmotte - How would the function be called from the variable??
Code:
if (ComboCheckerThree == updownleftright) {
_root.test = works;
}
??????
-
DOT-INVADER
RipX
it can be something like:
Code:
if (ComboCheckerThree == "down"+"down+right"+"right") {
gotoAndPlay("hadoken");
} else {
gotoAndPlay("normal punch");
}
i know, it's not the best code :-(
maybe i'll end up with something better when i'll re-work on my fighting game, or maybe if someone else's helping...
jonmack
mmmmyes... ^^ but in that case, it will be calculated on each frame even if i don't press any attack key, no? or maybe i missed something ^^
-
Nice rip!
I like
http://hem.passagen.se/bigmoor
-
Hmmm, Is something wrong with my code?
This is on the main timeline:
Code:
// Set variables
speed = 5;
// Set array for cheats
LastKey = new Array();
function SortKey() {
if (LastKey.length<8) {
if (CurrentKey != LastKey[(LastKey.length)-1]) {
LastKey.push(CurrentKey);
}
} else {
LastKey.shift();
}
}
// Get current key
var CurrentKey;
// Key Functions
function moveUp() {
if (hero._y>=5) {
hero._y -= speed;
}
CurrentKey = "up";
SortKey();
}
function moveDown() {
if (hero._y<=140) {
hero._y += speed;
}
CurrentKey = "down";
SortKey();
}
function moveLeft() {
if (hero._x>=5) {
hero._x -= speed;
shaddow._x = hero._x;
}
CurrentKey = "left";
SortKey();
}
function moveRight() {
if (hero._x<=227) {
hero._x += speed;
shaddow._x = hero._x;
}
CurrentKey = "right";
SortKey();
}
timer = 0;
if (LastKey.length>0) {
timer++;
} else {
timer = 0;
}
if (timer>=9000) {
timer = 0;
LastKey.shift();
}
_root.cheatOne = LastKey[LastKey.length-4]+LastKey[LastKey.length-3]+LastKey[LastKey.length-2]+LastKey[LastKey.length-1];
stop();
This is in a movieclip called actions:
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_parent.moveUp();
}
if (Key.isDown(Key.DOWN)) {
_parent.moveDown();
}
if (Key.isDown(Key.LEFT)) {
_parent.moveLeft();
}
if (Key.isDown(Key.RIGHT)) {
_parent.moveRight();
}
if (_root.cheatOne == "up"+"down"+"left"+"right") {
_parent.gotoAndStop(2);
}
}
-
aah, yes. i see. that's probably why your game is smooth running Suppose you could put it in some sort of if(keypressed) statement - only one more little check without actually calling function if not needed. Anyway... your code. I like to keep things as compact as i can.
Still can't get over how sweet this game is. I started making a one-on-on fighting game like this a while ago, but gave up very quickly, bit over my league. You've inspired me to at least re-think my plans
-
DOT-INVADER
jonmack
You've inspired me to at least re-think my plans
ahhhh, these are words i like to hear ^^
what kind of fighting game do you want to create? custom graphics, ripped graphics...?
RipX
mmmh, i suppose your code isn't working? did you trace your array to see the results?
in my case, the code was more like:
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_parent.moveUp();
}
if (Key.isDown(Key.DOWN)) {
_parent.moveDown();
}
if (Key.isDown(Key.LEFT)) {
_parent.moveLeft();
}
if (Key.isDown(Key.RIGHT)) {
if (_root.cheatOne == "up"+"down"+"left") {
_parent.gotoAndStop(2);
} else {
_parent.moveRight();
}
}
-
have u people been using any tutorials for your fighting games?
THE LOSTWOODS COMING SOON
(A Zelda Gaming Online re-encarnation)
-
DOT-INVADER
no.
(it's possible i'll prepare an open source though ^^)
-
DOT-INVADER
mmmhhh... just to let you know, i'm not very motivated for my work today, so...
i'm actively working on an open source! yes!
i already have the basic movments done (directions, jumps, attacks).
the things missing now is a dumb opponent and combos (i'll surely improve the above code)
anyway, i'll put a basic version first i think. stay tuned ^^
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|