attachmovie, hitTest & multidimentional array question...
Hi all
I'm trying to make a game (my first) and I'm having trouble making my dynamically attached bullets and enemies collide. I've tried so many variations, tutorials, forum searches... to no avail.
Here's my code:
bulletArr = new Array();
var bulletCount = 0;badArr = new Array();
var badCount = 0;
var badAmount = 0;onEnterFrame = function() {
if (Key.isDown(Key.SPACE)) {
bulletCount ++;
var bulletName = bulletArr.push("bullet" + bulletCount);
attachMovie("bullet", bulletName, bulletCount)
this[bulletName]._y = random(Stage.height);
}
badAmount ++;
if (badAmount > 50) {
badCount ++;
var badName = badArr.push("bad" + badCount);
attachMovie("bad", badName, badCount);
this[badName]._x = random(Stage.width);
this[badName]._y = random(Stage.height);
badAmount = 0;
}
this[bulletName].onEnterFrame = function() {
this._x += 10;
if (this._x > 560) {
this.removeMovieClip();
}for (i=0; i<badArr.length; i++) {
if (this.hitTest(badArr)) {
badArr._alpha -= 50;
}}
}}
Any help is appreciated.
Thanks