_root.createEmptyMovieClip('estrelas',_root.getNextHighestDepth()); _root.createEmptyMovieClip('inimigo1',_root.getNextHighestDepth()); _root.createEmptyMovieClip('nave',_root.getNextHighestDepth()); _root.createEmptyMovieClip('tiro',_root.getNextHighestDepth()); _root.createEmptyMovieClip('fire',_root.getNextHighestDepth()); _root.createTextField('pontuacao',_root.getNextHighestDepth(),Stage.width-250,0,250,25);
total_inimigos = 4;
var inimigo1:MovieClip; var nave:MovieClip; var tiro:MovieClip; var fire:MovieClip; var estrelas:MovieClip; var pontuacao:TextField; var tf:TextFormat = new TextFormat();
stage_width = Stage.width; stage_height = Stage.height;
inimigo1.beginFill(0xFF0000); inimigo1.lineTo(20,0); inimigo1.lineTo(10,25); inimigo1.lineTo(0,0); inimigo1.endFill(); inimigo1._y = - inimigo1._height;
nave.beginFill(0x00CCFF); nave.moveTo(0,25); nave.lineTo(20,25); nave.lineTo(10,0); nave.lineTo(0,25); nave.endFill(); nave._y = stage_height; nave._x = (stage_width/2) - (nave._width/2); nave.speed = 15; nave.iniciox = nave._x; nave.inicioy = nave._y;
tiro.beginFill(0x00FF00); tiro.lineTo(5,0); tiro.lineTo(5,5); tiro.lineTo(0,5); tiro.lineTo(0,0); tiro.endFill(); tiro._y = stage_height + tiro._height; tiro.speed = 20;
fire.beginFill(0xFFCC00); fire.lineTo(5,0); fire.lineTo(5,5); fire.lineTo(0,5); fire.lineTo(0,0); fire.endFill(); fire._y = stage_height + tiro._height; fire.speed = 10;
tf.align = "right"; tf.font = "Arial"; tf.size = 12; tf.italic = true; tf.bold = true; tf.color = 0xFFCC00; pontuacao.text = "0"; pontuacao.setTextFormat(tf);
// ações da nave nave.onEnterFrame = function () { if(Key.isDown(Key.UP)) { this._y-=this.speed; } if(Key.isDown(Key.DOWN)) { this._y+=this.speed; } if(Key.isDown(Key.LEFT)) { this._x-=this.speed; } if(Key.isDown(Key.RIGHT)) { this._x+=this.speed; } if(this._x < 0) { this._x = 0; } if(this._x > stage_width - this._width) { this._x = stage_width - this._width; } if(this._y < 0) { this._y = 0; } if(this._y > stage_height - this._height) { this._y = stage_height - this._height; } if(Key.isDown(Key.SPACE)) { this.atirar(); } }
nave.atirar = function () { var i = _root.getNextHighestDepth(); tiro.duplicateMovieClip('tiro'+i,i); var o = eval('tiro'+i); o._x = nave._x + (nave._width/2) - (o._width/2); o._y = nave._y - tiro._height; o.speed = this.speed + 5; o.onEnterFrame = function () { this._y -= this.speed; if(this._y < 0) { this.removeMovieClip(); } for(var j=1; j<=total_inimigos; j++) { if(this.hitTest(_root['inimigo'+j])) { _root['inimigo'+j].reset(); pontuacao.text = Number(pontuacao.text) + (stage_width - _root['inimigo'+j]._y); pontuacao.setTextFormat(tf); this.removeMovieClip(); } } } } nave.reset = function () { this._y = this.inicioy; this._x = this.iniciox; }
// ações dos inimigos for(var j=2; j<=total_inimigos; j++) { inimigo1.duplicateMovieClip('inimigo'+j, _root.getNextHighestDepth()); } for(var j=1; j<=total_inimigos; j++) { var enemy = eval('inimigo'+j); enemy.reset = function () { this._x = Math.random()*stage_width; if(this._x > stage_width - this._width) { this._x = stage_width - this._width; } this._y = 0; this.speed = (Math.random()*7) + 2; this.atirou = false; this.pos = Math.random()*stage_height; } enemy.onEnterFrame = function () { this._y += this.speed; if(this._y > stage_height) { this.reset(); } if(this.atirou == false) { if(this._y > this.pos) { this.atirar(); this.atirou = true; } } if(this.hitTest(nave)) { nave.reset(); this.reset(); } } enemy.atirar = function () { var alvox = (nave._x - this._x)/35; var alvoy = (nave._y - this._y)/35; var k = _root.getNextHighestDepth(); fire.duplicateMovieClip('fire'+k, k); var o = eval('fire'+k); o._x = this._x; o._y = this._y; o.ax = alvox; o.ay = alvoy; o.onEnterFrame = function () { o._x += this.ax; o._y += this.ay; if(this._x < 0 || this._x > stage_width || this._y < 0 || this._y > stage_height) { this.removeMovieClip(); } if(this.hitTest(nave)) { nave.reset(); this.removeMovieClip(); } } } enemy.reset(); }
estrelas.beginFill(0x000000,100); estrelas.lineTo(stage_width, 0); estrelas.lineTo(stage_width, stage_height*2); estrelas.lineTo(0, stage_height*2); estrelas.lineTo(0, 0); estrelas.endFill();
estrelas.createEmptyMovieClip('star',1); estrelas.star.beginFill(0xFFFFFF,100); estrelas.star.lineTo(1,0); estrelas.star.lineTo(1,1); estrelas.star.lineTo(0,1); estrelas.star.lineTo(0,0); estrelas.star.endFill();
for(var j=0; j<350; j++) { estrelas.star.duplicateMovieClip('star'+j, estrelas.getNextHighestDepth()); e = estrelas['star'+j]; e._x = Math.random()*stage_width; e._y = Math.random()*estrelas._height; } estrelas.onEnterFrame = function () { this._y++; if(this._y > 0) { this._y = stage_height * -1; } } |