Trouble hitTesting an array.
Hey everyone,
I am having trouble hitTesting items in an array...here is my full code:
PHP Code:
stop();
var gameStarted:Boolean = false;
var gamePaused:Boolean = false;
var generateSpeed:Number = 7;
var speed:Number = 0;
var score:Number = 0;
var health:Number = 100;
var spiderArray:Array = [];
hud.pauseBar._visible = false;
menuSound.stop();
inGameSound.start();
this.createEmptyMovieClip('spiders',this.getNextHighestDepth());
this.onEnterFrame = function() {
if (!gamePaused && gameStarted) {
score++;
}
if (score == 1000 || score == 2000 || score == 3000 || score == 4000 || score == 5000) {
generateSpeed += 3.5;
}
if (score == 6000) {
generateSpeed = 28;
}
if (generateSpeed>28) {
generateSpeed = 28;
}
if (health<0) {
health = 0;
}
if (health == 0) {
delete this.onEnterFrame;
gameStarted = false;
inGameSound.stop();
gameOverSound.start();
}
};
hud.onEnterFrame = function() {
if (gameStarted && !gamePaused) {
this.swapDepths(this.getNextHighestDepth());
}
};
car.onEnterFrame = function() {
if (gameStarted && !gamePaused) {
if (Key.isDown(Key.UP)) {
this._y -= speed/2;
}
if (Key.isDown(Key.DOWN)) {
this._y += speed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
}
speed += 0.3;
if (speed>=15) {
speed = 15;
}
if (this._x<=37.35) {
this._x = 37.35;
}
if (this._x>=762.65) {
this._x = 762.65;
}
if (this._y<=42.65) {
this._y = 42.65;
}
if (this._y>=507.40) {
this._y = 507.40;
}
for(x in spiderArray){
if (this.hitTest(_root[spiderArray[x]])) {
_root[spiderArray[x]].removeMovieClip();
this.removeMovieClip();
spiderArray.splice(x, 1);
}
}
}
};
grass.onEnterFrame = function() {
if (gameStarted && !gamePaused) {
this._y += speed;
}
if (this._y>0) {
this._y = -200;
}
};
spiderGenerator.onEnterFrame = function() {
if (!gamePaused && gameStarted) {
this._y -= generateSpeed;
}
if (this._y<0) {
growSpider();
this._y = 600;
}
};
function growSpider() {
if (!gamePaused && gameStarted) {
spiderCount = 0;
while (spiderCount<Math.floor(Math.random()*(9-7))+7) {
spiderCount++;
randomX = Math.floor(Math.random()*(745-55))+55;
spider = spiders.attachMovie('Spider', 'Spider'+spiders.getNextHighestDepth(), spiders.getNextHighestDepth(), {_x:randomX, _y:-32});
spiderArray.push(spider._name);
spider.onEnterFrame = function() {
if (!gamePaused) {
this._y += speed/2;
this.play();
}
if (this._y>=632) {
this.removeMovieClip();
}
};
}
}
}
function transitionToNextFrame() {
nextFrame();
}
Any ideas why it's not working?