Need To Have This Code Works 13.08.08
Hi, I have a code that is working pretty good when publish as version 6, only shooting sound is not working…. When publish as version 7, the shooting sound is working but the problem now is when I press space key the ship is gone. i don’t have much budget and is seeking a quick solution. thanks
:: code ::
_root.super_charge = 0;
_root.boomIscoming = 0;
// define the bounds of the movie.
_root.xmax = 850;
_root.xmin = -50;
_root.ymax = 400;
_root.ymin = 10;
//
var hitting_sound_x = new Sound();
hitting_sound_x.attachSound(”rocket_loop3″);
// initialize a variable “a” to keep count of our asteroids and depths.
this.a = 0;
// initialize a variable “f” to keep count of our lasers
this.f = 0;
// all the code that will make up the “ship”
function makeShip(depth) {
createEmptyMovieClip(”ship”,depth);
this.ship._x = this.ship._y=200;
this.ship._xscale = this.ship._yscale=50;
with (this.ship) {
ship.attachMovie(”theShip”,”instance1″,10);
}
}
function createShip() {
this.makeShip(”ship”,1);
this.ship.angle = 0;
this.ship.xv = 0;
this.ship._x = Stage.width/2;
this.ship._y = Stage.height/2;
this.ship.yv = 0;
this.ship.xa = 0;
this.ship.ya = 0;
this.ship.v = 0;
this.ship.visc = 0.02;
this.ship.drag = 0;
this.ship.score = 0;
this.ship.timer = 0;
_root.bullets = new Array();
this.ship.onEnterFrame = function() {
if (_root.gamePause == false) {
// ship enterframe activities begin…
if (this.timer>0) {
this.timer–;
}
if (Key.isDown(Key.SPACE) && this.timer == 0 && _root.lockship != 1) {
//
this.timer = 6;
// BEGIN firing — lock and load
trace(” Shooting “);
if (_root.bullets.length<1) {
bullets.push(_root.createEmptyMovieClip(”f”+_root.bl, 1000+ ++_root.bl));
var id = bullets.length-1;
var bullet = bullets[id];
bullet.id = id;
if (_root.bl>100) {
_root.bl = 0;
}
bullet.lineStyle(1,0xcccccc,100);
bullet.beginFill(0xcccccc,100);
bullet.moveTo(-2,-2);
bullet.lineTo(2,-2);
bullet.lineTo(2,2);
bullet.lineTo(-2,2);
bullet.lineTo(-2,-2);
bullet.endFill();
bullet.angle = this.angle;
bullet.alive = 20;// alive is what we use so your lasers don’t continue perpetually.
bullet._x = this._x;
bullet._y = this._y;
bullet.onEnterFrame = function() {
if (this.alive>0) {
this.alive–;
this._y += -15*Math.cos(Math.PI/180*this.angle);
this._x += 15*Math.sin(Math.PI/180*this.angle);
if (this._x<=_root.xmin) {
this._x += _root.xmax-10;
}
if (this._x>=_root.xmax) {
this._x -= _root.xmax-10;
}
if (this._y<=_root.ymin) {
this._y += _root.ymax-10;
}
if (this._y>=_root.ymax) {
this._y -= _root.ymax-10;
}
} else {
for (var k in _root.bullets) {
if (_root.bullets[k] == this) {
_root.bullets.splice(k,1);
}
}
this.removeMovieClip();
}
};
}
}
//
// BEGIN movement…
if (Key.isDown(Key.RIGHT)) {
this.torque = 5;
_root.NoScore = false;
} else if (Key.isDown(Key.LEFT)) {
this.torque = -5;
_root.NoScore = false;
} else {
this.torque = 0;
}
this.rtorque = 0.5*this.AngVelocity;
this.AngAcceleration = this.torque-this.rtorque;
this.AngVelocity += this.AngAcceleration;
this.angle += this.AngVelocity;
if (this.angle<0) {
this.angle += 360;
}
// constrain theta 0 < 360
if (this.angle>360) {
this.angle -= 360;
}
this.v = Math.sqrt((this.xv*this.xv)+(this.yv*this.yv));
this.drag = this.visc*this.v;
if (Key.isDown(Key.UP)) {
this.force = 1;
_root.thesuper_charge = 1;
_root.NoScore = false;
hitting_sound_x.start();
} else {
this.force = 0;
_root.thesuper_charge = 0;
hitting_sound_x.stop();
}
this.xa = ((this.drag*this.xv)*-1)+(this.force*Math.sin(Math.PI/180*this.angle));
this.ya = ((this.drag*this.yv)*-1)-(this.force*Math.cos(Math.PI/180*this.angle));
this.xv = this.xv+this.xa;
this.yv += this.ya;
if (this._x<=_root.xmin) {
this._x += _root.xmax-10;
}
if (this._x>=_root.xmax) {
this._x -= _root.xmax-10;
}
if (this._y<=_root.ymin) {
this._y += _root.ymax-10;
}
if (this._y>=_root.ymax) {
this._y -= _root.ymax-10;
}
if (_root.lockship != 1) {
this._y += this.yv;
this._x += this.xv;
this._rotation = this.angle;
}
}
// … END movement
};
}
var shooting_sound = new Sound();
shooting_sound.attachSound(”swarm_gun_08″);
var keyListener_obj:Object = new Object();
keyListener_obj.onKeyDown = function() {
switch (Key.getCode()) {
case Key.SPACE :
shooting_sound.start();
break;
}
};
Key.addListener(keyListener_obj);
function Game() {
_root.NoScore = true;
_root.gamePause = false;
_root.gameOver = false;
for (i in _root) {
_root[i].removeMovieClip();
}
at = new Array();
initializeGame();
createShip();
//
}
foo = new Game();
stop();



