Implemented inventory capacity
This commit is contained in:
@@ -21,10 +21,7 @@ import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -187,10 +184,16 @@ public class Player extends Unit{
|
||||
float backTrns = 4f, itemSize = 5f;
|
||||
if(inventory.hasItem()){
|
||||
ItemStack stack = inventory.getItem();
|
||||
Draw.rect(stack.item.region, x + Angles.trnsx(rotation + 180f, backTrns), y + Angles.trnsy(rotation + 180f, backTrns), itemSize, itemSize, rotation);
|
||||
//Draw.tint(Color.WHITE);
|
||||
//Lines.circle(x + Angles.trnsx(rotation + 180f, backTrns), y + Angles.trnsy(rotation + 180f, backTrns), 3f + Mathf.absin(Timers.time(), 3f, 0.8f));
|
||||
//Draw.tint(Color.WHITE);
|
||||
int stored = Mathf.clamp(stack.amount / 6, 1, 8);
|
||||
|
||||
for(int i = 0; i < stored; i ++) {
|
||||
float angT = i == 0 ? 0 : Mathf.randomSeedRange(i + 1, 60f);
|
||||
float lenT = i == 0 ? 0 : Mathf.randomSeedRange(i + 2, 1f) - 1f;
|
||||
Draw.rect(stack.item.region,
|
||||
x + Angles.trnsx(rotation + 180f + angT, backTrns + lenT),
|
||||
y + Angles.trnsy(rotation + 180f + angT, backTrns + lenT),
|
||||
itemSize, itemSize, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.alpha(1f);
|
||||
|
||||
@@ -18,7 +18,7 @@ public abstract class Unit extends SyncEntity {
|
||||
public static final float hitDuration = 9f;
|
||||
|
||||
public StatusController status = new StatusController();
|
||||
public UnitInventory inventory = new UnitInventory();
|
||||
public UnitInventory inventory = new UnitInventory(100);
|
||||
public Team team = Team.blue;
|
||||
public Vector2 velocity = new Vector2();
|
||||
public float hitTime;
|
||||
|
||||
@@ -4,8 +4,28 @@ import io.anuke.mindustry.resource.*;
|
||||
|
||||
public class UnitInventory {
|
||||
private final AmmoEntry ammo = new AmmoEntry(AmmoType.getByID(0), 0);
|
||||
|
||||
private CarryItem item;
|
||||
private int capacity;
|
||||
|
||||
public UnitInventory(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public int capacity(){
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public int itemCapacityUsed(Item type){
|
||||
if(canAcceptItem(type)){
|
||||
return !hasItem() ? capacity : (capacity - getItem().amount);
|
||||
}else{
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canAcceptItem(Item type){
|
||||
return !hasItem() || (getItem().item == type && capacity - getItem().amount > 0);
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
item = null;
|
||||
|
||||
Reference in New Issue
Block a user