(Slick2D and tileD) Player Movement and viewport scolling Problem

I am making a Slick2d Rpg So i took the advice given to me to in this thread.
http://www.java-gaming.org/topics/slick-2d-tiled-best-way-to-move-player-or-swap-maps/31886/view.html

and I made a seperate class to handle collision and input. but previously i have my screen followed player and according to map size the scrolling would stop when player got so close to edge of the map. Since i made this input class it no longer centers my player or follows them around the map. I didnt acually change any code i just simply exported it from game update method to a new class called InputHandler please help.
[spoiler]
Game Class

package com.oraclearts.javagame;

import java.util.Iterator;

import org.lwjgl.input.Keyboard;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class Game extends BasicGameState {
	GameMap gameMap;
	InputHandler inputHandler;
	Item items;
    Player player;
	Person person = new Person();
	boolean isCollDisplayed = false;
	boolean isTransDisplayed = false;
	static float viewportX = 0;
	static float viewportY = 0;
	static int viewportW = ConfigValues.RESOLUTION_WIDTH;
	static int viewportH = ConfigValues.RESOLUTION_HEIGHT;
	static int viewportWTile = viewportW / ConfigValues.MAP_TILE_SIZE;
	static int viewportHTile = viewportH / ConfigValues.MAP_TILE_SIZE;
	static int limitRight, limitLeft, limitTop, limitBottom;

	@Override
	public void init(GameContainer container, StateBasedGame state)
			throws SlickException {
		inputHandler = new InputHandler(container);
		gameMap = new GameMap(Constant.MAP_PATH);
		player = new Player("player", 8 * 32, 12*32);
		items = new Item();
		limitRight = gameMap.getWidth() * ConfigValues.MAP_TILE_SIZE
				- ConfigValues.RESOLUTION_WIDTH;
		limitLeft = 0;
		limitTop = 0;
		limitBottom = gameMap.getHeight() * ConfigValues.MAP_TILE_SIZE
				- ConfigValues.RESOLUTION_HEIGHT;
		
	}

	@Override
	public void render(GameContainer container, StateBasedGame state, Graphics g)
			throws SlickException {
		// offset x and y to display are calculated from a given tile
		int x = (int) (viewportX % ConfigValues.MAP_TILE_SIZE);
		int y = (int) (viewportY % ConfigValues.MAP_TILE_SIZE);

		gameMap.render(-x, -y,
				(int) (viewportX / ConfigValues.MAP_TILE_SIZE),
				(int) (viewportY / ConfigValues.MAP_TILE_SIZE),
				// We have to display one more tile on the left and on the
				// bottom because of offset x and y
				viewportWTile + ConfigValues.MAP_TILE_SIZE, viewportHTile
				+ ConfigValues.MAP_TILE_SIZE,
				gameMap.getLayerIndex(Constant.MAP_LAYER_BACKGROUND), false);
		
		gameMap.render(-x, -y, (int) (viewportX / ConfigValues.MAP_TILE_SIZE),
				(int) (viewportY / ConfigValues.MAP_TILE_SIZE), viewportWTile
				+ ConfigValues.MAP_TILE_SIZE, viewportHTile
				+ ConfigValues.MAP_TILE_SIZE,
				gameMap.getLayerIndex(Constant.MAP_LAYER_FOREGROUND), false);
		
		player.render(g);
		
		person.render(g);
		
		gameMap.render(-x, -y, (int) (viewportX / ConfigValues.MAP_TILE_SIZE),
				(int) (viewportY / ConfigValues.MAP_TILE_SIZE), viewportWTile
				+ ConfigValues.MAP_TILE_SIZE, viewportHTile
				+ ConfigValues.MAP_TILE_SIZE,
				gameMap.getLayerIndex(Constant.MAP_LAYER_TOP), false);
		
		// Draw hitbox
		if (isCollDisplayed) {
			Iterator<Shape> it = gameMap.getCollShapes().iterator();
			while (it.hasNext()) {
				g.draw(it.next());
			}
		}
		if (isTransDisplayed) {
			Iterator<Shape> jt = gameMap.getTranShapes().iterator();
			while (jt.hasNext()) {
				g.draw(jt.next());
			}
		}
		g.drawString("press h", 200, 10);
		g.drawString("press t", 200, 20);
		g.drawImage(items.BOOTS.get(5),200, 150);

	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		inputHandler.handleInput(this, delta);
		inputHandler.update(this, delta);
	}

	@Override
	public int getID() {
		System.out.println("Game.getID() called");
		return Constant.ID_GAME_STATE;

	}
}

InputHandler Class

package com.oraclearts.javagame;


import java.util.Iterator;

import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.KeyListener;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;

public class InputHandler {

	private final GameContainer container;
	private Input input;
	private int delta;

	public InputHandler(GameContainer gc ) {
		container = gc;
		
	}
	public void update(Game game, int delta) {
		input  = container.getInput();
		this.delta = delta;
		boolean keyLeft = container.getInput().isKeyDown(Input.KEY_LEFT)||container.getInput().isKeyDown(Input.KEY_A);
		boolean keyRight = container.getInput().isKeyDown(Input.KEY_RIGHT)||container.getInput().isKeyDown(Input.KEY_D);
		boolean keyUp = container.getInput().isKeyDown(Input.KEY_UP)||container.getInput().isKeyDown(Input.KEY_W);
		boolean keyDown = container.getInput().isKeyDown(Input.KEY_DOWN)||container.getInput().isKeyDown(Input.KEY_S);
		boolean mouseDown = container.getInput().isMouseButtonDown(0);
		boolean areTwoKeysDown = ((keyUp && keyLeft) || (keyUp && keyRight) || 
				(keyDown && keyLeft) || (keyDown && keyRight));
		float viewportXOffset = 0;
		float viewportYOffset = 0;
		float characterVelocityX = 0;
		float characterVelocityY = 0;
		int direction = -1;

	}
	
	public void handleInput(Game game, int delta) {
		input  = container.getInput();
		this.delta = delta;
		boolean keyLeft = container.getInput().isKeyDown(Input.KEY_LEFT)||container.getInput().isKeyDown(Input.KEY_A);
		boolean keyRight = container.getInput().isKeyDown(Input.KEY_RIGHT)||container.getInput().isKeyDown(Input.KEY_D);
		boolean keyUp = container.getInput().isKeyDown(Input.KEY_UP)||container.getInput().isKeyDown(Input.KEY_W);
		boolean keyDown = container.getInput().isKeyDown(Input.KEY_DOWN)||container.getInput().isKeyDown(Input.KEY_S);
		boolean mouseDown = container.getInput().isMouseButtonDown(0);
		boolean areTwoKeysDown = ((keyUp && keyLeft) || (keyUp && keyRight) || 
				(keyDown && keyLeft) || (keyDown && keyRight));
		float viewportXOffset = 0;
		float viewportYOffset = 0;
		float characterVelocityX = 0;
		float characterVelocityY = 0;
		int direction = -1;

		if (keyRight) {
			direction = Character.DIRECTION_RIGHT;
			if (game.player.isCenteredX()) {
				viewportXOffset = game.player.getSpeed();

				if (Game.viewportX + viewportXOffset > Game.limitRight) {
					viewportXOffset = 0;
					characterVelocityX = game.player.getSpeed();
				}
			} else {
				characterVelocityX = game.player.getSpeed();
			}
		} else if (keyLeft) {
			direction = Character.DIRECTION_LEFT;
			if (game.player.isCenteredX()) {
				viewportXOffset = -game.player.getSpeed();

				if (Game.viewportX + viewportXOffset < Game.limitLeft) {
					viewportXOffset = 0;
					characterVelocityX = -game.player.getSpeed();
				}
			} else {
				characterVelocityX = -game.player.getSpeed();
			}
		} else if (keyUp) {
			direction = Character.DIRECTION_UP;
			if (game.player.isCenteredY()) {
				viewportYOffset = -game.player.getSpeed();

				if (Game.viewportY + viewportYOffset < Game.limitTop) {
					viewportYOffset = 0;
					characterVelocityY = -game.player.getSpeed();
				}
			} else {
				characterVelocityY = -game.player.getSpeed();
			}
		} else if (keyDown) {
			direction = Character.DIRECTION_DOWN;
			if (game.player.isCenteredY()) {
				viewportYOffset = game.player.getSpeed();

				if (Game.viewportY + viewportYOffset > Game.limitBottom) {
					viewportYOffset = 0;
					characterVelocityY = game.player.getSpeed();
				}
			} else {
				characterVelocityY = game.player.getSpeed();
			}



		} else if (input.isKeyPressed(Keyboard.KEY_H)) {
			game.player.toggleDrawingCollision();
			game.isCollDisplayed = !game.isCollDisplayed;
		} else if (input.isKeyPressed(Keyboard.KEY_T)) {
			game.player.toggleDrawingTransport();
			game.isTransDisplayed = !game.isTransDisplayed;
		}


		///////////////////////  COLLISION DETECTION \\\\\\\\\\\\\\\\\\\\\\\\


		if(direction != -1) {
			// Character is colliding ?
			boolean collide = false;
			Iterator<Shape> it = game.gameMap.getCollShapes().iterator();
			while(it.hasNext()) {
				Shape s = it.next();
				Shape nextS = new Rectangle(s.getX()-viewportXOffset, s.getY()-viewportYOffset, s.getWidth(), s.getHeight());
				collide = nextS.intersects(game.player.getNextMoveCollbox(direction, characterVelocityX, characterVelocityY));
				if(collide)
					break;
			}
			// Character is transporting ?
			boolean transport = false;
			Iterator<Shape> jt = game.gameMap.getTranShapes().iterator();
			while(jt.hasNext()) {
				
				Shape s = jt.next();
				Shape nextS = new Rectangle(s.getX()-viewportXOffset, s.getY()-viewportYOffset, s.getWidth(), s.getHeight());

				transport = nextS.intersects(game.player.getNextMoveTranbox(direction, characterVelocityX, characterVelocityY));
				if(transport){
					for (int i = 0; i < game.gameMap.tranSpotX.size() ; i ++){
					game.player.setX(Float.parseFloat(game.gameMap.tranSpotX.get(i)) * 32);     //ConfigValues.MAP_TILE_SIZE);
					game.player.setY(Float.parseFloat(game.gameMap.tranSpotY.get(i)) * 32);      //ConfigValues.MAP_TILE_SIZE);
					break;}
				}
			}

			if(!collide) {
				// Updating viewport
				Game.viewportX += viewportXOffset;
				Game.viewportY += viewportYOffset;

				game.player.moveCharacter(direction, delta, characterVelocityX, characterVelocityY);

				// Updating hitbox coordinates depending on viewport
				it = game.gameMap.getCollShapes().iterator();
				while(it.hasNext()) {
					Shape s = it.next();
					s.setX(s.getX()-viewportXOffset);
					s.setY(s.getY()-viewportYOffset);
				}
				jt = game.gameMap.getTranShapes().iterator();
				while(jt.hasNext()) {
					Shape s = jt.next();
					s.setX(s.getX()-viewportXOffset);
					s.setY(s.getY()-viewportYOffset);
				}
			} else {
				game.player.moveCharacter(direction, delta, 0, 0);
			}

		}// End Collision Detection (if dir !=-1) 



		if (mouseDown) {
			//game.player.setX(container.getInput().getAbsoluteMouseX());
			//game.player.setY(container.getInput().getAbsoluteMouseY());
            System.out.println("Click Click "+game.player.getX()+", "+game.player.getY());
		}



		if (areTwoKeysDown) { return; }



	}

}

GameMap Class

package com.oraclearts.javagame;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.tiled.TiledMap;

public class GameMap extends TiledMap {

	private final List<Shape> collShapes = new ArrayList<Shape>();
	private final List<Shape> tranShapes = new ArrayList<Shape>();
	final List<String> tranSpotX = new ArrayList<String>();
	final List<String> tranSpotY = new ArrayList<String>();
	final int tranGroup = 1;
	final int collGroup = 0;
	static String xpos ;
	static String ypos ;
	
	public GameMap(String mapPath) throws SlickException {
		super(mapPath);
		
		System.out.println(this.collShapes);
		System.out.println(this.tranShapes);
		
		//group Id is the physical layers as int ie. 0 = collision  1 = transport
		

		for (int i = 0; i < super.getObjectCount(collGroup); i++) {

			Rectangle collRect = new Rectangle(super.getObjectX(collGroup, i),
					super.getObjectY(collGroup, i), super.getObjectWidth(
							collGroup, i), super.getObjectHeight(collGroup, i));
			collShapes.add(collRect);
		}
		
		for (int j = 0; j < super.getObjectCount(tranGroup); j++) {
			         xpos = super.getObjectProperty(1, j, "xpos", "0");
			         ypos = super.getObjectProperty(1, j, "ypos", "0");
			Rectangle tranRect = new Rectangle(super.getObjectX(tranGroup, j),
					super.getObjectY(tranGroup, j), super.getObjectWidth(
							tranGroup, j), super.getObjectHeight(tranGroup, j));
			tranShapes.add(tranRect);
			tranSpotX.add(xpos);
			tranSpotY.add(ypos);
		}
	}

	public List<Shape> getCollShapes() {
		return collShapes;
	}

	public List<Shape> getTranShapes() {
		return tranShapes;
	}

	public boolean isTransport(Shape s) {
		Iterator<Shape> jt = tranShapes.iterator();
		while (jt.hasNext()) {
			if (jt.next().intersects(s))
				return true;
		}

		return false;
	}

	public boolean isColliding(Shape s) {
		Iterator<Shape> it = collShapes.iterator();
		while (it.hasNext()) {
			if (it.next().intersects(s))
				return true;
		}

		return false;
	}

}

[/spoiler]

I don’t think you need that update method when it’s doing the exact same as the handleInput method?

Also, I think the code is pretty hard to read. That handleInput() method does a lot more than handling input, it’s even got collision detection in it if I see that right. Maybe do some more refactoring it will all become clear when it’s more readable, or at least it’s easier for others here to help you :slight_smile:

Thanks i will try and make a collisions class and mapHandler class