PDA

View Full Version : Shooting Game


hott5hotj
03-11-2008, 05:55 PM
Hi, I am trying to create a shooting game and have got it working, but now I want to add a new object to shoot, but when I try to create another object only the first object appears. I want basically the random appearance of the object1 and 2, so its either 1 or 2 that comes down but not alternating...it can show up randomly...Can anyone help me?


var bulletSpeed=9;
var bulletReady=true;
var bulletDelay=150;
var bulletArray=[];
var bulletCount=0;
function createBullets(){
var bulletMc= this.attachMovie("bullet","bullet"+bulletCount,1000+bulletCount);
bulletCount++;
bulletMc._x=AngrycanMc._x+(AngrycanMc._width/2)-(bulletMc._width/2);
bulletMc._y=AngrycanMc._y+bulletMc._height;
bulletArray.push(bulletMc);
}
function moveBullets(){
if(bulletReady &&Key.isDown(Key.SPACE)){
bulletReady= false;
currentTime= getTimer();
createBullets();
}else{
if(currentTime+bulletDelay<=getTimer()){
bulletReady=true;
}
}
for(var i = 0; i<bulletArray.length;i++){
var b = bulletArray[i];
if (b._y>-50) {
b._y-=bulletSpeed;
} else {
removeMovieClip(b);
bulletArray.splice(i, 1);
}
if (!hit) {
if(b.hitTest(ob,ob2)) {
hit = true;
ob.play();
removeMovieClip(b);
bulletArray.splice(i, 1);
}
}
}
}
var hit = false;
var obSpeed= 2;




function createObject(o) {
ob = this.attachMovie(o, o, 100);
ob._x = random(180)+20;

}





function resetObject() {
ob._x= random(180)+20
ob._y = -40;
ob.gotoAndStop(1);
ob.restart = false;
hit = false
}
function moveObject() {
if (ob._y<250) {
ob._y+=obSpeed;
} else {
resetObject();
}
if (ob.restart) {
resetObject();
}
}
createObject("object1");
this.onEnterFrame = function() {
moveObject();
moveAngrycan();
moveBullets();
}



;




AngrycanMc.onRollOver=function () {
getURL("http://www.mrkabz.com","_blank");
}