package com.fundynamic.d2tm.game.event;


import com.fundynamic.d2tm.Game;
import com.fundynamic.d2tm.game.drawing.DrawableViewPort;

public class DrawableViewPortMoverListener extends AbstractMouseListener {

    private final DrawableViewPort drawableViewPort;
    private float scrollSpeed;

    public DrawableViewPortMoverListener(DrawableViewPort drawableViewPort, float scrollSpeed) {
        this.drawableViewPort = drawableViewPort;
        this.scrollSpeed = scrollSpeed;
    }

    public DrawableViewPortMoverListener(DrawableViewPort drawableViewPort) {
        this(drawableViewPort, 1F);
    }

    @Override
    public void mouseWheelMoved(int change) {

    }

    @Override
    public void mouseClicked(int button, int x, int y, int clickCount) {

    }

    @Override
    public void mousePressed(int button, int x, int y) {

    }

    @Override
    public void mouseReleased(int button, int x, int y) {

    }

    @Override
    public void mouseMoved(int oldx, int oldy, int newx, int newy) {
        if (newx <= 2) {
            drawableViewPort.moveLeft(scrollSpeed);
        } else if (newx >= Game.SCREEN_WIDTH - 2) {
            drawableViewPort.moveRight(scrollSpeed);
        } else {
            drawableViewPort.moveRight(0F);
        }

        if (newy <= 2) {
            drawableViewPort.moveUp(scrollSpeed);
        } else if (newy >= Game.SCREEN_HEIGHT - 2) {
            drawableViewPort.moveDown(scrollSpeed);
        } else {
            drawableViewPort.moveDown(0F);
        }
    }

    @Override
    public void mouseDragged(int oldx, int oldy, int newx, int newy) {

    }
}

@@ -199,24 +199,76 @@
 Listener %7B%0A%0A
+    public static final int PIXELS_NEAR_BORDER = 2;%0A
     private 
@@ -1076,25 +1076,42 @@
 if (newx %3C= 
-2
+PIXELS_NEAR_BORDER
 ) %7B%0A        
@@ -1201,17 +1201,34 @@
 WIDTH - 
-2
+PIXELS_NEAR_BORDER
 ) %7B%0A    
@@ -1368,17 +1368,34 @@
 newy %3C= 
-2
+PIXELS_NEAR_BORDER
 ) %7B%0A    
@@ -1488,17 +1488,34 @@
 EIGHT - 
-2
+PIXELS_NEAR_BORDER
 ) %7B%0A    

put the magic number 2 into constant - it represents the amount of pixels near the border of the screen your mouse must be to trigger velocity changes