A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: here's the source code of the combos used in my fighting game

Threaded View

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center