Hi there, I’m pretty new to Flash and all new to these forums. After following the vertical shooter tutorial - which is great btw- I started playing around with the code, trying to add new features.
One of the features I wanted to implement was another type of enemy. In my case, a “good” duck which lowers the score when hit. My first idea was to copy the dragon code and modify the score to count down instead of up, however it doesn’t work. As long as the code of the dragons is working, my “good duck” is simply not displayed at all. Only if I remove the code of the dragons, the duck appears ingame and counting down the score works too.
Here’s the duck code:
function initBenten(){
for (e; e<benten; e++){
attachMovie("bente", "bente"+e, e);
bente = _root["bente"+e];
updateBenten(bente);
bente.onEnterFrame = function(){
if (bente.hitTest(steine)){
score -= 5;
trace(score);
steinActive = false;
removeMovieClip(steine);
updateBenten(this);
}
if (bente._x>0){
bente._x -= bente.velo;
} else {
updateBenten(bente);
}
}
}
}
initBenten();
function updateBenten(){
bente.gotoAndStop(random(4));
bente._x = random(100)+530;
bente._y = random(90)+190;
bente.velo = random(4)+1;
}
As you can see, I called my duck “bente”, “benten” is the number of ducks.
I thought that the code probably wouldn’t work because “this” and “which” are used for the ducks AND the dragons, that’s why I set the number of ducks to 1 and used its name instead of “this” and “which”. Didn’t help it, as soon as I add the dragon code, my ducks are not displayed anymore.
I hope that its not too confusing, just compare it to the dragon code from the tutorial I linked to see the changes I made.