Implemented desktop carrying
This commit is contained in:
@@ -32,10 +32,7 @@ import io.anuke.ucore.entities.EntityGroup;
|
|||||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.graphics.Lines;
|
import io.anuke.ucore.graphics.Lines;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.*;
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
import io.anuke.ucore.util.ThreadQueue;
|
|
||||||
import io.anuke.ucore.util.Timer;
|
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@@ -448,13 +445,26 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
|||||||
if(mech.flying){
|
if(mech.flying){
|
||||||
//prevent strafing backwards, have a penalty for doing so
|
//prevent strafing backwards, have a penalty for doing so
|
||||||
float angDist = Angles.angleDist(rotation, velocity.angle()) / 180f;
|
float angDist = Angles.angleDist(rotation, velocity.angle()) / 180f;
|
||||||
float penalty = 0.2f;
|
float penalty = 0.2f; //when going 180 degrees backwards, reduce speed to 0.2x
|
||||||
speed *= Mathf.lerp(1f, penalty, angDist);
|
speed *= Mathf.lerp(1f, penalty, angDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
//drop from carrier on key press
|
//drop from carrier on key press
|
||||||
if(Inputs.keyTap("drop_unit") && getCarrier() != null){
|
if(Inputs.keyTap("drop_unit")){
|
||||||
getCarrier().dropCarry();
|
if(!mech.flying) {
|
||||||
|
if (getCarrier() != null) {
|
||||||
|
CallEntity.dropSelf(this);
|
||||||
|
}
|
||||||
|
}else if(getCarry() != null){
|
||||||
|
dropCarry();
|
||||||
|
}else{
|
||||||
|
Unit unit = Units.getClosest(team, x, y, 8f,
|
||||||
|
u -> !u.isFlying() && u.getMass() <= mech.carryWeight);
|
||||||
|
|
||||||
|
if(unit != null){
|
||||||
|
carry(unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
movement.set(0, 0);
|
movement.set(0, 0);
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{
|
|||||||
CallEntity.setCarryOf(this instanceof Player ? (Player)this : null, this, unit);
|
CallEntity.setCarryOf(this instanceof Player ? (Player)this : null, this, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remote(called = Loc.server, targets = Loc.both, forward = true, in = In.entities)
|
||||||
|
static void dropSelf(Player player){
|
||||||
|
if(player.getCarrier() != null){
|
||||||
|
player.getCarrier().dropCarry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server, targets = Loc.both, forward = true, in = In.entities)
|
@Remote(called = Loc.server, targets = Loc.both, forward = true, in = In.entities)
|
||||||
static void setCarryOf(Player player, CarryTrait trait, CarriableTrait unit){
|
static void setCarryOf(Player player, CarryTrait trait, CarriableTrait unit){
|
||||||
if(player != null){ //when a server recieves this called from a player, set the carrier to the player.
|
if(player != null){ //when a server recieves this called from a player, set the carrier to the player.
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
|||||||
if(player.getCarry() != null){
|
if(player.getCarry() != null){
|
||||||
player.dropCarry(); //drop off unit
|
player.dropCarry(); //drop off unit
|
||||||
}else{
|
}else{
|
||||||
Unit unit = Units.getClosest(player.getTeam(), Graphics.world(x, y).x, Graphics.world(x, y).y, 4f, u -> !u.isFlying());
|
Unit unit = Units.getClosest(player.getTeam(), Graphics.world(x, y).x, Graphics.world(x, y).y, 4f, u -> !u.isFlying() && u.getMass() <= player.mech.carryWeight);
|
||||||
|
|
||||||
if(unit != null){
|
if(unit != null){
|
||||||
player.pickupTarget = unit;
|
player.pickupTarget = unit;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class Mech extends Upgrade {
|
|||||||
public float armor = 1f;
|
public float armor = 1f;
|
||||||
|
|
||||||
public int drillPower = -1;
|
public int drillPower = -1;
|
||||||
public float carryWeight = 1f;
|
public float carryWeight = 10f;
|
||||||
public float buildPower = 1f;
|
public float buildPower = 1f;
|
||||||
public boolean canRepair = false;
|
public boolean canRepair = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user