473,508 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Foosball Game Project

1 New Member
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.charLEF Tbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

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

}

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

}

if (_root.ball.hitTest(_root.enemies.enemies1.charRIG HTtop)) {
_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.charLEF Tbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

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

}

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

}

if (_root.ball.hitTest(_root.enemies.enemies2.charRIG HTtop)) {
_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.charLEF Tbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

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

}

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

}

if (_root.ball.hitTest(_root.enemies.enemies3.charRIG HTtop)) {
_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.charLEF Tbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

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

}

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

}

if (_root.ball.hitTest(_root.enemies.enemies4.charRIG HTtop)) {
_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.charLEF Tbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

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

}

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

}

if (_root.ball.hitTest(_root.enemies.enemies5.charRIG HTtop)) {
_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.charLEF Tbot)) {
_root.ball._x -= 100;
_root.ball._y -= yspeed*25;

}

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

}

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

}

if (_root.ball.hitTest(_root.enemies.enemies6.charRIG HTtop)) {
_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.ba ll._x < 0)) {
_root.ball._x += 120;
}

if ((_root.ball.hitTest(_root.groundRight))&&(_root.b all._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";
}
}
}
Feb 24 '10 #1
0 1366

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1829
by: yongbl | last post by:
Hi, I need to do a client-server project that involves TCP/IP and XML. I want to make it a meaningful project. My friends suggested doing a project on Web Service. What kind of web services...
1
1279
by: alcueca | last post by:
Hi, I've been programming with python and pygame for a year now, I started a RPG game, did some small toy apps (like exploring mandelbrot set) and an entire End-of-Career project about...
7
8032
by: ashwin2mittal | last post by:
Dear friends, I am looking for help regarding major project ideas in C and C++. This project is a part of the my computer engg curriculum. Kindly help me in finding out the ideas ASAP. ...
1
1586
by: Vladimír Kolesnik | last post by:
Hi, there we need help concerning setting project under source control. We want to have a project on the server, and developers in the local network working on this project. We decided to use...
20
1633
by: venkatmail20034u | last post by:
hai to everybody, i desired to do a project in c? if u have idea about what types of problem solved by the c language? and also specify if u have any project title with description please specify...
4
2186
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help...
0
982
by: rejwan | last post by:
Hello, i'm currently working on an online game (browser based), and obviously, since all of the contents is meta-data, I have loads of DB-related work. Recently I came into a brick wall while...
0
1488
by: Rahtgaz | last post by:
Hello everyone, I'm wanting to start implementation of a pet project game IO mechanism. The game is console based. A cross between MUD and Rogue types. For I/O operations I'll be using ncurses...
0
1672
by: Shawn Minisall | last post by:
For my final project, I'm trying to do a GUI based game similar to are you smarter then a 5th grader. I've been working on it and am stuck with some code someone helped me with to randomize the...
5
4091
by: Karlsen | last post by:
Hi everyone. I've been browsing your forums for a week or too, looking for information about RPG games. I'm very new to the whole C++ thing, but feel like im getting a hang of it. As a part of...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.