Foros del Web » Creando para Internet » Flash y Actionscript »

Problema con Juego de la gallina

Estas en el tema de Problema con Juego de la gallina en el foro de Flash y Actionscript en Foros del Web. Bueno empesemos or la verdad soy un pollisimo en esto de as3. Pero descargue un juego de una web. es el tipico juego de la ...
  #1 (permalink)  
Antiguo 22/02/2011, 12:54
Avatar de iimeh  
Fecha de Ingreso: septiembre-2009
Mensajes: 25
Antigüedad: 14 años, 7 meses
Puntos: 2
Problema con Juego de la gallina

Bueno empesemos or la verdad soy un pollisimo en esto de as3.
Pero descargue un juego de una web. es el tipico juego de la gallina que tira los huevos y tu los atrapas con una cesta el detalle es que el juego anda a la perfeccion pero no se como pudiera cargar antes de que empiece el juego un movie clip con las instrucciones. el codigo del juego a continuación.

Recuerdon que soy una piedra en esto asi que cualquier ayuda sera buena.

Este es el as3 Main:
Código:
package
{
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.utils.Timer;
	import flash.events.*;
	
	public class Main extends MovieClip
	{
		private var timer:Timer;
		private var timer_uova:Timer;
		
		public var livello:int=1;
		private var cambio:Number;
		public var numUova:int=10;
		public var punteggio:int=0;
		
		private var isPressed:Boolean=false;
		private var direzione:Boolean=true;
		private var destra:Boolean=false;
		private var sinistra:Boolean=false;
				
		public function Main()
		{
			init();
			attivaTimer();
			listeners();
			lanciaUova();
		}
		private function init():void
		{
			stage.frameRate=18;
			
			gallina_mc.x=stage.stageWidth/2;
			gallina_mc.y=gallina_mc.height+10;
			
			cambio=1000+Math.floor(Math.random()*6000);
			
			cambia_livello_mc.visible=false;
			game_over_mc.visible=false;
			punteggio_txt.text='puntage: '+punteggio;
		}
		
		private function attivaTimer():void
		{
			livello_txt.text='nivel: '+livello;
			timer=new Timer(cambio,1);
			timer.addEventListener(TimerEvent.TIMER,lanciaNumero);
			timer.start();
		}
		
		private function lanciaNumero(t:TimerEvent):void
		{
			cambio=1000+Math.floor(Math.random()*4000);
			livello*=-1;
			attivaTimer();
		}
		
		private function listeners():void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN,settaFocus);
			gallina_mc.addEventListener(Event.ENTER_FRAME,muoviGallina);
			cesto_mc.addEventListener(Event.ENTER_FRAME,muoviCesto);
			stage.stageFocusRect=false;
			stage.focus=this;
			this.addEventListener(KeyboardEvent.KEY_DOWN,controllaTasto);
			this.addEventListener(KeyboardEvent.KEY_UP,azzeraTasto);
		}
		
		private function settaFocus(m:MouseEvent):void
		{
			stage.focus=this;
		}
		
		private function muoviGallina(e:Event):void
		{
			gallina_mc.x+=livello*4;
			if(gallina_mc.x>=stage.stageWidth-gallina_mc.width/2)
				livello*=-1;
			if(gallina_mc.x<=gallina_mc.width/2)
				livello*=-1;
		}
		
		private function muoviCesto(e:Event):void
		{
			if(isPressed&&direzione)
				e.target.x+=Math.abs(livello)*5;
			if(isPressed&&!direzione)
				e.target.x-=Math.abs(livello)*5;
		}
		
		private function controllaTasto(k:KeyboardEvent):void
		{
			isPressed=true;
			if(k.keyCode==39)
			{
				destra=true;
				direzione=true;
			}
			if(k.keyCode==37)
			{
				sinistra=true;
				direzione=false;
			}
			k.updateAfterEvent();
		}
		
		private function azzeraTasto(k:KeyboardEvent):void
		{
			if(k.keyCode==39)
				destra=false;
			if(k.keyCode==37)
				sinistra=false;
			if(!destra&&!sinistra)
				isPressed=false;
		}
		
		private function lanciaUova():void
		{
			timer_uova=new Timer(1000-Math.abs(livello)*100,numUova);
			timer_uova.addEventListener(TimerEvent.TIMER,sgancia);
			timer_uova.start();
		}
		
		private function sgancia(t:TimerEvent):void
		{
			var uovo:Uovo=new Uovo(this,timer_uova.currentCount);
		}
		
		public function passaLivello():void
		{
			timer.stop();
			this.removeEventListener(MouseEvent.MOUSE_DOWN,settaFocus);
			gallina_mc.removeEventListener(Event.ENTER_FRAME,muoviGallina);
			cesto_mc.removeEventListener(Event.ENTER_FRAME,muoviCesto);
			this.removeEventListener(KeyboardEvent.KEY_DOWN,controllaTasto);
			this.removeEventListener(KeyboardEvent.KEY_UP,azzeraTasto);
			
			cambia_livello_mc.visible=true;
			cambia_livello_mc.addEventListener(MouseEvent.MOUSE_DOWN,avanza);
		}
		
		private function avanza(m:MouseEvent):void
		{
			livello=Math.abs(livello);
			livello++;
			attivaTimer();
			listeners();
			lanciaUova();
			cambia_livello_mc.visible=false;
		}
		
		public function gameOver():void
		{
			timer.stop();
			timer_uova.stop();
			this.removeEventListener(MouseEvent.MOUSE_DOWN,settaFocus);
			gallina_mc.removeEventListener(Event.ENTER_FRAME,muoviGallina);
			cesto_mc.removeEventListener(Event.ENTER_FRAME,muoviCesto);
			this.removeEventListener(KeyboardEvent.KEY_DOWN,controllaTasto);
			this.removeEventListener(KeyboardEvent.KEY_UP,azzeraTasto);
			
			game_over_mc.visible=true;
			game_over_mc.addEventListener(MouseEvent.MOUSE_DOWN,riprova);
		}
		
		private function riprova(m:MouseEvent):void
		{
			livello=1;
			punteggio=0;
			punteggio_txt.text='puntage: '+punteggio;
			attivaTimer();
			listeners();
			lanciaUova();
			game_over_mc.visible=false;
		}
	}
}
Este es el as3 del Huevo:
Código:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class Uovo extends MovieClip
	{
		private var Root:MovieClip;
		
		private var id:int;
		
		public function Uovo(m:MovieClip,n:int)
		{
			Root=m;
			id=n;
			Root.addChild(this);
			init();
		}
		
		private function init():void
		{
			x=Root.gallina_mc.x;
			y=Root.gallina_mc.y;
			this.addEventListener(Event.ENTER_FRAME,cadi);
		}
		
		private function cadi(e:Event):void
		{
			y+=Math.abs(Root.livello)*3;
			if(this.hitTestObject(Root.cesto_mc))
			{
				this.removeEventListener(Event.ENTER_FRAME,cadi);
				Root.removeChild(this);
				Root.punteggio++;
				Root.punteggio_txt.text='puntage: '+Root.punteggio;
				if(id==Root.numUova)
					Root.passaLivello();
			}
			
			if(y>=Root.linea_mc.y)
			{
				this.removeEventListener(Event.ENTER_FRAME,cadi);
				Root.gameOver();
			}
		}
	}
}

Etiquetas: as3, entrada, gallina, juegos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:49.