Skip to content

Commit

Permalink
Fixed elixir/wall bug, added isGround() function
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-j committed Nov 19, 2016
1 parent 419046b commit 2b4c445
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Score.txt
build/
*~
*#*

# Package Files #
*.jar
Expand Down
15 changes: 9 additions & 6 deletions src/edu/ucsb/cs56/projects/games/roguelike/LogicEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ public void move(int x,int y,int xOrig,int yOrig){
consumeItem(x,y);
}

floor[x][y] = floor[xOrig][yOrig];
floor[xOrig][yOrig] = null;
if (x != xOrig || y != yOrig) {
floor[x][y] = floor[xOrig][yOrig];
floor[xOrig][yOrig] = null;
}

int[] position = {x,y};
if(floor[x][y] instanceof Player) {
Expand Down Expand Up @@ -237,10 +239,11 @@ public boolean movable(int x,int y,int xOrig, int yOrig){
}

public boolean inBounds(int x, int y) {
if ((x < 1 || x >= floorWidth - 1) || (y < 1 || y >= floorHeight - 1))
return false;
else
return true;
return !((x < 1 || x >= floorWidth - 1) || (y < 1 || y >= floorHeight - 1));
}

public boolean isGround(int x, int y) {
return (inBounds(x,y));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/edu/ucsb/cs56/projects/games/roguelike/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Player implements GamePiece {
public Player(){
this.hitPoints = 100;
this.attack = 20;
this.speed = 1;
this.speed = 3;
this.score= 0;
this.setTypeOfPiece("player");
this.setIcon('@');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ public void moveHero(){
// }
// canvas.moveHeroAnimated(x, y,logicHandler.getPlayer().getHitPoints(),logicHandler.getPlayer().getScore());

while (!logicHandler.isGround(x, y)) {
if (x != origX)
x = (x > origX) ? x-1 : x+1;
else if (y != origY)
y = (y > origY) ? y-1 : y+1;
}

//Draws all items even when the player tries to move outside the boundaries
//Draws all items even when the player tries to move outside the boundaries
drawAllItems();
if ( logicHandler.movable(x,y,origX, origY)) {
logicHandler.move(x,y,origX,origY);
Expand Down

0 comments on commit 2b4c445

Please sign in to comment.