PDA

View Full Version : Multishoot on Multytarget



ypahnu
February 3rd, 2007, 10:27 AM
my ship game have multishoot to multi targets,
but some shoots don't hit targets




function ship_generator(num_ships){

//timespawn=720/num_ships*20;
timespawn=3000;
trace("TimeSpawn :"+timespawn);
setInterval(spawn_ship,timespawn);

}
function spawn_ship(){
//if(j==null){j=-1;}
j =(j==null)? -1 : j;
j++;

rand_ship_type=random(3);
_root.b_ship++;
//trace("rand"+rand_ship_type);

switch (rand_ship_type){
case 0 :
ship_type="bship";
break;
case 1 :
ship_type="fighter";
// trace("you pressed 1");
break;
case 2 :
ship_type="bomber";
// trace("you pressed B");
break;
}

//var ShipHolder: = new myship();

trace("Ship :"+j+" TYPE:"+ship_type);
deep=j+16000;
attachMovie("mc_"+ship_type,"ship"+j,deep);
//attachMovie("mc_fighter","ship"+j,deep);
ship=_root["ship"+j];
ship._x=550;
ship._y=250;//Math.random()*200;
ship.velx=-Math.random()*8+2;
ship.vely=0;//Math.random()*4;

ship.onEnterFrame = function() {

this._x+=this.velx;
//this._y+=this.vely+Math.random()*2;
_root.acerta(this);
_root.onScreenShip(this);
}

}

_root.acerta is the function that test de hittest


function acerta(objecto){
//trace(" FUK acerta "+objecto+" ");
if(objecto.hitTest(_root.my_ship)==true){
trace(objecto+" Hit MySHIP");
}

upper_bullet=_root.n_bullet+_global.max_Bullet;

//trace(_root.n_bullet+"/"+upper_bullet);

for(i=_root.n_bullet;i<upper_bullet;i++){
bullet_ito=eval("_root.bullet"+i);
if(objecto.hitTest(bullet_ito)==true){
//trace(objecto+" HITED By bullet"+i);
removeMovieClip(objecto);
removeMovieClip(bullet_ito);
_root.n_shipDestroi++;
_root.n_INbullet--;
_root.n_ship--;
}
}
}

I cannot figure what's wrong , i am gessing that when I fire more bullets the 1st miss target..

please check this for me

There's any way I can do a better script.. I mean the instead of the for go max bullets ( 16 ) it will just go on those that are on stage?

thaks

ypahnu
February 3rd, 2007, 10:32 AM
maybe I could do a array of shoots and run just those elements that have bullets in ?! instead of going 16(maxbullets) loops ?

thaks

SacrificialLamb
February 3rd, 2007, 05:01 PM
You don't have the fire code in there my may have missed some bullet between n_bullet and upper_bullet. But also if the bullets are moving too fast they might pass though the MC with out "hitting" it for this you might want to up the fps and adjust the speed accordingly

ypahnu
February 3rd, 2007, 11:04 PM
I figure out what is wrong with it,
I fire and add 'n_bullet', when I loop i start on the bullet i fired last.. and go to max bullets ex:


for(i=n_bullet;i<n_bullet+max_bullet;i++){

i should start on n_bullet-max_bullet and go until n_bullet+1, ex:


for(in_bullet-max_bullet;i<n_bullet+1;i++){

thaks

Now I want alien to fire ? what shall I do ? prototype? or shall i use class?
I notice that a function won't work since each alien have his own firing.

PS: Fighter , Bomber and BattleShips are aliens

:stare: nice and complex topic to talk about

SacrificialLamb
February 4th, 2007, 12:18 AM
I personally have not mastered using classes and don't know what a prototype is. What I would do is on the spawning I would give them an onEnterFrame depending on which they are that would do all that probably add all there bullets to an array that you could loop in the player MC but that might get a bit slow with too many alien bullets. From what I know of classes that it's just a nicer way to do the same (similar) thing