use of com.badlogic.gdx.math.Rectangle in project Entitas-Java by Rubentxu.
the class MoveSystem method execute.
@Override
public void execute(float deltatime) {
for (CoreEntity e : _group.getEntities()) {
Motion motion = e.getMotion();
View view = e.getView();
if (view.shape instanceof Rectangle) {
Rectangle ret = (Rectangle) view.shape;
ret.setPosition(ret.x + motion.velocity.x * Gdx.graphics.getDeltaTime(), ret.y + motion.velocity.y * Gdx.graphics.getDeltaTime());
} else {
Circle circle = (Circle) view.shape;
circle.setPosition(circle.x + motion.velocity.x * Gdx.graphics.getDeltaTime(), circle.y + motion.velocity.y * Gdx.graphics.getDeltaTime());
}
}
}
use of com.badlogic.gdx.math.Rectangle in project AmazingMaze by TheVirtualMachine.
the class MazeScreen method createBoundingBoxes.
/** Create the bounding boxes for collision detection. */
private void createBoundingBoxes() {
obstacleBoxes = new Array<Rectangle>(false, 16);
TiledMapTileLayer objects = (TiledMapTileLayer) map.getLayers().get(MapFactory.OBJECT_LAYER);
for (int r = 0; r < mapHeight; r++) {
for (int c = 0; c < mapWidth; c++) {
Cell cell = objects.getCell(c, r);
if (cell != null) {
obstacleBoxes.add(new Rectangle(c, r, 1, 1));
}
}
}
wireBoxes = new Array<Rectangle>(false, 16);
TiledMapTileLayer wires = (TiledMapTileLayer) map.getLayers().get(MapFactory.WIRE_LAYER);
for (int r = 0; r < mapHeight; r++) {
for (int c = 0; c < mapWidth; c++) {
WireCell wire = (WireCell) wires.getCell(c, r);
if (wire != null && wire.isOn()) {
wireBoxes.add(new Rectangle(c + 5f / 16f, r, 6f / 16f, 1));
}
}
}
fishBoxes = new Array<Rectangle>(false, 16);
cheeseBoxes = new Array<Rectangle>(false, 16);
TiledMapTileLayer items = (TiledMapTileLayer) map.getLayers().get(MapFactory.ITEM_LAYER);
for (int r = 0; r < mapHeight; r++) {
for (int c = 0; c < mapWidth; c++) {
Cell item = items.getCell(c, r);
if (item != null) {
if (item.getClass() == FishCell.class) {
fishBoxes.add(new Rectangle(c, r, 1, 1));
} else {
cheeseBoxes.add(new Rectangle(c, r, 1, 1));
}
}
}
}
}
use of com.badlogic.gdx.math.Rectangle in project AmazingMaze by TheVirtualMachine.
the class Player method collectFish.
/** Handle the player collecting fish. */
private void collectFish() {
Rectangle thisBox = getBoundingRectangle();
for (int i = 0; i < maze.fishBoxes.size; i++) {
if (thisBox.overlaps(maze.fishBoxes.get(i))) {
TiledMapTileLayer layer = (TiledMapTileLayer) maze.map.getLayers().get(MapFactory.ITEM_LAYER);
int x = (int) maze.fishBoxes.get(i).x;
int y = (int) maze.fishBoxes.get(i).y;
FishColour colour = ((FishCell) layer.getCell(x, y)).getColour();
layer.setCell(x, y, null);
maze.fishBoxes.removeIndex(i);
switch(colour) {
case BLUE:
blueCollected++;
break;
case PURPLE:
purpleCollected++;
break;
case GREEN:
greenCollected++;
break;
case RED:
redCollected++;
break;
case ORANGE:
orangeCollected++;
break;
}
break;
}
}
}
use of com.badlogic.gdx.math.Rectangle in project AmazingMaze by TheVirtualMachine.
the class Player method collectCheese.
/** Handle the player collecting cheese. */
private void collectCheese() {
Rectangle thisBox = getBoundingRectangle();
for (int i = 0; i < maze.cheeseBoxes.size; i++) {
if (thisBox.overlaps(maze.cheeseBoxes.get(i))) {
TiledMapTileLayer layer = (TiledMapTileLayer) maze.map.getLayers().get(MapFactory.ITEM_LAYER);
int x = (int) maze.cheeseBoxes.get(i).x;
int y = (int) maze.cheeseBoxes.get(i).y;
layer.setCell(x, y, null);
maze.cheeseBoxes.removeIndex(i);
lives++;
maze.updateLives(-1);
break;
}
}
}
use of com.badlogic.gdx.math.Rectangle in project AmazingMaze by TheVirtualMachine.
the class Player method doObjectCollision.
/**
* Return where the player should be after handling object collision.
*
* @param deltaPos the change in position since the last position update.
* @return the new position, as a {@link Point2D.Float}.
*/
private Point2D.Float doObjectCollision(Vector2 deltaPos) {
float newX = getX() + deltaPos.x;
float newY = getY() + deltaPos.y;
Point2D.Float nextTilePos = new Point2D.Float(newX, newY);
Rectangle nextBoundingBox = new Rectangle(nextTilePos.x, nextTilePos.y, PLAYER_SIZE, PLAYER_SIZE);
float nextStartX = nextBoundingBox.getX();
float nextEndX = nextStartX + nextBoundingBox.getWidth();
float nextStartY = nextBoundingBox.getY();
float nextEndY = nextStartY + nextBoundingBox.getHeight();
for (Rectangle obstacle : maze.obstacleBoxes) {
if (nextBoundingBox.overlaps(obstacle)) {
float objectStartX = obstacle.getX();
float objectEndX = objectStartX + obstacle.getWidth();
float objectStartY = obstacle.getY();
float objectEndY = objectStartY + obstacle.getHeight();
if (deltaPos.x != 0) {
if (nextStartX > objectStartX && nextStartX < objectEndX) {
// Collided on right.
newX = objectEndX;
} else if (nextEndX > objectStartX && nextEndX < objectEndX) {
// Collided on left.
newX = objectStartX - PLAYER_SIZE;
}
} else if (deltaPos.y != 0) {
if (nextStartY > objectStartY && nextStartY < objectEndY) {
// Collided on bottom.
newY = objectEndY;
} else if (nextEndY > objectStartY && nextEndY < objectEndY) {
// Collided on top.
newY = objectStartY - PLAYER_SIZE;
}
}
}
}
newX = Math.max(newX, 0);
newX = Math.min(newX, maze.mapWidth - PLAYER_SIZE);
nextTilePos.setLocation(newX, newY);
return nextTilePos;
}
Aggregations