Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Foosball Game Help

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;

}


//the code is the same as the above for the reset of the characters respectively


//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;

}


//the code is the same as the above for the reset of the enemies respectively




//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";
}
}
}



Sign In or Register to comment.