Comunidad de diseño web y desarrollo en internet online

ayuda con juego sencillo en flash

Citar            
MensajeEscrito el 05 Ago 2009 03:11 am
hola estoy tratando de hacer un juego sencillo con una pelota y una barra
me gustaria hacerle objetos tipo para ahccer un arkanoid pero nose como ahcerlo aqui mi codigo ojala me puedan ayudar ya q soy nuevo en esto
saludos
este archivo se llama FirstAnimation.as y mi .fla hace referencia a esta clase

Código ActionScript :

package {
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.events.KeyboardEvent;
   import flash.ui.Keyboard;
   
   import flash.events.KeyboardEvent;
   import flash.ui.Keyboard;
   
   

   // Clase = FirstAnimation ------------------
   public class FirstAnimation extends Sprite {
      private var ball:Sprite;         // ball es del tipo Sprite = MovieClip
      private var paleta:Sprite;         // paleta
      
      private var radio:uint=20;// radio
      private var velx:int= 10;// velocidad horizontal
      private var vely:int= 10;// velocidad vertical
      
      private var velPaletay:int    = 20;
      // Constructor de la clase: función con el mismo nombre que la clase
      public function FirstAnimation () {
         init ();// hace una llamada a la función init (ver más abajo)
      }

      // dibuja la pelota y agrega un "listener" para el evento: "para cada fotograma"
      private function init ():void{
         ball = new Sprite();
         addChild (ball);// pone la pelota en el stage, para que se vea.
         ball.graphics.beginFill (000000);// color de relleno
         ball.graphics.drawCircle (0, 0, radio);// dibuja un circulo (x,y,radio)
         ball.x=radio;// establece la coordenada "x"
         ball.y=stage.stageHeight/2;// establece la coordenada "y"
         
         stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardEvent);
         
         paleta = new Sprite();
         addChild (paleta);// pone la pelota en el stage, para que se vea.
         paleta.graphics.beginFill (000000);// color de relleno
         paleta.graphics.drawRect (0,0,100,10);// dibuja un rectangulo (x,y,,ancho,alto)
         paleta.x=stage.stageWidth/2;// establece la coordenada "x"
         paleta.y=stage.stageHeight-10;// establece la coordenada "y"
         
         
         addEventListener (Event.ENTER_FRAME, onEnterFrame);//aca movemo la paleta
         stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardEvent);//este es el evento de teclado
      }
         
      // esta funcion es llamada para cada fotograma
      private function onEnterFrame (event:Event):void{
         ball.x+=velx;// incrementa la coordena "x" 
         ball.y+=vely;


         if (ball.x >= (stage.stageWidth - radio)){
            ball.x=stage.stageWidth-radio;
            velx*=-1;
         }

         if (ball.x<=radio){
            ball.x=radio;
            velx*=-1;
         }


         /*if (ball.y >= (stage.stageHeight - radio)){
            ball.y=stage.stageHeight-radio;
            vely*=-1;
         }
         */

         if (ball.y<=radio)   {
            ball.y=radio;
            vely*=-1;
         }
         
         if (ball.hitTestObject(paleta)) {
            ball.y -= 10;//el 10 son pixeles
            vely *= -1;
            paleta.width -= 5;//esto hace que cuando la pelota choque con la paleta se agrande la paleta
            //ball.width-=5;
            vely=vely-2;//cuando choca la pelota con la paleta cambia la velocidad
            
            
            if (paleta.width>10){
               paleta.width-=5;
            }
         }
         
      }
      
      public function onKeyboardEvent(event:KeyboardEvent):void {
         switch(event.keyCode) {
            
         
                     
            case Keyboard.LEFT :
            if(paleta.x>20){
               paleta.x -= 20;
               
            }
            break;
            
            case Keyboard.RIGHT :
            
            if(paleta.x<stage.stageWidth-paleta.width)
               paleta.x += velPaletay;
               break;
            
            default:
            
            
               break;
         }
      }



   }
}

Por foos1987

11 de clabLevel



 

firefox
Citar            
MensajeEscrito el 05 Ago 2009 11:54 am

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 05 Ago 2009 04:56 pm
hola ok no tenia idea eso de los tags
si mi idea es esa seria como hacer un arkanoid
saludos

Por foos1987

11 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.