jon_lad
08-29-2011, 10:38 PM
i am trying to make a scrolling shooter and have used the following code to create the enemys
function enemy1Gen():Void{
//atach enemy and behaivior
var enemy1_mc:MovieClip = _root.attachMovie("enemy1", "e1_"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
for(var i:Number = 0; i < _root.getNextHighestDepth(); i++){
_root["e1_"+i].apply(collision());
}
i have used the same method to create the bullets
function fireWeapon():Void
{
//check if weapon is reloaded, if true, fire bullet
if(reloadComplete == true)
{
//attach bullet
var bullet_mc:MovieClip = _root.attachMovie("bullet", "b"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
//position bullet on player
bullet_mc._x = player_mc._x;
bullet_mc._y = player_mc._y - 32;
then the collision function is
function collision():Void{
if (this.hitTest(_root["b"+i])){
score += point1;
this._x = Math.random()*Stage.width;
this._y = -32-Math.random()*300;
trace(score);
}
if (this.hitTest(_root.player_mc)){
health -= colDam;
this._x = Math.random()*Stage.width;
this._y = -32-Math.random()*300;
trace(health);
}
};
i have put this in an on enter frame event handler in the for loop
for(var i:Number = 0 ; i<100; i++){
_root["e1_"+i].collision();
}
the results are that the variable health decreases at random intervals and the frame jumps about randomly collisions have no effect either between the bullets or the player.
i have tried putting the enemy1_mc name into the collision function instead of .this and taken it out the for loop and getting rid of the .apply this just makes the health variable go down on collisions but the enemy1_mc dosent move and collisions between it and bullets still do nothing.
any help would be appreciated.
function enemy1Gen():Void{
//atach enemy and behaivior
var enemy1_mc:MovieClip = _root.attachMovie("enemy1", "e1_"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
for(var i:Number = 0; i < _root.getNextHighestDepth(); i++){
_root["e1_"+i].apply(collision());
}
i have used the same method to create the bullets
function fireWeapon():Void
{
//check if weapon is reloaded, if true, fire bullet
if(reloadComplete == true)
{
//attach bullet
var bullet_mc:MovieClip = _root.attachMovie("bullet", "b"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
//position bullet on player
bullet_mc._x = player_mc._x;
bullet_mc._y = player_mc._y - 32;
then the collision function is
function collision():Void{
if (this.hitTest(_root["b"+i])){
score += point1;
this._x = Math.random()*Stage.width;
this._y = -32-Math.random()*300;
trace(score);
}
if (this.hitTest(_root.player_mc)){
health -= colDam;
this._x = Math.random()*Stage.width;
this._y = -32-Math.random()*300;
trace(health);
}
};
i have put this in an on enter frame event handler in the for loop
for(var i:Number = 0 ; i<100; i++){
_root["e1_"+i].collision();
}
the results are that the variable health decreases at random intervals and the frame jumps about randomly collisions have no effect either between the bullets or the player.
i have tried putting the enemy1_mc name into the collision function instead of .this and taken it out the for loop and getting rid of the .apply this just makes the health variable go down on collisions but the enemy1_mc dosent move and collisions between it and bullets still do nothing.
any help would be appreciated.