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._rotation += xspeed;
//collision detection

enemyScoreText.text = enemyScore;


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

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


if (_root.ball.hitTest(_root.men.char.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.men.char.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


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

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


if (_root.ball.hitTest(_root.men.char2.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char2.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.men.char2.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char2.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}

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

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


if (_root.ball.hitTest(_root.men.char3.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char3.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.men.char3.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char3.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


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

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


if (_root.ball.hitTest(_root.men.char4.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char4.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.men.char4.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char4.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}

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

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


if (_root.ball.hitTest(_root.men.char5.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char5.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.men.char5.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char5.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}

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

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


if (_root.ball.hitTest(_root.men.char6.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char6.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.men.char6.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.men.char6.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


//enemies
//Enemies01
if (_root.ball.hitTest(_root.enemies.enemies1.charBOT)) {
_root.ball._y -= yspeed*25;
}

if (_root.ball.hitTest(_root.enemies.enemies1.charTOP)) {
_root.ball._y -= yspeed*-25;
}


if (_root.ball.hitTest(_root.enemies.enemies1.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies1.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.enemies.enemies1.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies1.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


//Enemies02
if (_root.ball.hitTest(_root.enemies.enemies2.charBOT)) {
_root.ball._y -= yspeed*25;
}

if (_root.ball.hitTest(_root.enemies.enemies2.charTOP)) {
_root.ball._y -= yspeed*-25;
}


if (_root.ball.hitTest(_root.enemies.enemies2.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies2.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.enemies.enemies2.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies2.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


//Enemies03
if (_root.ball.hitTest(_root.enemies.enemies3.charBOT)) {
_root.ball._y -= yspeed*25;
}

if (_root.ball.hitTest(_root.enemies.enemies3.charTOP)) {
_root.ball._y -= yspeed*-25;
}


if (_root.ball.hitTest(_root.enemies.enemies3.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies3.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.enemies.enemies3.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies3.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


//Enemies04
if (_root.ball.hitTest(_root.enemies.enemies4.charBOT)) {
_root.ball._y -= yspeed*25;
}

if (_root.ball.hitTest(_root.enemies.enemies4.charTOP)) {
_root.ball._y -= yspeed*-25;
}


if (_root.ball.hitTest(_root.enemies.enemies4.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies4.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.enemies.enemies4.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies4.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


//Enemies05
if (_root.ball.hitTest(_root.enemies.enemies5.charBOT)) {
_root.ball._y -= yspeed*25;
}

if (_root.ball.hitTest(_root.enemies.enemies5.charTOP)) {
_root.ball._y -= yspeed*-25;
}


if (_root.ball.hitTest(_root.enemies.enemies5.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies5.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.enemies.enemies5.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies5.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}


//Enemies06
if (_root.ball.hitTest(_root.enemies.enemies6.charBOT)) {
_root.ball._y -= yspeed*25;
}

if (_root.ball.hitTest(_root.enemies.enemies6.charTOP)) {
_root.ball._y -= yspeed*-25;
}


if (_root.ball.hitTest(_root.enemies.enemies6.charLEFTbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies6.charLEFTtop)) {
_root.ball._x -= 100;
_root.ball._y += -yspeed*-25;

}

if (_root.ball.hitTest(_root.enemies.enemies6.charRIGHTbot)) {
_root.ball._x += 100;
_root.ball._y -= yspeed*25;

}

if (_root.ball.hitTest(_root.enemies.enemies6.charRIGHTtop)) {
_root.ball._x += 100;
_root.ball._y += -yspeed*-25;

}




//restrictions
if (_root.ball.hitTest(_root.groundBottom)) {
_root.ball._y -= yspeed*25;
_root.ball._x -= xspeed*25;
}


if ((_root.ball.hitTest(_root.groundLeft))&&(_root.ball._x < 0)) {
_root.ball._x += 120;
}

if ((_root.ball.hitTest(_root.groundRight))&&(_root.ball._x > 0)) {
_root.ball._x += -120;
}


if (_root.ball.hitTest(_root.groundTop)) {
_root.ball._y += yspeed*25;
_root.ball._x += xspeed*25;
}

//goals
if (_root.ball.hitTest(_root.homeGoal)) {
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 (enemystepsright == 50) {
enemystepsright = 0;
enemydir = "left";
} else if (enemystepsleft == 50) {
enemystepsleft = 0;
enemydir = "right";
}
}
}