Hi there guys; I have a Flash game that I’m working on at the moment that has progressed to the stage where I have a number of enemies appearing at the top of the screen as the game begins, slowly moving down to the ‘Missile Line’ (see screenshot, below) and then firing their missile, which currently travels in a vertical line down to the bottom of the screen.
I am having some problems at this stage, however, and with your help I was hoping I’d be able to solve some of these. My code is posted below, and underneath that are a number of problems I have identified which I was hoping to sort out. The code for the enemy generator is as follows:
//variable setup for later use
var hitLine = 150 //whatever the y position of you hitline is on the root timeline
var maxEnemies = 6
enemyArray = new Array
var hit = false
//
function enemies(){
for(var i=1; i<maxEnemies; i++){
var temp = _root.attachMovie("enemy_mc", "enemy_mc"+i, i)
// sets start positions
temp._x = random(Stage.width)
temp._y = 0 - (i*10)
temp.count = i
temp.ySpeed = i/6 //this is any number you fancy - having it dependent on i which is the 'depth' of the movieclip will make them gradually get faster
// sets bahaviour
temp.onEnterFrame = function(){
this.moveEnemies()
}
}
}
// calls the above enemies function
enemies()
MovieClip.prototype.moveEnemies = function(){
if(this._y<(Stage.height+this._height)){
this._y += this.ySpeed
if(this._y<hitLine-this.count || this._y>hitLine){
hit = false
} else {
hit = true
}
if(hit){
fireMissile(this)
// deleting the enemy here
}
} else {
delete this.onEnterFrame
}
}
var j = maxEnemies
function fireMissile(mc){
this.mc = mc
//trace(this.mc)
_root.j++
var Missile = _root.attachMovie("missile_mc", "missile_mc", j)
Missile._x = this.mc._x
Missile._y = this.mc._y
Missile.MissileSpeed = this.mc.ySpeed*3
Missile.onEnterFrame = function(){
this._y += this.MissileSpeed
}
}
[LIST]
[]I’d like each enemy to fade out as they reach the enemy line and fire their missile.
I tried adding new frames to the enemy timeline and then referencing these frames as they pass over the line, but ActionScript doesn’t like this and it appears not to work. Just having them fade out nicely (and then deleted from the scene) would be fantastic.[/LIST][LIST]
[]There is also a problem at the moment in which as soon as a second bullet is generated, it will cause the first bullet to disappear. The same happens when a third or fourth bullet appears on the screen at the same time. How can I solve this?
I’m pretty sure this would be a simple line fix or something, but I can’t see it. Can anyone point me in the right direction here? Cheers.[/LIST][LIST]
[*]The missiles should move down to the player who will always be in the middle of the screen, and not vertically down, missing the player.
This one is less important at the moment, as I’d rather get the other stuff working first, but I would like the missiles to always hit the center of the bottom of the screen regardless of where they are fired from. Any ideas?[/LIST]
Thanks again guys, I’m pretty sure that I can sort these out with your help, so I look forward to getting some replies soon.
: )