I have 2 classes in my game, the PlayStateController (InputHandler basically) and the MapController. At first, they were pretty well encapsulated, but as my project has advanced, they have all become so intertwined together that they almost seem like they belong in the same class file now. Many of their major functions are extremely dependent on using getters/setters to pass information to each other.
Here’s an example, in my PlayStateController, I handle my “floating” camera by detecting the player’s X and Y on the screen and sending a set statement to the MapController:
public void update(MapController mapCtrl, GameContainer gc, StateBasedGame sbg, PlayState play) throws SlickException{
if(!(controlLockout)){randomEncounter(sbg);}
if(!(Math.abs(mapCtrl.getMapY()) >= (Math.abs(mapCtrl.getMapHeight()*32)-(gc.getHeight()/3)-10))){
if(playerY > (gc.getHeight()/3)-140){
if(playerY > (gc.getHeight()/3)-120){
mapCtrl.setMapY(mapCtrl.getMapY()-2);
playerY -= 2;
}else{
mapCtrl.setMapY(mapCtrl.getMapY()-1);
playerY -= 1;
}
}
}
…and then, within the MapController I find myself doing this, using a getter that in itself relies on other classes (in this case the PlayStateController class) to gather data to send it to whatever is requesting it:
EDIT: Clarification, the second code example isnt actually a getStatement, it’s something used internally in the MapController to process mathmatics to figure out how to render only the section of the ma visible on screen…
//Top left corner to start drawing the map.
public int mapDrawStartX(PlayStateController ctrl){return (mapX+((Math.round(ctrl.getPlayerX()-mapX+16)/32-16)*32));}
public int mapDrawStartY(PlayStateController ctrl){return (mapY+((Math.round(ctrl.getPlayerY()-mapY+16)/32-16)*32));}
//Bottom right corner to end drawing the map.
public int mapTileStartX(PlayStateController ctrl){return (Math.round(ctrl.getPlayerX()-mapX+16)/32-16);}
public int mapTileStartY(PlayStateController ctrl){return (Math.round(ctrl.getPlayerY()-mapY+16)/32-16);}
So my question is, are these signs I should just merge the 2 classes together? They talk to each other so much they’re both basically useless without the other.