Implemented ammo ressuplying
This commit is contained in:
@@ -27,6 +27,7 @@ public class Bullet extends BulletEntity<BulletType>{
|
||||
bullet.owner = owner;
|
||||
|
||||
bullet.velocity.set(0, type.speed).setAngle(angle);
|
||||
bullet.velocity.add(owner instanceof Unit ? ((Unit)owner).velocity : Vector2.Zero);
|
||||
bullet.hitbox.setSize(type.hitsize);
|
||||
|
||||
bullet.team = team;
|
||||
|
||||
@@ -11,10 +11,7 @@ import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.resource.*;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -23,10 +20,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.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -46,8 +40,7 @@ public class Player extends Unit{
|
||||
public boolean isAdmin;
|
||||
public Color color = new Color();
|
||||
|
||||
public Weapon weaponLeft = Weapons.blaster;
|
||||
public Weapon weaponRight = Weapons.blaster;
|
||||
public Weapon weapon = Weapons.blaster;
|
||||
public Mech mech = Mechs.standard;
|
||||
|
||||
public float targetAngle = 0f;
|
||||
@@ -72,8 +65,8 @@ public class Player extends Unit{
|
||||
|
||||
@Override
|
||||
public void onRemoteShoot(BulletType type, float x, float y, float rotation, short data) {
|
||||
Weapon weapon = Upgrade.getByID((byte)data);
|
||||
weapon.shoot(player, x, y, rotation);
|
||||
Weapon weapon = Upgrade.getByID(Bits.getLeftByte(data));
|
||||
weapon.shoot(player, x, y, rotation, Bits.getRightByte(data) == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,8 +177,7 @@ public class Player extends Unit{
|
||||
Draw.rect(mname, x, y, rotation -90);
|
||||
|
||||
for (int i : Mathf.signs) {
|
||||
Weapon weapon = i < 0 ? weaponLeft : weaponRight;
|
||||
tr.trns(rotation - 90, 4*i, 3);
|
||||
tr.trns(rotation - 90, 4*i, 3 - weapon.getRecoil(this, i > 0)*1.5f);
|
||||
float w = i > 0 ? -8 : 8;
|
||||
Draw.rect(weapon.name + "-equip", x + tr.x, y + tr.y, w, 8, rotation - 90);
|
||||
}
|
||||
@@ -269,8 +261,8 @@ public class Player extends Unit{
|
||||
boolean shooting = control.input().canShoot() && control.input().isShooting();
|
||||
|
||||
if(shooting){
|
||||
weaponLeft.update(player, true);
|
||||
weaponRight.update(player, false);
|
||||
weapon.update(player, true);
|
||||
weapon.update(player, false);
|
||||
}
|
||||
|
||||
if(dashing && timer.get(timerDash, 3) && movement.len() > 0){
|
||||
@@ -302,6 +294,16 @@ public class Player extends Unit{
|
||||
rotation = Mathf.slerpDelta(rotation, targetAngle, 0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAmmo(Item item) {
|
||||
return weapon.getAmmoType(item) != null && inventory.canAcceptAmmo(weapon.getAmmoType(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAmmo(Item item) {
|
||||
inventory.addAmmo(weapon.getAmmoType(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player add(){
|
||||
return add(playerGroup);
|
||||
@@ -339,8 +341,7 @@ public class Player extends Unit{
|
||||
public void writeSpawn(ByteBuffer buffer) {
|
||||
buffer.put((byte)name.getBytes().length);
|
||||
buffer.put(name.getBytes());
|
||||
buffer.put(weaponLeft.id);
|
||||
buffer.put(weaponRight.id);
|
||||
buffer.put(weapon.id);
|
||||
buffer.put(mech.id);
|
||||
buffer.put(isAdmin ? 1 : (byte)0);
|
||||
buffer.putInt(Color.rgba8888(color));
|
||||
@@ -355,8 +356,7 @@ public class Player extends Unit{
|
||||
byte[] n = new byte[nlength];
|
||||
buffer.get(n);
|
||||
name = new String(n);
|
||||
weaponLeft = Upgrade.getByID(buffer.get());
|
||||
weaponRight = Upgrade.getByID(buffer.get());
|
||||
weapon = Upgrade.getByID(buffer.get());
|
||||
mech = Upgrade.getByID(buffer.get());
|
||||
isAdmin = buffer.get() == 1;
|
||||
color.set(buffer.getInt());
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.entities;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -18,12 +19,13 @@ import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public abstract class Unit extends SyncEntity implements SerializableEntity {
|
||||
//total duration of hit effect
|
||||
/**total duration of hit flash effect*/
|
||||
public static final float hitDuration = 9f;
|
||||
|
||||
public StatusController status = new StatusController();
|
||||
public UnitInventory inventory = new UnitInventory(100);
|
||||
public UnitInventory inventory = new UnitInventory(100, 100);
|
||||
public Team team = Team.blue;
|
||||
|
||||
public Vector2 velocity = new Vector2();
|
||||
public float hitTime;
|
||||
public float drownTime;
|
||||
@@ -146,6 +148,8 @@ public abstract class Unit extends SyncEntity implements SerializableEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean acceptsAmmo(Item item);
|
||||
public abstract void addAmmo(Item item);
|
||||
public abstract float getMass();
|
||||
public abstract boolean isFlying();
|
||||
public abstract float getSize();
|
||||
|
||||
@@ -5,10 +5,37 @@ import io.anuke.mindustry.resource.*;
|
||||
public class UnitInventory {
|
||||
private final AmmoEntry ammo = new AmmoEntry(AmmoType.getByID(0), 0);
|
||||
private ItemStack item;
|
||||
private int capacity;
|
||||
private int capacity, ammoCapacity;
|
||||
|
||||
public UnitInventory(int capacity) {
|
||||
public UnitInventory(int capacity, int ammoCapacity) {
|
||||
this.capacity = capacity;
|
||||
this.ammoCapacity = ammoCapacity;
|
||||
}
|
||||
|
||||
public AmmoType getAmmo() {
|
||||
return ammo.type;
|
||||
}
|
||||
|
||||
public boolean hasAmmo(){
|
||||
return ammo.amount > 0;
|
||||
}
|
||||
|
||||
public void useAmmo(){
|
||||
ammo.amount --;
|
||||
}
|
||||
|
||||
public int ammoCapacity(){
|
||||
return ammoCapacity;
|
||||
}
|
||||
|
||||
public boolean canAcceptAmmo(AmmoType type){
|
||||
return ammo.amount + type.quantityMultiplier <= ammoCapacity;
|
||||
}
|
||||
|
||||
public void addAmmo(AmmoType type){
|
||||
if(ammo.type != type) ammo.amount = 0;
|
||||
ammo.type = type;
|
||||
ammo.amount += Math.min((int)type.quantityMultiplier, ammoCapacity - ammo.amount);
|
||||
}
|
||||
|
||||
public int capacity(){
|
||||
@@ -33,6 +60,8 @@ public class UnitInventory {
|
||||
|
||||
public void clear(){
|
||||
item = null;
|
||||
ammo.amount = 0;
|
||||
ammo.type = AmmoType.getByID(0);
|
||||
}
|
||||
|
||||
public boolean hasItem(){
|
||||
@@ -48,7 +77,6 @@ public class UnitInventory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getItem(){
|
||||
if(!hasItem()) throw new RuntimeException("This inventory has no item! Check hasItem() first.");
|
||||
return item;
|
||||
|
||||
@@ -96,6 +96,20 @@ public class Units {
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/**Iterates over all units in a rectangle.*/
|
||||
public static void getNearby(Team team, Rectangle rect, Consumer<Unit> cons){
|
||||
|
||||
EntityGroup<BaseUnit> group = unitGroups[team.ordinal()];
|
||||
if(!group.isEmpty()){
|
||||
Entities.getNearby(group, rect, entity -> cons.accept((Unit)entity));
|
||||
}
|
||||
|
||||
//now check all enemy players
|
||||
Entities.getNearby(playerGroup, rect, player -> {
|
||||
if(((Unit)player).team == team) cons.accept((Unit)player);
|
||||
});
|
||||
}
|
||||
|
||||
/**Iterates over all units in a rectangle.*/
|
||||
public static void getNearby(Rectangle rect, Consumer<Unit> cons){
|
||||
|
||||
@@ -128,4 +142,6 @@ public class Units {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GroundEffectEntity extends EffectEntity {
|
||||
public GroundEffect(float life, float staticLife, EffectRenderer draw) {
|
||||
super(life, draw);
|
||||
this.staticLife = staticLife;
|
||||
this.isStatic = false;
|
||||
this.isStatic = true;
|
||||
}
|
||||
|
||||
public GroundEffect(boolean isStatic, float life, EffectRenderer draw) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class ItemTransferEffect extends Entity {
|
||||
private static final float size = 5f;
|
||||
private static final float alpha = 0.1f;
|
||||
|
||||
private final Item item;
|
||||
private final Entity target;
|
||||
|
||||
public ItemTransferEffect(Item item, float x, float y, Entity target) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.item = item;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
x = Mathf.lerpDelta(x, target.x, alpha);
|
||||
y = Mathf.lerpDelta(y, target.y, alpha);
|
||||
|
||||
if(distanceTo(target) <= 2f){
|
||||
remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
float s = size;
|
||||
Draw.rect(item.region, x, y, s, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add() {
|
||||
return super.add(Vars.effectGroup);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
@@ -39,6 +40,16 @@ public class BaseUnit extends Unit{
|
||||
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
|
||||
}
|
||||
|
||||
//TODO
|
||||
@Override
|
||||
public boolean acceptsAmmo(Item item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAmmo(Item item) {
|
||||
|
||||
}
|
||||
//TODO
|
||||
@Override
|
||||
public float getSize() {
|
||||
|
||||
Reference in New Issue
Block a user