PDA

View Full Version : help w/ hitTest in game


coreball
03-11-2005, 05:06 PM
Hi. I'm relativly new in the world of ActionScripting, and am having problems.

I am making a dumb game where you drive a bus for about 1 minute, and during that minute you have to avoid cars.

I have been taking bits and pieces from other tutorials, and everything was going smoothly, until I tried working with HitTest.

Right now, you can drive the bus, however, you can not crash into the cars. The cars are MC's named "enemy1" through "enemy4". The bus is a MC named "bus".

When the collision happens, I want the movie to skip to the "gameover" scene.

Here is a link to the game so far:
http://www.geocities.com/coreball/bus.swf

Any advice will help. Thanks

webguy
03-11-2005, 06:32 PM
var myArray = (_root.enemy1,_root.enemy2,_root.enemy3);

for(var i=0; i<myArray.length; i++) {
if (this.hitTest(myArray[i])==true) {
// you hit a car!
// blow in breathalizer
}
}


Put that in the bus mc in an onEnterFrame event and it should detect a hit on any of the cars, granted they are referenced correctly in the array.

webG