use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class AndroidInput method breakBlock.
public void breakBlock() {
Tile tile = selected();
breaktime += Timers.delta();
if (breaktime >= tile.block().breaktime) {
brokeBlock = true;
breakBlock(tile.x, tile.y, true);
breaktime = 0f;
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class AndroidInput method touchDown.
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (ui.hasMouse()) {
brokeBlock = true;
return false;
}
lmousex = screenX;
lmousey = screenY;
if ((!placeMode.pan || breaking()) && pointer == 0) {
mousex = screenX;
mousey = screenY;
}
placing = pointer == 0;
warmup = 0;
if (!state.is(State.menu)) {
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
if (cursor != null && !ui.hasMouse(screenX, screenY)) {
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
if (linked != null && linked.block().isConfigurable(linked)) {
ui.configfrag.showConfig(linked);
} else if (!ui.configfrag.hasConfigMouse()) {
ui.configfrag.hideConfig();
}
if (linked != null) {
linked.block().tapped(linked);
if (Net.active())
NetEvents.handleBlockTap(linked);
}
}
}
return false;
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class AndroidInput method update.
@Override
public void update() {
enableHold = breakMode == PlaceMode.holdDelete;
float xa = Inputs.getAxis("move_x");
float ya = Inputs.getAxis("move_y");
if (Math.abs(xa) < controllerMin)
xa = 0;
if (Math.abs(ya) < controllerMin)
ya = 0;
player.x += xa * 4f;
player.y += ya * 4f;
rotation += Inputs.getAxis("rotate_alt");
rotation += Inputs.getAxis("rotate");
rotation = Mathf.mod(rotation, 4);
if (enableHold && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.scl(50)) && !ui.hasMouse()) {
warmup += Timers.delta();
float lx = mousex, ly = mousey;
mousex = Gdx.input.getX(0);
mousey = Gdx.input.getY(0);
Tile sel = selected();
if (sel == null)
return;
if (warmup > warmupDelay && validBreak(sel.x, sel.y)) {
breaktime += Timers.delta();
if (breaktime > selected().block().breaktime) {
breakBlock();
breaktime = 0;
}
}
mousex = lx;
mousey = ly;
} else {
warmup = 0;
breaktime = 0;
mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());
mousey = Mathf.clamp(mousey, 0, Gdx.graphics.getHeight());
}
}
use of io.anuke.mindustry.world.Tile 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.mindustry.world.Tile in project Mindustry by Anuken.
the class EnemyType method update.
public void update(Enemy enemy) {
float lastx = enemy.x, lasty = enemy.y;
if (enemy.hitTime > 0) {
enemy.hitTime -= Timers.delta();
}
if (enemy.lane >= world.getSpawns().size || enemy.lane < 0)
enemy.lane = 0;
boolean waiting = enemy.lane >= world.getSpawns().size || enemy.lane < 0 || world.getSpawns().get(enemy.lane).pathTiles == null || enemy.node <= 0;
move(enemy);
enemy.velocity.set(enemy.x - lastx, enemy.y - lasty).scl(1f / Timers.delta());
enemy.totalMove.add(enemy.velocity);
float minv = 0.07f;
if (enemy.timer.get(timerReset, 80)) {
enemy.totalMove.setZero();
}
if (enemy.velocity.len() < minv && !waiting && enemy.target == null) {
enemy.idletime += Timers.delta();
} else {
enemy.idletime = 0;
}
if (enemy.timer.getTime(timerReset) > 50 && enemy.totalMove.len() < 0.2f && !waiting && enemy.target == null) {
enemy.idletime = 999999f;
}
Tile tile = world.tileWorld(enemy.x, enemy.y);
if (tile != null && tile.floor().liquid && tile.block() == Blocks.air) {
// drown
enemy.damage(enemy.health + 1);
}
if (Float.isNaN(enemy.angle)) {
enemy.angle = 0;
}
if (enemy.target == null || alwaysRotate) {
enemy.angle = Mathf.slerpDelta(enemy.angle, enemy.velocity.angle(), rotatespeed);
} else {
enemy.angle = Mathf.slerpDelta(enemy.angle, enemy.angleTo(enemy.target), turretrotatespeed);
}
enemy.x = Mathf.clamp(enemy.x, 0, world.width() * tilesize);
enemy.y = Mathf.clamp(enemy.y, 0, world.height() * tilesize);
}
Aggregations