Hi Guys,
I’ve been working on my first vertical shooter, based on _Bruno’s tutorial on Kirupa.com. It’s just something to fill a gap on a web page, which is why it’s so slim!
There are 3 frames. An opening page, the game and a closing page.
All the code is in the actions layer except the hit areas on frame 1 and 3, within the spaceship mc (the blinking is randomised) and within the starfield mc.
I have 2 problems I hope you can help me with.
Firstly, on the closing page hit area on frame 3, I have:
on(release){
_root.gotoAndStop(1);
}
I thought that this would stop at frame 01, especially as the frame’s code also starts with a stop();. As it stands, it jumps straight back to frame 3.
Secondly, I don’t know how to stop the movie clips generating on frame 03. There is probably a simple built-in function for this, but google hasn’t helped!
I can’t include the 400k fla (it’s too big), but here’s the code on frame02:
stop();
/*SPACESHIP GAME*/
//---- variables ----
var steps:Number = 5;
var spriteX:Number = 50;
var spriteY:Number = 350;
var speed:Number = 20;
var bulletSpeed:Number = 5;
var missileActive:Boolean = false;
var bulletActive:Boolean = false;
var mcArray = new Array();
var enemies:Number = 4;
var i:Number = 0;
var score:Number = 0;
var lives:Number = 3;
var dianas:Number = 1;
var d:Number = 0;
life.text=lives;
//---- functions ----
function alienFire(){
if(bulletActive == false){
fire = Math.random()*100;
if(fire<=5){
attachMovie("bullet", "bullets", 3);
bullets._x = spaceship._x+20;
bullets._y = 0;
bulletActive = true;
}
}
}
function checkLives(){
if (lives<=0){
for (i=0; i<mcArray.length; i++) {
removeMovieClip(mcArray*);
}
gotoAndStop(3);
}
}
function checkKeys() {
if (Key.isDown(Key.RIGHT)&& spriteX<120) {
spriteX += steps;
} else if (Key.isDown(Key.LEFT)&& spriteX>-25) {
spriteX -= steps;
}
if (Key.isDown(Key.UP) && missileActive == false) {
spaceship.gun.play();
attachMovie("missile", "missiles", 6);
missiles._x = spriteX+29;
missiles._y = spriteY;
missileActive = true;
}
}
function updateSpaceship() {
spaceship._x = spriteX;
spaceship._y = spriteY;
spaceship.onEnterFrame = function() {
if (this.hitTest(bullets)) {
lives -= 1;
life.text=lives;
bulletActive = false;
removeMovieClip(bullets);
}
}
}
function updateMissile() {
if (missileActive == true) {
missiles._y -= speed;
}
if (missiles._y<-10) {
missileActive = false;
removeMovieClip(missiles);
}
}
function updateBullet() {
if (bulletActive == true) {
bullets._y += bulletSpeed;
}
if (bullets._y>=410) {
bulletActive = false;
removeMovieClip(bullets);
}
}
function initEnemies() {
for (i; i<enemies; i++) {
attachMovie("baddy", "enemy"+i,i);
enemy = _root["enemy"+i];
mcArray.push(enemy);
updateEnemies(enemy);
enemy.onEnterFrame = function() {
if (this.hitTest(missiles)) {
score += 5;
counter.text=score;
missileActive = false;
removeMovieClip(missiles);
updateEnemies(this);
}
if (this._x>-50) {
this._x -= this.velo;
} else {
updateEnemies(this);
}
};
}
}
function updateEnemies(grr) {
//****.gotoAndStop(random(4));
grr._x = random(100)+150;
grr._y = random(200)+40;
grr.velo = random(8)+1;
}
function initDianas() {
for (d; d<dianas; d++) {
attachMovie("ladydi", "ladydi"+d, d);
ladydi = _root["ladydi"+d];
mcArray.push(ladydi);
updateDianas(ladydi);
ladydi.onEnterFrame = function() {
if (this.hitTest(missiles)) {
score -= 10;
counter.text=score;
removeMovieClip(missiles);
missileActive = false;
updateDianas(this);
}
if (this._x>-50) {
this._x -= this.velo;
} else {
updateDianas(this);
}
};
}
}
function updateDianas(landmine) {
//landmine.gotoAndStop(random(4));
landmine._x = random(100)+150;
landmine._y = random(200)+40;
landmine.velo = random(8)+1;
}
this.onEnterFrame = function() {
alienFire();
checkKeys();
updateSpaceship();
updateMissile();
updateBullet();
checkLives();
}
initEnemies();
initDianas();
Yes, you get docked points for shooting the Princess Dianas!
In updateDianas(), I commented out a line I didn’t understand the purpose of (original tutorial). It didn’t seem to make a difference.
Hope you can help,
Andy