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

public class GestionnaireMouvementImage implements MouseMotionListener {

	private Fenetre fenetre;
	private Balle balle;
	private int posX;
	private int posY;
	private GestionSouris gestionSouris;

	public GestionnaireMouvementImage(Fenetre fenetre, Balle balle, int x, int y, GestionSouris gestionSouris) {
		this.fenetre = fenetre;
		this.balle = balle;
		this.posX = x;
		this.posY = y;
		this.gestionSouris = gestionSouris;
	}

	public void mouseDragged(MouseEvent evenement) {
		if (evenement.getX()-4 >= this.posX && evenement.getX()-4 <= this.posX+29 && 
			evenement.getY()-26 >= this.posY && evenement.getY()-26 <= this.posY+28) {
			System.out.println("I'm gonna fucking kill myself");
			this.fenetre.remove(balle);
			int diffX = (evenement.getX()-4) - this.gestionSouris.getSourisX();
			int diffY = (evenement.getY()-26) - this.gestionSouris.getSourisY();
			this.posX += diffX;
			this.posY += diffY;

			this.gestionSouris.setSourisX(evenement.getX()-4);
			this.gestionSouris.setSourisY(evenement.getY()-26);
			Balle balle = new Balle(this.posX, this.posY);
			this.balle = balle;
			this.fenetre.add(balle);
			this.fenetre.revalidate();
			this.fenetre.repaint();
		}
	}

	public void mouseMoved(MouseEvent evenement) {

	}
}

