Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. package
  2. {
  3.  
  4. import flash.display.MovieClip;
  5. import flash.utils.Timer;
  6. import flash.events.TimerEvent;
  7. import flash.events.MouseEvent;
  8. import flash.utils.getQualifiedSuperclassName;
  9. import flash.media.Sound;
  10. import flash.net.URLRequest;
  11. import flash.media.SoundChannel;
  12.  
  13.  
  14.  
  15.  
  16. public class juego extends MovieClip
  17. {
  18. var intervaloEnemigo:Timer;
  19. var intervaloTiempo:Timer;
  20. var puntaje:int;
  21. var tiempo;
  22. var _panel:panel;
  23. var canalSonido:SoundChannel /*CONTROLAR SONIDO*/
  24. var sfondo:Sound
  25. var posicionSonido:Number
  26.  
  27. public function juego()
  28. {
  29. mostrarInicio()
  30. }
  31. function mostrarInicio(){
  32. var _inicio:inicio
  33. _inicio = new inicio();
  34. addChild(_inicio)
  35. _inicio.btnIniciar.addEventListener(
  36. MouseEvent.CLICK,inicioJuego)
  37.  
  38. }
  39. function inicioJuego(e:MouseEvent){
  40. removeChild(e.target.parent)
  41. //e.target hace referencia al objeto que genera
  42. //el evento (el botón en este ejemplo)
  43. //parent a su objeto padre (la ventana inicio)
  44. crearPanel()
  45. puntaje = 50000;
  46. tiempo = 10;
  47. _panel.txtTiempo.text = String(tiempo)
  48. _panel.txtPuntos.text = String(puntaje);
  49. intervaloEnemigo = new Timer(500);
  50. intervaloEnemigo.addEventListener(
  51. TimerEvent.TIMER,crearEnemigo);
  52. intervaloEnemigo.start();
  53. intervaloTiempo = new Timer(1000);
  54. intervaloTiempo.addEventListener(
  55. TimerEvent.TIMER, actualizarTiempo);
  56. intervaloTiempo.start();
  57. crearMira()
  58. reproducirSonido()
  59. _panel._altavoz.addEventListener(MouseEvent.CLICK,detenerSonido)
  60. }
  61. function detenerSonido(e:MouseEvent)
  62. {
  63. if(e.target.currentFrame==2)
  64. { posicionSonido=canalSonido.position
  65. canalSonido.stop();
  66.  
  67. }
  68. else
  69. {
  70. canalSonido=sfondo.play(posicionSonido,9999)
  71. }
  72. }
  73.  
  74. function reproducirSonido()
  75. {
  76.  
  77. sfondo=new Sound()
  78. canalSonido=new SoundChannel()
  79. var ruta:URLRequest
  80. ruta =new URLRequest()
  81. ruta.url="sonidofondo.mp3"
  82. sfondo.load(ruta);
  83. canalSonido=sfondo.play(0,9999)
  84. }
  85.  
  86. function crearMira(){
  87. var _mira:mira;
  88. _mira = new mira()
  89. addChild(_mira)
  90. }
  91. function crearPanel(){
  92. _panel = new panel();
  93. addChild(_panel)
  94. _panel.x = 20;
  95. _panel.y = 20;
  96. }
  97. function actualizarTiempo(e:TimerEvent)
  98. {
  99. tiempo--;
  100. _panel.txtTiempo.text = String(tiempo);
  101. if (tiempo == 0)
  102. {
  103. intervaloEnemigo.stop();
  104. intervaloTiempo.stop();
  105. if (puntaje>=50500)
  106. {
  107. mostrarVentana("Tiempo terminado ... Ganó");
  108. }
  109. else
  110. {
  111. mostrarVentana("Tiempo terminado \n... Ya fuiste!... Looser");
  112. }
  113. }
  114. }
  115. function crearEnemigo(e:TimerEvent)
  116. {
  117. var _enemigo:enemigo;
  118. _enemigo = new enemigo();
  119. addChild(_enemigo);
  120. }
  121. function actualizarPuntaje(puntos:int)
  122. {
  123. puntaje += puntos;
  124. _panel.txtPuntos.text = String(puntaje);
  125. }
  126. function mostrarVentana(textoMensaje:String)
  127. {
  128. var _ventana:ventana;
  129. _ventana = new ventana();
  130. _ventana.txtMensaje.text = textoMensaje;
  131. addChild(_ventana);
  132. _ventana.btnReiniciar.addEventListener(
  133. MouseEvent.CLICK,reiniciar)
  134. }
  135. function reiniciar(e:MouseEvent){
  136.  
  137. for(var i:int=0;i<=numChildren-1;i++)
  138. {
  139. if(getQualifiedSuperclassName(this.getChildAt(i))=="enemigo")
  140. {
  141. Object(this.getChildAt(i)).desactivar()
  142.  
  143. }
  144. }
  145. removeChildren(0,numChildren-1)
  146. mostrarInicio()
  147. }
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement