Set view boundaries between room areas to prevent bleeding screens between each other

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent 77f078693a
commit 62e2c75f00
  1. BIN
      bin/RabiClone.jar
  2. BIN
      maps/world1.map
  3. 2
      src/sig/map/Maps.java
  4. 1
      src/sig/map/View.java
  5. 77
      src/sig/objects/Player.java

Binary file not shown.

Binary file not shown.

@ -41,7 +41,7 @@ public enum Maps {
public View getView(int x,int y) {
int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X;
if (index<0||index>=this.map.views.length) {
return View.DIRECT_FOLLOW;
return View.FIXED;
} else {
return View.values()[this.map.views[index]];
}

@ -1,7 +1,6 @@
package sig.map;
public enum View {
DIRECT_FOLLOW, //Follows the player directly.
LIGHT_FOLLOW,
// Follows the player loosely, but makes sure there's
// still a border between the edge of the screen and the player.

@ -36,6 +36,7 @@ public class Player extends Object{
final double viewBoundaryX=RabiClone.BASE_WIDTH/3;
final double viewBoundaryY=RabiClone.BASE_HEIGHT/3;
View lastCameraView = View.FIXED;
public Player(Panel panel) {
super(panel);
@ -55,45 +56,85 @@ public class Player extends Object{
private void handleCameraRoomMovement() {
int tileX = (int)(getX())/Tile.TILE_WIDTH;
int tileY = (int)(getY())/Tile.TILE_HEIGHT;
double newX=RabiClone.level_renderer.getX(),newY=RabiClone.level_renderer.getY(); //By default we use a fixed view.
View currentView = RabiClone.CURRENT_MAP.getView(tileX, tileY);
if (currentView!=lastCameraView) {
lastCameraView=currentView;
newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH;
newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT;
}
switch (currentView) {
case DIRECT_FOLLOW:
RabiClone.level_renderer.setX(getX()-RabiClone.BASE_WIDTH/2);
RabiClone.level_renderer.setY(getY()-RabiClone.BASE_HEIGHT/2);
break;
case FIXED:
RabiClone.level_renderer.setX((tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH);
RabiClone.level_renderer.setY((tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT);
break;
case LIGHT_FOLLOW:
if (getX()-RabiClone.level_renderer.getX()<viewBoundaryX) {
RabiClone.level_renderer.setX(getX()-viewBoundaryX);
newX=getX()-viewBoundaryX;
int newTileX = (int)(newX)/Tile.TILE_WIDTH;
View newView = RabiClone.CURRENT_MAP.getView(newTileX, tileY);
if (newView!=currentView) {
newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH;
}
} else if (getX()-RabiClone.level_renderer.getX()>RabiClone.BASE_WIDTH-viewBoundaryX) {
RabiClone.level_renderer.setX(getX()-(RabiClone.BASE_WIDTH-viewBoundaryX));
newX=getX()-(RabiClone.BASE_WIDTH-viewBoundaryX);
int newTileX = (int)(getX()+viewBoundaryX)/Tile.TILE_WIDTH;
View newView = RabiClone.CURRENT_MAP.getView(newTileX, tileY);
if (newView!=currentView) {
newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH;
}
}
if (getY()-RabiClone.level_renderer.getY()<viewBoundaryY) {
RabiClone.level_renderer.setY(getY()-viewBoundaryY);
newY=getY()-viewBoundaryY;
int newTileY = (int)(getY()-viewBoundaryY)/Tile.TILE_HEIGHT;
View newView = RabiClone.CURRENT_MAP.getView(tileX, newTileY);
if (newView!=currentView) {
newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT;
}
} else if (getY()-RabiClone.level_renderer.getY()>RabiClone.BASE_HEIGHT-viewBoundaryY) {
RabiClone.level_renderer.setY(getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY));
newY=getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY);
int newTileY = (int)(getY()+viewBoundaryY)/Tile.TILE_HEIGHT;
View newView = RabiClone.CURRENT_MAP.getView(tileX, newTileY);
if (newView!=currentView) {
newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT;
}
}
break;
case LIGHT_HORIZONTAL_FOLLOW:
if (getX()-RabiClone.level_renderer.getX()<viewBoundaryX) {
RabiClone.level_renderer.setX(getX()-viewBoundaryX);
newX=getX()-viewBoundaryX;
int newTileX = (int)(newX)/Tile.TILE_WIDTH;
View newView = RabiClone.CURRENT_MAP.getView(newTileX, tileY);
if (newView!=currentView) {
newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH;
}
} else if (getX()-RabiClone.level_renderer.getX()>RabiClone.BASE_WIDTH-viewBoundaryX) {
RabiClone.level_renderer.setX(getX()-(RabiClone.BASE_WIDTH-viewBoundaryX));
newX=getX()-(RabiClone.BASE_WIDTH-viewBoundaryX);
int newTileX = (int)(getX()+viewBoundaryX)/Tile.TILE_WIDTH;
View newView = RabiClone.CURRENT_MAP.getView(newTileX, tileY);
if (newView!=currentView) {
newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH;
}
}
RabiClone.level_renderer.setY((tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT);
newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT;
break;
case LIGHT_VERTICAL_FOLLOW:
RabiClone.level_renderer.setX((tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH);
newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH;
if (getY()-RabiClone.level_renderer.getY()<viewBoundaryY) {
RabiClone.level_renderer.setY(getY()-viewBoundaryY);
newY=getY()-viewBoundaryY;
int newTileY = (int)(getY()-viewBoundaryY)/Tile.TILE_HEIGHT;
View newView = RabiClone.CURRENT_MAP.getView(tileX, newTileY);
if (newView!=currentView) {
newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT;
}
} else if (getY()-RabiClone.level_renderer.getY()>RabiClone.BASE_HEIGHT-viewBoundaryY) {
RabiClone.level_renderer.setY(getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY));
newY=getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY);
int newTileY = (int)(getY()+viewBoundaryY)/Tile.TILE_HEIGHT;
View newView = RabiClone.CURRENT_MAP.getView(tileX, newTileY);
if (newView!=currentView) {
newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT;
}
}
break;
}
RabiClone.level_renderer.setX(newX);
RabiClone.level_renderer.setY(newY);
}

Loading…
Cancel
Save