Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package runmaurorun;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Toolkit;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.ImageIcon;
- import javax.swing.JPanel;
- /**
- * Board
- *
- * Modela la definición de todos los objetos de tipo <code>Board</code>.
- *
- * @author Fabián Montemayor A01280156, Mauro Amarante A01191903,
- * Patricio Sánchez A01191893 & David Benítez A01191731
- * @version 3.0
- * @date 8/04/2015
- */
- public class Board extends JPanel implements Runnable, KeyListener,
- MouseListener {
- //variables de medidaas del JPanel
- private final int iWidth = 1280; //define ancho del JPanel
- private final int iHeight = 739; //define altura del JPanel
- //objetos
- private Mauro mauMauro; //objeto para Mauro
- private Map mapMaps; //objeto para Map
- private Morpheus morMorpheus; //objeto para morfeo
- //objetos ed tipo MenuButton
- private MenuButton mbtBack; //botón de Back
- private MenuButton mbtAbout; //botón de About
- private MenuButton mbtPlay; //botón de Play
- private MenuButton mbtInstructions; //botón de Instrucciones
- private MenuButton mbtOptions; //botón de Opciones
- private MenuButton mbtScores; //botón de Puntajes
- private MenuButton mbtExit; //botón de Salida
- private MenuButton mbtGameOverMenu; //boton al menu cuando pierede el juego
- //variables de Mauro
- private final int iHeightMauro = 32; //define altura de Mauro
- private final int iWidthMauro = 18; //deine anho de Mauro
- private int iVelocityMauro; //define la velocidad de Mauro
- private int iDirectionMauro; //define la direccion de Mauro
- //variables de morfeo
- private final int iHeightMorpheus = 32; //define altura de morfeo
- private final int iWidthMorpheus = 18; //deine anho de morfeo
- private int iDirectionMorpheus; //define la direccion de morfeo
- //variables de tipo integer
- private int iLevel; //define nivel actual en el juego
- private int iPosX; //define la ubicacion de un objeto en X
- private int iPosY; //define la ubicacion de un objeto en Y
- private int iDoorOpenKey; //auxiliar para contorl de puertas y llaves
- private int iMouseX; //deinfe la posicion en X del mouse
- private int iMouseY; //define la posicion en Y del mouse
- private int iMenu; //define el menú correspondiente
- private int iLevelChange; //auxiliar que checa si hubo cambio de nivel
- private int iPreviousX; //auxiliar para revisar posicion previa
- private int iPreviousY; //auxiliar para revisar posicion previa
- //variables de tipo long
- private long lImmuneTimeMauro; //define el tiempo que Mauro es immune
- private long lTime; //tiempo restante en el juego
- private long lAnimationTime; //tiempo animacion
- private long lPauseTime; //tiempo al activar pausa
- private long lStopPauseTime; //tiempo al desactivar pausa
- private long lCurrentTimePauseFix; /*auxiliar que ayuda a resolver
- conflicto de tiempo durante la pausa*/
- //variables de tipo boolean
- private boolean bTime; //define si tiempo del juego ha terminado
- private boolean bEndGame; //define si termian el juego o no
- private boolean bGameOver; //si se acabo el juego
- private boolean bMorpheusStart; //si paso el tiempo morfeo aparece
- private boolean bPause; //define si el jeugo esta en pausa
- private boolean bLightPause; //auxiliar que desactiva luz durante pausa
- //listas
- private ArrayList arlEnemies; //lista de enemigos
- private ArrayList arlMapObjectsLevel1; //lista de Maps del nivel 1
- private ArrayList arlMapObjectsLevel2; //lista de Maps del nivel 2
- private ArrayList arlMapObjectsLevel3; //lista de Maps del nivel 3
- private ArrayList arlMapObjectsLevel4; //lista de Maps del nivel 4
- private ArrayList arlMorpheusSteps; //pasos que seguira morfeo
- private ArrayList arlCarLevel3; //carros del nivel 3
- private ArrayList arlCarLevel4; //carros del nivel 4
- //arreglos
- private boolean[] bButtonsLevel1; //define cuales botones estan activos
- private boolean[] bButtonsLevel2; //define cuales botones estan activos
- private boolean[] bButtonsLevel3; //define cuales botones estan activos
- private boolean[] bButtonsLevel4; //define cuales botones estan activos
- //thread
- private Thread thread; //variable para el thread del JPanel
- //variables de control de tiempo para animacion
- private long lCurrentTime; //tiempo actual
- private long lInitialTime; //tiempo inicial
- private long lElapsedTime; //tiempo transcurrido
- //variables control de tiempo para morfeo
- private long lMorpheusStartTime;
- private long lMorpheusCurrentTime;
- private int iMorpheusElapsedTime;
- private int iMorpheusTimeLimit;
- //variables control de tiempo para pwrup de zapatos
- private long lShoesStartTime;
- private long lShoesCurrentTime;
- private int iShoesElapsedTime;
- private int iShoesTimeLimit;
- //variables para controlar la barra de tiempo
- private long lTimerInitial; //tiempo en donde se empieza a contar la barra
- private long lCurrentTimer; //tiempo actual
- private int iElapsedTimeTimer;//tiempo transcurrido
- private int iLimitTime; //tiempo limite del nivel en segundos
- //variables para controlar los powerups
- private boolean bLightOn; //deinfe si esta prendido
- private long lInitialTimeLight;//define el seg. donde hay colision con Mauro
- private int iElapsedTimeLight; //define cuantos segundos han pasado
- private boolean bClockOn; //define si hubo colision con Mauro
- //variables de sonido
- private SoundClip sndLevel1Song; //cancion nivel 1
- private SoundClip sndLevel2Song; //cancion nivel 2
- private SoundClip sndLevel3Song; //cancion nivel 3
- private SoundClip sndLevel4Song; //cancion nivel 4
- //variables efecto de sonido
- private SoundClip bPwrUp; //efecto de sonido de pwr up
- private SoundClip sndCarCrash; //efecto de choque de carro
- private SoundClip sndDoor; //efecto de sonido de puerta
- private SoundClip sndStarbucks; //efecto al tomar el starbucks
- private SoundClip sndCarSound; //efecto de sonido de carro arrancando
- private SoundClip sndWin; //efecto de victoria
- private SoundClip sndTrap; //efecto de sonido de la trampa
- private SoundClip sndGameOver; //efecto de sonido de game over
- private SoundClip sndBark; //efecto de sonido de ladrido de perro
- private SoundClip sndMenuClick; //efecto de sonido de presionar boton
- private SoundClip sndPwrDown; //efecto de sonido de pwr down
- private SoundClip sndYawn; //efecto de sonido de boztezo
- /**
- * Board
- *
- * Metodo sobrescrito de la clase <code>JPanel</code>.<P>
- * En este metodo se inizializan las variables o se crean los objetos
- * a usarse en el <code>JPanel</code> y se definen funcionalidades.
- *
- */
- public Board() {
- /* se le añade la opcion al JFrame de ser escuchado por los eventos
- del teclado y mouse*/
- addKeyListener(this);
- addMouseListener(this);
- //define en cual panel definir enfoque
- setFocusable(true);
- //iniciar juego
- GameInit();
- setDoubleBuffered(true);
- }
- /**
- * GameInit
- *
- * Metodo que inicializa el juego.
- *
- */
- public void GameInit() {
- //Nivel de inicio, animacion inical
- iLevel = 0; // era 0
- //siguiente nivel
- iLevelChange = 1; //era 1
- //menu inicial
- iMenu = 1;
- //no inicia en pausa
- bPause = false;
- //no se utiliza todavia
- bLightPause = false;
- //no es necesario si la pausa no esta activa
- lCurrentTimePauseFix = 0;
- //variables que definen que le juego no ha terminado o perdido el juego
- bEndGame = false;
- bGameOver = false;
- //Se define sonido de fondo para cada nivel
- //nivel 1
- sndLevel1Song = new SoundClip("Musica/nivel1.wav");
- sndLevel1Song.setLooping(true);
- //nivel 2
- sndLevel2Song = new SoundClip("Musica/nivel2.wav");
- sndLevel2Song.setLooping(true);
- //nivel 3
- sndLevel3Song = new SoundClip("Musica/nivel3.wav");
- sndLevel3Song.setLooping(true);
- //nivel 4
- sndLevel4Song = new SoundClip("Musica/nivel4.wav");
- sndLevel4Song.setLooping(true);
- //incializar efectos de sonido
- bPwrUp = new SoundClip("Sfx/powerup.wav");
- bPwrUp.setLooping(false);
- sndCarCrash = new SoundClip("Sfx/carcrash.wav");
- sndCarCrash.setLooping(false);
- sndDoor = new SoundClip("Sfx/door.wav");
- sndDoor.setLooping(false);
- sndStarbucks = new SoundClip("Sfx/starbucks.wav");
- sndStarbucks.setLooping(false);
- sndCarSound = new SoundClip("Sfx/vroom.wav");
- sndCarSound.setLooping(false);
- sndWin = new SoundClip("Sfx/win.wav");
- sndWin.setLooping(false);
- sndTrap = new SoundClip("Sfx/stab.wav");
- sndTrap.setLooping(false);
- sndGameOver = new SoundClip("Sfx/gameover.wav");
- sndGameOver.setLooping(false);
- sndBark = new SoundClip("Sfx/bark.wav");
- sndBark.setLooping(false);
- sndMenuClick = new SoundClip("Sfx/menuclick.wav");
- sndMenuClick.setLooping(false);
- sndPwrDown = new SoundClip("Sfx/powerdown.wav");
- sndPwrDown.setLooping(false);
- sndYawn = new SoundClip("Sfx/yawn.wav");
- sndYawn.setLooping(false);
- //inicializar arreglo de botones
- bButtonsLevel1 = new boolean[5];
- bButtonsLevel2 = new boolean[9];
- bButtonsLevel3 = new boolean[5];
- bButtonsLevel4 = new boolean[5];
- //llenar arreglos
- for (int i = 0; i < 5; i++) {
- bButtonsLevel1[i] = false;
- }
- for (int i = 0; i < 5; i++) {
- bButtonsLevel2[i] = false;
- }
- for (int i = 0; i < 5; i++) {
- bButtonsLevel3[i] = false;
- }
- for (int i = 0; i < 5; i++) {
- bButtonsLevel4[i] = false;
- }
- //incializar a Mauro
- iVelocityMauro = 2;
- iDirectionMauro = 0;
- lImmuneTimeMauro = 0;
- String sMauro = "Animation/Mauro/mauro1.png";
- ImageIcon imiImage = new ImageIcon(this.getClass().getResource(sMauro));
- mauMauro = new Mauro(iVelocityMauro, iDirectionMauro,
- iWidthMauro, iHeightMauro, imiImage.getImage(),
- lImmuneTimeMauro);
- //inicializar a morfeo
- iDirectionMorpheus = 0;
- String sMorpheus = "Animation/Mauro/mauro1.png";
- imiImage = new ImageIcon(this.getClass().getResource(sMauro));
- morMorpheus = new Morpheus(iDirectionMorpheus, iWidthMorpheus,
- iHeightMorpheus, imiImage.getImage());
- //inicializar lista de pasos morfeo
- arlMorpheusSteps = new ArrayList();
- //inicializar tiempo de morfeo en 9
- iMorpheusTimeLimit = 9; //en segundos
- //inicializar tiempo de los zapatos en 5
- iShoesTimeLimit = 5; //en segundos
- //incicializar posiciones previas
- iPreviousX = -1; //auxiliar para definri posiciones de morfeo
- iPreviousY = -1; //auxiliar para definri posiciones de morfeo
- //inicializar que morfeo no se pinta aun
- bMorpheusStart = false;
- //crea las listas de los Mapas
- arlMapObjectsLevel1 = new ArrayList();
- arlMapObjectsLevel2 = new ArrayList();
- arlMapObjectsLevel3 = new ArrayList();
- arlMapObjectsLevel4 = new ArrayList();
- //crea lista de carros
- arlCarLevel3 = new ArrayList();
- //Inicializa todos los mapas
- try {
- GameInitMaps();
- } catch (IOException ex) {
- Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
- }
- // Inicializa botones del menu
- String sBack = "Menus/bot_back.png";
- String sAbout = "Menus/bot_acerca.png";
- String sInstructions = "Menus/bot_instrucciones.png";
- String sOptions = "Menus/bot_opciones.png";
- String sPlay = "Menus/bot_jugar.png";
- String sScores = "Menus/bot_puntos.png";
- String sExit = "Menus/bot_salir.png";
- String sGameOverMenu = "Menus/boton_menu.png";
- imiImage = new ImageIcon(this.getClass().getResource(sBack));
- mbtBack = new MenuButton(imiImage.getImage(),
- 1280 - imiImage.getIconWidth(), 30,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sAbout));
- mbtAbout = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 420,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sInstructions));
- mbtInstructions = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 330,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sOptions));
- mbtOptions = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 360,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sPlay));
- mbtPlay = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 300,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sScores));
- mbtScores = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 390,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sExit));
- mbtExit = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 450,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- imiImage = new ImageIcon(this.getClass().getResource(sGameOverMenu));
- mbtGameOverMenu = new MenuButton(imiImage.getImage(),
- 1280/2 - imiImage.getIconWidth()/2, 450,
- imiImage.getIconWidth(), imiImage.getIconHeight());
- // inicializa el thread
- if (thread == null || !bEndGame) {
- thread = new Thread(this);
- thread.start();
- }
- }
- /**
- * GameInitMaps
- *
- * Metodo que inicializa todos los mapas del juego.
- *
- */
- private void GameInitMaps() throws IOException {
- //variables
- //variables que definen un=bicacion de imagenes
- String sLevel1WallVertical = "Nivel1/paredVerticalNivel1.jpg";
- String sLevel1WallHorizontal = "Nivel1/paredHorizontalNivel1.png";
- String sLevel1Trap = "Nivel1/picos0.png";
- String sLevel1Finish = "Nivel1/meta_nivel1.png";
- String sLevel1Text = "src/runmaurorun/Nivel1/Nivel1.txt";
- String sLevel2Text = "src/runmaurorun/nivel2/Nivel2.txt";
- String sLevel3Text = "src/runmaurorun/nivel3/Nivel3.txt";
- String sLevel4Text = "src/runmaurorun/nivel4/Nivel4.txt";
- String sData; //almacena lectura de texto
- char cObjectType; //revisa tipo objeto a leer
- char cAuxObjectType; //auxiliar q almacena el tipo de objeto
- int iWidthObject; //variable para ancho del objeto
- int iHeightObject; //variable para altura del objeto
- int iDoorKey; //varaible para control de acceso de puertas
- int iX;
- int iY;
- int iDoorLength;
- int iDirectionCar; //variable para control de la direccion del perro
- boolean bFinishFileRead; //variable que define si se termino la lectura
- ImageIcon imiImage; //imagen utilizada para crear mapas
- //buscar y leer archivo de Nivel 1
- BufferedReader fileIn;
- //inicializar variables
- cObjectType = ' ';
- iWidthObject = 0;
- iHeightObject = 0;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel1WallHorizontal));
- Map mapObject;
- Enemy emyObject;
- //--------------------------NIVEL 1------------------------------------
- //duracion del juego
- iLimitTime = 200; //2 minutos
- //pwrup de luz
- bLightOn = false; //no tiene el powerUp
- //pwrup reloj
- bClockOn = false; //No tiene el powerup
- try {
- fileIn = new BufferedReader(new FileReader(sLevel1Text));
- } catch (FileNotFoundException e) {
- System.out.println("FILE NOT FOUND!");
- fileIn = new BufferedReader(new FileReader(
- sLevel1Text));
- }
- //file has not been read
- bFinishFileRead = false;
- //leer archivo hasta terminar de leerlo
- sData = fileIn.readLine();
- do {
- //si el primer caracter es una letra
- if (sData.charAt(0) - 97 >= 0 ) {
- cObjectType = sData.charAt(0);
- sData = fileIn.readLine();
- }
- //si la linea es un comentario
- if (sData.charAt(0) == '/') {
- sData = fileIn.readLine();
- }
- //leer coordenadas X y Y
- iX = Integer.parseInt(sData);
- sData = fileIn.readLine();
- iY = Integer.parseInt(sData);
- //definir medidas e imagen a utilizar dependiendo del objeto
- switch (cObjectType) {
- case 'a': //pared horizontal
- iWidthObject = 76;
- iHeightObject = 19;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel1WallHorizontal));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'b': //pared vertical
- iWidthObject = 19;
- iHeightObject = 76;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel1WallVertical));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'c': //trampa
- iWidthObject = 32;
- iHeightObject = 19;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel1Trap));
- mapObject = new Trap(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject, -1,
- false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'd': //puerta horizontal
- iWidthObject = 92;
- iHeightObject = 8;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'e': //puerta vertical
- iWidthObject = 8;
- iHeightObject = 90;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'f': //boton
- iWidthObject = 32;
- iHeightObject = 19;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Button(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, false, iDoorKey);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'g': //powerup
- iWidthObject = 16;
- iHeightObject = 25;
- sData = fileIn.readLine();
- int iPwrUpType = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new PwrUp(false, false, imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- iPwrUpType, -1);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- case 'h': //meta
- iWidthObject = 83;
- iHeightObject = 47;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel1Finish));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel1.add(mapObject);
- break;
- default:
- break;
- }
- sData = fileIn.readLine();
- //si se termino la lectura
- if (sData.charAt(0) == 'x') {
- bFinishFileRead = true;
- }
- } while (!bFinishFileRead);
- //--------------------------NIVEL 2------------------------------------
- String sLevel2WallVertical = "Nivel2/pared_vertical_nivel2.png";
- String sLevel2WallHorizontal = "Nivel2/pared_horizontal_nivel2.png";
- try {
- fileIn = new BufferedReader(new FileReader(sLevel2Text));
- } catch (FileNotFoundException e) {
- System.out.println("FILE NOT FOUND!");
- fileIn = new BufferedReader(new FileReader(sLevel2Text));
- }
- //file has not been read
- bFinishFileRead = false;
- //leer archivo hasta terminar de leerlo
- sData = fileIn.readLine();
- do {
- //si el primer caracter es una letra
- if (sData.charAt(0) - 97 >= 0 ) {
- cObjectType = sData.charAt(0);
- sData = fileIn.readLine();
- }
- //si la linea es un comentario
- if (sData.charAt(0) == '/') {
- sData = fileIn.readLine();
- }
- //leer coordenadas X y Y
- iX = Integer.parseInt(sData);
- sData = fileIn.readLine();
- iY = Integer.parseInt(sData);
- //definir medidas e imagen a utilizar dependiendo del objeto
- switch (cObjectType) {
- case 'a': //pared horizontal
- iWidthObject = 76;
- iHeightObject = 19;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel2WallHorizontal));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'b': //pared vertical
- iWidthObject = 19;
- iHeightObject = 76;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel2WallVertical));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'c': //decoracion de casa
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'd': //puerta horizontal
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'e': //puerta vertical
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'f': //boton
- iWidthObject = 32;
- iHeightObject = 19;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Button(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false, iDoorKey);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'g': //powerup
- iWidthObject = 16;
- iHeightObject = 25;
- sData = fileIn.readLine();
- int iPwrUpType = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new PwrUp(false, true, imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- iPwrUpType, -1);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'h': //meta
- iWidthObject = 52;
- iHeightObject = 30;
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- case 'i': //barandales
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- boolean bVisible = Boolean.parseBoolean(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- bVisible, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel2.add(mapObject);
- break;
- default:
- break;
- }
- sData = fileIn.readLine();
- //si se termino la lectura
- if (sData.charAt(0) == 'x') {
- bFinishFileRead = true;
- }
- } while (!bFinishFileRead);
- //--------------------------NIVEL 3------------------------------------
- String sLevel3WallVertical = "nivel3/pared_vertical_nivel3.png";
- String sLevel3WallHorizontal = "nivel3/pared_horizontal_nivel3.png";
- try {
- fileIn = new BufferedReader(new FileReader(sLevel3Text));
- } catch (FileNotFoundException e) {
- System.out.println("FILE NOT FOUND!");
- fileIn = new BufferedReader(new FileReader(sLevel3Text));
- }
- //file has not been read
- bFinishFileRead = false;
- //leer archivo hasta terminar de leerlo
- sData = fileIn.readLine();
- do {
- //si el primer caracter es una letra
- if (sData.charAt(0) - 97 >= 0 ) {
- cObjectType = sData.charAt(0);
- sData = fileIn.readLine();
- }
- //si la linea es un comentario
- if (sData.charAt(0) == '/') {
- sData = fileIn.readLine();
- }
- //leer coordenadas X y Y
- iX = Integer.parseInt(sData);
- sData = fileIn.readLine();
- iY = Integer.parseInt(sData);
- //definir medidas e imagen a utilizar dependiendo del objeto
- switch (cObjectType) {
- case 'a': //paredes horizontales
- iWidthObject = 83;
- iHeightObject = 27;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel3WallHorizontal));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'b': //pared vertical
- iWidthObject = 27;
- iHeightObject = 83;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel3WallVertical));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'c': //decoracion
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'd': //puerta horizontal
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'e': //puerta vertical
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'f': //botones
- iWidthObject = 48;
- iHeightObject = 28;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Button(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false, iDoorKey);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'g': //carros
- sData = fileIn.readLine();
- iDirectionCar = Integer.parseInt(sData);
- sData = fileIn.readLine();
- if(iDirectionCar == 1 || iDirectionCar == 2){ //Si el carro es horizontal
- iWidthObject = 84;
- iHeightObject = 48;
- }
- else{ //si el carro es vertical
- iWidthObject = 48;
- iHeightObject = 84;
- }
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- emyObject = new Enemy(iX, iY, 3, iDirectionCar, iWidthObject, iHeightObject, imiImage.getImage());
- arlCarLevel3.add(emyObject);
- break;
- case 'h': //meta
- iWidthObject = 52;
- iHeightObject = 30;
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'i': //paredes invisibles para carros horizontal
- iWidthObject = 83;
- iHeightObject = 27;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel3WallHorizontal));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject+50, iHeightObject,
- false, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- case 'j':
- iWidthObject = 27;
- iHeightObject = 83;
- imiImage = new ImageIcon(this.getClass().getResource(
- sLevel3WallVertical));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel3.add(mapObject);
- break;
- default:
- //no hay otra opcion
- break;
- }
- sData = fileIn.readLine();
- //si se termino la lectura
- if (sData.charAt(0) == 'x') {
- bFinishFileRead = true;
- }
- } while (!bFinishFileRead);
- /**
- //--------------------------NIVEL 4------------------------------------
- try {
- fileIn = new BufferedReader(new FileReader(sLevel4Text));
- } catch (FileNotFoundException e) {
- System.out.println("FILE NOT FOUND!");
- fileIn = new BufferedReader(new FileReader(sLevel4Text));
- }
- //file has not been read
- bFinishFileRead = false;
- //leer archivo hasta terminar de leerlo
- sData = fileIn.readLine();
- do {
- //si el primer caracter es una letra
- if (sData.charAt(0) - 97 >= 0 ) {
- cObjectType = sData.charAt(0);
- sData = fileIn.readLine();
- }
- //si la linea es un comentario
- if (sData.charAt(0) == '/') {
- sData = fileIn.readLine();
- }
- //leer coordenadas X y Y
- iX = Integer.parseInt(sData);
- sData = fileIn.readLine();
- iY = Integer.parseInt(sData);
- //definir medidas e imagen a utilizar dependiendo del objeto
- switch (cObjectType) {
- case 'a': //paredes horizontales
- break;
- case 'b': //pared vertical
- break;
- case 'c': //colisionables
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel4.add(mapObject);
- break;
- case 'd': //puerta horizontal
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel4.add(mapObject);
- break;
- case 'e': //puerta vertical
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iWidthObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorLength = Integer.parseInt(sData);
- iHeightObject = iDoorLength;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Door(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- false, iDoorKey, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel4.add(mapObject);
- break;
- case 'f': //botones
- iWidthObject = 48;
- iHeightObject = 28;
- sData = fileIn.readLine();
- iDoorKey = Integer.parseInt(sData);
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Button(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, false, iDoorKey);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel4.add(mapObject);
- break;
- case 'g': //
- break;
- case 'h': //meta
- iWidthObject = 52;
- iHeightObject = 30;
- sData = fileIn.readLine();
- imiImage = new ImageIcon(this.getClass().getResource(
- sData));
- mapObject = new Map(imiImage.getImage(),
- iX, iY, iWidthObject, iHeightObject,
- true, true);
- mapObject.setImage(imiImage.getImage());
- arlMapObjectsLevel4.add(mapObject);
- break;
- case 'i': //
- break;
- default:
- break;
- }
- sData = fileIn.readLine();
- //si se termino la lectura
- if (sData.charAt(0) == 'x') {
- bFinishFileRead = true;
- }
- } while (!bFinishFileRead); **/
- }
- /**
- * run
- *
- * Metodo que corre el juego y actualiza el hilo.
- *
- */
- public void run() {
- //variables para el control de tiempo
- long lTimeDiff; //diferencia del tiempo contra tiempo actual en un punto
- long lSleep; //canitdad limite para dormir el thread en ms
- //loop que cicla el juego hasta que termina
- while (!bEndGame) {
- //pinta y actualiza
- repaint();
- if (!bPause) {
- //actualiza datos
- AnimationCycle();
- }
- //Calcula la diferencia de tiempo con la ultima marca de tiempo
- lTimeDiff = System.currentTimeMillis() - lCurrentTime;
- lSleep = 17 - lTimeDiff;
- //define canitdad a dormir el thread
- if (lSleep < 0)
- lSleep = 2;
- try {
- Thread.sleep(lSleep);
- } catch (InterruptedException e) {
- System.out.println("interrupted");
- }
- //actuializa el tiempo actual
- lCurrentTime = System.currentTimeMillis();
- }
- }
- /**
- * AnimationCycle
- *
- * Metodo que actualiza el juego
- *
- */
- public void AnimationCycle() {
- /*Determina el tiempo que ha transcurrido desde que el Applet inicio su
- ejecución*/
- lElapsedTime = System.currentTimeMillis() - lCurrentTime;
- //Guarda el tiempo actual
- lCurrentTime += lElapsedTime;
- //actualiza el jugador
- mauMauro.updateMovement(iDirectionMauro);
- //si se cambio al siguiente nivel define posicion inical de mauro
- if (iLevel == iLevelChange) {
- switch (iLevel) {
- case 1: { //nivel 1
- mauMauro.setX(1200); //70
- mauMauro.setY(100); //640
- break;
- }
- case 2: { //nivel 2
- mauMauro.setX(20); //1200
- mauMauro.setY(515); //100
- break;
- }
- case 3: { //nivel 3
- mauMauro.setX(50);
- mauMauro.setY(50);
- break;
- }
- case 4: { //nivel 4
- mauMauro.setX(70);
- mauMauro.setY(640);
- break;
- }
- default: {
- break;
- }
- }
- //incrementar variable para estar listo para el siguiente nivel
- iLevelChange++;
- }
- //--------------------------NIVEL 1------------------------------------
- //actualizar efectos nivel 1
- if (iLevel == 1) {
- //variables
- int iPositionDifferenceMauro; //diferencia en posision de Mauro
- int iIncreaseRectangleSize; //incremento en tamaño de rectangulo
- int iTimeLimitLight = 5; //duracion maxima efecto luz
- //si pwrup de luz NO esta activo
- if (!bLightOn || bLightPause) {
- iPositionDifferenceMauro = 100;
- iIncreaseRectangleSize = 150;
- }
- else {
- iPositionDifferenceMauro = 1000;
- iIncreaseRectangleSize = 1750;
- //si termina el tiempo apagar pwrup
- if ((lCurrentTime-lInitialTimeLight)/1000 >= iTimeLimitLight) {
- bLightOn = !bLightOn;
- sndPwrDown.play();
- }
- }
- //iterador de objetos de la lista
- Iterator it = arlMapObjectsLevel1.iterator();
- // mientras existan objetos en la lista
- while (it.hasNext()) {
- Map mapObject = (Map) it.next();
- // revisar si estan en el area de Mauro
- if (mapObject.PlayerColission(mapObject, mauMauro,
- iPositionDifferenceMauro,
- iIncreaseRectangleSize)) {
- mapObject.setVisible(true); //muestra el objeto
- }
- else {
- mapObject.setVisible(false); //esconde el objeto
- }
- //si es un puerta revisar si debe estar abierta
- if (mapObject instanceof Door) {
- Door mapDoor = (Door) mapObject;
- if (bButtonsLevel1[mapDoor.getDoorNo()]) {
- mapDoor.setOpen(true);
- mapDoor.setSolid(false);
- }
- }
- }
- //si el foco estaba activo y se encendio la pausa
- if (bLightPause) {
- bPause = true;
- }
- //cambios barra del tiempo
- //Saca el tiempo actual para barra del tiempo
- lCurrentTimer = System.currentTimeMillis();
- //Saca el tiempo que ha pasado desde el inicio del nivel
- iElapsedTimeTimer = (int)(lCurrentTimer - lTimerInitial)/1000;
- //si el pwrup del reloj esta activo aumentar reloj
- if (bClockOn) {
- lTimerInitial += 8000;
- bClockOn = !bClockOn;
- }
- //si el tiempo en el juego se termino
- if (iLimitTime - iElapsedTimeTimer < 0) {
- bGameOver = true;
- iLevel = 5;
- sndLevel1Song.stop();
- sndGameOver.play();
- gameOverRestart();
- //regresar a primera posicion
- mauMauro.setX(70);
- mauMauro.setY(640);
- //reset de siguiente nivel
- iLevelChange = 1;
- }
- //checa colision
- checkCollisionLevel1();
- }
- //--------------------------NIVEL 2------------------------------------
- else if (iLevel == 2) {
- //grabar posiciones de mauro para morfeo si no esta detenido
- if (iDirectionMauro != 0 && (mauMauro.getX() != iPreviousX ||
- mauMauro.getY() != iPreviousY)) {
- if (iVelocityMauro == 4) {
- arlMorpheusSteps.add(iDirectionMauro);
- arlMorpheusSteps.add(mauMauro.getX());
- arlMorpheusSteps.add(mauMauro.getY());
- arlMorpheusSteps.add(iDirectionMauro);
- arlMorpheusSteps.add(mauMauro.getX());
- arlMorpheusSteps.add(mauMauro.getY());
- }
- else {
- arlMorpheusSteps.add(iDirectionMauro);
- arlMorpheusSteps.add(mauMauro.getX());
- arlMorpheusSteps.add(mauMauro.getY());
- }
- }
- //empezar a contar tiempo de aparicion de morfeo
- //tiempo actual
- lMorpheusCurrentTime = System.currentTimeMillis();
- lShoesCurrentTime = System.currentTimeMillis();
- //calculo de tiempo transcurrido desde que inicio nivel
- iMorpheusElapsedTime = (int)(lMorpheusCurrentTime -
- lMorpheusStartTime)/1000;
- //calculo de tiempo transcurrido desde que se agrarraron los zapatos
- iShoesElapsedTime = (int)(lShoesCurrentTime -
- lShoesStartTime)/1000;
- //si ya pasaron los 90 segundos empezar a pintar a morfeo
- if (iMorpheusTimeLimit - iMorpheusElapsedTime < 0) {
- bMorpheusStart = true;
- }
- //si ya pasaron los 90 segundos empezar a pintar a morfeo
- if (iShoesTimeLimit - iShoesElapsedTime < 0) {
- iVelocityMauro = 2;
- mauMauro.setVelocity(iVelocityMauro);
- }
- if (bMorpheusStart) {
- //variables posiciones
- int iX;
- int iY;
- //iterador de objetos de la lista
- Iterator it = arlMorpheusSteps.iterator();
- //obtener direccion de morfeo
- int iDirection = (int) it.next();
- it.remove();
- iX = (int) it.next();
- it.remove();
- iY = (int) it.next();
- it.remove();
- //si mauro no esta detenido
- if (iDirection != 0 && (iX != iPreviousX || iY != iPreviousY)) {
- iDirectionMorpheus = iDirection;
- //obtener X de morfeo
- morMorpheus.setX(iX);
- iPreviousX = iX;
- //obtener Y de morfeo
- morMorpheus.setY(iY);
- iPreviousY = iY;
- }
- }
- //cambios barra del tiempo
- //Saca el tiempo actual para barra del tiempo
- lCurrentTimer = System.currentTimeMillis();
- //Saca el tiempo que ha pasado desde el inicio del nivel
- iElapsedTimeTimer = (int)(lCurrentTimer - lTimerInitial)/1000;
- //si el tiempo en el juego se termino
- if (iLimitTime - iElapsedTimeTimer < 0) {
- bGameOver = true;
- iLevel = 5;
- sndLevel2Song.stop();
- sndGameOver.play();
- gameOverRestart();
- //regresar a primera posicion
- mauMauro.setX(70);
- mauMauro.setY(640);
- //reset de siguiente nivel
- iLevelChange = 1;
- }
- //checa colision
- checkCollisionLevel2();
- }
- //--------------------------NIVEL 3------------------------------------
- else if (iLevel == 3) {
- //actualiza posicion de los carros
- //mauMauro.updateMovement(iDirectionMauro);
- Iterator it3C = arlCarLevel3.iterator();
- // mientras existan objetos en la lista
- while (it3C.hasNext()) {
- Enemy emyObject = (Enemy) it3C.next();
- emyObject.updateMovement();
- }
- //checa colision
- checkCollisionLevel3();
- }
- //--------------------------NIVEL 3------------------------------------
- else if (iLevel == 4) {
- //checa colision
- checkCollisionLevel4();
- }
- }
- public void checkCollisionLevel1() {
- //colision con las paredes
- Iterator it = arlMapObjectsLevel1.iterator();
- // mientras existan objetos en la lista
- while (it.hasNext()) {
- Map mapObject = (Map) it.next();
- //Si el objeto es solido y existe colision...
- if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
- //Si es una trampa
- if (mapObject instanceof Trap) {
- //regresar a mauro a posicion inicial
- mauMauro.setX(70);
- mauMauro.setY(640);
- sndTrap.play();
- }
- //Si es un boton, abrir puerta
- else if (mapObject instanceof Button) {
- Button mapButton = (Button) mapObject;
- iDoorOpenKey = mapButton.getButtonNo();
- if (!bButtonsLevel1[iDoorOpenKey]) {
- sndDoor.play();
- }
- mapButton.setClicked(true);
- bButtonsLevel1[iDoorOpenKey] = true;
- }
- //Si agarra un PowerUp
- else if (mapObject instanceof PwrUp) {
- PwrUp mapUp = (PwrUp) mapObject;
- //Si es un foco
- if (mapUp.getType() == 2) {
- if (!mapUp.getGrabbed()) {
- bPwrUp.play();
- lInitialTimeLight = System.currentTimeMillis();
- bLightOn = true;
- mapUp.setGrabbed(true);
- mapUp.setVisible(false);
- }
- }
- //Si es un reloj
- else{
- if (!mapUp.getGrabbed()) {
- bPwrUp.play();
- bClockOn = true;
- mapUp.setGrabbed(true);
- mapUp.setVisible(false);
- }
- }
- }
- //cambiar de nivel si llega a la salida
- else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
- iLevel != iLevelChange) {
- iLevel++;
- sndWin.play();
- sndLevel1Song.stop();
- lMorpheusStartTime = System.currentTimeMillis();
- sndLevel2Song.play();
- iLimitTime = 200;
- lTimerInitial = System.currentTimeMillis()+5000;
- }
- //Si es una pared (o puerta solida), anular movimiento
- else{
- if (iDirectionMauro == 1) {
- mauMauro.updateMovement(2);
- }
- else if (iDirectionMauro == 2) {
- mauMauro.updateMovement(1);
- }
- else if (iDirectionMauro == 3) {
- mauMauro.updateMovement(4);
- }
- else if (iDirectionMauro == 4) {
- mauMauro.updateMovement(3);
- }
- }
- }
- }
- }
- public void checkCollisionLevel2() {
- //colision con las paredes
- Iterator it = arlMapObjectsLevel2.iterator();
- // mientras existan objetos en la lista
- while (it.hasNext()) {
- Map mapObject = (Map) it.next();
- //Si el objeto es solido y existe colision...
- if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
- //Si es una trampa
- if (mapObject instanceof Trap) {
- //regresar a mauro a posicion inicial
- mauMauro.setX(70);
- mauMauro.setY(640);
- }
- //Si es un boton, abrir puerta
- else if (mapObject instanceof Button) {
- Button mapButton = (Button) mapObject;
- iDoorOpenKey = mapButton.getButtonNo();
- if (!bButtonsLevel2[iDoorOpenKey]) {
- sndDoor.play();
- }
- mapButton.setClicked(true);
- bButtonsLevel2[iDoorOpenKey] = true;
- //busca su puerta correspondiente
- Iterator it2 = arlMapObjectsLevel2.iterator();
- // mientras existan objetos en la lista
- while (it2.hasNext()) {
- Map mapObject2 = (Map) it2.next();
- //si es un puerta revisar si debe estar abierta
- if (mapObject2 instanceof Door) {
- Door mapDoor = (Door) mapObject2;
- if (bButtonsLevel2[mapDoor.getDoorNo()]) {
- mapDoor.setOpen(true);
- mapDoor.setSolid(false);
- }
- }
- }
- }
- //Si agarra un PowerUp
- else if (mapObject instanceof PwrUp) {
- PwrUp mapUp = (PwrUp) mapObject;
- //Si son los zapatos
- if (mapUp.getType() == 3) {
- if (!mapUp.getGrabbed()) {
- bPwrUp.play();
- mapUp.setGrabbed(true);
- mapUp.setVisible(false);
- lShoesStartTime = System.currentTimeMillis();
- iVelocityMauro = 4;
- mauMauro.setVelocity(iVelocityMauro);
- }
- }
- //Si es la puerta de la izquierda
- else if (mapUp.getType() == 4) {
- if (!mapUp.getGrabbed()) {
- bPwrUp.play();
- mauMauro.setX(700);
- }
- }
- //si es la puerta de derecha
- else {
- bPwrUp.play();
- mauMauro.setX(303);
- }
- }
- //cambiar de nivel si llega a la salida
- else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
- iLevel != iLevelChange) {
- iLevel++;
- sndLevel2Song.stop();
- }
- //Si es una pared (o puerta solida), anular movimiento
- else {
- if (iDirectionMauro == 1) {
- mauMauro.updateMovement(2);
- }
- else if (iDirectionMauro == 2) {
- mauMauro.updateMovement(1);
- }
- else if (iDirectionMauro == 3) {
- mauMauro.updateMovement(4);
- }
- else if (iDirectionMauro == 4) {
- mauMauro.updateMovement(3);
- }
- }
- }
- }
- //si mauro colisiona con morfeo
- if (mauMauro.colission(morMorpheus)) {
- //tocar sonido
- sndYawn.play();
- //reinicar nivel
- gameOverRestart();
- //asignar nivel 2
- iLevel = 2;
- //reposicionar a mauro
- //regresar a primera posicion
- mauMauro.setX(1200);
- mauMauro.setY(100);
- //reinciio tiempo morfeo
- lMorpheusStartTime = System.currentTimeMillis();
- //vaciar lista de pasos de morfeo
- arlMorpheusSteps.clear();
- //reinciar variable
- bMorpheusStart = false;
- //reiniciar musica
- sndLevel2Song.stop();
- sndLevel2Song.play();
- }
- }
- public void checkCollisionLevel3() {
- //colision con las paredes
- Iterator it = arlMapObjectsLevel3.iterator();
- // mientras existan objetos en la lista
- while (it.hasNext()) {
- Map mapObject = (Map) it.next();
- //Si el objeto es solido y existe colision...
- if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
- if (mapObject instanceof Button) {
- Button mapButton = (Button) mapObject;
- iDoorOpenKey = mapButton.getButtonNo();
- if (!bButtonsLevel3[iDoorOpenKey]) {
- sndDoor.play();
- }
- mapButton.setClicked(true);
- bButtonsLevel3[iDoorOpenKey] = true;
- //busca su puerta correspondiente
- Iterator it2 = arlMapObjectsLevel3.iterator();
- // mientras existan objetos en la lista
- while (it2.hasNext()) {
- Map mapObject2 = (Map) it2.next();
- //si es un puerta revisar si debe estar abierta
- if (mapObject2 instanceof Door) {
- Door mapDoor = (Door) mapObject2;
- if (bButtonsLevel3[mapDoor.getDoorNo()]) {
- mapDoor.setOpen(true);
- mapDoor.setSolid(false);
- }
- }
- }
- }
- //cambiar de nivel si llega a la salida
- else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
- iLevel != iLevelChange) {
- iLevel++;
- sndLevel3Song.stop();
- }
- //Si es una pared (o puerta solida), anular movimiento
- else {
- if (iDirectionMauro == 1) {
- mauMauro.updateMovement(2);
- }
- else if (iDirectionMauro == 2) {
- mauMauro.updateMovement(1);
- }
- else if (iDirectionMauro == 3) {
- mauMauro.updateMovement(4);
- }
- else if (iDirectionMauro == 4) {
- mauMauro.updateMovement(3);
- }
- }
- }
- Iterator it3C = arlCarLevel3.iterator();
- // mientras existan objetos en la lista
- while (it3C.hasNext()) {
- Enemy emyObject = (Enemy) it3C.next();
- if(emyObject.colission(mapObject)){
- if(emyObject.getDirection() == 1){
- emyObject.setDirection(2);
- }
- else if(emyObject.getDirection() == 2){
- emyObject.setDirection(1);
- }
- else if(emyObject.getDirection() == 3){
- emyObject.setDirection(4);
- }
- else if(emyObject.getDirection() == 4){
- emyObject.setDirection(3);
- }
- }
- }
- }
- }
- public void checkCollisionLevel4() {
- //colision con las paredes
- Iterator it = arlMapObjectsLevel4.iterator();
- // mientras existan objetos en la lista
- while (it.hasNext()) {
- Map mapObject = (Map) it.next();
- //Si el objeto es solido y existe colision...
- if (mapObject.isSolid() && mauMauro.colission(mapObject)) {
- if (mapObject instanceof Button) {
- Button mapButton = (Button) mapObject;
- iDoorOpenKey = mapButton.getButtonNo();
- if (!bButtonsLevel4[iDoorOpenKey]) {
- sndDoor.play();
- }
- mapButton.setClicked(true);
- bButtonsLevel4[iDoorOpenKey] = true;
- //busca su puerta correspondiente
- Iterator it2 = arlMapObjectsLevel4.iterator();
- // mientras existan objetos en la lista
- while (it2.hasNext()) {
- Map mapObject2 = (Map) it2.next();
- //si es un puerta revisar si debe estar abierta
- if (mapObject2 instanceof Door) {
- Door mapDoor = (Door) mapObject2;
- if (bButtonsLevel4[mapDoor.getDoorNo()]) {
- mapDoor.setOpen(true);
- mapDoor.setSolid(false);
- }
- }
- }
- }
- //cambiar de nivel si llega a la salida
- else if (mapObject.isExit() && mauMauro.colission(mapObject) &&
- iLevel != iLevelChange) {
- iLevel++;
- sndLevel4Song.stop();
- }
- //Si es una pared (o puerta solida), anular movimiento
- else {
- if (iDirectionMauro == 1) {
- mauMauro.updateMovement(2);
- }
- else if (iDirectionMauro == 2) {
- mauMauro.updateMovement(1);
- }
- else if (iDirectionMauro == 3) {
- mauMauro.updateMovement(4);
- }
- else if (iDirectionMauro == 4) {
- mauMauro.updateMovement(3);
- }
- }
- }
- }
- }
- public void gameOverRestart() {
- //reset de botones de puertas en los niveles
- for (int i = 0; i < 5; i++) {
- bButtonsLevel1[i] = false;
- }
- for (int i = 0; i < 5; i++) {
- bButtonsLevel2[i] = false;
- }
- for (int i = 0; i < 5; i++) {
- bButtonsLevel3[i] = false;
- }
- for (int i = 0; i < 5; i++) {
- bButtonsLevel4[i] = false;
- }
- //reset variables Mauro
- iVelocityMauro = 2;
- iDirectionMauro = 0;
- lImmuneTimeMauro = 0;
- //reinicializa todos los mapas
- try {
- GameInitMaps();
- } catch (IOException ex) {
- Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * Metodo <I>paint</I> sobrescrito
- * de la clase <code>JPanel</code>,
- * heredado de la clase Container.<P>
- * En este metodo se dibuja la imagen con la posicion actualizada,
- * ademas que cuando la imagen es cargada te despliega una advertencia.
- * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
- */
- public void paint(Graphics graGrafico) {
- //llama al paint de la clase que heredaste
- super.paint(graGrafico);
- switch (iLevel) {
- case -1: //animacion inical
- break;
- case 0: //menu
- drawMenu(graGrafico);
- break;
- case 1:
- Graphics2D g2d = (Graphics2D) graGrafico;
- g2d.setColor(Color.decode("#1d2e4c"));
- g2d.fillOval(mauMauro.getX()-50, mauMauro.getY()-45, 120,
- 120);
- g2d.drawOval(mauMauro.getX()-50, mauMauro.getY()-45, 120,
- 120);
- setBackground(Color.black);
- drawMaps(graGrafico);
- drawMauro(graGrafico);
- if (!bGameOver) {
- drawTimeBar(graGrafico);
- }
- break;
- case 2:
- String sLevel2Background = "Nivel2/background.png";
- ImageIcon imiImage = new ImageIcon(this.getClass().
- getResource(sLevel2Background));
- graGrafico.drawImage(imiImage.getImage(), 0, 0, this);
- drawMaps(graGrafico);
- drawMauro(graGrafico);
- if (bMorpheusStart) {
- drawMorpheus(graGrafico);
- }
- if (!bGameOver) {
- drawTimeBar(graGrafico);
- }
- break;
- case 3:
- String sLevel3Background = "nivel3/background.png";
- ImageIcon imiImage3 = new ImageIcon(this.getClass().
- getResource(sLevel3Background));
- graGrafico.drawImage(imiImage3.getImage(), 0, 0, this);
- drawMaps(graGrafico);
- drawMauro(graGrafico);
- break;
- case 4:
- graGrafico.setColor(Color.gray);
- drawMaps(graGrafico);
- drawMauro(graGrafico);
- break;
- default: // game over
- drawGameOver(graGrafico);
- break;
- }
- //comandos para paint
- Toolkit.getDefaultToolkit().sync();
- graGrafico.dispose();
- }
- /**
- * drawMauro
- *
- * Metodo que dibuja a Mauro.
- *
- * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
- */
- public void drawMauro(Graphics graGrafico) {
- // mientras exista Mauro
- if (mauMauro.isVisible() && iLevel != 0) {
- mauMauro.getAnimation().actualiza(lElapsedTime);
- mauMauro.setAnimation(iDirectionMauro);
- graGrafico.drawImage(mauMauro.getAnimation().getImagen(),
- mauMauro.getX(), mauMauro.getY(), this);
- }
- }
- public void drawMorpheus(Graphics graGrafico) {
- if (morMorpheus.isVisible()) {
- morMorpheus.getAnimation().actualiza(lElapsedTime);
- morMorpheus.setAnimation(iDirectionMorpheus);
- graGrafico.drawImage(morMorpheus.getAnimation().getImagen(),
- morMorpheus.getX(), morMorpheus.getY(), this);
- }
- }
- /**
- * drawMaps
- *
- * Metodo que dibuja los Maps
- *
- * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
- */
- public void drawMaps(Graphics graGrafico) {
- //dependiendo del nivel se pintara dichos objetos
- switch (iLevel) {
- case 1:
- Iterator it = arlMapObjectsLevel1.iterator();
- // mientras existan objetos en la lista
- while (it.hasNext()) {
- Map mapObject = (Map) it.next();
- mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
- }
- break;
- case 2:
- Iterator it2 = arlMapObjectsLevel2.iterator();
- // mientras existan objetos en la lista
- while (it2.hasNext()) {
- Map mapObject = (Map) it2.next();
- mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
- }
- break;
- case 3:
- Iterator it3 = arlMapObjectsLevel3.iterator();
- // mientras existan objetos en la lista
- while (it3.hasNext()) {
- Map mapObject = (Map) it3.next();
- mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
- }
- Iterator it3C = arlCarLevel3.iterator();
- // mientras existan objetos en la lista
- while (it3C.hasNext()) {
- Enemy emyObject = (Enemy) it3C.next();
- graGrafico.drawImage(emyObject.getImage(), emyObject.getX(), emyObject.getY(), this);
- }
- break;
- case 4:
- Iterator it4 = arlMapObjectsLevel4.iterator();
- // mientras existan objetos en la lista
- while (it4.hasNext()) {
- Map mapObject = (Map) it4.next();
- mapObject.paint(graGrafico, mapObject, lElapsedTime, this);
- }
- break;
- default:
- break;
- }
- }
- /**
- * drawGameOver
- *
- * Metodo que dibuja el game over
- *
- * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
- */
- public void drawGameOver(Graphics graGrafico) {
- graGrafico.setColor(Color.black);
- String sGameOver = "Menus/gameover.png";
- ImageIcon imiImageGameOver2 = new ImageIcon(this.getClass().
- getResource(sGameOver));
- graGrafico.drawImage(imiImageGameOver2.getImage(), 0, 0,
- this);
- //boton
- mbtGameOverMenu.paint(graGrafico, this);
- }
- /**
- * drawTimeBar
- *
- * Metodo que dibuja la barra del tiempo
- *
- * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
- */
- public void drawTimeBar(Graphics graGrafico) {
- //Crea el fondo de la barra de tiempo
- String sBar = "Menus/barraTiempo_Fondo.png";
- ImageIcon imiImage = new ImageIcon(this.getClass().getResource(sBar));
- graGrafico.drawImage(imiImage.getImage(), 0, iHeight-41, this);
- //si el limite de tiempo no ha sido alcanzado
- if (iLimitTime - iElapsedTimeTimer > 0) {
- //Se dibuja la barra verde que se modifica con el tiempo
- graGrafico.setColor(Color.GREEN);
- graGrafico.fillRect(85, iHeight - 38,(1115 / iLimitTime) *
- (iLimitTime - iElapsedTimeTimer),13);
- }
- }
- /**
- * drawMenu
- *
- * Metodo que dibuja el menu y los submenús.
- *
- * @param graGrafico es el <code>objeto grafico</code> usado para dibujar.
- */
- public void drawMenu(Graphics graGrafico) {
- URL urlMenu;
- Image imaMenu;
- // Switch que se utiliza para ver qué pantalla desplegar
- switch (iMenu) {
- case 1: { // se despliega el MENU
- // dibuja el fondo
- urlMenu = this.getClass().getResource("Menus/menu3.png");
- imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
- graGrafico.drawImage(imaMenu, 0, 0, this);
- // dibuja los botones
- mbtPlay.paint(graGrafico, this);
- mbtInstructions.paint(graGrafico, this);
- mbtAbout.paint(graGrafico, this);
- mbtOptions.paint(graGrafico, this);
- mbtScores.paint(graGrafico, this);
- mbtExit.paint(graGrafico, this);
- break;
- }
- case 2: { // se dibujan las instrucciones
- // dibuja el fondo
- urlMenu = this.getClass().getResource("Menus/menu4.png");
- imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
- graGrafico.drawImage(imaMenu, 0, 0, this);
- // dibuja el botón back y lo pone visible
- mbtBack.paint(graGrafico, this);
- break;
- }
- case 3: { // se dibujan las opciones
- urlMenu = this.getClass().getResource("Menus/menu5.png");
- imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
- graGrafico.drawImage(imaMenu, 0, 0, this);
- // dibuja el botón back y lo pone visible
- mbtBack.paint(graGrafico, this);
- break;
- }
- case 4: { // se dibuja el acerca
- urlMenu = this.getClass().getResource("Menus/menu6.png");
- imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
- graGrafico.drawImage(imaMenu, 0, 0, this);
- // dibuja el botón back y lo pone visible
- mbtBack.paint(graGrafico, this);
- break;
- }
- case 5: { // se dibujan los puntajes
- urlMenu = this.getClass().getResource("Menus/menu7.png");
- imaMenu = Toolkit.getDefaultToolkit().getImage(urlMenu);
- graGrafico.drawImage(imaMenu, 0, 0, this);
- // dibuja el botón back y lo pone visible
- mbtBack.paint(graGrafico, this);
- break;
- }
- }
- }
- /**
- * keyTyped
- *
- * Metodo sobrescrito de la interface <code>KeyListener</code>.<P>
- * En este metodo maneja el evento que se genera al presionar una
- * tecla que no es de accion.
- *
- * @param keyEvent es el <code>KeyEvent</code> que se genera en al
- * presionar.
- *
- */
- public void keyTyped(KeyEvent keyEvent) {
- // no hay codigo pero se debe escribir el metodo
- }
- /**
- * keyPressed
- *
- * Metodo sobrescrito de la interface <code>KeyListener</code>.<P>
- * En este metodo maneja el evento que se genera al dejar presionada
- * alguna tecla.
- * Se cambia la direccion al presionar una tecla
- *
- * @param keyEvent es el <code>KeyEvent</code> que se genera en al
- * presionar.
- *
- */
- public void keyPressed(KeyEvent keyEvent) {
- // si presiono la flecha arriba
- if (keyEvent.getKeyCode() == KeyEvent.VK_UP) {
- iDirectionMauro = 1;
- }
- // si presiono la flecha abajo
- if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
- iDirectionMauro = 2;
- }
- // si presiono la flecha izquierda
- if (keyEvent.getKeyCode() == KeyEvent.VK_LEFT) {
- iDirectionMauro = 3;
- }
- // si presiono la flecha derecha
- if (keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) {
- iDirectionMauro = 4;
- }
- }
- /**
- * keyReleased
- * Metodo sobrescrito de la interface <code>KeyListener</code>.<P>
- * En este metodo maneja el evento que se genera al soltar la tecla.
- *
- * @param keyEvent es el <code>KeyEvent</code> que se genera en al soltar.
- *
- */
- public void keyReleased(KeyEvent keyEvent) {
- // si presiono la flecha arriba
- if (keyEvent.getKeyCode() == KeyEvent.VK_UP) {
- iDirectionMauro = 0;
- }
- // si presiono la flecha abajo
- if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
- iDirectionMauro = 0;
- }
- // si presiono la flecha izquierda
- if (keyEvent.getKeyCode() == KeyEvent.VK_LEFT) {
- iDirectionMauro = 0;
- }
- // si presiono la flecha derecha
- if (keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) {
- iDirectionMauro = 0;
- }
- // si presiono la tecla p
- if (keyEvent.getKeyCode() == KeyEvent.VK_P) {
- if (!bPause && (iLevel == 1 || iLevel == 2 || iLevel == 3 || iLevel == 4)) {
- bPause = true;
- lPauseTime = System.currentTimeMillis();
- //si la luz esta encendida
- if (bLightOn) {
- bLightOn = false;
- bPause = false;
- bLightPause = true;
- }
- }
- else {
- bPause = false;
- lStopPauseTime = System.currentTimeMillis();
- //actualiza tiempo que ayuda a arreglar tiempo durante pausa
- lCurrentTimePauseFix = lStopPauseTime - lPauseTime;
- lTimerInitial += lCurrentTimePauseFix;
- if (iLevel == 1) {
- //si la luz esta encendida
- if (bLightOn || bLightPause) {
- lInitialTimeLight += lCurrentTimePauseFix;
- bLightOn = !bLightOn;
- bLightPause = false;
- }
- }
- else if (iLevel == 2) {
- lMorpheusStartTime += lCurrentTimePauseFix;
- }
- else if (iLevel == 3) {
- }
- else if (iLevel == 4) {
- }
- }
- }
- }
- /**
- * mouseClicked
- *
- * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
- * En este metodo maneja el evento que se genera al clickear el mouse.
- *
- * @param mseEvent es el <code>MouseEvent</code> que se genera en
- * al presionar.
- *
- */
- public void mouseClicked(MouseEvent mseEvent) {
- // no hay codigo pero se debe escribir el metodo
- }
- /**
- * mousePressed
- *
- * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
- * En este metodo maneja el evento que se genera al presionar el mouse.
- *
- * @param mseEvent es el <code>MouseEvent</code> que se genera en
- * al presionar.
- *
- */
- public void mousePressed(MouseEvent mseEvent) {
- // no hay codigo pero se debe escribir el metodo
- }
- /**
- * mouseReleased
- *
- * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
- * En este metodo maneja el evento que se genera al soltar el mouse.
- *
- * @param mseEvent es el <code>MoseEvent</code> que se genera en
- * al presionar.
- *
- */
- public void mouseReleased(MouseEvent mseEvent) {
- // variables que guardan la posición del mouse
- iMouseX = mseEvent.getX();
- iMouseY = mseEvent.getY();
- if (iLevel == 0) {
- sndMenuClick.play();
- /* Checa si el mouse colisiona con algún botón y cambia la variable de
- menú a la adecuada.
- */
- if (mbtBack.intersectMouse(iMouseX, iMouseY) && iMenu != 1) {
- iMenu = 1;
- }
- else if (mbtPlay.intersectMouse(iMouseX, iMouseY) && iMenu == 1) {
- iMenu = 1;
- iLevel = 1;
- //define el tiempo que se tiene en el nivel 1
- lTimerInitial = System.currentTimeMillis()+5000;
- //se toca cancion nivel 1
- sndLevel1Song.play();
- //el juego no se ha perdido
- bGameOver = false;
- }
- else if (mbtInstructions.intersectMouse(iMouseX, iMouseY) &&
- iMenu == 1) {
- iMenu = 2;
- }
- else if (mbtOptions.intersectMouse(iMouseX, iMouseY) &&
- iMenu == 1) {
- iMenu = 3;
- }
- else if (mbtAbout.intersectMouse(iMouseX, iMouseY) &&
- iMenu == 1) {
- iMenu = 4;
- }
- else if (mbtScores.intersectMouse(iMouseX, iMouseY) &&
- iMenu == 1) {
- iMenu = 5;
- }
- else if (mbtExit.intersectMouse(iMouseX, iMouseY) &&
- iMenu != 1) {
- System.exit(0);
- }
- }
- if(iLevel == 5) { //si es game over
- sndMenuClick.play();
- if (mbtGameOverMenu.intersectMouse(iMouseX, iMouseY)) {
- iMenu = 1;
- iLevel = 0;
- System.out.println("FUCK");
- }
- }
- }
- /**
- * mouseEntered
- *
- * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
- * En este metodo maneja el evento que se genera cuando el mouse entra en
- * el applet.
- *
- * @param mseEvent es el <code>MoseEvent</code> que se genera en
- * al presionar.
- *
- */
- public void mouseEntered(MouseEvent mseEvent) {
- // no hay codigo pero se debe escribir el metodo
- }
- /**
- * mouseExited
- *
- * Metodo sobrescrito de la clase <code>MouseListener</code>.<P>
- * En este metodo maneja el evento que se genera cuando el mouse sale en
- * el applet.
- *
- * @param mseEvent es el <code>MoseEvent</code> que se genera en
- * al presionar.
- *
- */
- public void mouseExited(MouseEvent mseEvent) {
- // no hay codigo pero se debe escribir el metodo
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement