Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/05/2012, 20:12
apocaliptica100
 
Fecha de Ingreso: abril-2012
Mensajes: 8
Antigüedad: 13 años
Puntos: 0
frogger detectar caiga al agua

Hola ojale y me puedan ayudar con un problema que tengo con un programa es que no puedo hacer que mi juego detecte cuando la rana caiga al agua ya intente todas las formas pero no me sale ojale y me puedan ayudar con este problema aqui dejare el codigo para que lo analisen
Código:
package mover;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class mover extends fondo implements KeyListener {
	static int x = 100;
	static int y = 400;
	static int vidas = 3,nivel=0,puntos=0;
	public static JPanel panel;
	public static mover mover;
	public static int x1 = 0, x2 = 0, x3 = 470, x4=470,y1 = 240, y2 = 360, y3 = 280,y4=320;
	public static int t1=0,t2=470,t3=0,t4=470,l1=40,l2=80,l3=120,l4=160;

	public mover() {
		// sonido = Applet.newAudioClip(getClass().getResource("salto.wav"));
		JFrame ventana = new JFrame();
		ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBackground(Color.white);
		ventana.add(this);
		ventana.setVisible(true);
		ventana.setSize(417, 469);

		ventana.addKeyListener(this);
		test();
	}

	private void test() {
		while(true) {
		try {
			repaint();
			Thread.sleep(15);
		} catch(Exception e) {
			System.out.println("Hubo un error wey");
		}
		}
	}

	public void paintComponent(Graphics papel) {

		ImageIcon miImagen = new ImageIcon("sapo.gif");
		ImageIcon dead = new ImageIcon("sapo_muerto.png");
		ImageIcon carro1 = new ImageIcon("carro.gif");
		ImageIcon carro2 = new ImageIcon("carro2.gif");
		ImageIcon tronco = new ImageIcon("tronco.jpg");
		fondo fondo1 = new fondo();
		fondo1.dibujar(papel);
		tronco.paintIcon(this, papel, t1++, l1);
		tronco.paintIcon(this, papel, t2--, l2);
		tronco.paintIcon(this, papel, t3++, l3);
		tronco.paintIcon(this, papel, t4--, l4);
		carro1.paintIcon(this, papel, x1=x1+5, y1);
		carro2.paintIcon(this, papel, x3=x3-4, y3);
		carro2.paintIcon(this, papel, x4=x4-2, y4);
		carro1.paintIcon(this, papel, x2++, y2);
		miImagen.paintIcon(this, papel, x, y);
		super.paintComponents(papel);
		if(x1>=470)
		{
			x1=-10;
		}
		if(x2>=470)
		{
			x2=-10;
		}
		if(x3<=-10)
		{
			x3=480;
		}
		if(x4<=-10)
		{
			x4=480;
		}
		if(t1>=470)
		{
			t1=-10;
			t3=-10;
		}
		if(t2<=-10)
		{
			t2=480;
			t4=480;
		}
		if(y==y2&&x==x2)
		{
			y=400;
			vidas--;
			JOptionPane.showMessageDialog(null,
					"LA RANA  HA SIDO APLASTADA AHORA TIENES " + vidas + " VIDAS");
		}
		if(y==y4&&x==x4)
		{
			y=400;
			vidas--;
			JOptionPane.showMessageDialog(null,
					"LA RANA HA SIDO APLASTADA AHORA TIENES " + vidas + " VIDAS");
		}
		if(y==y3&&x==x3)
		{
			y=400;
			vidas--;
			JOptionPane.showMessageDialog(null,
					"LA RANA SE HA SIDO APLASTADA AHORA TIENES " + vidas + " VIDAS");
		}
		if(y==y1&&x==x1)
		{
			y=400;
			vidas--;
			JOptionPane.showMessageDialog(null,
					"LA RANA  HA SIDO APLASTADA AHORA TIENES " + vidas + " VIDAS");
		}
		
	
		if(y==l4&&x==t4)
		{
			miImagen.paintIcon(this, papel, x--, y);
		}
	
	
		
		if(y==l3&&x==t3)
		{
			miImagen.paintIcon(this, papel, x++, y);
		}
		
		if(y==l2&&x==t2)
		{
			miImagen.paintIcon(this, papel, x--, y);
		}
		
		if(y==l1&&x==t1)
		{
			miImagen.paintIcon(this, papel, x++, y);
		}

	}

	public static void main(String[] args) {
		mover = new mover();
		//carro = new hilo();
		//carro.start();
		
		
	}

	public void keyPressed(KeyEvent e) {
	
		
		if (KeyEvent.getKeyText(e.getKeyCode()).equals("Izquierda")) {
			x -= 40;
			puntos=puntos+20;
			

		} else if (KeyEvent.getKeyText(e.getKeyCode()).equals("Derecha")) {
			x += 40;
			
			puntos=puntos+20;
		}

		else if (KeyEvent.getKeyText(e.getKeyCode()).equals("Arriba")) {
			y -= 40;
		
			puntos=puntos+100;
		}

		else if (KeyEvent.getKeyText(e.getKeyCode()).equals("Abajo")) {
			y += 40;
			puntos=puntos+20;
			
		}
		
		// CONTROLA EL ESTADO GANADOR
		if (vidas == 0) {
			JOptionPane.showMessageDialog(null, "GAME OVER cantidad de puntos"+puntos);
			System.exit(0);// cierra la ventana

		}
		if(y>=400)
		{
			y=400;
		}
		if(x<=0)
		{
			x=0;
		}
		if(x>=360)
		{
			x=360;
		}
		// si llega ala meta
		if (y <= -15) {
			y = 400;
			nivel++;
			JOptionPane.showMessageDialog(null, "HAS CRUSADO EL NIVEL: "+nivel);
			if(nivel==5)
			{
				JOptionPane.showMessageDialog(null, "HAS TERMINADO EL JUEGO FELIZIDADES!!! total de puntos: "+puntos);
				System.exit(0);
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

}