Updated uCore, added new respawn mechanics

This commit is contained in:
Anuken
2018-05-31 11:41:31 -04:00
parent 857b76980b
commit 277d75016c
14 changed files with 584 additions and 498 deletions

View File

@@ -19,7 +19,11 @@ import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.Floor;
import io.anuke.ucore.core.*;
import io.anuke.mindustry.world.blocks.types.storage.CoreBlock.CoreEntity;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
@@ -55,8 +59,8 @@ public class Player extends Unit implements BlockBuilder {
public boolean isLocal = false;
public Timer timer = new Timer(4);
private boolean respawning;
private float walktime;
private float respawntime;
private Queue<BuildRequest> placeQueue = new Queue<>();
public Player(){
@@ -113,6 +117,7 @@ public class Player extends Unit implements BlockBuilder {
@Override
public void onDeath(){
dead = true;
respawning = false;
placeQueue.clear();
if(Net.active()){
NetEvents.handleUnitDeath(this);
@@ -122,14 +127,13 @@ public class Player extends Unit implements BlockBuilder {
float flammability = (inventory.hasItem() ? inventory.getItem().item.flammability * inventory.getItem().amount : 0f);
DamageArea.dynamicExplosion(x, y, flammability, explosiveness, 0f, getSize()/2f, Palette.darkFlame);
Effects.sound("die", this);
respawntime = respawnduration;
super.onDeath();
}
@Override
public void onRemoteDeath(){
dead = true;
respawning = true;
Effects.effect(ExplosionFx.explosion, this);
Effects.shake(4f, 5f, this);
Effects.sound("die", this);
@@ -296,19 +300,14 @@ public class Player extends Unit implements BlockBuilder {
return;
}
if(respawntime > 0){
if(isDead()){
CoreEntity entity = (CoreEntity)getClosestCore();
respawntime -= Timers.delta();
if(respawntime <= 0){
set(world.getSpawnX(), world.getSpawnY());
heal();
add();
Effects.sound("respawn");
}
}
if(isDead()) return;
if(!respawning && entity != null && entity.trySetPlayer(this)){
respawning = true;
}
return;
}
if(mech.flying){
updateFlying();
@@ -328,7 +327,6 @@ public class Player extends Unit implements BlockBuilder {
public void reset(){
weapon = Weapons.blaster;
team = Team.blue;
respawntime = -1;
inventory.clear();
upgrades.clear();
placeQueue.clear();

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
@@ -19,6 +20,24 @@ import static io.anuke.mindustry.Vars.*;
public class Units {
private static Rectangle rect = new Rectangle();
/**Returns whether there are any entities on this tile.*/
public static boolean anyEntities(Tile tile){
Block type = tile.block();
rect.setSize(type.size * tilesize, type.size * tilesize);
rect.setCenter(tile.drawx(), tile.drawy());
boolean[] value = new boolean[1];
Units.getNearby(rect, unit -> {
if(value[0]) return;
if(unit.hitbox.getRect(unit.x, unit.y).overlaps(rect)){
value[0] = true;
}
});
return value[0];
}
/**Returns the neareset ally tile in a range.*/
public static TileEntity findAllyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
return findTile(x, y, range, tile -> !state.teams.areEnemies(team, tile.getTeam()) && pred.test(tile));
@@ -130,7 +149,7 @@ public class Units {
Entities.getNearby(group, rect, entity -> cons.accept((Unit)entity));
}
//now check all enemy players
//now check all ally players
Entities.getNearby(playerGroup, rect, player -> {
if(((Unit)player).team == team) cons.accept((Unit)player);
});