Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip;
- import flash.utils.Timer;
- import flash.events.TimerEvent;
- import flash.events.MouseEvent;
- import flash.utils.getQualifiedSuperclassName;
- import flash.media.Sound;
- import flash.net.URLRequest;
- import flash.media.SoundChannel;
- public class juego extends MovieClip
- {
- var intervaloEnemigo:Timer;
- var intervaloTiempo:Timer;
- var puntaje:int;
- var tiempo;
- var _panel:panel;
- var canalSonido:SoundChannel /*CONTROLAR SONIDO*/
- var sfondo:Sound
- var posicionSonido:Number
- public function juego()
- {
- mostrarInicio()
- }
- function mostrarInicio(){
- var _inicio:inicio
- _inicio = new inicio();
- addChild(_inicio)
- _inicio.btnIniciar.addEventListener(
- MouseEvent.CLICK,inicioJuego)
- }
- function inicioJuego(e:MouseEvent){
- removeChild(e.target.parent)
- //e.target hace referencia al objeto que genera
- //el evento (el botón en este ejemplo)
- //parent a su objeto padre (la ventana inicio)
- crearPanel()
- puntaje = 50000;
- tiempo = 10;
- _panel.txtTiempo.text = String(tiempo)
- _panel.txtPuntos.text = String(puntaje);
- intervaloEnemigo = new Timer(500);
- intervaloEnemigo.addEventListener(
- TimerEvent.TIMER,crearEnemigo);
- intervaloEnemigo.start();
- intervaloTiempo = new Timer(1000);
- intervaloTiempo.addEventListener(
- TimerEvent.TIMER, actualizarTiempo);
- intervaloTiempo.start();
- crearMira()
- reproducirSonido()
- _panel._altavoz.addEventListener(MouseEvent.CLICK,detenerSonido)
- }
- function detenerSonido(e:MouseEvent)
- {
- if(e.target.currentFrame==2)
- { posicionSonido=canalSonido.position
- canalSonido.stop();
- }
- else
- {
- canalSonido=sfondo.play(posicionSonido,9999)
- }
- }
- function reproducirSonido()
- {
- sfondo=new Sound()
- canalSonido=new SoundChannel()
- var ruta:URLRequest
- ruta =new URLRequest()
- ruta.url="sonidofondo.mp3"
- sfondo.load(ruta);
- canalSonido=sfondo.play(0,9999)
- }
- function crearMira(){
- var _mira:mira;
- _mira = new mira()
- addChild(_mira)
- }
- function crearPanel(){
- _panel = new panel();
- addChild(_panel)
- _panel.x = 20;
- _panel.y = 20;
- }
- function actualizarTiempo(e:TimerEvent)
- {
- tiempo--;
- _panel.txtTiempo.text = String(tiempo);
- if (tiempo == 0)
- {
- intervaloEnemigo.stop();
- intervaloTiempo.stop();
- if (puntaje>=50500)
- {
- mostrarVentana("Tiempo terminado ... Ganó");
- }
- else
- {
- mostrarVentana("Tiempo terminado \n... Ya fuiste!... Looser");
- }
- }
- }
- function crearEnemigo(e:TimerEvent)
- {
- var _enemigo:enemigo;
- _enemigo = new enemigo();
- addChild(_enemigo);
- }
- function actualizarPuntaje(puntos:int)
- {
- puntaje += puntos;
- _panel.txtPuntos.text = String(puntaje);
- }
- function mostrarVentana(textoMensaje:String)
- {
- var _ventana:ventana;
- _ventana = new ventana();
- _ventana.txtMensaje.text = textoMensaje;
- addChild(_ventana);
- _ventana.btnReiniciar.addEventListener(
- MouseEvent.CLICK,reiniciar)
- }
- function reiniciar(e:MouseEvent){
- for(var i:int=0;i<=numChildren-1;i++)
- {
- if(getQualifiedSuperclassName(this.getChildAt(i))=="enemigo")
- {
- Object(this.getChildAt(i)).desactivar()
- }
- }
- removeChildren(0,numChildren-1)
- mostrarInicio()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement