use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Player method update.
@Override
public void update() {
if (!isLocal || isAndroid) {
if (isAndroid && isLocal) {
angle = Mathf.slerpDelta(angle, targetAngle, 0.2f);
}
if (!isLocal)
interpolate();
return;
}
if (isDead())
return;
Tile tile = world.tileWorld(x, y);
// if player is in solid block
if (tile != null && ((tile.floor().liquid && tile.block() == Blocks.air) || tile.solid())) {
// die instantly
damage(health + 1);
}
if (ui.chatfrag.chatOpen())
return;
dashing = Inputs.keyDown("dash");
float speed = dashing ? (debug ? Player.dashSpeed * 5f : Player.dashSpeed) : Player.speed;
if (health < maxhealth && timer.get(timerRegen, 20))
health++;
health = Mathf.clamp(health, -1, maxhealth);
movement.set(0, 0);
float xa = Inputs.getAxis("move_x");
float ya = Inputs.getAxis("move_y");
if (Math.abs(xa) < 0.3)
xa = 0;
if (Math.abs(ya) < 0.3)
ya = 0;
movement.y += ya * speed;
movement.x += xa * speed;
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.input().recipe == null && !ui.hasMouse() && !control.input().onConfigurable();
if (shooting) {
weaponLeft.update(player, true);
weaponRight.update(player, false);
}
if (dashing && timer.get(timerDash, 3) && movement.len() > 0) {
Effects.effect(Fx.dashsmoke, x + Angles.trnsx(angle + 180f, 3f), y + Angles.trnsy(angle + 180f, 3f));
}
movement.limit(speed);
if (!noclip) {
move(movement.x * Timers.delta(), movement.y * Timers.delta());
} else {
x += movement.x * Timers.delta();
y += movement.y * Timers.delta();
}
if (!shooting) {
if (!movement.isZero())
angle = Mathf.slerpDelta(angle, movement.angle(), 0.13f);
} else {
float angle = Angles.mouseAngle(x, y);
this.angle = Mathf.slerpDelta(this.angle, angle, 0.1f);
}
x = Mathf.clamp(x, 0, world.width() * tilesize);
y = Mathf.clamp(y, 0, world.height() * tilesize);
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class DesktopInput method update.
@Override
public void update() {
if (player.isDead())
return;
if (Inputs.keyRelease("select")) {
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}
if (Inputs.keyRelease("break") && !beganBreak) {
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}
if ((Inputs.keyTap("select") && recipe != null) || Inputs.keyTap("break")) {
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
mousex = vec.x;
mousey = vec.y;
}
if (!Inputs.keyDown("select") && !Inputs.keyDown("break")) {
mousex = Graphics.mouseWorld().x;
mousey = Graphics.mouseWorld().y;
}
endx = Gdx.input.getX();
endy = Gdx.input.getY();
boolean controller = KeyBinds.getSection("default").device.type == DeviceType.controller;
if (Inputs.getAxisActive("zoom") && (Inputs.keyDown("zoom_hold") || controller) && !state.is(State.menu) && !ui.hasDialog()) {
if ((!zoomed || !controller)) {
renderer.scaleCamera((int) Inputs.getAxis("zoom"));
}
zoomed = true;
} else {
zoomed = false;
}
if (!rotated) {
rotation += Inputs.getAxis("rotate_alt");
rotated = true;
}
if (!Inputs.getAxisActive("rotate_alt"))
rotated = false;
if (!rotatedAlt) {
rotation += Inputs.getAxis("rotate");
rotatedAlt = true;
}
if (!Inputs.getAxisActive("rotate"))
rotatedAlt = false;
rotation = Mathf.mod(rotation, 4);
if (Inputs.keyDown("break")) {
breakMode = PlaceMode.areaDelete;
} else {
breakMode = PlaceMode.hold;
}
for (int i = 1; i <= 6 && i <= control.upgrades().getWeapons().size; i++) {
if (Inputs.keyTap("weapon_" + i)) {
player.weaponLeft = player.weaponRight = control.upgrades().getWeapons().get(i - 1);
if (Net.active())
NetEvents.handleWeaponSwitch();
ui.hudfrag.updateWeapons();
}
}
Tile cursor = world.tile(tilex(), tiley());
Tile target = cursor == null ? null : cursor.isLinked() ? cursor.getLinked() : cursor;
boolean showCursor = false;
if (recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info") && target.block().fullDescription != null) {
showCursor = true;
if (Inputs.keyTap("select")) {
ui.hudfrag.blockfrag.showBlockInfo(target.block());
Cursors.restoreCursor();
}
}
if (target != null && target.block().isConfigurable(target)) {
showCursor = true;
}
if (target != null && Inputs.keyTap("select") && !ui.hasMouse()) {
if (target.block().isConfigurable(target)) {
ui.configfrag.showConfig(target);
} else if (!ui.configfrag.hasConfigMouse()) {
ui.configfrag.hideConfig();
}
target.block().tapped(target);
if (Net.active())
NetEvents.handleBlockTap(target);
}
if (Inputs.keyTap("break")) {
ui.configfrag.hideConfig();
}
if (Inputs.keyRelease("break")) {
beganBreak = false;
}
if (recipe != null && Inputs.keyTap("break")) {
beganBreak = true;
recipe = null;
}
// block breaking
if (enableHold && Inputs.keyDown("break") && cursor != null && validBreak(tilex(), tiley())) {
breaktime += Timers.delta();
if (breaktime >= cursor.getBreakTime()) {
breakBlock(cursor.x, cursor.y, true);
breaktime = 0f;
}
} else {
breaktime = 0f;
}
if (recipe != null) {
showCursor = validPlace(tilex(), tiley(), control.input().recipe.result) && control.input().cursorNear();
}
if (!ui.hasMouse()) {
if (showCursor)
Cursors.setHand();
else
Cursors.restoreCursor();
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Save12 method read.
@Override
public void read(DataInputStream stream) throws IOException {
/*long loadTime = */
stream.readLong();
// general state
byte mode = stream.readByte();
byte mapid = stream.readByte();
int wave = stream.readInt();
float wavetime = stream.readFloat();
float playerx = stream.readFloat();
float playery = stream.readFloat();
int playerhealth = stream.readInt();
Vars.player.x = playerx;
Vars.player.y = playery;
Vars.player.health = playerhealth;
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
// weapons
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
for (int i = 0; i < weapons; i++) {
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
ui.hudfrag.updateWeapons();
// inventory
int totalItems = stream.readByte();
Arrays.fill(state.inventory.getItems(), 0);
for (int i = 0; i < totalItems; i++) {
Item item = Item.getByID(stream.readByte());
int amount = stream.readInt();
state.inventory.getItems()[item.id] = amount;
}
ui.hudfrag.updateItems();
// enemies
Entities.clear();
int enemies = stream.readInt();
Array<Enemy> enemiesToUpdate = new Array<>();
for (int i = 0; i < enemies; i++) {
byte type = stream.readByte();
int lane = stream.readByte();
float x = stream.readFloat();
float y = stream.readFloat();
byte tier = stream.readByte();
int health = stream.readInt();
try {
Enemy enemy = new Enemy(EnemyType.getByID(type));
enemy.lane = lane;
enemy.health = health;
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add(enemyGroup);
enemiesToUpdate.add(enemy);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
if (!android)
Vars.player.add();
// map
int seed = stream.readInt();
int tiles = stream.readInt();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for (Enemy enemy : enemiesToUpdate) {
enemy.node = -2;
}
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
// remove breakables like rocks
if (tile.breakable()) {
world.tile(x, y).setBlock(Blocks.air);
}
}
}
for (int i = 0; i < tiles; i++) {
int pos = stream.readInt();
byte link = stream.readByte();
boolean hasEntity = stream.readBoolean();
int blockid = stream.readInt();
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(BlockLoader.getByOldID(blockid));
tile.link = link;
if (hasEntity) {
byte rotation = stream.readByte();
int health = stream.readInt();
int items = stream.readByte();
tile.entity.health = health;
tile.setRotation(rotation);
for (int j = 0; j < items; j++) {
int itemid = stream.readByte();
int itemamount = stream.readInt();
tile.entity.items[itemid] = itemamount;
}
tile.entity.read(stream);
}
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Save13 method write.
@Override
public void write(DataOutputStream stream) throws IOException {
// --META--
// version id
stream.writeInt(version);
// last saved
stream.writeLong(TimeUtils.millis());
// --GENERAL STATE--
// gamemode
stream.writeByte(state.mode.ordinal());
// map ID
stream.writeByte(world.getMap().id);
// wave
stream.writeInt(state.wave);
// wave countdown
stream.writeFloat(state.wavetime);
// player x/y
stream.writeFloat(Vars.player.x);
stream.writeFloat(Vars.player.y);
// player health
stream.writeInt(Vars.player.health);
// amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1);
// start at 1, because the first weapon is always the starter - ignore that
for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
// weapon ordinal
stream.writeByte(control.upgrades().getWeapons().get(i).id);
}
// --INVENTORY--
int l = state.inventory.getItems().length;
int itemsize = 0;
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
itemsize++;
}
}
// amount of items
stream.writeByte(itemsize);
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(state.inventory.getItems()[i]);
}
}
// --ENEMIES--
EntityContainer<Enemy> enemies = enemyGroup.all();
// enemy amount
stream.writeInt(enemies.size());
for (int i = 0; i < enemies.size(); i++) {
Enemy enemy = enemies.get(i);
// type
stream.writeByte(enemy.type.id);
// lane
stream.writeByte(enemy.lane);
// x
stream.writeFloat(enemy.x);
// y
stream.writeFloat(enemy.y);
// tier
stream.writeByte(enemy.tier);
// health
stream.writeShort(enemy.health);
}
// --MAP DATA--
// seed
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable()) {
if (tile.block() instanceof Rock) {
totalrocks++;
} else {
totalblocks++;
}
}
}
}
// amount of rocks
stream.writeInt(totalrocks);
// write all rocks
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
}
}
}
// write all blocks
stream.writeInt(totalblocks);
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable() && !(tile.block() instanceof Rock)) {
// tile pos
stream.writeInt(x + y * world.width());
// block ID
stream.writeInt(tile.block().id);
if (tile.block() instanceof BlockPart)
stream.writeByte(tile.link);
if (tile.entity != null) {
// rotation
stream.writeByte(tile.getRotation());
// health
stream.writeShort((short) tile.entity.health);
byte amount = 0;
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0)
amount++;
}
// amount of items
stream.writeByte(amount);
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(tile.entity.items[i]);
}
}
tile.entity.write(stream);
}
}
}
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Save14 method write.
@Override
public void write(DataOutputStream stream) throws IOException {
// --META--
// version id
stream.writeInt(version);
// last saved
stream.writeLong(TimeUtils.millis());
// --GENERAL STATE--
// gamemode
stream.writeByte(state.mode.ordinal());
// map ID
stream.writeByte(world.getMap().id);
// wave
stream.writeInt(state.wave);
// wave countdown
stream.writeFloat(state.wavetime);
// --BLOCK HEADER--
stream.writeInt(Block.getAllBlocks().size);
for (int i = 0; i < Block.getAllBlocks().size; i++) {
Block block = Block.getAllBlocks().get(i);
writeString(stream, block.name);
stream.writeShort(block.id);
}
// player x/y
stream.writeFloat(Vars.player.x);
stream.writeFloat(Vars.player.y);
// player health
stream.writeInt(Vars.player.health);
// amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1);
// start at 1, because the first weapon is always the starter - ignore that
for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
// weapon ordinal
stream.writeByte(control.upgrades().getWeapons().get(i).id);
}
// --INVENTORY--
int l = state.inventory.getItems().length;
int itemsize = 0;
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
itemsize++;
}
}
// amount of items
stream.writeByte(itemsize);
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(state.inventory.getItems()[i]);
}
}
// --ENEMIES--
EntityContainer<Enemy> enemies = enemyGroup.all();
// enemy amount
stream.writeInt(enemies.size());
for (int i = 0; i < enemies.size(); i++) {
Enemy enemy = enemies.get(i);
// type
stream.writeByte(enemy.type.id);
// lane
stream.writeByte(enemy.lane);
// x
stream.writeFloat(enemy.x);
// y
stream.writeFloat(enemy.y);
// tier
stream.writeByte(enemy.tier);
// health
stream.writeShort(enemy.health);
}
// --MAP DATA--
// seed
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable()) {
if (tile.block() instanceof Rock) {
totalrocks++;
} else {
totalblocks++;
}
}
}
}
// amount of rocks
stream.writeInt(totalrocks);
// write all rocks
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
}
}
}
// write all blocks
stream.writeInt(totalblocks);
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable() && !(tile.block() instanceof Rock)) {
// tile pos
stream.writeInt(x + y * world.width());
// block ID
stream.writeInt(tile.block().id);
if (tile.block() instanceof BlockPart)
stream.writeByte(tile.link);
if (tile.entity != null) {
// rotation
stream.writeByte(tile.getRotation());
// health
stream.writeShort((short) tile.entity.health);
byte amount = 0;
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0)
amount++;
}
// amount of items
stream.writeByte(amount);
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(tile.entity.items[i]);
}
}
tile.entity.write(stream);
}
}
}
}
}
Aggregations