I have a game where there is a spaceship shooting at bubbles. The score goes up by 10 each time it hits.
How can I make it so that when the score reaches a certain point, something new happens? (Aka. a gotoandplay so-and-so?)
Here's my code:
Code:
var DARTSPEED:Number = 20;
var BUBBLESPEED:Number = 5;
var STAGEWIDTH:Number = 500;
var total:Number = new Number ();
total = 0;
var DARTSTART:Number = dart._y; // save dart start position
// define the bubbles' behavior
bubble1.onEnterFrame =
bubble2.onEnterFrame =
bubble3.onEnterFrame =
bubble4.onEnterFrame =
bubble5.onEnterFrame = function() {
// while bubble is still onstage:
if (this._x < STAGEWIDTH) {
this._x += BUBBLESPEED;
// easier to check here against dart rather than vice versa
// MUST check if in frame 1 or command will be executed repeatedly
if (this.hitTest(dart) && this._currentframe==1) {
this.gotoAndPlay("explode");
_root.total = _root.total + 10;
}
// when bubble goes offstage:
} else {
// the following three lines of code add randomness to the balloons' appearance
// reposition on left, between 0 and 50 pixels to the left of the stage
this._x = 0-this._width - Math.random()*50;
// randomly move up or down, up to 20 pixels
this._y += -20 + Math.random()*40;
// randomly change size +/- up to 10%
this._xscale = this._yscale = -10 + this._xscale + Math.random()*20;
// set back to normal (unexploded) view
this.gotoAndStop(1);
}
}
// define the shooter behavior
shooter.onPress = function() {
this.startDrag(false, 0, this._y, STAGEWIDTH-this._width, this._y);
this.onMouseMove = function() {
dart._x = this._x + 4;
}
}
shooter.onRelease = shooter.onReleaseOutside = function() {
this.stopDrag();
delete this.onMouseMove;
dart.onEnterFrame = function() {
// if the dart is still onstage, move it upwards a defined number of pixels per frame
if (this._y > 0-dart._height) {
this._y -= DARTSPEED;
// if it has gone off the top of the stage, reset it to its original position
// and stop the enterFrame to wait for the next release of shooter
} else {
this._y = DARTSTART;
delete this.onEnterFrame;
}
}
}
I'd also like to say thank you to everyone who's helped me thus far. I hope I'm not annoying you!