heya guys,
I have made a part of a game which makes the enemycome on the screen and you can shoot them but THEY DONT DIE!!! I need to know how to say hitTest when using arrays. The file is too big to attach but here is the code
var score = 0;
var enemyspeed = 5;
var shoot = true;
var bulletcount = 0;
var bulletarray = [];
var bulletspeed = 15;
var initialammo = 15;
var ammo = initialammo;
var ammotime = 0;
var ammodelay = 30;
function attachbullet() {
if (Key.isDown(Key.SPACE) && shoot == true) {
currentbullet = attachMovie("bullet", "bullet"+bulletcount, bulletcount);
currentbullet._x = _root.char._x;
currentbullet._y = _root.char._y;
bulletcount++;
shoot = false;
bulletarray.push(currentbullet);
ammo--;
}
if (Key.isDown(Key.SPACE)) {
spaceup = false;
} else {
spaceup = true;
}
if (spaceup && ammo>0) {
shoot = true;
}
}
function movebullet() {
for (var i = 0; i<bulletarray.length; i++) {
bulletarray*._x += bulletspeed;
var bullets = bulletarray*;
}
}
var ammobaradd = initialammo*1000/ammodelay;
function checkammo() {
if (ammo<0) {
ammo = 0;
}
if (ammo == 0) {
reload = true;
ammotime++;
}
if (ammotime>=ammodelay) {
ammo += initialammo;
ammotime = 0;
}
if (reload == true) {
_root.ammobar._xscale += ammobaradd-50;
} else {
_root.ammobar._xscale = ammo*1000;
}
reload = false;
}
var enemycount = 0;
var enemytimer = 0;
var enemydelay = 2*30;
var enemyarray = [];
var enemyleftboundary = 120;
function attachenemy() {
enemytimer++;
if (enemytimer>enemydelay) {
currentenemy = attachMovie("enemy", " enemy"+enemycount, enemycount+1000);
enemycount++;
enemytimer = 0;
currentenemy._x = 600;
currentenemy._y = random(400);
enemyarray.push(currentenemy);
currentenemy._xscale = 200;
currentenemy._yscale = 200;
}
if (currentenemy._y>350) {
currentenemy._x = 350;
}
if (currentenemy._y<30) {
currentenemy._x = 30;
}
}
function moveenemy() {
for (var e = 0; e<enemyarray.length; e++) {
enemyarray[e]._x -= 2;
if (enemyarray[e]._y<40) {
enemyarray[e]._y = 40;
}
if (enemyarray[e]._y>350) {
enemyarray[e]._y = 350;
}
if (enemyarray[e]._x<enemyleftboundary) {
enemyarray[e]._x = enemyleftboundary;
enemyarray[e].gotoAndStop(2);
} else {
enemyarray[e].gotoAndStop(1);
}
var enemies = enemyarray[e];
}
}
var enemies = enemyarray[e];
var bullets = bulletarray*;
function checkcollision() {
if (bullets.hitTest(enemies)) {
enemies.removeMovieClip();
ammo++;
}
}
var wallhealth = 100;
function wall() {
if (wallhealth<0) {
wallhealth = 0;
}
_root.healthbar._xscale = wallhealth*100;
}
this.onEnterFrame = function() {
attachenemy();
checkammo();
movebullet();
attachbullet();
moveenemy();
checkcollision();
wall();
};
stop();
Thanks in advance