..:: MX Studio Fóruns ::..: Joguinho de nave criado só com AS - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Joguinho de nave criado só com AS Código fonte

#1 User is offline   hufersil 

  • Group: Moderadores
  • Posts: 1265
  • Joined: 15-January 04

  Posted 22 February 2005 - 12:53 PM

Galera, vamos postar aeh!
Daqui a pouco vão dizer que esse fórum foi aberto só pra mim! biggrin.gif
hehehehehehe

Autor: Hugo Ferreira da Silva
Descrição: Um joguinho de nave, bem simples, onde os inimigos atiram também. Para o jogo ficar legal, coloque a taxa de quadros do seu filme em 60 fps.

ActionScript

_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;
       }
}


@braços! smartass.gif
0

#2 User is offline   Natan 

  • Group: Moderador Global
  • Posts: 7350
  • Joined: 28-February 04

Posted 25 February 2005 - 11:02 AM

10, muito loko esse jogo
0

#3 User is offline   bruno_dam 

  • Group: Membros
  • Posts: 331
  • Joined: 16-February 05

Posted 09 May 2005 - 10:32 AM

Mto bom!
0

#4 User is offline   raelbr 

  • Group: Membros
  • Posts: 11
  • Joined: 01-August 05

Posted 01 August 2005 - 10:01 AM

cara, q legal.
eu lembro q a uns 5 ou 6 anos atras eu fiz um joguinho de nave no Flash 4....

via gambiarra total! mas deu certo!
tinha ficado legal... pena q eu perdi ele, senao mostrava pra vcs hehehe

achei muito legal esse espaço para criação de jogos.... é uma area q eu adoro, mas eu sou da parte de design, não de programação... infelizmente sad.gif
0

#5 User is offline   reivin 

  • Group: Membros
  • Posts: 10
  • Joined: 25-November 05

Posted 28 November 2005 - 04:37 PM

so uma perguntinha pra quem ainda esta iniciando no flash.
se eu pegar este codigo ai como eu faco para ver o jogo..
valeu...

0

#6 User is offline   Thiago Action 

  • Group: Membros
  • Posts: 40
  • Joined: 06-November 05

Posted 15 December 2005 - 07:06 PM

Eu queria saber como se colocaria vida eu como aparecer uma tela d game over
flw

0

#7 User is offline   Manezao 

  • Group: Membros
  • Posts: 43
  • Joined: 17-June 05

Posted 22 January 2006 - 02:24 PM

vo faze uma pergunta besta tá? hahahaha
Eu olhei o código, e rodou legal aqui, parabens, muito bom.
Só nao entendi como vc fez pra fazer o formato dos desenhos, aonde que vc deu a forma pra eles???
Valeu
0

#8 User is offline   Natan 

  • Group: Moderador Global
  • Posts: 7350
  • Joined: 28-February 04

Posted 22 January 2006 - 07:32 PM

Simples. Ele criou as naves por essas linhas:

ActionScript
nave.beginFill(0x00CCFF);
nave.moveTo(0,25);
nave.lineTo(20,25);
nave.lineTo(10,0);
nave.lineTo(0,25);
nave.endFill();


Olha esse Tuto que tem no portal:

http://www.mxstudio.com.br/views.tutorial....w&cid=3&aid=447

E outro exemplo aqui no Fórum:

http://forum.mxstudio.com.br/index.php?showtopic=9449

Tmb dá uma lida no Help do Flash que ajuda tmb.

Falow
0

#9 User is offline   Micheeel 

  • Group: Membros
  • Posts: 173
  • Joined: 06-July 06

Posted 06 July 2006 - 11:36 AM

O jogo precisava de mais uns detalhes, mas fazer só por AS é o capeta hehehehehhe

Tá bem bacana smile.gif
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic



Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)