package Cameus;

import java.awt.*;

import MyMain.CameraPointingGame;

public class KamesMouse {
    
    public int x = 0;
    public int y = 0;
    public Robot robot;
    
    PointerInfo pI;
    Point point;
    Point framePoint;
    CameraPointingGame cameraPointingGame;
    
    public KamesMouse(CameraPointingGame cameraPointingGame)
    {
    	this.cameraPointingGame = cameraPointingGame;
        try {
			robot = new Robot();
		} catch (AWTException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
        
    }
    
    public Point GetNowCursor()
    {
        pI = MouseInfo.getPointerInfo();
        point = pI.getLocation();
        x = point.x;
        y = point.y;
        return point;
    }

    public void MoveMouse(Point point) {

        
        //フレームの中からマウスポインタが出ないようにする
        framePoint = this.cameraPointingGame.frame.getLocationOnScreen();
        if (framePoint.x > x + point.x - 30)
        	point.x = 0;
        else if ((framePoint.x + this.cameraPointingGame.frame.getSize().width) < x + point.x + 30)
        	point.x = 0;
        if (framePoint.y > y + point.y - 100)
        	point.y = 0;
        else if ((framePoint.y + this.cameraPointingGame.frame.getSize().height < y + point.y + 30))
        	point.y = 0;
        
        robot.mouseMove(x + point.x, y + point.y);
    }
}