Foosball Game Project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nixav
    New Member
    • Feb 2010
    • 1

    Foosball Game Project

    Could anyone help me with creating a flash foosball game for actionscript 2.0? Need to hand in a brief on Friday and mine is really not working. Please if someone could read through this code and correct me or can anyone provide me with any script for the game?


    I have created 6 enemies with rectangles inside them that are the hitTests for the ball. The same with my characters. This is the code on my frame.



    onLoad = function() {
    enemyScore = 0;
    yspeed = 0;
    xspeed = 0;
    friction = 5;
    gravity = 5;
    thrust = 5;
    xspeed *= friction;
    yspeed += gravity;
    };

    onEnterFrame = function () {





    _root.ball._y += yspeed;
    _root.ball._x += xspeed;
    _root.ball._rot ation += xspeed;
    //collision detection

    enemyScoreText. text = enemyScore;


    //Char01
    if (_root.ball.hit Test(_root.men. char.charTOP)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.men. char.charBOT)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.men. char.charLEFTto p)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char.charLEFTbo t)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.men. char.charRIGHTt op)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char.charRIGHTb ot)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Char02
    if (_root.ball.hit Test(_root.men. char2.charTOP)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.men. char2.charBOT)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.men. char2.charLEFTt op)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char2.charLEFTb ot)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.men. char2.charRIGHT top)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char2.charRIGHT bot)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }

    //Char03
    if (_root.ball.hit Test(_root.men. char3.charTOP)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.men. char3.charBOT)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.men. char3.charLEFTt op)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char3.charLEFTb ot)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.men. char3.charRIGHT top)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char3.charRIGHT bot)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Char04
    if (_root.ball.hit Test(_root.men. char4.charTOP)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.men. char4.charBOT)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.men. char4.charLEFTt op)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char4.charLEFTb ot)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.men. char4.charRIGHT top)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char4.charRIGHT bot)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }

    //Char05
    if (_root.ball.hit Test(_root.men. char5.charTOP)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.men. char5.charBOT)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.men. char5.charLEFTt op)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char5.charLEFTb ot)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.men. char5.charRIGHT top)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char5.charRIGHT bot)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }

    //Char06
    if (_root.ball.hit Test(_root.men. char6.charTOP)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.men. char6.charBOT)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.men. char6.charLEFTt op)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char6.charLEFTb ot)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.men. char6.charRIGHT top)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.men. char6.charRIGHT bot)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //enemies
    //Enemies01
    if (_root.ball.hit Test(_root.enem ies.enemies1.ch arBOT)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.enem ies.enemies1.ch arTOP)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.enem ies.enemies1.ch arLEFTbot)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies1.ch arLEFTtop)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies1.ch arRIGHTbot)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies1.ch arRIGHTtop)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Enemies02
    if (_root.ball.hit Test(_root.enem ies.enemies2.ch arBOT)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.enem ies.enemies2.ch arTOP)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.enem ies.enemies2.ch arLEFTbot)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies2.ch arLEFTtop)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies2.ch arRIGHTbot)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies2.ch arRIGHTtop)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Enemies03
    if (_root.ball.hit Test(_root.enem ies.enemies3.ch arBOT)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.enem ies.enemies3.ch arTOP)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.enem ies.enemies3.ch arLEFTbot)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies3.ch arLEFTtop)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies3.ch arRIGHTbot)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies3.ch arRIGHTtop)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Enemies04
    if (_root.ball.hit Test(_root.enem ies.enemies4.ch arBOT)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.enem ies.enemies4.ch arTOP)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.enem ies.enemies4.ch arLEFTbot)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies4.ch arLEFTtop)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies4.ch arRIGHTbot)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies4.ch arRIGHTtop)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Enemies05
    if (_root.ball.hit Test(_root.enem ies.enemies5.ch arBOT)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.enem ies.enemies5.ch arTOP)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.enem ies.enemies5.ch arLEFTbot)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies5.ch arLEFTtop)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies5.ch arRIGHTbot)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies5.ch arRIGHTtop)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }


    //Enemies06
    if (_root.ball.hit Test(_root.enem ies.enemies6.ch arBOT)) {
    _root.ball._y -= yspeed*25;
    }

    if (_root.ball.hit Test(_root.enem ies.enemies6.ch arTOP)) {
    _root.ball._y -= yspeed*-25;
    }


    if (_root.ball.hit Test(_root.enem ies.enemies6.ch arLEFTbot)) {
    _root.ball._x -= 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies6.ch arLEFTtop)) {
    _root.ball._x -= 100;
    _root.ball._y += -yspeed*-25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies6.ch arRIGHTbot)) {
    _root.ball._x += 100;
    _root.ball._y -= yspeed*25;

    }

    if (_root.ball.hit Test(_root.enem ies.enemies6.ch arRIGHTtop)) {
    _root.ball._x += 100;
    _root.ball._y += -yspeed*-25;

    }




    //restrictions
    if (_root.ball.hit Test(_root.grou ndBottom)) {
    _root.ball._y -= yspeed*25;
    _root.ball._x -= xspeed*25;
    }


    if ((_root.ball.hi tTest(_root.gro undLeft))&&(_ro ot.ball._x < 0)) {
    _root.ball._x += 120;
    }

    if ((_root.ball.hi tTest(_root.gro undRight))&&(_r oot.ball._x > 0)) {
    _root.ball._x += -120;
    }


    if (_root.ball.hit Test(_root.grou ndTop)) {
    _root.ball._y += yspeed*25;
    _root.ball._x += xspeed*25;
    }

    //goals
    if (_root.ball.hit Test(_root.home Goal)) {
    enemyScore++;

    }



    };


    //This is the code on my characters.
    onClipEvent (load) {
    rotate = 0;

    }

    onClipEvent (enterFrame) {



    if (Key.isDown(Key .RIGHT)) {
    this._x += 15;
    }
    if (Key.isDown(Key .LEFT)) {
    this._x -= 15;
    }






    }


    //This is the code on my enemies.
    onClipEvent (load) {
    enemyspeed = 2;
    enemystepsright = 0;
    enemystepsleft = 0;
    enemydir = "left";
    }
    onClipEvent (enterFrame) {

    if (this.hitTest(_ root.groundLeft )) {
    enemyspeed = 0;
    enemystepsright = 0;
    enemystepsleft = 0;
    dead = true;
    }

    if (!dead) {
    if (enemydir == "right") {
    enemystepsright += 0.5;
    this._x += enemyspeed;
    } else if (enemydir == "left") {
    enemystepsleft += 0.5;
    this._x -= enemyspeed;
    }
    if (enemystepsrigh t == 50) {
    enemystepsright = 0;
    enemydir = "left";
    } else if (enemystepsleft == 50) {
    enemystepsleft = 0;
    enemydir = "right";
    }
    }
    }
Working...