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);
        if (newx >= Game.SCREEN_WIDTH - 2) drawableViewPort.moveRight(scrollSpeed);
        if (newy <= 2) drawableViewPort.moveUp(scrollSpeed);
        if (newy >= Game.SCREEN_HEIGHT - 2) drawableViewPort.moveDown(scrollSpeed);

        if (newy > 2 && newy < Game.SCREEN_HEIGHT) drawableViewPort.moveDown(0F);
        if (newx > 2 && newx < Game.SCREEN_WIDTH) drawableViewPort.moveRight(0F);
    }

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

    }
}

@@ -1026,24 +1026,38 @@
  (newx %3C= 2)
+ %7B%0A           
  drawableVie
@@ -1085,32 +1085,39 @@
 Speed);%0A        
+%7D else 
 if (newx %3E= Game
@@ -1130,24 +1130,38 @@
 N_WIDTH - 2)
+ %7B%0A           
  drawableVie
@@ -1202,22 +1202,28 @@
     
-if (newy %3C= 2)
+%7D else %7B%0A           
  dra
@@ -1244,24 +1244,29 @@
 move
-Up(scrollSpeed);
+Right(0F);%0A        %7D%0A
 %0A   
@@ -1283,34 +1283,27 @@
 ewy 
-%3E= Game.SCREEN_HEIGHT - 2)
+%3C= 2) %7B%0A           
  dra
@@ -1320,20 +1320,18 @@
 ort.move
-Down
+Up
 (scrollS
@@ -1337,25 +1337,24 @@
 Speed);%0A
-%0A
         
 if (newy
@@ -1337,32 +1337,39 @@
 Speed);%0A        
+%7D else 
 if (newy %3E 2 && 
@@ -1366,20 +1366,9 @@
 wy %3E
- 2 && newy %3C
+=
  Gam
@@ -1382,17 +1382,35 @@
 N_HEIGHT
-)
+ - 2) %7B%0A           
  drawabl
@@ -1432,62 +1432,50 @@
 own(
-0F);%0A        if (newx %3E 2 && newx %3C Game.SCREEN_WIDTH)
+scrollSpeed);%0A        %7D else %7B%0A           
  dra
@@ -1488,34 +1488,43 @@
 iewPort.move
-Right(0F);
+Down(0F);%0A        %7D
 %0A    %7D%0A%0A    

refactor to if/else so it is easier to follow