So I’m doing a little project that requires movie clips to be created through action script.
Im not sure how to get them to hitTest because they are both created in seperate functions.
//Enemy function
newEnemy = function () {
var Enemy = _root.attachMovie("angryEyes", "angryEyes"+i, _root.getNextHighestDepth());
Enemy._y = random(550);
Enemy._x = Stage.width;
Enemy.onEnterFrame = function() {
this._x -= random(20);
this._y += -5+random(10);
i++;
if (wall.wall1.hitTest(this)) {
removeMovieClip(this);
}
/*hitTest arrow with zombie!?
function shootZombie() {
if (this.hitTest(angryEyes+i)) {
trace("hit");
}
}*/
};
};
//Spawn new Enemy at an interval of 800ms
setInterval(newEnemy, 800);
//Function for shooting arrows and their direction
//(all things related to how they travel and are created)
ShootBullet = function () {
var Bullet = _root.attachMovie("Bullet", "Bullet"+Num, _root.getNextHighestDepth());
var point = {x:this.hero.gunTip._x, y:this.hero.gunTip._y};
this.hero.localToGlobal(point);
Bullet._x = point.x;
Bullet._y = point.y;
Bullet._rotation = _root.hero._rotation;
Bullet.onEnterFrame = function() {
Bullet._x += Math.cos(Bullet._rotation*(Math.PI/180))*35-5+random(10);
Bullet._y += Math.sin(Bullet._rotation*(Math.PI/180))*35-5+random(10);
//This is so that arrows will clear outside of the stage
//It seems redundant, should use a switch case? or something
if (wall.wall1.hitTest(Bullet) == true) {
removeMovieClip(this);
}
if (wall.wall2.hitTest(Bullet) == true) {
removeMovieClip(this);
}
if (wall.wall3.hitTest(Bullet) == true) {
removeMovieClip(this);
}
if (wall.wall4.hitTest(Bullet) == true) {
removeMovieClip(this);
}
};
//unique identifier for each arrow
Num++;
//shows how many how many have been shot
//trace(Num);
shootZombie();
};