Skip to content

Commit

Permalink
Player can no longer hit enemies if dead etc.
Browse files Browse the repository at this point in the history
Other tweaks and bugfix
  • Loading branch information
antionio committed Nov 30, 2013
1 parent dde19c9 commit bfddbf8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,42 +228,42 @@ protected void fetchCollidableRects() {
LevelTile tile3 = level.getTiles()[p3x][p3y];
LevelTile tile4 = level.getTiles()[p4x][p4y];

if (tile1.isHole())
if (tile1 != null && tile1.isHole())
holes[0].set(p1x + 0.4f, p1y + 0.5f, 0.2f, 0.05f);
else
holes[0].unset();
if (tile1.isCollidable()) {
if (tile1 != null && tile1.isCollidable()) {
r[0].set(p1x, p1y, 1, 1);
} else {
r[0].set(-1, -1, 0, 0);
}

if (tile2.isHole())
if (tile2 != null && tile2.isHole())
holes[1].set(p2x + 0.4f, p2y + 0.5f, 0.2f, 0.05f);
else
holes[1].unset();
if (tile2.isCollidable()) {
if (tile2 != null && tile2.isCollidable()) {
r[1].set(p2x, p2y, 1, 1);
} else {
r[1].set(-1, -1, 0, 0);
}

if (tile3.isHole())
if (tile3 != null && tile3.isHole())
holes[2].set(p3x + 0.4f, p3y + 0.5f, 0.2f, 0.05f);
else
holes[2].unset();
if (tile3.isCollidable()) {
if (tile3 != null && tile3.isCollidable()) {
r[2].set(p3x, p3y, 1, 1);

} else {
r[2].set(-1, -1, 0, 0);
}

if (tile4.isHole())
if (tile4 != null && tile4.isHole())
holes[3].set(p4x + 0.4f, p4y + 0.5f, 0.2f, 0.05f);
else
holes[3].unset();
if (tile4.isCollidable()) {
if (tile4 != null && tile4.isCollidable()) {
r[3].set(p4x, p4y, 1, 1);
} else {
r[3].set(-1, -1, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,39 +108,40 @@ public void update(float fixedStep) {
private final Rectangle leverRect = new Rectangle();

public void tryHit() {
tryHitTime = 0f;
hitBounds.x = bounds.x;
hitBounds.y = bounds.y;
if (direction == Direction.LEFT) {
hitBounds.x -= HIT_DISTANCE;
} else if (direction == Direction.RIGHT) {
hitBounds.x += HIT_DISTANCE;
} else if (direction == Direction.UP) {
hitBounds.y += HIT_DISTANCE;
} else if (direction == Direction.DOWN) {
hitBounds.y -= HIT_DISTANCE;
}

for (int i = 0; i < level.entities.size; i++) {
final Entity entity = level.entities.get(i);
entity.hit(hitBounds);
}
if (!isDying() && !isDead() && !isFalling()) {
tryHitTime = 0f;
hitBounds.x = bounds.x;
hitBounds.y = bounds.y;
if (direction == Direction.LEFT) {
hitBounds.x -= HIT_DISTANCE;
} else if (direction == Direction.RIGHT) {
hitBounds.x += HIT_DISTANCE;
} else if (direction == Direction.UP) {
hitBounds.y += HIT_DISTANCE;
} else if (direction == Direction.DOWN) {
hitBounds.y -= HIT_DISTANCE;
}

// double the hit distance for tiles
if (direction == Direction.LEFT) {
hitBounds.x -= HIT_DISTANCE;
} else if (direction == Direction.RIGHT) {
hitBounds.x += HIT_DISTANCE;
} else if (direction == Direction.UP) {
hitBounds.y += HIT_DISTANCE;
} else if (direction == Direction.DOWN) {
hitBounds.y -= HIT_DISTANCE;
}
for (int i = 0; i < level.entities.size; i++) {
final Entity entity = level.entities.get(i);
entity.hit(hitBounds);
}

tryHitLever((int) hitBounds.x, (int) hitBounds.y);
tryHitLever((int) hitBounds.x + 1, (int) hitBounds.y);
tryHitLever((int) hitBounds.x, (int) hitBounds.y + 1);
// double the hit distance for tiles
if (direction == Direction.LEFT) {
hitBounds.x -= HIT_DISTANCE;
} else if (direction == Direction.RIGHT) {
hitBounds.x += HIT_DISTANCE;
} else if (direction == Direction.UP) {
hitBounds.y += HIT_DISTANCE;
} else if (direction == Direction.DOWN) {
hitBounds.y -= HIT_DISTANCE;
}

tryHitLever((int) hitBounds.x, (int) hitBounds.y);
tryHitLever((int) hitBounds.x + 1, (int) hitBounds.y);
tryHitLever((int) hitBounds.x, (int) hitBounds.y + 1);
}
}

private void tryHitLever(int x, int y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void renderScreen(float delta) {
spriteBatch.begin();

spriteBatch
.draw(Assets.getFullGameObject("gameover"), -4f, -2f, 8f, 4f);
.draw(Assets.getFullGameObject("gameover"), -2f, -1f, 4f, 2f);
spriteBatch.end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void renderScreen(float delta) {
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();

spriteBatch.draw(Assets.getFullGameObject("help"), -4f, -2f, 8f, 4f);
spriteBatch.draw(Assets.getFullGameObject("help"), -2f, -1f, 4f, 2f);
spriteBatch.end();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void renderScreen(float delta) {
} else if (leverDirection == NEUTRAL) {
region = Assets.getFullGameObject("lever-neutral");
}
spriteBatch.draw(region, -2f, -2f, 4f, 4f);
spriteBatch.draw(region, -1f, -1f, 2f, 2f);
spriteBatch.end();
}

Expand Down

0 comments on commit bfddbf8

Please sign in to comment.