Added (mobile) pickup/dropping of units
This commit is contained in:
@@ -65,6 +65,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
public boolean isLocal = false;
|
||||
public Timer timer = new Timer(4);
|
||||
public TargetTrait target;
|
||||
public CarriableTrait pickupTarget;
|
||||
|
||||
private boolean respawning;
|
||||
private float walktime;
|
||||
@@ -141,7 +142,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
|
||||
@Override
|
||||
public boolean isFlying(){
|
||||
return mech.flying || noclip;
|
||||
return mech.flying || noclip || isCarried();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,10 +173,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
respawning = false;
|
||||
placeQueue.clear();
|
||||
|
||||
if(carrying != null){
|
||||
carrying.setCarrier(null);
|
||||
carrying = null;
|
||||
}
|
||||
dropCarry();
|
||||
|
||||
float explosiveness = 2f + (inventory.hasItem() ? inventory.getItem().item.explosiveness * inventory.getItem().amount : 0f);
|
||||
float flammability = (inventory.hasItem() ? inventory.getItem().item.flammability * inventory.getItem().amount : 0f);
|
||||
@@ -196,10 +194,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
if(carrying != null){
|
||||
carrying.setCarrier(null);
|
||||
carrying = null;
|
||||
}
|
||||
dropCarry();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,10 +202,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
return playerGroup;
|
||||
}
|
||||
|
||||
public void toggleTeam(){
|
||||
team = (team == Team.blue ? Team.red : Team.blue);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region draw methods
|
||||
@@ -301,7 +292,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
drawBuilding(this);
|
||||
}
|
||||
|
||||
if(isFlying()){
|
||||
if(mech.flying){
|
||||
trail.draw(Palette.lighterOrange, Palette.lightishOrange, 5f);
|
||||
}
|
||||
}
|
||||
@@ -479,6 +470,20 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
float targetX = Core.camera.position.x, targetY = Core.camera.position.y;
|
||||
float attractDst = 15f;
|
||||
|
||||
if(pickupTarget != null && !pickupTarget.isDead()){
|
||||
targetX = pickupTarget.getX();
|
||||
targetY = pickupTarget.getY();
|
||||
attractDst = 0f;
|
||||
|
||||
if(distanceTo(pickupTarget) < 2f){
|
||||
carry(pickupTarget);
|
||||
|
||||
pickupTarget = null;
|
||||
}
|
||||
}else{
|
||||
pickupTarget = null;
|
||||
}
|
||||
|
||||
movement.set(targetX - x, targetY - y).limit(flySpeed);
|
||||
movement.setAngle(Mathf.slerpDelta(movement.angle(), velocity.angle(), 0.05f));
|
||||
|
||||
@@ -531,6 +536,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
|
||||
//region utility methods
|
||||
|
||||
public void toggleTeam(){
|
||||
team = (team == Team.blue ? Team.red : Team.blue);
|
||||
}
|
||||
|
||||
/**Resets all values of the player.*/
|
||||
public void reset(){
|
||||
weapon = Weapons.blaster;
|
||||
@@ -541,11 +550,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
dead = true;
|
||||
respawning = false;
|
||||
|
||||
if(carrying != null){
|
||||
carrying.setCarrier(null);
|
||||
carrying = null;
|
||||
}
|
||||
|
||||
add();
|
||||
heal();
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.impl.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.trait.DamageTrait;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.entities.impl.DestructibleEntity;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
@@ -148,6 +148,12 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
public void updateVelocityStatus(float drag, float maxVelocity){
|
||||
if(isCarried()){ //carried units do not take into account velocity normally
|
||||
set(carrier.getX(), carrier.getY());
|
||||
velocity.set(carrier.getVelocity());
|
||||
return;
|
||||
}
|
||||
|
||||
Floor floor = getFloorOn();
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
|
||||
|
||||
@@ -7,14 +7,13 @@ import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.impl.TimedEntity;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -25,7 +24,7 @@ import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Fire extends TimedEntity implements SaveTrait, Poolable, DrawTrait {
|
||||
public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
private static final IntMap<Fire> map = new IntMap<>();
|
||||
private static final float baseLifetime = 1000f;
|
||||
|
||||
@@ -115,11 +114,6 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable, DrawTrait
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float drawSize() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutputStream stream) throws IOException {
|
||||
stream.writeInt(tile.packedPosition());
|
||||
|
||||
@@ -72,5 +72,11 @@ public class GroundEffectEntity extends EffectEntity {
|
||||
this.staticLife = 0f;
|
||||
this.isStatic = isStatic;
|
||||
}
|
||||
|
||||
public GroundEffect(float life, EffectRenderer draw) {
|
||||
super(life, draw);
|
||||
this.staticLife = 0f;
|
||||
this.isStatic = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,14 @@ import io.anuke.mindustry.world.blocks.types.defense.ShieldBlock;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.impl.BaseEntity;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.shieldGroup;
|
||||
|
||||
//todo re-implement
|
||||
public class Shield extends BaseEntity {
|
||||
public class Shield extends BaseEntity implements DrawTrait {
|
||||
public boolean active;
|
||||
public boolean hitPlayers = false;
|
||||
public float radius = 0f;
|
||||
|
||||
@@ -1,9 +1,39 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.mindustry.content.fx.UnitFx;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
|
||||
public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{
|
||||
/**Returns the thing this carrier is carrying.*/
|
||||
CarriableTrait getCarry();
|
||||
/**Sets the carrying unit. Internal use only! Use {@link #carry(CarriableTrait)} to set state.*/
|
||||
void setCarry(CarriableTrait unit);
|
||||
/**Returns maximum mass this carrier can carry.*/
|
||||
float getCarryWeight();
|
||||
|
||||
/**Drops the unit that is being carried, if applicable.*/
|
||||
default void dropCarry(){
|
||||
carry(null);
|
||||
}
|
||||
|
||||
/**Do not override unless absolutely necessary.
|
||||
* Carries a unit. To drop a unit, call with {@code null}.*/
|
||||
default void carry(CarriableTrait unit){
|
||||
if(getCarry() != null){ //already carrying something, drop it
|
||||
//drop current
|
||||
Effects.effect(UnitFx.unitDrop, getCarry());
|
||||
getCarry().setCarrier(null);
|
||||
setCarry(null);
|
||||
|
||||
if(unit != null){
|
||||
carry(unit); //now carry this new thing
|
||||
}
|
||||
}else if(unit != null){ //not currently carrying anything, make sure it's not null
|
||||
setCarry(unit);
|
||||
unit.setCarrier(this);
|
||||
|
||||
Effects.effect(UnitFx.unitPickup, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,11 +221,6 @@ public abstract class BaseUnit extends Unit{
|
||||
return !isFlying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void added(){
|
||||
hitbox.setSize(type.hitsize);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.traits.CarriableTrait;
|
||||
import io.anuke.mindustry.entities.traits.CarryTrait;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Trail;
|
||||
@@ -16,17 +18,33 @@ import io.anuke.ucore.util.Translator;
|
||||
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class FlyingUnit extends BaseUnit {
|
||||
public class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
protected static Translator vec = new Translator();
|
||||
protected static float maxAim = 30f;
|
||||
protected static float wobblyness = 0.6f;
|
||||
|
||||
protected Trail trail = new Trail(16);
|
||||
protected CarriableTrait carrying;
|
||||
|
||||
public FlyingUnit(UnitType type, Team team) {
|
||||
super(type, team);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarriableTrait getCarry() {
|
||||
return carrying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCarry(CarriableTrait unit) {
|
||||
this.carrying = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCarryWeight() {
|
||||
return type.carryWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
@@ -69,6 +87,17 @@ public class FlyingUnit extends BaseUnit {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
dropCarry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath() {
|
||||
super.onDeath();
|
||||
dropCarry();
|
||||
}
|
||||
|
||||
protected void circle(float circleLength){
|
||||
vec.set(target.getX() - x, target.getY() - y);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ public class UnitType {
|
||||
public float reload = 40f;
|
||||
public float retreatPercent = 0.2f;
|
||||
public float armor = 0f;
|
||||
public float carryWeight = 1f;
|
||||
public ObjectMap<Item, AmmoType> ammo = new ObjectMap<>();
|
||||
|
||||
public UnitType(String name, UnitCreator creator){
|
||||
|
||||
Reference in New Issue
Block a user