Advertisement
Guest User

AIB_Jogo_AS3

a guest
May 1st, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.events.KeyboardEvent;
  2.  
  3. stop();
  4.  
  5. var estado_bala : int =0;
  6. var timer_bala : uint = setInterval(moveBala,100);
  7. var velocidadeBala : int = 15;
  8. var timer_inimigo:uint = setInterval(moveInimigo,100);
  9. var velocidadeInimigo : int =10;
  10. var pontos:int=0;
  11.  
  12. stage.addEventListener(KeyboardEvent.KEY_DOWN,teclado);
  13.  
  14. function teclado(e: KeyboardEvent):void{
  15.     if(e.keyCode == Keyboard.LEFT){
  16.         player.x -= 5;
  17.     }
  18.     if(e.keyCode == Keyboard.RIGHT){
  19.         player.x += 5;
  20.     }
  21.     if(e.keyCode == Keyboard.SPACE){
  22.         if(estado_bala==1) return;
  23.         estado_bala=1;
  24.         bala.x=player.x + player.width/2-bala.width/2;
  25.         bala.y=player.y-bala.height;
  26.         bala.alpha=100;
  27.     }
  28. }
  29.  
  30. function moveBala() : void{
  31.     if(estado_bala==0) return;
  32.     bala.y -= velocidadeBala;
  33.     //testar colisão
  34.     if(bala.hitTestObject(inimigo)){
  35.        estado_bala=0;
  36.        inimigo.x=sortear(5,500);
  37.        bala.alpha=0;
  38.        pontos++;
  39.        pontuacao.text="Pontos: " + pontos.toString();
  40.     }
  41.     if(bala.y<inimigo.y){
  42.         estado_bala=0;
  43.         bala.alpha=0;
  44.     }
  45. }
  46. function moveInimigo() : void
  47. {
  48.     inimigo.x += velocidadeInimigo;
  49.     if(inimigo.x+inimigo.width>540 && velocidadeInimigo>0){
  50.         velocidadeInimigo *= -1;
  51.         inimigo.x += velocidadeInimigo;
  52.     }
  53.     if(inimigo.x<10 && velocidadeInimigo<0){
  54.         velocidadeInimigo *= -1;
  55.         inimigo.x += velocidadeInimigo;
  56.     }
  57. }
  58. //função para sortear
  59. function sortear(min:int=0,max:int=1):int
  60. {
  61.     return Math.floor(Math.random() * (1+max-min))+min;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement