Skip to content

Commit

Permalink
Enemies no longer go over holes
Browse files Browse the repository at this point in the history
  • Loading branch information
antionio committed Nov 30, 2013
1 parent 6a4e558 commit fb0304b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.sturdyhelmetgames.roomforchange.entity;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.sturdyhelmetgames.roomforchange.RandomUtil;
import com.sturdyhelmetgames.roomforchange.assets.Assets;
import com.sturdyhelmetgames.roomforchange.level.Level;
import com.sturdyhelmetgames.roomforchange.level.Level.LevelTile;

public class Enemy extends Entity {

Expand Down Expand Up @@ -63,4 +65,66 @@ protected void fall() {
// do nothing
}

@Override
protected void fetchCollidableRects() {
int p1x = (int) bounds.x;
int p1y = (int) Math.floor(bounds.y);
int p2x = (int) (bounds.x + bounds.width);
int p2y = (int) Math.floor(bounds.y);
int p3x = (int) (bounds.x + bounds.width);
int p3y = (int) (bounds.y + bounds.height);
int p4x = (int) bounds.x;
int p4y = (int) (bounds.y + bounds.height);

try {
LevelTile tile1 = null;
if (level.getTiles().length >= p1x && p1x >= 0
&& level.getTiles()[p1x].length >= p1y && p1y >= 0)
tile1 = level.getTiles()[p1x][p1y];
LevelTile tile2 = null;
if (level.getTiles().length >= p2x && p1x >= 0
&& level.getTiles()[p2x].length >= p2y && p2y >= 0)
tile2 = level.getTiles()[p2x][p2y];
LevelTile tile3 = null;
if (level.getTiles().length >= p3x && p3x >= 0
&& level.getTiles()[p3x].length >= p3y && p3y >= 0)
tile3 = level.getTiles()[p3x][p3y];
LevelTile tile4 = null;
if (level.getTiles().length >= p4x && p4x >= 0
&& level.getTiles()[p4x].length >= p4y && p4y >= 0)
tile4 = level.getTiles()[p4x][p4y];

holes[0].unset();
if (tile1 != null && (tile1.isCollidable() || tile1.isHole())) {
r[0].set(p1x, p1y, 1, 1);
} else {
r[0].set(-1, -1, 0, 0);
}

holes[1].unset();
if (tile2 != null && (tile2.isCollidable() || tile2.isHole())) {
r[1].set(p2x, p2y, 1, 1);
} else {
r[1].set(-1, -1, 0, 0);
}

holes[2].unset();
if (tile3 != null && (tile3.isCollidable() || tile3.isHole())) {
r[2].set(p3x, p3y, 1, 1);

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

holes[3].unset();
if (tile4 != null && (tile4.isCollidable() || tile4.isHole())) {
r[3].set(p4x, p4y, 1, 1);
} else {
r[3].set(-1, -1, 0, 0);
}
} catch (ArrayIndexOutOfBoundsException e) {
Gdx.app.log("Creature", "Creature went off screen");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Mummy extends Enemy {
public Mummy(float x, float y, Level level) {
super(x, y, 1f, 0.6f, level);
state = EntityState.WALKING;
health = 2;
health = 3;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Spider extends Enemy {

public Spider(float x, float y, Level level) {
super(x, y, 1f, 1f, level);
health = 3;
health = 1;
}

@Override
Expand Down

0 comments on commit fb0304b

Please sign in to comment.