Skip to content

Commit

Permalink
Completed feature: Ledges are now feature complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommai78101 committed Mar 28, 2014
1 parent ae5b93b commit 930cfcf
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 125 deletions.
Binary file modified bin/entity/Player.class
Binary file not shown.
Binary file modified bin/level/Area.class
Binary file not shown.
Binary file modified bin/level/OverWorld.class
Binary file not shown.
Binary file modified bin/level/PixelData.class
Binary file not shown.
Binary file modified bin/level/WorldConstants.class
Binary file not shown.
Binary file modified bin/resources/Art.class
Binary file not shown.
Binary file modified res/area/test/testArea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/area/test/testArea_debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 28 additions & 1 deletion src/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,39 @@ public void setLockJumping(int red, int green, int blue, int from, int to) {
if (from == to)
throw new IllegalArgumentException("The parameters, from and to, must not be the same.");
switch (red) {
case 0x00: //Horizontal bottom
case 0x00: //Bottom
//this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = true;
this.facingsBlocked[DOWN] = this.facingsBlocked[LEFT] = this.facingsBlocked[RIGHT] = true;
this.facingsBlocked[UP] = false;
this.lockJumping = true;
break;
case 0x01: //Bottom Left
this.facingsBlocked[DOWN] = this.facingsBlocked[LEFT] = this.facingsBlocked[RIGHT] = this.facingsBlocked[UP] = true;
break;
case 0x02: //Left
this.facingsBlocked[DOWN] = this.facingsBlocked[LEFT] = this.facingsBlocked[UP] = true;
this.facingsBlocked[RIGHT] = false;
this.lockJumping = true;
break;
case 0x03: //Top Left
this.facingsBlocked[DOWN] = this.facingsBlocked[LEFT] = this.facingsBlocked[RIGHT] = this.facingsBlocked[UP] = true;
break;
case 0x04: //Top
this.facingsBlocked[UP] = this.facingsBlocked[LEFT] = this.facingsBlocked[RIGHT] = true;
this.facingsBlocked[DOWN] = false;
this.lockJumping = true;
break;
case 0x05: //Top Right
this.facingsBlocked[DOWN] = this.facingsBlocked[LEFT] = this.facingsBlocked[RIGHT] = this.facingsBlocked[UP] = true;
break;
case 0x06: //Right
this.facingsBlocked[DOWN] = this.facingsBlocked[UP] = this.facingsBlocked[RIGHT] = true;
this.facingsBlocked[LEFT] = false;
this.lockJumping = true;
break;
case 0x07: //Bottom Right
this.facingsBlocked[DOWN] = this.facingsBlocked[LEFT] = this.facingsBlocked[RIGHT] = this.facingsBlocked[UP] = true;
break;
default: //Any other tiles should not cause the player to jump.
this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = true;
this.lockJumping = false;
Expand Down
101 changes: 48 additions & 53 deletions src/level/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,13 @@ public void tick() {
if (!this.player.isLockedWalking()) {
xPlayerPosition = player.getXInArea();
yPlayerPosition = player.getYInArea();
//System.out.println("X: " + xPlayerPosition + " Y: " + yPlayerPosition);
if (xPlayerPosition < 0 || xPlayerPosition >= this.width || yPlayerPosition < 0 || yPlayerPosition >= this.height)
return;

//Another method of detecting obstacles: Find all currently blocking obstacles
// of each direction at the same time.
// PixelData data_up = null;
// PixelData data_down = null;
// PixelData data_left = null;
// PixelData data_right = null;

try {
// data_up = areaData.get(this.yPlayerPosition - 1).get(this.xPlayerPosition);
// data_down = areaData.get(this.yPlayerPosition + 1).get(this.xPlayerPosition);
// data_left = areaData.get(this.yPlayerPosition).get(this.xPlayerPosition - 1);
// data_right = areaData.get(this.yPlayerPosition).get(this.xPlayerPosition + 1);

//this.player.setAllBlockingDirections(checkData(data_up, 0, -1), checkData(data_down, 0, 1), checkData(data_left, -1, 0), checkData(data_right, 1, 0));
this.player.setAllBlockingDirections(checkSurroundingData(0, -1), checkSurroundingData(0, 1), checkSurroundingData(-1, 0), checkSurroundingData(1, 0));
}
catch (Exception e) {
//this.player.setAllBlockingDirections(checkData(data_up, 0, -1), checkData(data_down, 0, 1), checkData(data_left, -1, 0), checkData(data_right, 1, 0));
this.player.setAllBlockingDirections(checkSurroundingData(0, -1), checkSurroundingData(0, 1), checkSurroundingData(-1, 0), checkSurroundingData(1, 0));
}

Expand All @@ -112,13 +97,6 @@ else if (!this.player.isLockedJumping() && this.player.isLockedWalking()) {
if (xPlayerPosition < 0 || xPlayerPosition >= this.width || yPlayerPosition < 0 || yPlayerPosition >= this.height)
return;
this.currentPixelData = areaData.get(this.yPlayerPosition).get(xPlayerPosition);
// int pixel = this.currentPixelData.getColor();
// int red = (pixel >> 16) & 0xFF;
// int green = (pixel >> 8) & 0xFF;
// int blue = pixel & 0xFF;
// if (blue == 0xDD) {
// this.player.setLockJumping(red, green, blue, Player.UP, Player.DOWN);
// }
this.checkCurrentPositionDataAndSetProperties();
}
else {
Expand All @@ -139,14 +117,32 @@ private void checkCurrentPositionDataAndSetProperties() {
int alpha = (pixel >> 24) & 0xFF;
int red = (pixel >> 16) & 0xFF;
int green = (pixel >> 8) & 0xFF;
int blue = pixel & 0xFF;
switch (alpha) {
case 0x02: //Ledges
{
switch (red) {
case 0x00: //Horizontal bottom
int blue = pixel & 0xFF;
case 0x00: //Bottom
this.player.setLockJumping(red, green, blue, Player.UP, Player.DOWN);
break;
case 0x01: //Bottom Left
//this.player.setLockJumping(red, green, blue, Player.UP, Player.DOWN);
break;
case 0x02: //left
this.player.setLockJumping(red, green, blue, Player.RIGHT, Player.LEFT);
break;
case 0x03: //top left
break;
case 0x04: //top
this.player.setLockJumping(red, green, blue, Player.DOWN, Player.UP);
break;
case 0x05: //top right
break;
case 0x06: //right
this.player.setLockJumping(red, green, blue, Player.LEFT, Player.RIGHT);
break;
case 0x07: //bottom right
break;
default:
break;
}
Expand Down Expand Up @@ -206,11 +202,38 @@ private boolean checkSurroundingData(int xOffset, int yOffset) {
{
switch (red) {
//TODO: Add the other ledges.
case 0x00: //Horizontal Bottom
case 0x00: { //Bottom
int y = this.yPlayerPosition + yOffset;
if (this.yPlayerPosition < y)
return false;
return true;
}
case 0x01: //Bottom Left
return true;
case 0x02: {//Left
int x = this.xPlayerPosition + xOffset;
if (this.xPlayerPosition < x)
return false;
return true;
}
case 0x03: //Top Left
return true;
case 0x04: {//Top
int y = this.yPlayerPosition + yOffset;
if (this.yPlayerPosition > y)
return false;
return true;
}
case 0x05: //Top Right
return true;
case 0x06: { //Right
int x = this.xPlayerPosition + xOffset;
if (this.xPlayerPosition > x)
return false;
return true;
}
case 0x07: //Bottom Right
return true;
}
break;
}
Expand All @@ -226,21 +249,6 @@ private boolean checkSurroundingData(int xOffset, int yOffset) {
}
}
return true;
// int red = (data.getColor() >> 16) & 0xFF;
// if (red == 0x04) {
// this.isInWarpZone = true;
// return false;
// }
//
// //B
// //This goes with A. (30 lines up above.)
// int green = (pixel >> 8) & 0xFF;
// int blue = pixel & 0xFF;
//
// //Determine ledges (horizontal)
// if (blue == 0xDD) {
// this.player.setLockJumping(red, green, blue, Player.UP, Player.DOWN);
// }
}

public void renderTiles(BaseScreen screen, int xOff, int yOff) {
Expand Down Expand Up @@ -274,19 +282,6 @@ public void setDebugDefaultPosition() {
}

public void setDefaultPosition(PixelData data) {
// PixelData targetData = null;
// if (data.isWarpZoneEnabled()) {
// LOOP_BREAK_Area_setDefaultPosition_1: for (ArrayList<PixelData> list : this.areaData) {
// for (PixelData p : list) {
// if (((p.getColor() & 0xFF0000) >> 16) == 0x7F) {
// targetData = p;
// break LOOP_BREAK_Area_setDefaultPosition_1;
// }
// }
// }
// this.player.setAreaPosition(targetData.xPosition, targetData.yPosition);
// }

int color = data.getColor();
int alpha = (color >> 24) & 0xFF;
switch (alpha) {
Expand Down
2 changes: 1 addition & 1 deletion src/level/OverWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public OverWorld(Player player) {
this.player = player;

//Going to set this area as test default only. This will need to change in the future.
this.currentArea = this.areas.get(0);
this.currentArea = this.areas.get(4);
this.currentArea.setPlayer(player);
this.currentArea.setDebugDefaultPosition();
this.currentAreaSectorID = 1;
Expand Down
106 changes: 36 additions & 70 deletions src/level/PixelData.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ public PixelData(int pixel, int x, int y) {
prepareBitmap(alpha, red, green, blue);
}

// public void setAsWarpZone(int targetArea,) {
// //Enabled by default.
// //this.parentArea = parentArea;
// this.targetArea = targetArea;
// this.isWarpZone = true;
// }

public void disableWarpZone() {
this.isWarpZone = false;
}
Expand All @@ -72,53 +65,39 @@ public boolean isWarpZoneEnabled() {
}

public void prepareBitmap(int alpha, int red, int green, int blue) {
//This is the only way to separate warp zones from regular tiles.
// if (this.isWarpZone) {
// //Default implementation of the warp zone tile bitmap.
// this.bitmap = null;
// //If Area ID is 0 ~ 15, then it's a forest type area.
// if ((this.parentArea & 0xF) < 0x10)
// this.bitmap = Art.forestEntrance;
// return;
// }

//Tiles only.
//Check the documentation for official implementation.
// switch (color) {
// case 0xFFFF0000:
// this.bitmap = Art.grass;
// break;
// case 0xFF0000DD:
// //Green values determine the orientation.
// //Red values determine the type (Mountain rock climb trails, plain ledge, bicycle ledges etc.)
// this.bitmap = Art.ledge_horizontal;
// break;
// case 0xFF0000AA:
// this.bitmap = Art.smallTree;
// break;
// default:
// this.bitmap = Art.grass;
// break;
// }
switch (alpha) {
case 0x01: //Flat grass
this.bitmap = Art.grass;
break;
case 0x02: //Ledge
{
switch (red) {
case 0x00: //Horizontal Bottom
case 0x00: //Bottom
this.bitmap = Art.ledge_bottom;
break;
case 0x01: //Bottom left
this.bitmap = Art.ledge_bottom_left;
break;
case 0x02: //Left
this.bitmap = Art.ledge_left;
case 0x02: //Right
//DEBUG: Understand why the game thinks it's the other way around.
this.bitmap = Art.ledge_right;
break;
case 0x03: //Top Left
this.bitmap = Art.ledge_top_left;
break;
case 0x04: //Top
this.bitmap = Art.ledge_top;
break;
case 0x05: //Top Right
this.bitmap = Art.ledge_top_right;
break;
case 0x06: //Left
//DEBUG: Left and right ledges are reversed. Find out why.
this.bitmap = Art.ledge_left;
break;
case 0x07: //Bottom Right
this.bitmap = Art.ledge_bottom_right;
break;
}
break;
}
Expand All @@ -143,37 +122,6 @@ public void setProperties(int alpha, int red, int green, int blue) {
//TODO: Refactor the code to make it more readable and more modular than if...elses.
this.targetArea = 0;
this.isWarpZone = false;

// if (r == 0x7F) {
// //Warp Zone
// //r: Parent Area
// //g: Target Area
//
// //TODO: Set orientations of the warp zone.
//
// this.parentArea = g;
// this.targetArea = b;
// this.isWarpZone = true;
// this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = true;
// return;
// }
// if (b == 0xDD) {
// //Ledges
// if (g == 0x00) {
// //Horizontal ledges - Jump from top
// this.facingsBlocked[Player.UP] = false;
// this.facingsBlocked[Player.DOWN] = true;
// this.facingsBlocked[Player.LEFT] = false;
// this.facingsBlocked[Player.RIGHT] = false;
// return;
// }
// return;
// }
// if (b == 0xAA) {
// //Trees
// this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = false;
// return;
// }
switch (alpha) {
case 0x01: //Grass
break;
Expand All @@ -189,12 +137,30 @@ public void setProperties(int alpha, int red, int green, int blue) {
this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = false;
break;
case 0x02: //Left
this.facingsBlocked[Player.UP] = false;
this.facingsBlocked[Player.DOWN] = false;
this.facingsBlocked[Player.LEFT] = true;
this.facingsBlocked[Player.RIGHT] = false;
break;
case 0x03: //Top left
this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = false;
break;
case 0x04: //Top
this.facingsBlocked[Player.UP] = true;
this.facingsBlocked[Player.DOWN] = false;
this.facingsBlocked[Player.LEFT] = false;
this.facingsBlocked[Player.RIGHT] = false;
break;
case 0x05: //Top Right
this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = false;
break;
case 0x06: //Right
this.facingsBlocked[Player.UP] = false;
this.facingsBlocked[Player.DOWN] = false;
this.facingsBlocked[Player.LEFT] = false;
this.facingsBlocked[Player.RIGHT] = true;
break;
case 0x03: //Top left
case 0x07: //Bottom Right
this.facingsBlocked[0] = this.facingsBlocked[1] = this.facingsBlocked[2] = this.facingsBlocked[3] = false;
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/level/WorldConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ private WorldConstants() {
public static final int TEST_WORLD_2 = 0x02;
public static final int TEST_WORLD_3 = 0x03;
public static final int TEST_WORLD_4 = 0x04;
public static final int DEBUG = 0x05;

// //Temporary double variable for all common usages.
// public static double tempDouble = 0.0;
Expand All @@ -34,6 +35,8 @@ public static Area convertToArea(int areaID) {
return new Area(Art.testArea3, TEST_WORLD_3);
case TEST_WORLD_4:
return new Area(Art.testArea4, TEST_WORLD_4);
case DEBUG:
return new Area(Art.testArea_debug, DEBUG);
default:
return null;
}
Expand All @@ -45,6 +48,7 @@ public static List<Area> getAllAreas() {
result.add(new Area(Art.testArea2, TEST_WORLD_2));
result.add(new Area(Art.testArea3, TEST_WORLD_3));
result.add(new Area(Art.testArea4, TEST_WORLD_4));
result.add(new Area(Art.testArea_debug, DEBUG));
return result;
}
}
Loading

0 comments on commit 930cfcf

Please sign in to comment.