Advertisement
Debml

backup videojuegos, mayo 6 1:26 am

May 6th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.70 KB | None | 0 0
  1. package runmaurorun;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Toolkit;
  8. import java.awt.event.KeyEvent;
  9. import java.awt.event.KeyListener;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.io.BufferedReader;
  13. import java.io.FileNotFoundException;
  14. import java.io.FileReader;
  15. import java.io.IOException;
  16. import java.net.URL;
  17. import java.util.ArrayList;
  18. import java.util.Iterator;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import javax.swing.ImageIcon;
  22. import javax.swing.JPanel;
  23.  
  24. /**
  25. * Board
  26. *
  27. * Modela la definición de todos los objetos de tipo <code>Board</code>.
  28. *
  29. * @author Fabián Montemayor A01280156, Mauro Amarante A01191903,
  30. * Patricio Sánchez A01191893 & David Benítez A01191731
  31. * @version 3.0
  32. * @date 8/04/2015
  33. */
  34. public class Board extends JPanel implements Runnable, KeyListener,
  35. MouseListener {
  36. //variables de medidaas del JPanel
  37. private final int iWidth = 1280; //define ancho del JPanel
  38. private final int iHeight = 739; //define altura del JPanel
  39.  
  40. //objetos
  41. private Mauro mauMauro; //objeto para Mauro
  42. private Map mapMaps; //objeto para Map
  43. private Morpheus morMorpheus; //objeto para morfeo
  44.  
  45. //objetos ed tipo MenuButton
  46. private MenuButton mbtBack; //botón de Back
  47. private MenuButton mbtAbout; //botón de About
  48. private MenuButton mbtPlay; //botón de Play
  49. private MenuButton mbtInstructions; //botón de Instrucciones
  50. private MenuButton mbtOptions; //botón de Opciones
  51. private MenuButton mbtScores; //botón de Puntajes
  52. private MenuButton mbtExit; //botón de Salida
  53. private MenuButton mbtGameOverMenu; //boton al menu cuando pierede el juego
  54.  
  55. //variables de Mauro
  56. private final int iHeightMauro = 32; //define altura de Mauro
  57. private final int iWidthMauro = 18; //deine anho de Mauro
  58. private int iVelocityMauro; //define la velocidad de Mauro
  59. private int iDirectionMauro; //define la direccion de Mauro
  60.  
  61. //variables de morfeo
  62. private final int iHeightMorpheus = 32; //define altura de morfeo
  63. private final int iWidthMorpheus = 18; //deine anho de morfeo
  64. private int iDirectionMorpheus; //define la direccion de morfeo
  65.  
  66. //variables de tipo integer
  67. private int iLevel; //define nivel actual en el juego
  68. private int iPosX; //define la ubicacion de un objeto en X
  69. private int iPosY; //define la ubicacion de un objeto en Y
  70. private int iDoorOpenKey; //auxiliar para contorl de puertas y llaves
  71. private int iMouseX; //deinfe la posicion en X del mouse
  72. private int iMouseY; //define la posicion en Y del mouse
  73. private int iMenu; //define el menú correspondiente
  74. private int iLevelChange; //auxiliar que checa si hubo cambio de nivel
  75. private int iPreviousX; //auxiliar para revisar posicion previa
  76. private int iPreviousY; //auxiliar para revisar posicion previa
  77.  
  78. //variables de tipo long
  79. private long lImmuneTimeMauro; //define el tiempo que Mauro es immune
  80. private long lTime; //tiempo restante en el juego
  81. private long lAnimationTime; //tiempo animacion
  82. private long lPauseTime; //tiempo al activar pausa
  83. private long lStopPauseTime; //tiempo al desactivar pausa
  84. private long lCurrentTimePauseFix; /*auxiliar que ayuda a resolver
  85. conflicto de tiempo durante la pausa*/
  86.  
  87. //variables de tipo boolean
  88. private boolean bTime; //define si tiempo del juego ha terminado
  89. private boolean bEndGame; //define si termian el juego o no
  90. private boolean bGameOver; //si se acabo el juego
  91. private boolean bMorpheusStart; //si paso el tiempo morfeo aparece
  92. private boolean bPause; //define si el jeugo esta en pausa
  93. private boolean bLightPause; //auxiliar que desactiva luz durante pausa
  94.  
  95. //listas
  96. private ArrayList arlEnemies; //lista de enemigos
  97. private ArrayList arlMapObjectsLevel1; //lista de Maps del nivel 1
  98. private ArrayList arlMapObjectsLevel2; //lista de Maps del nivel 2
  99. private ArrayList arlMapObjectsLevel3; //lista de Maps del nivel 3
  100. private ArrayList arlMapObjectsLevel4; //lista de Maps del nivel 4
  101. private ArrayList arlMorpheusSteps; //pasos que seguira morfeo
  102. private ArrayList arlCarLevel3; //carros del nivel 3
  103. private ArrayList arlCarLevel4; //carros del nivel 4
  104.  
  105. //arreglos
  106. private boolean[] bButtonsLevel1; //define cuales botones estan activos
  107. private boolean[] bButtonsLevel2; //define cuales botones estan activos
  108. private boolean[] bButtonsLevel3; //define cuales botones estan activos
  109. private boolean[] bButtonsLevel4; //define cuales botones estan activos
  110.  
  111. //thread
  112. private Thread thread; //variable para el thread del JPanel
  113.  
  114. //variables de control de tiempo para animacion
  115. private long lCurrentTime; //tiempo actual
  116. private long lInitialTime; //tiempo inicial
  117. private long lElapsedTime; //tiempo transcurrido
  118.  
  119. //variables control de tiempo para morfeo
  120. private long lMorpheusStartTime;
  121. private long lMorpheusCurrentTime;
  122. private int iMorpheusElapsedTime;
  123. private int iMorpheusTimeLimit;
  124.  
  125. //variables control de tiempo para pwrup de zapatos
  126. private long lShoesStartTime;
  127. private long lShoesCurrentTime;
  128. private int iShoesElapsedTime;
  129. private int iShoesTimeLimit;
  130.  
  131. //variables para controlar la barra de tiempo
  132. private long lTimerInitial; //tiempo en donde se empieza a contar la barra
  133. private long lCurrentTimer; //tiempo actual
  134. private int iElapsedTimeTimer;//tiempo transcurrido
  135. private int iLimitTime; //tiempo limite del nivel en segundos
  136.  
  137. //variables para controlar los powerups
  138. private boolean bLightOn; //deinfe si esta prendido
  139. private long lInitialTimeLight;//define el seg. donde hay colision con Mauro
  140. private int iElapsedTimeLight; //define cuantos segundos han pasado
  141. private boolean bClockOn; //define si hubo colision con Mauro
  142.  
  143. //variables de sonido
  144. private SoundClip sndLevel1Song; //cancion nivel 1
  145. private SoundClip sndLevel2Song; //cancion nivel 2
  146. private SoundClip sndLevel3Song; //cancion nivel 3
  147. private SoundClip sndLevel4Song; //cancion nivel 4
  148.  
  149. //variables efecto de sonido
  150. private SoundClip bPwrUp; //efecto de sonido de pwr up
  151. private SoundClip sndCarCrash; //efecto de choque de carro
  152. private SoundClip sndDoor; //efecto de sonido de puerta
  153. private SoundClip sndStarbucks; //efecto al tomar el starbucks
  154. private SoundClip sndCarSound; //efecto de sonido de carro arrancando
  155. private SoundClip sndWin; //efecto de victoria
  156. private SoundClip sndTrap; //efecto de sonido de la trampa
  157. private SoundClip sndGameOver; //efecto de sonido de game over
  158. private SoundClip sndBark; //efecto de sonido de ladrido de perro
  159. private SoundClip sndMenuClick; //efecto de sonido de presionar boton
  160. private SoundClip sndPwrDown; //efecto de sonido de pwr down
  161. private SoundClip sndYawn; //efecto de sonido de boztezo
  162.  
  163. /**
  164. * Board
  165. *
  166. * Metodo sobrescrito de la clase <code>JPanel</code>.<P>
  167. * En este metodo se inizializan las variables o se crean los objetos
  168. * a usarse en el <code>JPanel</code> y se definen funcionalidades.
  169. *
  170. */
  171. public Board() {
  172. /* se le añade la opcion al JFrame de ser escuchado por los eventos
  173. del teclado y mouse*/
  174. addKeyListener(this);
  175. addMouseListener(this);
  176.  
  177. //define en cual panel definir enfoque
  178. setFocusable(true);
  179.  
  180. //iniciar juego
  181. GameInit();
  182. setDoubleBuffered(true);
  183. }
  184.  
  185. /**
  186. * GameInit
  187. *
  188. * Metodo que inicializa el juego.
  189. *
  190. */
  191. public void GameInit() {
  192. //Nivel de inicio, animacion inical
  193. iLevel = 0; // era 0
  194.  
  195. //siguiente nivel
  196. iLevelChange = 1; //era 1
  197.  
  198. //menu inicial
  199. iMenu = 1;
  200.  
  201. //no inicia en pausa
  202. bPause = false;
  203.  
  204. //no se utiliza todavia
  205. bLightPause = false;
  206.  
  207. //no es necesario si la pausa no esta activa
  208. lCurrentTimePauseFix = 0;
  209.  
  210. //variables que definen que le juego no ha terminado o perdido el juego
  211. bEndGame = false;
  212. bGameOver = false;
  213.  
  214. //Se define sonido de fondo para cada nivel
  215. //nivel 1
  216. sndLevel1Song = new SoundClip("Musica/nivel1.wav");
  217. sndLevel1Song.setLooping(true);
  218. //nivel 2
  219. sndLevel2Song = new SoundClip("Musica/nivel2.wav");
  220. sndLevel2Song.setLooping(true);
  221. //nivel 3
  222. sndLevel3Song = new SoundClip("Musica/nivel3.wav");
  223. sndLevel3Song.setLooping(true);
  224. //nivel 4
  225. sndLevel4Song = new SoundClip("Musica/nivel4.wav");
  226. sndLevel4Song.setLooping(true);
  227.  
  228. //incializar efectos de sonido
  229. bPwrUp = new SoundClip("Sfx/powerup.wav");
  230. bPwrUp.setLooping(false);
  231. sndCarCrash = new SoundClip("Sfx/carcrash.wav");
  232. sndCarCrash.setLooping(false);
  233. sndDoor = new SoundClip("Sfx/door.wav");
  234. sndDoor.setLooping(false);
  235. sndStarbucks = new SoundClip("Sfx/starbucks.wav");
  236. sndStarbucks.setLooping(false);
  237. sndCarSound = new SoundClip("Sfx/vroom.wav");
  238. sndCarSound.setLooping(false);
  239. sndWin = new SoundClip("Sfx/win.wav");
  240. sndWin.setLooping(false);
  241. sndTrap = new SoundClip("Sfx/stab.wav");
  242. sndTrap.setLooping(false);
  243. sndGameOver = new SoundClip("Sfx/gameover.wav");
  244. sndGameOver.setLooping(false);
  245. sndBark = new SoundClip("Sfx/bark.wav");
  246. sndBark.setLooping(false);
  247. sndMenuClick = new SoundClip("Sfx/menuclick.wav");
  248. sndMenuClick.setLooping(false);
  249. sndPwrDown = new SoundClip("Sfx/powerdown.wav");
  250. sndPwrDown.setLooping(false);
  251. sndYawn = new SoundClip("Sfx/yawn.wav");
  252. sndYawn.setLooping(false);
  253.  
  254. //inicializar arreglo de botones
  255. bButtonsLevel1 = new boolean[5];
  256. bButtonsLevel2 = new boolean[9];
  257. bButtonsLevel3 = new boolean[5];
  258. bButtonsLevel4 = new boolean[5];
  259.  
  260. //llenar arreglos
  261. for (int i = 0; i < 5; i++) {
  262. bButtonsLevel1[i] = false;
  263. }
  264. for (int i = 0; i < 5; i++) {
  265. bButtonsLevel2[i] = false;
  266. }
  267. for (int i = 0; i < 5; i++) {
  268. bButtonsLevel3[i] = false;
  269. }
  270. for (int i = 0; i < 5; i++) {
  271. bButtonsLevel4[i] = false;
  272. }
  273.  
  274. //incializar a Mauro
  275. iVelocityMauro = 2;
  276. iDirectionMauro = 0;
  277. lImmuneTimeMauro = 0;
  278. String sMauro = "Animation/Mauro/mauro1.png";
  279. ImageIcon imiImage = new ImageIcon(this.getClass().getResource(sMauro));
  280. mauMauro = new Mauro(iVelocityMauro, iDirectionMauro,
  281. iWidthMauro, iHeightMauro, imiImage.getImage(),
  282. lImmuneTimeMauro);
  283.  
  284. //inicializar a morfeo
  285. iDirectionMorpheus = 0;
  286. String sMorpheus = "Animation/Mauro/mauro1.png";
  287. imiImage = new ImageIcon(this.getClass().getResource(sMauro));
  288. morMorpheus = new Morpheus(iDirectionMorpheus, iWidthMorpheus,
  289. iHeightMorpheus, imiImage.getImage());
  290.  
  291. //inicializar lista de pasos morfeo
  292. arlMorpheusSteps = new ArrayList();
  293.  
  294. //inicializar tiempo de morfeo en 9
  295. iMorpheusTimeLimit = 9; //en segundos
  296.  
  297. //inicializar tiempo de los zapatos en 5
  298. iShoesTimeLimit = 5; //en segundos
  299.  
  300. //incicializar posiciones previas
  301. iPreviousX = -1; //auxiliar para definri posiciones de morfeo
  302. iPreviousY = -1; //auxiliar para definri posiciones de morfeo
  303.  
  304. //inicializar que morfeo no se pinta aun
  305. bMorpheusStart = false;
  306.  
  307. //crea las listas de los Mapas
  308. arlMapObjectsLevel1 = new ArrayList();
  309. arlMapObjectsLevel2 = new ArrayList();
  310. arlMapObjectsLevel3 = new ArrayList();
  311. arlMapObjectsLevel4 = new ArrayList();
  312.  
  313. //crea lista de carros
  314. arlCarLevel3 = new ArrayList();
  315.  
  316. //Inicializa todos los mapas
  317. try {
  318. GameInitMaps();
  319. } catch (IOException ex) {
  320. Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
  321. }
  322.  
  323. // Inicializa botones del menu
  324. String sBack = "Menus/bot_back.png";
  325. String sAbout = "Menus/bot_acerca.png";
  326. String sInstructions = "Menus/bot_instrucciones.png";
  327. String sOptions = "Menus/bot_opciones.png";
  328. String sPlay = "Menus/bot_jugar.png";
  329. String sScores = "Menus/bot_puntos.png";
  330. String sExit = "Menus/bot_salir.png";
  331. String sGameOverMenu = "Menus/boton_menu.png";
  332.  
  333. imiImage = new ImageIcon(this.getClass().getResource(sBack));
  334. mbtBack = new MenuButton(imiImage.getImage(),
  335. 1280 - imiImage.getIconWidth(), 30,
  336. imiImage.getIconWidth(), imiImage.getIconHeight());
  337. imiImage = new ImageIcon(this.getClass().getResource(sAbout));
  338. mbtAbout = new MenuButton(imiImage.getImage(),
  339. 1280/2 - imiImage.getIconWidth()/2, 420,
  340. imiImage.getIconWidth(), imiImage.getIconHeight());
  341. imiImage = new ImageIcon(this.getClass().getResource(sInstructions));
  342. mbtInstructions = new MenuButton(imiImage.getImage(),
  343. 1280/2 - imiImage.getIconWidth()/2, 330,
  344. imiImage.getIconWidth(), imiImage.getIconHeight());
  345. imiImage = new ImageIcon(this.getClass().getResource(sOptions));
  346. mbtOptions = new MenuButton(imiImage.getImage(),
  347. 1280/2 - imiImage.getIconWidth()/2, 360,
  348. imiImage.getIconWidth(), imiImage.getIconHeight());
  349. imiImage = new ImageIcon(this.getClass().getResource(sPlay));
  350. mbtPlay = new MenuButton(imiImage.getImage(),
  351. 1280/2 - imiImage.getIconWidth()/2, 300,
  352. imiImage.getIconWidth(), imiImage.getIconHeight());
  353. imiImage = new ImageIcon(this.getClass().getResource(sScores));
  354. mbtScores = new MenuButton(imiImage.getImage(),
  355. 1280/2 - imiImage.getIconWidth()/2, 390,
  356. imiImage.getIconWidth(), imiImage.getIconHeight());
  357. imiImage = new ImageIcon(this.getClass().getResource(sExit));
  358. mbtExit = new MenuButton(imiImage.getImage(),
  359. 1280/2 - imiImage.getIconWidth()/2, 450,
  360. imiImage.getIconWidth(), imiImage.getIconHeight());
  361. imiImage = new ImageIcon(this.getClass().getResource(sGameOverMenu));
  362. mbtGameOverMenu = new MenuButton(imiImage.getImage(),
  363. 1280/2 - imiImage.getIconWidth()/2, 450,
  364. imiImage.getIconWidth(), imiImage.getIconHeight());
  365.  
  366. // inicializa el thread
  367. if (thread == null || !bEndGame) {
  368. thread = new Thread(this);
  369. thread.start();
  370. }
  371. }
  372.  
  373. /**
  374. * GameInitMaps
  375. *
  376. * Metodo que inicializa todos los mapas del juego.
  377. *
  378. */
  379. private void GameInitMaps() throws IOException {
  380. //variables
  381. //variables que definen un=bicacion de imagenes
  382. String sLevel1WallVertical = "Nivel1/paredVerticalNivel1.jpg";
  383. String sLevel1WallHorizontal = "Nivel1/paredHorizontalNivel1.png";
  384. String sLevel1Trap = "Nivel1/picos0.png";
  385. String sLevel1Finish = "Nivel1/meta_nivel1.png";
  386. String sLevel1Text = "src/runmaurorun/Nivel1/Nivel1.txt";
  387. String sLevel2Text = "src/runmaurorun/nivel2/Nivel2.txt";
  388. String sLevel3Text = "src/runmaurorun/nivel3/Nivel3.txt";
  389. String sLevel4Text = "src/runmaurorun/nivel4/Nivel4.txt";
  390.  
  391. String sData; //almacena lectura de texto
  392.  
  393. char cObjectType; //revisa tipo objeto a leer
  394. char cAuxObjectType; //auxiliar q almacena el tipo de objeto
  395.  
  396. int iWidthObject; //variable para ancho del objeto
  397. int iHeightObject; //variable para altura del objeto
  398. int iDoorKey; //varaible para control de acceso de puertas
  399. int iX;
  400. int iY;
  401. int iDoorLength;
  402. int iDirectionCar; //variable para control de la direccion del perro
  403.  
  404. boolean bFinishFileRead; //variable que define si se termino la lectura
  405.  
  406. ImageIcon imiImage; //imagen utilizada para crear mapas
  407.  
  408. //buscar y leer archivo de Nivel 1
  409. BufferedReader fileIn;
  410.  
  411. //inicializar variables
  412. cObjectType = ' ';
  413. iWidthObject = 0;
  414. iHeightObject = 0;
  415. imiImage = new ImageIcon(this.getClass().getResource(
  416. sLevel1WallHorizontal));
  417.  
  418. Map mapObject;
  419. Enemy emyObject;
  420. //--------------------------NIVEL 1------------------------------------
  421. //duracion del juego
  422. iLimitTime = 200; //2 minutos
  423.  
  424. //pwrup de luz
  425. bLightOn = false; //no tiene el powerUp
  426.  
  427. //pwrup reloj
  428. bClockOn = false; //No tiene el powerup
  429.  
  430. try {
  431. fileIn = new BufferedReader(new FileReader(sLevel1Text));
  432. } catch (FileNotFoundException e) {
  433. System.out.println("FILE NOT FOUND!");
  434. fileIn = new BufferedReader(new FileReader(
  435. sLevel1Text));
  436. }
  437.  
  438. //file has not been read
  439. bFinishFileRead = false;
  440.  
  441. //leer archivo hasta terminar de leerlo
  442. sData = fileIn.readLine();
  443. do {
  444. //si el primer caracter es una letra
  445. if (sData.charAt(0) - 97 >= 0 ) {
  446. cObjectType = sData.charAt(0);
  447. sData = fileIn.readLine();
  448. }
  449.  
  450. //si la linea es un comentario
  451. if (sData.charAt(0) == '/') {
  452. sData = fileIn.readLine();
  453. }
  454.  
  455. //leer coordenadas X y Y
  456. iX = Integer.parseInt(sData);
  457. sData = fileIn.readLine();
  458. iY = Integer.parseInt(sData);
  459.  
  460. //definir medidas e imagen a utilizar dependiendo del objeto
  461. switch (cObjectType) {
  462. case 'a': //pared horizontal
  463. iWidthObject = 76;
  464. iHeightObject = 19;
  465. imiImage = new ImageIcon(this.getClass().getResource(
  466. sLevel1WallHorizontal));
  467. mapObject = new Map(imiImage.getImage(),
  468. iX, iY, iWidthObject, iHeightObject,
  469. false, false);
  470. mapObject.setImage(imiImage.getImage());
  471. arlMapObjectsLevel1.add(mapObject);
  472. break;
  473. case 'b': //pared vertical
  474. iWidthObject = 19;
  475. iHeightObject = 76;
  476. imiImage = new ImageIcon(this.getClass().getResource(
  477. sLevel1WallVertical));
  478. mapObject = new Map(imiImage.getImage(),
  479. iX, iY, iWidthObject, iHeightObject,
  480. false, false);
  481. mapObject.setImage(imiImage.getImage());
  482. arlMapObjectsLevel1.add(mapObject);
  483. break;
  484. case 'c': //trampa
  485. iWidthObject = 32;
  486. iHeightObject = 19;
  487. imiImage = new ImageIcon(this.getClass().getResource(
  488. sLevel1Trap));
  489. mapObject = new Trap(imiImage.getImage(),
  490. iX, iY, iWidthObject, iHeightObject, -1,
  491. false);
  492. mapObject.setImage(imiImage.getImage());
  493. arlMapObjectsLevel1.add(mapObject);
  494. break;
  495. case 'd': //puerta horizontal
  496. iWidthObject = 92;
  497. iHeightObject = 8;
  498. sData = fileIn.readLine();
  499. iDoorKey = Integer.parseInt(sData);
  500. sData = fileIn.readLine();
  501. imiImage = new ImageIcon(this.getClass().getResource(
  502. sData));
  503. mapObject = new Door(imiImage.getImage(),
  504. iX, iY, iWidthObject, iHeightObject,
  505. false, iDoorKey, false);
  506. mapObject.setImage(imiImage.getImage());
  507. arlMapObjectsLevel1.add(mapObject);
  508. break;
  509. case 'e': //puerta vertical
  510. iWidthObject = 8;
  511. iHeightObject = 90;
  512. sData = fileIn.readLine();
  513. iDoorKey = Integer.parseInt(sData);
  514. sData = fileIn.readLine();
  515. imiImage = new ImageIcon(this.getClass().getResource(
  516. sData));
  517. mapObject = new Door(imiImage.getImage(),
  518. iX, iY, iWidthObject, iHeightObject,
  519. false, iDoorKey, false);
  520. mapObject.setImage(imiImage.getImage());
  521. arlMapObjectsLevel1.add(mapObject);
  522. break;
  523. case 'f': //boton
  524. iWidthObject = 32;
  525. iHeightObject = 19;
  526. sData = fileIn.readLine();
  527. iDoorKey = Integer.parseInt(sData);
  528. sData = fileIn.readLine();
  529. imiImage = new ImageIcon(this.getClass().getResource(
  530. sData));
  531. mapObject = new Button(imiImage.getImage(),
  532. iX, iY, iWidthObject, iHeightObject,
  533. false, false, iDoorKey);
  534. mapObject.setImage(imiImage.getImage());
  535. arlMapObjectsLevel1.add(mapObject);
  536. break;
  537. case 'g': //powerup
  538. iWidthObject = 16;
  539. iHeightObject = 25;
  540. sData = fileIn.readLine();
  541. int iPwrUpType = Integer.parseInt(sData);
  542. sData = fileIn.readLine();
  543. imiImage = new ImageIcon(this.getClass().getResource(
  544. sData));
  545. mapObject = new PwrUp(false, false, imiImage.getImage(),
  546. iX, iY, iWidthObject, iHeightObject,
  547. iPwrUpType, -1);
  548. mapObject.setImage(imiImage.getImage());
  549. arlMapObjectsLevel1.add(mapObject);
  550. break;
  551. case 'h': //meta
  552. iWidthObject = 83;
  553. iHeightObject = 47;
  554. imiImage = new ImageIcon(this.getClass().getResource(
  555. sLevel1Finish));
  556. mapObject = new Map(imiImage.getImage(),
  557. iX, iY, iWidthObject, iHeightObject,
  558. false, true);
  559. mapObject.setImage(imiImage.getImage());
  560. arlMapObjectsLevel1.add(mapObject);
  561. break;
  562. default:
  563. break;
  564. }
  565.  
  566. sData = fileIn.readLine();
  567.  
  568. //si se termino la lectura
  569. if (sData.charAt(0) == 'x') {
  570. bFinishFileRead = true;
  571. }
  572. } while (!bFinishFileRead);
  573.  
  574. //--------------------------NIVEL 2------------------------------------
  575. String sLevel2WallVertical = "Nivel2/pared_vertical_nivel2.png";
  576. String sLevel2WallHorizontal = "Nivel2/pared_horizontal_nivel2.png";
  577.  
  578. try {
  579. fileIn = new BufferedReader(new FileReader(sLevel2Text));
  580. } catch (FileNotFoundException e) {
  581. System.out.println("FILE NOT FOUND!");
  582. fileIn = new BufferedReader(new FileReader(sLevel2Text));
  583. }
  584.  
  585. //file has not been read
  586. bFinishFileRead = false;
  587.  
  588. //leer archivo hasta terminar de leerlo
  589. sData = fileIn.readLine();
  590. do {
  591. //si el primer caracter es una letra
  592. if (sData.charAt(0) - 97 >= 0 ) {
  593. cObjectType = sData.charAt(0);
  594. sData = fileIn.readLine();
  595. }
  596.  
  597. //si la linea es un comentario
  598. if (sData.charAt(0) == '/') {
  599. sData = fileIn.readLine();
  600. }
  601.  
  602. //leer coordenadas X y Y
  603. iX = Integer.parseInt(sData);
  604. sData = fileIn.readLine();
  605. iY = Integer.parseInt(sData);
  606.  
  607. //definir medidas e imagen a utilizar dependiendo del objeto
  608. switch (cObjectType) {
  609. case 'a': //pared horizontal
  610. iWidthObject = 76;
  611. iHeightObject = 19;
  612. imiImage = new ImageIcon(this.getClass().getResource(
  613. sLevel2WallHorizontal));
  614. mapObject = new Map(imiImage.getImage(),
  615. iX, iY, iWidthObject, iHeightObject,
  616. true, false);
  617. mapObject.setImage(imiImage.getImage());
  618. arlMapObjectsLevel2.add(mapObject);
  619. break;
  620. case 'b': //pared vertical
  621. iWidthObject = 19;
  622. iHeightObject = 76;
  623. imiImage = new ImageIcon(this.getClass().getResource(
  624. sLevel2WallVertical));
  625. mapObject = new Map(imiImage.getImage(),
  626. iX, iY, iWidthObject, iHeightObject,
  627. true, false);
  628. mapObject.setImage(imiImage.getImage());
  629. arlMapObjectsLevel2.add(mapObject);
  630. break;
  631. case 'c': //decoracion de casa
  632. sData = fileIn.readLine();
  633. iDoorLength = Integer.parseInt(sData);
  634. iWidthObject = iDoorLength;
  635. sData = fileIn.readLine();
  636. iDoorLength = Integer.parseInt(sData);
  637. iHeightObject = iDoorLength;
  638. sData = fileIn.readLine();
  639. imiImage = new ImageIcon(this.getClass().getResource(
  640. sData));
  641. mapObject = new Map(imiImage.getImage(),
  642. iX, iY, iWidthObject, iHeightObject,
  643. true, false);
  644. mapObject.setImage(imiImage.getImage());
  645. arlMapObjectsLevel2.add(mapObject);
  646. break;
  647. case 'd': //puerta horizontal
  648. sData = fileIn.readLine();
  649. iDoorLength = Integer.parseInt(sData);
  650. iWidthObject = iDoorLength;
  651. sData = fileIn.readLine();
  652. iDoorLength = Integer.parseInt(sData);
  653. iHeightObject = iDoorLength;
  654. sData = fileIn.readLine();
  655. iDoorKey = Integer.parseInt(sData);
  656. sData = fileIn.readLine();
  657. imiImage = new ImageIcon(this.getClass().getResource(
  658. sData));
  659. mapObject = new Door(imiImage.getImage(),
  660. iX, iY, iWidthObject, iHeightObject,
  661. false, iDoorKey, true);
  662. mapObject.setImage(imiImage.getImage());
  663. arlMapObjectsLevel2.add(mapObject);
  664. break;
  665. case 'e': //puerta vertical
  666. sData = fileIn.readLine();
  667. iDoorLength = Integer.parseInt(sData);
  668. iWidthObject = iDoorLength;
  669. sData = fileIn.readLine();
  670. iDoorLength = Integer.parseInt(sData);
  671. iHeightObject = iDoorLength;
  672. sData = fileIn.readLine();
  673. iDoorKey = Integer.parseInt(sData);
  674. sData = fileIn.readLine();
  675. imiImage = new ImageIcon(this.getClass().getResource(
  676. sData));
  677. mapObject = new Door(imiImage.getImage(),
  678. iX, iY, iWidthObject, iHeightObject,
  679. false, iDoorKey, true);
  680. mapObject.setImage(imiImage.getImage());
  681. arlMapObjectsLevel2.add(mapObject);
  682. break;
  683. case 'f': //boton
  684. iWidthObject = 32;
  685. iHeightObject = 19;
  686. sData = fileIn.readLine();
  687. iDoorKey = Integer.parseInt(sData);
  688. sData = fileIn.readLine();
  689. imiImage = new ImageIcon(this.getClass().getResource(
  690. sData));
  691. mapObject = new Button(imiImage.getImage(),
  692. iX, iY, iWidthObject, iHeightObject,
  693. true, false, iDoorKey);
  694. mapObject.setImage(imiImage.getImage());
  695. arlMapObjectsLevel2.add(mapObject);
  696. break;
  697. case 'g': //powerup
  698. iWidthObject = 16;
  699. iHeightObject = 25;
  700. sData = fileIn.readLine();
  701. int iPwrUpType = Integer.parseInt(sData);
  702. sData = fileIn.readLine();
  703.  
  704. imiImage = new ImageIcon(this.getClass().getResource(
  705. sData));
  706. mapObject = new PwrUp(false, true, imiImage.getImage(),
  707. iX, iY, iWidthObject, iHeightObject,
  708. iPwrUpType, -1);
  709. mapObject.setImage(imiImage.getImage());
  710. arlMapObjectsLevel2.add(mapObject);
  711. break;
  712. case 'h': //meta
  713. iWidthObject = 52;
  714. iHeightObject = 30;
  715. sData = fileIn.readLine();
  716. imiImage = new ImageIcon(this.getClass().getResource(
  717. sData));
  718. mapObject = new Map(imiImage.getImage(),
  719. iX, iY, iWidthObject, iHeightObject,
  720. true, true);
  721. mapObject.setImage(imiImage.getImage());
  722. arlMapObjectsLevel2.add(mapObject);
  723. break;
  724. case 'i': //barandales
  725. sData = fileIn.readLine();
  726. iDoorLength = Integer.parseInt(sData);
  727. iWidthObject = iDoorLength;
  728. sData = fileIn.readLine();
  729. iDoorLength = Integer.parseInt(sData);
  730. iHeightObject = iDoorLength;
  731. sData = fileIn.readLine();
  732. boolean bVisible = Boolean.parseBoolean(sData);
  733.  
  734. sData = fileIn.readLine();
  735. imiImage = new ImageIcon(this.getClass().getResource(
  736. sData));
  737.  
  738. mapObject = new Map(imiImage.getImage(),
  739. iX, iY, iWidthObject, iHeightObject,
  740. bVisible, false);
  741. mapObject.setImage(imiImage.getImage());
  742. arlMapObjectsLevel2.add(mapObject);
  743. break;
  744. default:
  745. break;
  746. }
  747.  
  748. sData = fileIn.readLine();
  749.  
  750. //si se termino la lectura
  751. if (sData.charAt(0) == 'x') {
  752. bFinishFileRead = true;
  753. }
  754. } while (!bFinishFileRead);
  755.  
  756. //--------------------------NIVEL 3------------------------------------
  757. String sLevel3WallVertical = "nivel3/pared_vertical_nivel3.png";
  758. String sLevel3WallHorizontal = "nivel3/pared_horizontal_nivel3.png";
  759.  
  760. try {
  761. fileIn = new BufferedReader(new FileReader(sLevel3Text));
  762. } catch (FileNotFoundException e) {
  763. System.out.println("FILE NOT FOUND!");
  764. fileIn = new BufferedReader(new FileReader(sLevel3Text));
  765. }
  766.  
  767. //file has not been read
  768. bFinishFileRead = false;
  769.  
  770. //leer archivo hasta terminar de leerlo
  771. sData = fileIn.readLine();
  772. do {
  773. //si el primer caracter es una letra
  774. if (sData.charAt(0) - 97 >= 0 ) {
  775. cObjectType = sData.charAt(0);
  776. sData = fileIn.readLine();
  777. }
  778.  
  779. //si la linea es un comentario
  780. if (sData.charAt(0) == '/') {
  781. sData = fileIn.readLine();
  782. }
  783.  
  784. //leer coordenadas X y Y
  785. iX = Integer.parseInt(sData);
  786. sData = fileIn.readLine();
  787. iY = Integer.parseInt(sData);
  788.  
  789. //definir medidas e imagen a utilizar dependiendo del objeto
  790. switch (cObjectType) {
  791. case 'a': //paredes horizontales
  792. iWidthObject = 83;
  793. iHeightObject = 27;
  794. imiImage = new ImageIcon(this.getClass().getResource(
  795. sLevel3WallHorizontal));
  796. mapObject = new Map(imiImage.getImage(),
  797. iX, iY, iWidthObject, iHeightObject,
  798. true, false);
  799. mapObject.setImage(imiImage.getImage());
  800. arlMapObjectsLevel3.add(mapObject);
  801.  
  802. break;
  803. case 'b': //pared vertical
  804. iWidthObject = 27;
  805. iHeightObject = 83;
  806. imiImage = new ImageIcon(this.getClass().getResource(
  807. sLevel3WallVertical));
  808. mapObject = new Map(imiImage.getImage(),
  809. iX, iY, iWidthObject, iHeightObject,
  810. true, false);
  811. mapObject.setImage(imiImage.getImage());
  812. arlMapObjectsLevel3.add(mapObject);
  813. break;
  814. case 'c': //decoracion
  815. sData = fileIn.readLine();
  816. iDoorLength = Integer.parseInt(sData);
  817. iWidthObject = iDoorLength;
  818. sData = fileIn.readLine();
  819. iDoorLength = Integer.parseInt(sData);
  820. iHeightObject = iDoorLength;
  821. sData = fileIn.readLine();
  822. imiImage = new ImageIcon(this.getClass().getResource(
  823. sData));
  824. mapObject = new Map(imiImage.getImage(),
  825. iX, iY, iWidthObject, iHeightObject,
  826. true, false);
  827. mapObject.setImage(imiImage.getImage());
  828. arlMapObjectsLevel3.add(mapObject);
  829. break;
  830. case 'd': //puerta horizontal
  831. sData = fileIn.readLine();
  832. iDoorLength = Integer.parseInt(sData);
  833. iWidthObject = iDoorLength;
  834. sData = fileIn.readLine();
  835. iDoorLength = Integer.parseInt(sData);
  836. iHeightObject = iDoorLength;
  837. sData = fileIn.readLine();
  838. iDoorKey = Integer.parseInt(sData);
  839. sData = fileIn.readLine();
  840. imiImage = new ImageIcon(this.getClass().getResource(
  841. sData));
  842. mapObject = new Door(imiImage.getImage(),
  843. iX, iY, iWidthObject, iHeightObject,
  844. false, iDoorKey, true);
  845. mapObject.setImage(imiImage.getImage());
  846. arlMapObjectsLevel3.add(mapObject);
  847. break;
  848. case 'e': //puerta vertical
  849. sData = fileIn.readLine();
  850. iDoorLength = Integer.parseInt(sData);
  851. iWidthObject = iDoorLength;
  852. sData = fileIn.readLine();
  853. iDoorLength = Integer.parseInt(sData);
  854. iHeightObject = iDoorLength;
  855. sData = fileIn.readLine();
  856. iDoorKey = Integer.parseInt(sData);
  857. sData = fileIn.readLine();
  858. imiImage = new ImageIcon(this.getClass().getResource(
  859. sData));
  860. mapObject = new Door(imiImage.getImage(),
  861. iX, iY, iWidthObject, iHeightObject,
  862. false, iDoorKey, true);
  863. mapObject.setImage(imiImage.getImage());
  864. arlMapObjectsLevel3.add(mapObject);
  865. break;
  866. case 'f': //botones
  867. iWidthObject = 48;
  868. iHeightObject = 28;
  869. sData = fileIn.readLine();
  870. iDoorKey = Integer.parseInt(sData);
  871. sData = fileIn.readLine();
  872. imiImage = new ImageIcon(this.getClass().getResource(
  873. sData));
  874. mapObject = new Button(imiImage.getImage(),
  875. iX, iY, iWidthObject, iHeightObject,
  876. true, false, iDoorKey);
  877. mapObject.setImage(imiImage.getImage());
  878. arlMapObjectsLevel3.add(mapObject);
  879. break;
  880. case 'g': //carros
  881. sData = fileIn.readLine();
  882. iDirectionCar = Integer.parseInt(sData);
  883. sData = fileIn.readLine();
  884. if(iDirectionCar == 1 || iDirectionCar == 2){ //Si el carro es horizontal
  885. iWidthObject = 84;
  886. iHeightObject = 48;
  887. }
  888. else{ //si el carro es vertical
  889. iWidthObject = 48;
  890. iHeightObject = 84;
  891. }
  892. imiImage = new ImageIcon(this.getClass().getResource(
  893. sData));
  894. emyObject = new Enemy(iX, iY, 3, iDirectionCar, iWidthObject, iHeightObject, imiImage.getImage());
  895. arlCarLevel3.add(emyObject);
  896. break;
  897. case 'h': //meta
  898. iWidthObject = 52;
  899. iHeightObject = 30;
  900. sData = fileIn.readLine();
  901. imiImage = new ImageIcon(this.getClass().getResource(
  902. sData));
  903. mapObject = new Map(imiImage.getImage(),
  904. iX, iY, iWidthObject, iHeightObject,
  905. true, true);
  906. mapObject.setImage(imiImage.getImage());
  907. arlMapObjectsLevel3.add(mapObject);
  908. break;
  909. case 'i': //paredes invisibles para carros horizontal
  910. iWidthObject = 83;
  911. iHeightObject = 27;
  912. imiImage = new ImageIcon(this.getClass().getResource(
  913. sLevel3WallHorizontal));
  914. mapObject = new Map(imiImage.getImage(),
  915. iX, iY, iWidthObject+50, iHeightObject,
  916. false, false);
  917. mapObject.setImage(imiImage.getImage());
  918. arlMapObjectsLevel3.add(mapObject);
  919. break;
  920. case 'j':
  921. iWidthObject = 27;
  922. iHeightObject = 83;
  923. imiImage = new ImageIcon(this.getClass().getResource(
  924. sLevel3WallVertical));
  925. mapObject = new Map(imiImage.getImage(),
  926. iX, iY, iWidthObject, iHeightObject,
  927. false, false);
  928. mapObject.setImage(imiImage.getImage());
  929. arlMapObjectsLevel3.add(mapObject);
  930. break;
  931. default:
  932. //no hay otra opcion
  933. break;
  934. }
  935.  
  936. sData = fileIn.readLine();
  937.  
  938. //si se termino la lectura
  939. if (sData.charAt(0) == 'x') {
  940. bFinishFileRead = true;
  941. }
  942. } while (!bFinishFileRead);
  943.  
  944. /**
  945. //--------------------------NIVEL 4------------------------------------
  946. try {
  947. fileIn = new BufferedReader(new FileReader(sLevel4Text));
  948. } catch (FileNotFoundException e) {
  949. System.out.println("FILE NOT FOUND!");
  950. fileIn = new BufferedReader(new FileReader(sLevel4Text));
  951. }
  952.  
  953. //file has not been read
  954. bFinishFileRead = false;
  955.  
  956. //leer archivo hasta terminar de leerlo
  957. sData = fileIn.readLine();
  958. do {
  959. //si el primer caracter es una letra
  960. if (sData.charAt(0) - 97 >= 0 ) {
  961. cObjectType = sData.charAt(0);
  962. sData = fileIn.readLine();
  963. }
  964.  
  965. //si la linea es un comentario
  966. if (sData.charAt(0) == '/') {
  967. sData = fileIn.readLine();
  968. }
  969.  
  970. //leer coordenadas X y Y
  971. iX = Integer.parseInt(sData);
  972. sData = fileIn.readLine();
  973. iY = Integer.parseInt(sData);
  974.  
  975. //definir medidas e imagen a utilizar dependiendo del objeto
  976. switch (cObjectType) {
  977. case 'a': //paredes horizontales
  978.  
  979. break;
  980. case 'b': //pared vertical
  981.  
  982. break;
  983. case 'c': //colisionables
  984. sData = fileIn.readLine();
  985. iDoorLength = Integer.parseInt(sData);
  986. iWidthObject = iDoorLength;
  987. sData = fileIn.readLine();
  988. iDoorLength = Integer.parseInt(sData);
  989. iHeightObject = iDoorLength;
  990. sData = fileIn.readLine();
  991. imiImage = new ImageIcon(this.getClass().getResource(
  992. sData));
  993. mapObject = new Map(imiImage.getImage(),
  994. iX, iY, iWidthObject, iHeightObject,
  995. true, false);
  996. mapObject.setImage(imiImage.getImage());
  997. arlMapObjectsLevel4.add(mapObject);
  998. break;
  999. case 'd': //puerta horizontal
  1000. sData = fileIn.readLine();
  1001. iDoorLength = Integer.parseInt(sData);
  1002. iWidthObject = iDoorLength;
  1003. sData = fileIn.readLine();
  1004. iDoorLength = Integer.parseInt(sData);
  1005. iHeightObject = iDoorLength;
  1006. sData = fileIn.readLine();
  1007. iDoorKey = Integer.parseInt(sData);
  1008. sData = fileIn.readLine();
  1009. imiImage = new ImageIcon(this.getClass().getResource(
  1010. sData));
  1011. mapObject = new Door(imiImage.getImage(),
  1012. iX, iY, iWidthObject, iHeightObject,
  1013. false, iDoorKey, true);
  1014. mapObject.setImage(imiImage.getImage());
  1015. arlMapObjectsLevel4.add(mapObject);
  1016. break;
  1017. case 'e': //puerta vertical
  1018. sData = fileIn.readLine();
  1019. iDoorLength = Integer.parseInt(sData);
  1020. iWidthObject = iDoorLength;
  1021. sData = fileIn.readLine();
  1022. iDoorLength = Integer.parseInt(sData);
  1023. iHeightObject = iDoorLength;
  1024. sData = fileIn.readLine();
  1025. iDoorKey = Integer.parseInt(sData);
  1026. sData = fileIn.readLine();
  1027. imiImage = new ImageIcon(this.getClass().getResource(
  1028. sData));
  1029. mapObject = new Door(imiImage.getImage(),
  1030. iX, iY, iWidthObject, iHeightObject,
  1031. false, iDoorKey, true);
  1032. mapObject.setImage(imiImage.getImage());
  1033. arlMapObjectsLevel4.add(mapObject);
  1034. break;
  1035. case 'f': //botones
  1036. iWidthObject = 48;
  1037. iHeightObject = 28;
  1038. sData = fileIn.readLine();
  1039. iDoorKey = Integer.parseInt(sData);
  1040. sData = fileIn.readLine();
  1041. imiImage = new ImageIcon(this.getClass().getResource(
  1042. sData));
  1043. mapObject = new Button(imiImage.getImage(),
  1044. iX, iY, iWidthObject, iHeightObject,
  1045. true, false, iDoorKey);
  1046. mapObject.setImage(imiImage.getImage());
  1047. arlMapObjectsLevel4.add(mapObject);
  1048. break;
  1049. case 'g': //
  1050.  
  1051. break;
  1052. case 'h': //meta
  1053. iWidthObject = 52;
  1054. iHeightObject = 30;
  1055. sData = fileIn.readLine();
  1056. imiImage = new ImageIcon(this.getClass().getResource(
  1057. sData));
  1058. mapObject = new Map(imiImage.getImage(),
  1059. iX, iY, iWidthObject, iHeightObject,
  1060. true, true);
  1061. mapObject.setImage(imiImage.getImage());
  1062. arlMapObjectsLevel4.add(mapObject);
  1063. break;
  1064. case 'i': //
  1065.  
  1066. break;
  1067. default:
  1068. break;
  1069. }
  1070.  
  1071. sData = fileIn.readLine();
  1072.  
  1073. //si se termino la lectura
  1074. if (sData.charAt(0) == 'x') {
  1075. bFinishFileRead = true;
  1076. }
  1077. } while (!bFinishFileRead); **/
  1078. }
  1079.  
  1080. /**
  1081. * run
  1082. *
  1083. * Metodo que corre el juego y actualiza el hilo.
  1084. *
  1085. */
  1086. public void run() {
  1087. //variables para el control de tiempo
  1088. long lTimeDiff; //diferencia del tiempo contra tiempo actual en un punto
  1089. long lSleep; //canitdad limite para dormir el thread en ms
  1090.  
  1091. //loop que cicla el juego hasta que termina
  1092. while (!bEndGame) {
  1093. //pinta y actualiza
  1094. repaint();
  1095. if (!bPause) {
  1096. //actualiza datos
  1097. AnimationCycle();
  1098. }
  1099.  
  1100. //Calcula la diferencia de tiempo con la ultima marca de tiempo
  1101. lTimeDiff = System.currentTimeMillis() - lCurrentTime;
  1102. lSleep = 17 - lTimeDiff;
  1103.  
  1104. //define canitdad a dormir el thread
  1105. if (lSleep < 0)
  1106. lSleep = 2;
  1107. try {
  1108. Thread.sleep(lSleep);
  1109. } catch (InterruptedException e) {
  1110. System.out.println("interrupted");
  1111. }
  1112.  
  1113. //actuializa el tiempo actual
  1114. lCurrentTime = System.currentTimeMillis();
  1115. }
  1116. }
  1117.  
  1118. /**
  1119. * AnimationCycle
  1120. *
  1121. * Metodo que actualiza el juego
  1122. *
  1123. */
  1124. public void AnimationCycle() {
  1125. /*Determina el tiempo que ha transcurrido desde que el Applet inicio su
  1126. ejecución*/
  1127. lElapsedTime = System.currentTimeMillis() - lCurrentTime;
  1128.  
  1129. //Guarda el tiempo actual
  1130. lCurrentTime += lElapsedTime;
  1131.  
  1132. //actualiza el jugador
  1133. mauMauro.updateMovement(iDirectionMauro);
  1134.  
  1135. //si se cambio al siguiente nivel define posicion inical de mauro
  1136. if (iLevel == iLevelChange) {
  1137. switch (iLevel) {
  1138. case 1: { //nivel 1
  1139. mauMauro.setX(1200); //70
  1140. mauMauro.setY(100); //640
  1141. break;
  1142. }
  1143. case 2: { //nivel 2
  1144. mauMauro.setX(20); //1200
  1145. mauMauro.setY(515); //100
  1146. break;
  1147. }
  1148. case 3: { //nivel 3
  1149. mauMauro.setX(50);
  1150. mauMauro.setY(50);
  1151. break;
  1152. }
  1153. case 4: { //nivel 4
  1154. mauMauro.setX(70);
  1155. mauMauro.setY(640);
  1156. break;
  1157. }
  1158. default: {
  1159. break;
  1160. }
  1161. }
  1162. //incrementar variable para estar listo para el siguiente nivel
  1163. iLevelChange++;
  1164. }
  1165.  
  1166. //--------------------------NIVEL 1------------------------------------
  1167. //actualizar efectos nivel 1
  1168. if (iLevel == 1) {
  1169. //variables
  1170. int iPositionDifferenceMauro; //diferencia en posision de Mauro
  1171. int iIncreaseRectangleSize; //incremento en tamaño de rectangulo
  1172. int iTimeLimitLight = 5; //duracion maxima efecto luz
  1173.  
  1174. //si pwrup de luz NO esta activo
  1175. if (!bLightOn || bLightPause) {
  1176. iPositionDifferenceMauro = 100;
  1177. iIncreaseRectangleSize = 150;
  1178. }
  1179.  
  1180. else {
  1181. iPositionDifferenceMauro = 1000;
  1182. iIncreaseRectangleSize = 1750;
  1183.  
  1184. //si termina el tiempo apagar pwrup
  1185. if ((lCurrentTime-lInitialTimeLight)/1000 >= iTimeLimitLight) {
  1186. bLightOn = !bLightOn;
  1187. sndPwrDown.play();
  1188. }
  1189. }
  1190.  
  1191. //iterador de objetos de la lista
  1192. Iterator it = arlMapObjectsLevel1.iterator();
  1193.  
  1194. // mientras existan objetos en la lista
  1195. while (it.hasNext()) {
  1196. Map mapObject = (Map) it.next();
  1197. // revisar si estan en el area de Mauro
  1198. if (mapObject.PlayerColission(mapObject, mauMauro,
  1199. iPositionDifferenceMauro,
  1200. iIncreaseRectangleSize)) {
  1201. mapObject.setVisible(true); //muestra el objeto
  1202. }
  1203. else {
  1204. mapObject.setVisible(false); //esconde el objeto
  1205. }
  1206.  
  1207. //si es un puerta revisar si debe estar abierta
  1208. if (mapObject instanceof Door) {
  1209. Door mapDoor = (Door) mapObject;
  1210. if (bButtonsLevel1[mapDoor.getDoorNo()]) {
  1211. mapDoor.setOpen(true);
  1212. mapDoor.setSolid(false);
  1213. }
  1214. }
  1215. }
  1216.  
  1217. //si el foco estaba activo y se encendio la pausa
  1218. if (bLightPause) {
  1219. bPause = true;
  1220. }
  1221.  
  1222. //cambios barra del tiempo
  1223. //Saca el tiempo actual para barra del tiempo
  1224. lCurrentTimer = System.currentTimeMillis();
  1225.  
  1226. //Saca el tiempo que ha pasado desde el inicio del nivel
  1227. iElapsedTimeTimer = (int)(lCurrentTimer - lTimerInitial)/1000;
  1228.  
  1229. //si el pwrup del reloj esta activo aumentar reloj
  1230. if (bClockOn) {
  1231. lTimerInitial += 8000;
  1232. bClockOn = !bClockOn;
  1233. }
  1234.  
  1235. //si el tiempo en el juego se termino
  1236. if (iLimitTime - iElapsedTimeTimer < 0) {
  1237. bGameOver = true;
  1238. iLevel = 5;
  1239. sndLevel1Song.stop();
  1240. sndGameOver.play();
  1241. gameOverRestart();
  1242.  
  1243. //regresar a primera posicion
  1244. mauMauro.setX(70);
  1245. mauMauro.setY(640);
  1246.  
  1247. //reset de siguiente nivel
  1248. iLevelChange = 1;
  1249. }
  1250.  
  1251. //checa colision
  1252. checkCollisionLevel1();
  1253. }
  1254.  
  1255. //--------------------------NIVEL 2------------------------------------
  1256. else if (iLevel == 2) {
  1257. //grabar posiciones de mauro para morfeo si no esta detenido
  1258. if (iDirectionMauro != 0 && (mauMauro.getX() != iPreviousX ||
  1259. mauMauro.getY() != iPreviousY)) {
  1260. if (iVelocityMauro == 4) {
  1261. arlMorpheusSteps.add(iDirectionMauro);
  1262. arlMorpheusSteps.add(mauMauro.getX());
  1263. arlMorpheusSteps.add(mauMauro.getY());
  1264. arlMorpheusSteps.add(iDirectionMauro);
  1265. arlMorpheusSteps.add(mauMauro.getX());
  1266. arlMorpheusSteps.add(mauMauro.getY());
  1267. }
  1268. else {
  1269. arlMorpheusSteps.add(iDirectionMauro);
  1270. arlMorpheusSteps.add(mauMauro.getX());
  1271. arlMorpheusSteps.add(mauMauro.getY());
  1272. }
  1273.  
  1274. }
  1275.  
  1276. //empezar a contar tiempo de aparicion de morfeo
  1277. //tiempo actual
  1278. lMorpheusCurrentTime = System.currentTimeMillis();
  1279. lShoesCurrentTime = System.currentTimeMillis();
  1280.  
  1281. //calculo de tiempo transcurrido desde que inicio nivel
  1282. iMorpheusElapsedTime = (int)(lMorpheusCurrentTime -
  1283. lMorpheusStartTime)/1000;
  1284.  
  1285. //calculo de tiempo transcurrido desde que se agrarraron los zapatos
  1286. iShoesElapsedTime = (int)(lShoesCurrentTime -
  1287. lShoesStartTime)/1000;
  1288.  
  1289. //si ya pasaron los 90 segundos empezar a pintar a morfeo
  1290. if (iMorpheusTimeLimit - iMorpheusElapsedTime < 0) {
  1291. bMorpheusStart = true;
  1292. }
  1293.  
  1294. //si ya pasaron los 90 segundos empezar a pintar a morfeo
  1295. if (iShoesTimeLimit - iShoesElapsedTime < 0) {
  1296. iVelocityMauro = 2;
  1297. mauMauro.setVelocity(iVelocityMauro);
  1298. }
  1299.  
  1300.  
  1301. if (bMorpheusStart) {
  1302. //variables posiciones
  1303. int iX;
  1304. int iY;
  1305.  
  1306. //iterador de objetos de la lista
  1307. Iterator it = arlMorpheusSteps.iterator();
  1308.  
  1309. //obtener direccion de morfeo
  1310. int iDirection = (int) it.next();
  1311. it.remove();
  1312. iX = (int) it.next();
  1313. it.remove();
  1314. iY = (int) it.next();
  1315. it.remove();
  1316.  
  1317.  
  1318.  
  1319. //si mauro no esta detenido
  1320. if (iDirection != 0 && (iX != iPreviousX || iY != iPreviousY)) {
  1321. iDirectionMorpheus = iDirection;
  1322. //obtener X de morfeo
  1323. morMorpheus.setX(iX);
  1324. iPreviousX = iX;
  1325. //obtener Y de morfeo
  1326. morMorpheus.setY(iY);
  1327. iPreviousY = iY;
  1328. }
  1329. }
  1330.  
  1331. //cambios barra del tiempo
  1332. //Saca el tiempo actual para barra del tiempo
  1333. lCurrentTimer = System.currentTimeMillis();
  1334.  
  1335. //Saca el tiempo que ha pasado desde el inicio del nivel
  1336. iElapsedTimeTimer = (int)(lCurrentTimer - lTimerInitial)/1000;
  1337.  
  1338. //si el tiempo en el juego se termino
  1339. if (iLimitTime - iElapsedTimeTimer < 0) {
  1340. bGameOver = true;
  1341. iLevel = 5;
  1342. sndLevel2Song.stop();
  1343. sndGameOver.play();
  1344. gameOverRestart();
  1345.  
  1346. //regresar a primera posicion
  1347. mauMauro.setX(70);
  1348. mauMauro.setY(640);
  1349.  
  1350. //reset de siguiente nivel
  1351. iLevelChange = 1;
  1352. }
  1353.  
  1354. //checa colision
  1355. checkCollisionLevel2();
  1356. }
  1357. //--------------------------NIVEL 3------------------------------------
  1358. else if (iLevel == 3) {
  1359.  
  1360. //actualiza posicion de los carros
  1361. //mauMauro.updateMovement(iDirectionMauro);
  1362.  
  1363. Iterator it3C = arlCarLevel3.iterator();
  1364.  
  1365. // mientras existan objetos en la lista
  1366. while (it3C.hasNext()) {
  1367. Enemy emyObject = (Enemy) it3C.next();
  1368. emyObject.updateMovement();
  1369. }
  1370.  
  1371. //checa colision
  1372. checkCollisionLevel3();
  1373. }
  1374. //--------------------------NIVEL 3------------------------------------
  1375. else if (iLevel == 4) {
  1376.  
  1377. //checa colision
  1378. checkCollisionLevel4();
  1379. }
  1380. }
  1381.  
  1382. public void checkCollisionLevel1() {
  1383. //colision con las paredes
  1384. Iterator it = arlMapObjectsLevel1.iterator();
  1385.  
  1386. // mientras existan objetos en la lista
  1387. while (it.hasNext()) {
  1388. Map mapObject = (Map) it.next();
  1389.  
  1390. //Si el objeto es solido y existe colision...
  1391. if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
  1392. //Si es una trampa
  1393. if (mapObject instanceof Trap) {
  1394. //regresar a mauro a posicion inicial
  1395. mauMauro.setX(70);
  1396. mauMauro.setY(640);
  1397. sndTrap.play();
  1398. }
  1399.  
  1400. //Si es un boton, abrir puerta
  1401. else if (mapObject instanceof Button) {
  1402. Button mapButton = (Button) mapObject;
  1403. iDoorOpenKey = mapButton.getButtonNo();
  1404. if (!bButtonsLevel1[iDoorOpenKey]) {
  1405. sndDoor.play();
  1406. }
  1407. mapButton.setClicked(true);
  1408. bButtonsLevel1[iDoorOpenKey] = true;
  1409. }
  1410.  
  1411. //Si agarra un PowerUp
  1412. else if (mapObject instanceof PwrUp) {
  1413. PwrUp mapUp = (PwrUp) mapObject;
  1414.  
  1415. //Si es un foco
  1416. if (mapUp.getType() == 2) {
  1417. if (!mapUp.getGrabbed()) {
  1418. bPwrUp.play();
  1419. lInitialTimeLight = System.currentTimeMillis();
  1420. bLightOn = true;
  1421. mapUp.setGrabbed(true);
  1422. mapUp.setVisible(false);
  1423. }
  1424. }
  1425. //Si es un reloj
  1426. else{
  1427. if (!mapUp.getGrabbed()) {
  1428. bPwrUp.play();
  1429. bClockOn = true;
  1430. mapUp.setGrabbed(true);
  1431. mapUp.setVisible(false);
  1432. }
  1433. }
  1434. }
  1435.  
  1436. //cambiar de nivel si llega a la salida
  1437. else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
  1438. iLevel != iLevelChange) {
  1439. iLevel++;
  1440. sndWin.play();
  1441. sndLevel1Song.stop();
  1442. lMorpheusStartTime = System.currentTimeMillis();
  1443. sndLevel2Song.play();
  1444. iLimitTime = 200;
  1445. lTimerInitial = System.currentTimeMillis()+5000;
  1446. }
  1447.  
  1448. //Si es una pared (o puerta solida), anular movimiento
  1449. else{
  1450. if (iDirectionMauro == 1) {
  1451. mauMauro.updateMovement(2);
  1452. }
  1453. else if (iDirectionMauro == 2) {
  1454. mauMauro.updateMovement(1);
  1455. }
  1456. else if (iDirectionMauro == 3) {
  1457. mauMauro.updateMovement(4);
  1458. }
  1459. else if (iDirectionMauro == 4) {
  1460. mauMauro.updateMovement(3);
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466.  
  1467. public void checkCollisionLevel2() {
  1468. //colision con las paredes
  1469. Iterator it = arlMapObjectsLevel2.iterator();
  1470.  
  1471. // mientras existan objetos en la lista
  1472. while (it.hasNext()) {
  1473. Map mapObject = (Map) it.next();
  1474.  
  1475. //Si el objeto es solido y existe colision...
  1476. if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
  1477. //Si es una trampa
  1478. if (mapObject instanceof Trap) {
  1479. //regresar a mauro a posicion inicial
  1480. mauMauro.setX(70);
  1481. mauMauro.setY(640);
  1482. }
  1483.  
  1484. //Si es un boton, abrir puerta
  1485. else if (mapObject instanceof Button) {
  1486. Button mapButton = (Button) mapObject;
  1487. iDoorOpenKey = mapButton.getButtonNo();
  1488. if (!bButtonsLevel2[iDoorOpenKey]) {
  1489. sndDoor.play();
  1490. }
  1491. mapButton.setClicked(true);
  1492. bButtonsLevel2[iDoorOpenKey] = true;
  1493.  
  1494. //busca su puerta correspondiente
  1495. Iterator it2 = arlMapObjectsLevel2.iterator();
  1496.  
  1497. // mientras existan objetos en la lista
  1498. while (it2.hasNext()) {
  1499. Map mapObject2 = (Map) it2.next();
  1500.  
  1501. //si es un puerta revisar si debe estar abierta
  1502. if (mapObject2 instanceof Door) {
  1503. Door mapDoor = (Door) mapObject2;
  1504. if (bButtonsLevel2[mapDoor.getDoorNo()]) {
  1505. mapDoor.setOpen(true);
  1506. mapDoor.setSolid(false);
  1507. }
  1508. }
  1509. }
  1510. }
  1511.  
  1512. //Si agarra un PowerUp
  1513. else if (mapObject instanceof PwrUp) {
  1514. PwrUp mapUp = (PwrUp) mapObject;
  1515.  
  1516. //Si son los zapatos
  1517. if (mapUp.getType() == 3) {
  1518. if (!mapUp.getGrabbed()) {
  1519. bPwrUp.play();
  1520. mapUp.setGrabbed(true);
  1521. mapUp.setVisible(false);
  1522. lShoesStartTime = System.currentTimeMillis();
  1523. iVelocityMauro = 4;
  1524. mauMauro.setVelocity(iVelocityMauro);
  1525. }
  1526. }
  1527. //Si es la puerta de la izquierda
  1528. else if (mapUp.getType() == 4) {
  1529. if (!mapUp.getGrabbed()) {
  1530. bPwrUp.play();
  1531. mauMauro.setX(700);
  1532. }
  1533. }
  1534. //si es la puerta de derecha
  1535. else {
  1536. bPwrUp.play();
  1537. mauMauro.setX(303);
  1538. }
  1539. }
  1540.  
  1541. //cambiar de nivel si llega a la salida
  1542. else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
  1543. iLevel != iLevelChange) {
  1544. iLevel++;
  1545. sndLevel2Song.stop();
  1546. }
  1547.  
  1548. //Si es una pared (o puerta solida), anular movimiento
  1549. else {
  1550. if (iDirectionMauro == 1) {
  1551. mauMauro.updateMovement(2);
  1552. }
  1553. else if (iDirectionMauro == 2) {
  1554. mauMauro.updateMovement(1);
  1555. }
  1556. else if (iDirectionMauro == 3) {
  1557. mauMauro.updateMovement(4);
  1558. }
  1559. else if (iDirectionMauro == 4) {
  1560. mauMauro.updateMovement(3);
  1561. }
  1562. }
  1563. }
  1564. }
  1565.  
  1566. //si mauro colisiona con morfeo
  1567. if (mauMauro.colission(morMorpheus)) {
  1568. //tocar sonido
  1569. sndYawn.play();
  1570. //reinicar nivel
  1571. gameOverRestart();
  1572. //asignar nivel 2
  1573. iLevel = 2;
  1574. //reposicionar a mauro
  1575. //regresar a primera posicion
  1576. mauMauro.setX(1200);
  1577. mauMauro.setY(100);
  1578. //reinciio tiempo morfeo
  1579. lMorpheusStartTime = System.currentTimeMillis();
  1580. //vaciar lista de pasos de morfeo
  1581. arlMorpheusSteps.clear();
  1582. //reinciar variable
  1583. bMorpheusStart = false;
  1584. //reiniciar musica
  1585. sndLevel2Song.stop();
  1586. sndLevel2Song.play();
  1587. }
  1588. }
  1589.  
  1590. public void checkCollisionLevel3() {
  1591. //colision con las paredes
  1592. Iterator it = arlMapObjectsLevel3.iterator();
  1593.  
  1594. // mientras existan objetos en la lista
  1595. while (it.hasNext()) {
  1596. Map mapObject = (Map) it.next();
  1597.  
  1598. //Si el objeto es solido y existe colision...
  1599. if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
  1600.  
  1601. if (mapObject instanceof Button) {
  1602. Button mapButton = (Button) mapObject;
  1603. iDoorOpenKey = mapButton.getButtonNo();
  1604. if (!bButtonsLevel3[iDoorOpenKey]) {
  1605. sndDoor.play();
  1606. }
  1607. mapButton.setClicked(true);
  1608. bButtonsLevel3[iDoorOpenKey] = true;
  1609.  
  1610. //busca su puerta correspondiente
  1611. Iterator it2 = arlMapObjectsLevel3.iterator();
  1612.  
  1613. // mientras existan objetos en la lista
  1614. while (it2.hasNext()) {
  1615. Map mapObject2 = (Map) it2.next();
  1616.  
  1617. //si es un puerta revisar si debe estar abierta
  1618. if (mapObject2 instanceof Door) {
  1619. Door mapDoor = (Door) mapObject2;
  1620. if (bButtonsLevel3[mapDoor.getDoorNo()]) {
  1621. mapDoor.setOpen(true);
  1622. mapDoor.setSolid(false);
  1623. }
  1624. }
  1625. }
  1626. }
  1627.  
  1628. //cambiar de nivel si llega a la salida
  1629. else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
  1630. iLevel != iLevelChange) {
  1631. iLevel++;
  1632. sndLevel3Song.stop();
  1633. }
  1634.  
  1635. //Si es una pared (o puerta solida), anular movimiento
  1636. else {
  1637. if (iDirectionMauro == 1) {
  1638. mauMauro.updateMovement(2);
  1639. }
  1640. else if (iDirectionMauro == 2) {
  1641. mauMauro.updateMovement(1);
  1642. }
  1643. else if (iDirectionMauro == 3) {
  1644. mauMauro.updateMovement(4);
  1645. }
  1646. else if (iDirectionMauro == 4) {
  1647. mauMauro.updateMovement(3);
  1648. }
  1649. }
  1650. }
  1651.  
  1652. Iterator it3C = arlCarLevel3.iterator();
  1653.  
  1654. // mientras existan objetos en la lista
  1655. while (it3C.hasNext()) {
  1656. Enemy emyObject = (Enemy) it3C.next();
  1657. if(emyObject.colission(mapObject)){
  1658. if(emyObject.getDirection() == 1){
  1659. emyObject.setDirection(2);
  1660. }
  1661. else if(emyObject.getDirection() == 2){
  1662. emyObject.setDirection(1);
  1663. }
  1664. else if(emyObject.getDirection() == 3){
  1665. emyObject.setDirection(4);
  1666. }
  1667. else if(emyObject.getDirection() == 4){
  1668. emyObject.setDirection(3);
  1669. }
  1670. }
  1671. }
  1672. }
  1673. }
  1674.  
  1675. public void checkCollisionLevel4() {
  1676. //colision con las paredes
  1677. Iterator it = arlMapObjectsLevel4.iterator();
  1678.  
  1679. // mientras existan objetos en la lista
  1680. while (it.hasNext()) {
  1681. Map mapObject = (Map) it.next();
  1682.  
  1683. //Si el objeto es solido y existe colision...
  1684. if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
  1685.  
  1686. if (mapObject instanceof Button) {
  1687. Button mapButton = (Button) mapObject;
  1688. iDoorOpenKey = mapButton.getButtonNo();
  1689. if (!bButtonsLevel4[iDoorOpenKey]) {
  1690. sndDoor.play();
  1691. }
  1692. mapButton.setClicked(true);
  1693. bButtonsLevel4[iDoorOpenKey] = true;
  1694.  
  1695. //busca su puerta correspondiente
  1696. Iterator it2 = arlMapObjectsLevel4.iterator();
  1697.  
  1698. // mientras existan objetos en la lista
  1699. while (it2.hasNext()) {
  1700. Map mapObject2 = (Map) it2.next();
  1701.  
  1702. //si es un puerta revisar si debe estar abierta
  1703. if (mapObject2 instanceof Door) {
  1704. Door mapDoor = (Door) mapObject2;
  1705. if (bButtonsLevel4[mapDoor.getDoorNo()]) {
  1706. mapDoor.setOpen(true);
  1707. mapDoor.setSolid(false);
  1708. }
  1709. }
  1710. }
  1711. }
  1712.  
  1713. //cambiar de nivel si llega a la salida
  1714. else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
  1715. iLevel != iLevelChange) {
  1716. iLevel++;
  1717. sndLevel4Song.stop();
  1718. }
  1719.  
  1720. //Si es una pared (o puerta solida), anular movimiento
  1721. else {
  1722. if (iDirectionMauro == 1) {
  1723. mauMauro.updateMovement(2);
  1724. }
  1725. else if (iDirectionMauro == 2) {
  1726. mauMauro.updateMovement(1);
  1727. }
  1728. else if (iDirectionMauro == 3) {
  1729. mauMauro.updateMovement(4);
  1730. }
  1731. else if (iDirectionMauro == 4) {
  1732. mauMauro.updateMovement(3);
  1733. }
  1734. }
  1735. }
  1736. }
  1737. }
  1738.  
  1739. public void gameOverRestart() {
  1740. //reset de botones de puertas en los niveles
  1741. for (int i = 0; i < 5; i++) {
  1742. bButtonsLevel1[i] = false;
  1743. }
  1744. for (int i = 0; i < 5; i++) {
  1745. bButtonsLevel2[i] = false;
  1746. }
  1747. for (int i = 0; i < 5; i++) {
  1748. bButtonsLevel3[i] = false;
  1749. }
  1750. for (int i = 0; i < 5; i++) {
  1751. bButtonsLevel4[i] = false;
  1752. }
  1753.  
  1754. //reset variables Mauro
  1755. iVelocityMauro = 2;
  1756. iDirectionMauro = 0;
  1757. lImmuneTimeMauro = 0;
  1758.  
  1759. //reinicializa todos los mapas
  1760. try {
  1761. GameInitMaps();
  1762. } catch (IOException ex) {
  1763. Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
  1764. }
  1765. }
  1766.  
  1767. /**
  1768. * Metodo <I>paint</I> sobrescrito
  1769. * de la clase <code>JPanel</code>,
  1770. * heredado de la clase Container.<P>
  1771. * En este metodo se dibuja la imagen con la posicion actualizada,
  1772. * ademas que cuando la imagen es cargada te despliega una advertencia.
  1773. * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
  1774. */
  1775. public void paint(Graphics graGrafico) {
  1776. //llama al paint de la clase que heredaste
  1777. super.paint(graGrafico);
  1778.  
  1779. switch (iLevel) {
  1780. case -1: //animacion inical
  1781.  
  1782. break;
  1783. case 0: //menu
  1784. drawMenu(graGrafico);
  1785. break;
  1786. case 1:
  1787. Graphics2D g2d = (Graphics2D) graGrafico;
  1788. g2d.setColor(Color.decode("#1d2e4c"));
  1789. g2d.fillOval(mauMauro.getX()-50, mauMauro.getY()-45, 120,
  1790. 120);
  1791. g2d.drawOval(mauMauro.getX()-50, mauMauro.getY()-45, 120,
  1792. 120);
  1793. setBackground(Color.black);
  1794. drawMaps(graGrafico);
  1795. drawMauro(graGrafico);
  1796. if (!bGameOver) {
  1797. drawTimeBar(graGrafico);
  1798. }
  1799. break;
  1800. case 2:
  1801. String sLevel2Background = "Nivel2/background.png";
  1802. ImageIcon imiImage = new ImageIcon(this.getClass().
  1803. getResource(sLevel2Background));
  1804. graGrafico.drawImage(imiImage.getImage(), 0, 0, this);
  1805. drawMaps(graGrafico);
  1806. drawMauro(graGrafico);
  1807. if (bMorpheusStart) {
  1808. drawMorpheus(graGrafico);
  1809. }
  1810. if (!bGameOver) {
  1811. drawTimeBar(graGrafico);
  1812. }
  1813. break;
  1814. case 3:
  1815. String sLevel3Background = "nivel3/background.png";
  1816. ImageIcon imiImage3 = new ImageIcon(this.getClass().
  1817. getResource(sLevel3Background));
  1818. graGrafico.drawImage(imiImage3.getImage(), 0, 0, this);
  1819. drawMaps(graGrafico);
  1820. drawMauro(graGrafico);
  1821. break;
  1822. case 4:
  1823. graGrafico.setColor(Color.gray);
  1824. drawMaps(graGrafico);
  1825. drawMauro(graGrafico);
  1826. break;
  1827. default: // game over
  1828. drawGameOver(graGrafico);
  1829. break;
  1830. }
  1831.  
  1832. //comandos para paint
  1833. Toolkit.getDefaultToolkit().sync();
  1834. graGrafico.dispose();
  1835. }
  1836.  
  1837. /**
  1838. * drawMauro
  1839. *
  1840. * Metodo que dibuja a Mauro.
  1841. *
  1842. * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
  1843. */
  1844. public void drawMauro(Graphics graGrafico) {
  1845. // mientras exista Mauro
  1846. if (mauMauro.isVisible() && iLevel != 0) {
  1847. mauMauro.getAnimation().actualiza(lElapsedTime);
  1848. mauMauro.setAnimation(iDirectionMauro);
  1849. graGrafico.drawImage(mauMauro.getAnimation().getImagen(),
  1850. mauMauro.getX(), mauMauro.getY(), this);
  1851. }
  1852. }
  1853.  
  1854. public void drawMorpheus(Graphics graGrafico) {
  1855. if (morMorpheus.isVisible()) {
  1856. morMorpheus.getAnimation().actualiza(lElapsedTime);
  1857. morMorpheus.setAnimation(iDirectionMorpheus);
  1858. graGrafico.drawImage(morMorpheus.getAnimation().getImagen(),
  1859. morMorpheus.getX(), morMorpheus.getY(), this);
  1860. }
  1861. }
  1862.  
  1863. /**
  1864. * drawMaps
  1865. *
  1866. * Metodo que dibuja los Maps
  1867. *
  1868. * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
  1869. */
  1870. public void drawMaps(Graphics graGrafico) {
  1871. //dependiendo del nivel se pintara dichos objetos
  1872. switch (iLevel) {
  1873. case 1:
  1874. Iterator it = arlMapObjectsLevel1.iterator();
  1875.  
  1876. // mientras existan objetos en la lista
  1877. while (it.hasNext()) {
  1878. Map mapObject = (Map) it.next();
  1879. mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
  1880. }
  1881. break;
  1882. case 2:
  1883. Iterator it2 = arlMapObjectsLevel2.iterator();
  1884.  
  1885. // mientras existan objetos en la lista
  1886. while (it2.hasNext()) {
  1887. Map mapObject = (Map) it2.next();
  1888. mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
  1889. }
  1890. break;
  1891. case 3:
  1892. Iterator it3 = arlMapObjectsLevel3.iterator();
  1893.  
  1894. // mientras existan objetos en la lista
  1895. while (it3.hasNext()) {
  1896. Map mapObject = (Map) it3.next();
  1897. mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
  1898. }
  1899.  
  1900. Iterator it3C = arlCarLevel3.iterator();
  1901.  
  1902. // mientras existan objetos en la lista
  1903. while (it3C.hasNext()) {
  1904. Enemy emyObject = (Enemy) it3C.next();
  1905. graGrafico.drawImage(emyObject.getImage(), emyObject.getX(), emyObject.getY(), this);
  1906. }
  1907. break;
  1908. case 4:
  1909. Iterator it4 = arlMapObjectsLevel4.iterator();
  1910.  
  1911. // mientras existan objetos en la lista
  1912. while (it4.hasNext()) {
  1913. Map mapObject = (Map) it4.next();
  1914. mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
  1915. }
  1916. break;
  1917. default:
  1918.  
  1919. break;
  1920. }
  1921. }
  1922.  
  1923. /**
  1924. * drawGameOver
  1925. *
  1926. * Metodo que dibuja el game over
  1927. *
  1928. * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
  1929. */
  1930. public void drawGameOver(Graphics graGrafico) {
  1931. graGrafico.setColor(Color.black);
  1932. String sGameOver = "Menus/gameover.png";
  1933. ImageIcon imiImageGameOver2 = new ImageIcon(this.getClass().
  1934. getResource(sGameOver));
  1935. graGrafico.drawImage(imiImageGameOver2.getImage(), 0, 0,
  1936. this);
  1937. //boton
  1938. mbtGameOverMenu.paint(graGrafico, this);
  1939. }
  1940.  
  1941. /**
  1942. * drawTimeBar
  1943. *
  1944. * Metodo que dibuja la barra del tiempo
  1945. *
  1946. * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
  1947. */
  1948. public void drawTimeBar(Graphics graGrafico) {
  1949. //Crea el fondo de la barra de tiempo
  1950. String sBar = "Menus/barraTiempo_Fondo.png";
  1951. ImageIcon imiImage = new ImageIcon(this.getClass().getResource(sBar));
  1952. graGrafico.drawImage(imiImage.getImage(), 0, iHeight-41, this);
  1953.  
  1954. //si el limite de tiempo no ha sido alcanzado
  1955. if (iLimitTime - iElapsedTimeTimer > 0) {
  1956. //Se dibuja la barra verde que se modifica con el tiempo
  1957. graGrafico.setColor(Color.GREEN);
  1958. graGrafico.fillRect(85, iHeight - 38,(1115 / iLimitTime) *
  1959. (iLimitTime - iElapsedTimeTimer),13);
  1960. }
  1961. }
  1962.  
  1963. /**
  1964. * drawMenu
  1965. *
  1966. * Metodo que dibuja el menu y los submenús.
  1967. *
  1968. * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
  1969. */
  1970. public void drawMenu(Graphics graGrafico) {
  1971. URL urlMenu;
  1972. Image imaMenu;
  1973. // Switch que se utiliza para ver qué pantalla desplegar
  1974. switch (iMenu) {
  1975. case 1: { // se despliega el MENU
  1976. // dibuja el fondo
  1977. urlMenu = this.getClass().getResource("Menus/menu3.png");
  1978. imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
  1979. graGrafico.drawImage(imaMenu, 0, 0, this);
  1980. // dibuja los botones
  1981. mbtPlay.paint(graGrafico, this);
  1982. mbtInstructions.paint(graGrafico, this);
  1983. mbtAbout.paint(graGrafico, this);
  1984. mbtOptions.paint(graGrafico, this);
  1985. mbtScores.paint(graGrafico, this);
  1986. mbtExit.paint(graGrafico, this);
  1987. break;
  1988. }
  1989. case 2: { // se dibujan las instrucciones
  1990. // dibuja el fondo
  1991. urlMenu = this.getClass().getResource("Menus/menu4.png");
  1992. imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
  1993. graGrafico.drawImage(imaMenu, 0, 0, this);
  1994. // dibuja el botón back y lo pone visible
  1995. mbtBack.paint(graGrafico, this);
  1996. break;
  1997. }
  1998. case 3: { // se dibujan las opciones
  1999. urlMenu = this.getClass().getResource("Menus/menu5.png");
  2000. imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
  2001. graGrafico.drawImage(imaMenu, 0, 0, this);
  2002. // dibuja el botón back y lo pone visible
  2003. mbtBack.paint(graGrafico, this);
  2004. break;
  2005. }
  2006. case 4: { // se dibuja el acerca
  2007. urlMenu = this.getClass().getResource("Menus/menu6.png");
  2008. imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
  2009. graGrafico.drawImage(imaMenu, 0, 0, this);
  2010. // dibuja el botón back y lo pone visible
  2011. mbtBack.paint(graGrafico, this);
  2012. break;
  2013. }
  2014. case 5: { // se dibujan los puntajes
  2015. urlMenu = this.getClass().getResource("Menus/menu7.png");
  2016. imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
  2017. graGrafico.drawImage(imaMenu, 0, 0, this);
  2018. // dibuja el botón back y lo pone visible
  2019. mbtBack.paint(graGrafico, this);
  2020. break;
  2021. }
  2022. }
  2023. }
  2024.  
  2025. /**
  2026. * keyTyped
  2027. *
  2028. * Metodo sobrescrito de la interface <code>KeyListener</code>.<P>
  2029. * En este metodo maneja el evento que se genera al presionar una
  2030. * tecla que no es de accion.
  2031. *
  2032. * @param keyEvent es el <code>KeyEvent</code> que se genera en al
  2033. * presionar.
  2034. *
  2035. */
  2036. public void keyTyped(KeyEvent keyEvent) {
  2037. // no hay codigo pero se debe escribir el metodo
  2038. }
  2039.  
  2040. /**
  2041. * keyPressed
  2042. *
  2043. * Metodo sobrescrito de la interface <code>KeyListener</code>.<P>
  2044. * En este metodo maneja el evento que se genera al dejar presionada
  2045. * alguna tecla.
  2046. * Se cambia la direccion al presionar una tecla
  2047. *
  2048. * @param keyEvent es el <code>KeyEvent</code> que se genera en al
  2049. * presionar.
  2050. *
  2051. */
  2052. public void keyPressed(KeyEvent keyEvent) {
  2053. // si presiono la flecha arriba
  2054. if (keyEvent.getKeyCode() == KeyEvent.VK_UP) {
  2055. iDirectionMauro = 1;
  2056. }
  2057. // si presiono la flecha abajo
  2058. if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
  2059. iDirectionMauro = 2;
  2060. }
  2061. // si presiono la flecha izquierda
  2062. if (keyEvent.getKeyCode() == KeyEvent.VK_LEFT) {
  2063. iDirectionMauro = 3;
  2064. }
  2065. // si presiono la flecha derecha
  2066. if (keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) {
  2067. iDirectionMauro = 4;
  2068. }
  2069. }
  2070.  
  2071. /**
  2072. * keyReleased
  2073. * Metodo sobrescrito de la interface <code>KeyListener</code>.<P>
  2074. * En este metodo maneja el evento que se genera al soltar la tecla.
  2075. *
  2076. * @param keyEvent es el <code>KeyEvent</code> que se genera en al soltar.
  2077. *
  2078. */
  2079. public void keyReleased(KeyEvent keyEvent) {
  2080. // si presiono la flecha arriba
  2081. if (keyEvent.getKeyCode() == KeyEvent.VK_UP) {
  2082. iDirectionMauro = 0;
  2083. }
  2084. // si presiono la flecha abajo
  2085. if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
  2086. iDirectionMauro = 0;
  2087. }
  2088. // si presiono la flecha izquierda
  2089. if (keyEvent.getKeyCode() == KeyEvent.VK_LEFT) {
  2090. iDirectionMauro = 0;
  2091. }
  2092. // si presiono la flecha derecha
  2093. if (keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) {
  2094. iDirectionMauro = 0;
  2095. }
  2096. // si presiono la tecla p
  2097. if (keyEvent.getKeyCode() == KeyEvent.VK_P) {
  2098. if (!bPause && (iLevel == 1 || iLevel == 2 || iLevel == 3 || iLevel == 4)) {
  2099. bPause = true;
  2100. lPauseTime = System.currentTimeMillis();
  2101.  
  2102. //si la luz esta encendida
  2103. if (bLightOn) {
  2104. bLightOn = false;
  2105. bPause = false;
  2106. bLightPause = true;
  2107. }
  2108. }
  2109. else {
  2110. bPause = false;
  2111. lStopPauseTime = System.currentTimeMillis();
  2112. //actualiza tiempo que ayuda a arreglar tiempo durante pausa
  2113. lCurrentTimePauseFix = lStopPauseTime - lPauseTime;
  2114. lTimerInitial += lCurrentTimePauseFix;
  2115.  
  2116. if (iLevel == 1) {
  2117. //si la luz esta encendida
  2118. if (bLightOn || bLightPause) {
  2119. lInitialTimeLight += lCurrentTimePauseFix;
  2120. bLightOn = !bLightOn;
  2121. bLightPause = false;
  2122. }
  2123.  
  2124.  
  2125. }
  2126.  
  2127. else if (iLevel == 2) {
  2128. lMorpheusStartTime += lCurrentTimePauseFix;
  2129. }
  2130.  
  2131. else if (iLevel == 3) {
  2132.  
  2133. }
  2134.  
  2135. else if (iLevel == 4) {
  2136.  
  2137. }
  2138. }
  2139. }
  2140. }
  2141.  
  2142. /**
  2143. * mouseClicked
  2144. *
  2145. * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
  2146. * En este metodo maneja el evento que se genera al clickear el mouse.
  2147. *
  2148. * @param mseEvent es el <code>MouseEvent</code> que se genera en
  2149. * al presionar.
  2150. *
  2151. */
  2152. public void mouseClicked(MouseEvent mseEvent) {
  2153. // no hay codigo pero se debe escribir el metodo
  2154. }
  2155.  
  2156. /**
  2157. * mousePressed
  2158. *
  2159. * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
  2160. * En este metodo maneja el evento que se genera al presionar el mouse.
  2161. *
  2162. * @param mseEvent es el <code>MouseEvent</code> que se genera en
  2163. * al presionar.
  2164. *
  2165. */
  2166. public void mousePressed(MouseEvent mseEvent) {
  2167. // no hay codigo pero se debe escribir el metodo
  2168. }
  2169.  
  2170. /**
  2171. * mouseReleased
  2172. *
  2173. * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
  2174. * En este metodo maneja el evento que se genera al soltar el mouse.
  2175. *
  2176. * @param mseEvent es el <code>MoseEvent</code> que se genera en
  2177. * al presionar.
  2178. *
  2179. */
  2180. public void mouseReleased(MouseEvent mseEvent) {
  2181. // variables que guardan la posición del mouse
  2182. iMouseX = mseEvent.getX();
  2183. iMouseY = mseEvent.getY();
  2184. if (iLevel == 0) {
  2185. sndMenuClick.play();
  2186.  
  2187. /* Checa si el mouse colisiona con algún botón y cambia la variable de
  2188. menú a la adecuada.
  2189. */
  2190. if (mbtBack.intersectMouse(iMouseX, iMouseY) && iMenu != 1) {
  2191. iMenu = 1;
  2192. }
  2193.  
  2194. else if (mbtPlay.intersectMouse(iMouseX, iMouseY) && iMenu == 1) {
  2195. iMenu = 1;
  2196. iLevel = 1;
  2197. //define el tiempo que se tiene en el nivel 1
  2198. lTimerInitial = System.currentTimeMillis()+5000;
  2199.  
  2200. //se toca cancion nivel 1
  2201. sndLevel1Song.play();
  2202.  
  2203. //el juego no se ha perdido
  2204. bGameOver = false;
  2205.  
  2206. }
  2207. else if (mbtInstructions.intersectMouse(iMouseX, iMouseY) &&
  2208. iMenu == 1) {
  2209. iMenu = 2;
  2210. }
  2211. else if (mbtOptions.intersectMouse(iMouseX, iMouseY) &&
  2212. iMenu == 1) {
  2213. iMenu = 3;
  2214. }
  2215. else if (mbtAbout.intersectMouse(iMouseX, iMouseY) &&
  2216. iMenu == 1) {
  2217. iMenu = 4;
  2218.  
  2219. }
  2220. else if (mbtScores.intersectMouse(iMouseX, iMouseY) &&
  2221. iMenu == 1) {
  2222. iMenu = 5;
  2223.  
  2224. }
  2225. else if (mbtExit.intersectMouse(iMouseX, iMouseY) &&
  2226. iMenu != 1) {
  2227. System.exit(0);
  2228. }
  2229. }
  2230.  
  2231. if(iLevel == 5) { //si es game over
  2232. sndMenuClick.play();
  2233. if (mbtGameOverMenu.intersectMouse(iMouseX, iMouseY)) {
  2234. iMenu = 1;
  2235. iLevel = 0;
  2236. System.out.println("FUCK");
  2237. }
  2238. }
  2239.  
  2240. }
  2241.  
  2242. /**
  2243. * mouseEntered
  2244. *
  2245. * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
  2246. * En este metodo maneja el evento que se genera cuando el mouse entra en
  2247. * el applet.
  2248. *
  2249. * @param mseEvent es el <code>MoseEvent</code> que se genera en
  2250. * al presionar.
  2251. *
  2252. */
  2253. public void mouseEntered(MouseEvent mseEvent) {
  2254. // no hay codigo pero se debe escribir el metodo
  2255. }
  2256.  
  2257. /**
  2258. * mouseExited
  2259. *
  2260. * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
  2261. * En este metodo maneja el evento que se genera cuando el mouse sale en
  2262. * el applet.
  2263. *
  2264. * @param mseEvent es el <code>MoseEvent</code> que se genera en
  2265. * al presionar.
  2266. *
  2267. */
  2268. public void mouseExited(MouseEvent mseEvent) {
  2269. // no hay codigo pero se debe escribir el metodo
  2270. }
  2271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement