use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.
the class Door method anyEntities.
boolean anyEntities(Tile tile) {
int x = tile.x, y = tile.y;
Block type = tile.block();
rect.setSize(type.width * tilesize, type.height * tilesize);
rect.setCenter(tile.drawx(), tile.drawy());
for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if (this.rect.overlaps(rect)) {
return true;
}
}
for (SolidEntity e : Entities.getNearby(playerGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if (this.rect.overlaps(rect)) {
return true;
}
}
return false;
}
use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.
the class Placement method validPlace.
public static boolean validPlace(int x, int y, Block type) {
for (int i = 0; i < world.getSpawns().size; i++) {
SpawnPoint spawn = world.getSpawns().get(i);
if (Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace) {
return false;
}
}
Recipe recipe = Recipes.getByResult(type);
if (recipe == null || !state.inventory.hasItems(recipe.requirements)) {
return false;
}
rect.setSize(type.width * tilesize, type.height * tilesize);
Vector2 offset = type.getPlaceOffset();
rect.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
synchronized (Entities.entityLock) {
for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
// not sure why this happens?
if (e == null)
continue;
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if (Placement.rect.overlaps(rect)) {
return false;
}
}
}
if (type.solid || type.solidifes) {
for (Player player : playerGroup.all()) {
if (!player.isAndroid && rect.overlaps(player.hitbox.getRect(player.x, player.y))) {
return false;
}
}
}
Tile tile = world.tile(x, y);
if (tile == null || (isSpawnPoint(tile) && (type.solidifes || type.solid)))
return false;
if (type.isMultiblock()) {
int offsetx = -(type.width - 1) / 2;
int offsety = -(type.height - 1) / 2;
for (int dx = 0; dx < type.width; dx++) {
for (int dy = 0; dy < type.height; dy++) {
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if (other == null || (other.block() != Blocks.air && !other.block().alwaysReplace) || isSpawnPoint(other)) {
return false;
}
}
}
return true;
} else {
return tile.block() != type && (type.canReplace(tile.block()) || tile.block().alwaysReplace) && tile.block().isMultiblock() == type.isMultiblock() || tile.block() == Blocks.air;
}
}
use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.
the class DamageArea method damage.
public static void damage(boolean enemies, float x, float y, float radius, int damage) {
Consumer<SolidEntity> cons = entity -> {
DestructibleEntity enemy = (DestructibleEntity) entity;
if (enemy.distanceTo(x, y) > radius || (entity instanceof Player && ((Player) entity).isAndroid)) {
return;
}
int amount = calculateDamage(x, y, enemy.x, enemy.y, radius, damage);
enemy.damage(amount);
};
if (enemies) {
Entities.getNearby(enemyGroup, x, y, radius * 2, cons);
} else {
int trad = (int) (radius / tilesize);
for (int dx = -trad; dx <= trad; dx++) {
for (int dy = -trad; dy <= trad; dy++) {
Tile tile = world.tile(Mathf.scl2(x, tilesize) + dx, Mathf.scl2(y, tilesize) + dy);
if (tile != null && tile.entity != null && Vector2.dst(dx, dy, 0, 0) <= trad) {
int amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
tile.entity.damage(amount);
}
}
}
Entities.getNearby(playerGroup, x, y, radius * 2, cons);
}
}
use of io.anuke.ucore.entities.SolidEntity in project Mindustry by Anuken.
the class TeslaOrb method shock.
void shock() {
float stopchance = 0.1f;
float curx = x, cury = y;
float shake = 3f;
int max = 7;
while (points.size < max) {
if (Mathf.chance(stopchance)) {
break;
}
Array<SolidEntity> enemies = Entities.getNearby(enemyGroup, curx, cury, range * 2f);
for (SolidEntity entity : enemies) {
if (entity != null && entity.distanceTo(curx, cury) < range && !hit.contains((Enemy) entity)) {
hit.add((Enemy) entity);
points.add(new Vector2(entity.x + Mathf.range(shake), entity.y + Mathf.range(shake)));
damageEnemy((Enemy) entity);
curx = entity.x;
cury = entity.y;
break;
}
}
}
if (points.size == 0) {
remove();
}
}
Aggregations