mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 04:28:27 +07:00
Added carry traits
This commit is contained in:
parent
210967cfef
commit
b10fa9e5b2
@ -9,7 +9,7 @@ import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.entities.bullet.LiquidBulletType;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.effect.Fire;
|
||||
import io.anuke.mindustry.entities.effect.Lightning;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
@ -101,7 +101,7 @@ public class TurretBullets implements ContentList {
|
||||
|
||||
@Override
|
||||
public void init(Bullet b) {
|
||||
DamageArea.collideLine(b, b.getTeam(), hiteffect, b.x, b.y, b.angle(), length);
|
||||
Damage.collideLine(b, b.getTeam(), hiteffect, b.x, b.y, b.angle(), length);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
@ -7,8 +7,7 @@ import io.anuke.mindustry.content.bullets.TurretBullets;
|
||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.effect.Lightning;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -24,7 +23,7 @@ import io.anuke.ucore.util.Translator;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Utility class for damaging in an area.*/
|
||||
public class DamageArea{
|
||||
public class Damage {
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static Rectangle hitrect = new Rectangle();
|
||||
private static Translator tr = new Translator();
|
||||
@ -33,14 +32,12 @@ public class DamageArea{
|
||||
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){
|
||||
for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i ++){
|
||||
int branches = 5 + Mathf.clamp((int)(power/30), 1, 20);
|
||||
Timers.run(i*2f + Mathf.random(4f), () -> {
|
||||
Lightning.create(Team.none, Fx.none, Palette.power, 3, x, y, Mathf.random(360f), branches + Mathf.range(2));
|
||||
});
|
||||
Timers.run(i*2f + Mathf.random(4f), () -> Lightning.create(Team.none, Fx.none, Palette.power, 3,
|
||||
x, y, Mathf.random(360f), branches + Mathf.range(2)));
|
||||
}
|
||||
|
||||
for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i ++){
|
||||
Timers.run(i/2, () ->
|
||||
Bullet.create(TurretBullets.fireball, null, Team.none, x, y, Mathf.random(360f)));
|
||||
Timers.run(i/2, () -> Bullet.create(TurretBullets.fireball, null, Team.none, x, y, Mathf.random(360f)));
|
||||
}
|
||||
|
||||
int waves = Mathf.clamp((int)(explosiveness / 4), 0, 30);
|
||||
@ -48,7 +45,7 @@ public class DamageArea{
|
||||
for(int i = 0; i < waves; i ++){
|
||||
int f = i;
|
||||
Timers.run(i*2f, () -> {
|
||||
DamageArea.damage(x, y, Mathf.clamp(radius + explosiveness, 0, 50f) * ((f + 1f)/waves), explosiveness/2f);
|
||||
Damage.damage(x, y, Mathf.clamp(radius + explosiveness, 0, 50f) * ((f + 1f)/waves), explosiveness/2f);
|
||||
Effects.effect(ExplosionFx.blockExplosionSmoke, x + Mathf.range(radius), y + Mathf.range(radius));
|
||||
});
|
||||
}
|
@ -10,9 +10,10 @@ import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.content.Weapons;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||
import io.anuke.mindustry.entities.traits.CarriableTrait;
|
||||
import io.anuke.mindustry.entities.traits.CarryTrait;
|
||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
@ -39,7 +40,7 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Player extends Unit implements BuilderTrait {
|
||||
public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
private static final float walkSpeed = 1.1f;
|
||||
private static final float flySpeed = 0.4f;
|
||||
private static final float flyMaxSpeed = 3f;
|
||||
@ -69,6 +70,7 @@ public class Player extends Unit implements BuilderTrait {
|
||||
private float walktime;
|
||||
private Queue<BuildRequest> placeQueue = new Queue<>();
|
||||
private Tile mining;
|
||||
private CarriableTrait carrying;
|
||||
private Trail trail = new Trail(16);
|
||||
|
||||
public Player(){
|
||||
@ -82,6 +84,20 @@ public class Player extends Unit implements BuilderTrait {
|
||||
|
||||
//region unit and event overrides, utility methods
|
||||
|
||||
@Override
|
||||
public CarriableTrait getCarry() {
|
||||
return carrying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCarry(CarriableTrait unit) {
|
||||
this.carrying = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCarryWeight() {
|
||||
return mech.carryWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBuildPower(Tile tile) {
|
||||
@ -156,9 +172,14 @@ public class Player extends Unit implements BuilderTrait {
|
||||
respawning = false;
|
||||
placeQueue.clear();
|
||||
|
||||
if(carrying != null){
|
||||
carrying.setCarrier(null);
|
||||
carrying = null;
|
||||
}
|
||||
|
||||
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);
|
||||
DamageArea.dynamicExplosion(x, y, flammability, explosiveness, 0f, getSize()/2f, Palette.darkFlame);
|
||||
Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, getSize()/2f, Palette.darkFlame);
|
||||
Effects.sound("die", this);
|
||||
super.onDeath();
|
||||
}
|
||||
@ -173,6 +194,14 @@ public class Player extends Unit implements BuilderTrait {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
if(carrying != null){
|
||||
carrying.setCarrier(null);
|
||||
carrying = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityGroup targetGroup() {
|
||||
return playerGroup;
|
||||
@ -186,7 +215,6 @@ public class Player extends Unit implements BuilderTrait {
|
||||
|
||||
//region draw methods
|
||||
|
||||
|
||||
@Override
|
||||
public float drawSize() {
|
||||
return 40;
|
||||
@ -513,6 +541,11 @@ public class Player extends Unit implements BuilderTrait {
|
||||
dead = true;
|
||||
respawning = false;
|
||||
|
||||
if(carrying != null){
|
||||
carrying.setCarrier(null);
|
||||
carrying = null;
|
||||
}
|
||||
|
||||
add();
|
||||
heal();
|
||||
}
|
||||
|
@ -2,10 +2,7 @@ package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||
import io.anuke.mindustry.entities.traits.TeamTrait;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
@ -29,7 +26,7 @@ import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public abstract class Unit extends DestructibleEntity implements SaveTrait, TargetTrait, SyncTrait, DrawTrait, TeamTrait {
|
||||
public abstract class Unit extends DestructibleEntity implements SaveTrait, TargetTrait, SyncTrait, DrawTrait, TeamTrait, CarriableTrait {
|
||||
/**total duration of hit flash effect*/
|
||||
public static final float hitDuration = 9f;
|
||||
|
||||
@ -40,10 +37,21 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
protected StatusController status = new StatusController();
|
||||
protected Team team = Team.blue;
|
||||
|
||||
protected CarryTrait carrier;
|
||||
protected Vector2 velocity = new Vector2(0f, 0.0001f);
|
||||
protected float hitTime;
|
||||
protected float drownTime;
|
||||
|
||||
@Override
|
||||
public void setCarrier(CarryTrait carrier) {
|
||||
this.carrier = carrier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarryTrait getCarrier() {
|
||||
return carrier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Team getTeam(){
|
||||
return team;
|
||||
@ -65,7 +73,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
|
||||
@Override
|
||||
public void damage(float amount){
|
||||
super.damage(amount);
|
||||
super.damage(amount * Mathf.clamp(1f-getArmor()/100f));
|
||||
hitTime = hitDuration;
|
||||
}
|
||||
|
||||
@ -112,10 +120,10 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
this.health = health;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.status.set(io.anuke.mindustry.type.StatusEffect.getByID(effect), etime);
|
||||
this.status.set(StatusEffect.getByID(effect), etime);
|
||||
}
|
||||
|
||||
public io.anuke.mindustry.type.StatusEffect getStatus(){
|
||||
public StatusEffect getStatus(){
|
||||
return status.current();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
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.world.Block;
|
||||
@ -106,7 +107,7 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable, DrawTrait
|
||||
if(damage){
|
||||
entity.damage(0.4f);
|
||||
}
|
||||
DamageArea.damageUnits(null, tile.worldx(), tile.worldy(), tilesize, 3f, unit -> unit.applyEffect(StatusEffects.burning, 0.8f));
|
||||
Damage.damageUnits(null, tile.worldx(), tile.worldy(), tilesize, 3f, unit -> unit.applyEffect(StatusEffects.burning, 0.8f));
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.05 * Timers.delta())){
|
||||
|
@ -51,6 +51,7 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
|
||||
/**Internal use only!*/
|
||||
public ItemDrop(){
|
||||
hitbox.setSize(5f);
|
||||
hitboxTile.setSize(5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,8 +100,8 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
|
||||
int stored = Mathf.clamp(amount / 6, 1, 8);
|
||||
|
||||
for(int i = 0; i < stored; i ++) {
|
||||
float px = Mathf.randomSeedRange(i + 1, 4f);
|
||||
float py = Mathf.randomSeedRange(i + 2, 4f);
|
||||
float px = stored == 1 ? 0 : Mathf.randomSeedRange(i + 1, 4f);
|
||||
float py = stored == 1 ? 0 : Mathf.randomSeedRange(i + 2, 4f);
|
||||
Draw.rect(item.region, x + px, y + py, size, size);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.entities.impl.TimedEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@ -22,7 +23,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
|
||||
public class Lightning extends TimedEntity implements Poolable{
|
||||
public class Lightning extends TimedEntity implements Poolable, DrawTrait{
|
||||
private static Array<SolidTrait> entities = new Array<>();
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static Rectangle hitrect = new Rectangle();
|
||||
|
@ -4,13 +4,14 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.entities.traits.BelowLiquidTrait;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.impl.TimedEntity;
|
||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.groundEffectGroup;
|
||||
|
||||
/**Class for creating block rubble on the ground.*/
|
||||
public class Rubble extends TimedEntity implements BelowLiquidTrait {
|
||||
public class Rubble extends TimedEntity implements BelowLiquidTrait, DrawTrait {
|
||||
private static final Color color = Color.valueOf("52504e");
|
||||
private int size;
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
|
||||
public interface CarriableTrait extends TeamTrait, TargetTrait, SolidTrait{
|
||||
|
||||
default boolean isCarried(){
|
||||
return getCarrier() != null;
|
||||
}
|
||||
|
||||
void setCarrier(CarryTrait carrier);
|
||||
CarryTrait getCarrier();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
|
||||
public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{
|
||||
CarriableTrait getCarry();
|
||||
void setCarry(CarriableTrait unit);
|
||||
float getCarryWeight();
|
||||
}
|
@ -4,6 +4,7 @@ public class Mech extends Upgrade {
|
||||
public boolean flying;
|
||||
public float mass = 1f;
|
||||
public int drillPower = -1;
|
||||
public float carryWeight = 1f;
|
||||
|
||||
public Mech(String name, boolean flying){
|
||||
super(name);
|
||||
|
@ -34,7 +34,6 @@ public class BlockInventoryFragment implements Fragment {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
table = new Table();
|
||||
@ -105,22 +104,15 @@ public class BlockInventoryFragment implements Fragment {
|
||||
ItemImage image = new ItemImage(item.region, () -> round(items[f]), Color.WHITE);
|
||||
image.addListener(l);
|
||||
image.tapped(() -> {
|
||||
if(!canPick.get()) return;
|
||||
if (items[f] > 0) {
|
||||
int amount = Math.min(Inputs.keyDown("item_withdraw") ? items[f] : 1, player.inventory.itemCapacityUsed(item));
|
||||
tile.block().removeStack(tile, item, amount);
|
||||
if(!canPick.get() || items[f] == 0) return;
|
||||
int amount = Math.min(Inputs.keyDown("item_withdraw") ? items[f] : 1, player.inventory.itemCapacityUsed(item));
|
||||
tile.block().removeStack(tile, item, amount);
|
||||
|
||||
int sent = Mathf.clamp(amount/3, 1, 8);
|
||||
int per = Math.min(amount/sent, 5);
|
||||
int[] soFar = {amount};
|
||||
for(int j = 0; j < sent; j ++){
|
||||
boolean all = j == sent-1;
|
||||
Timers.run(j*5, () -> ItemTransfer.create(item, tile.drawx(), tile.drawy(), player, () -> {
|
||||
player.inventory.addItem(item, all ? soFar[0] : per);
|
||||
soFar[0] -= per;
|
||||
}));
|
||||
}
|
||||
player.inventory.addItem(item, amount);
|
||||
for(int j = 0; j < Mathf.clamp(amount/3, 1, 8); j ++){
|
||||
Timers.run(j*3f, () -> ItemTransfer.create(item, tile.drawx(), tile.drawy(), player, () -> {}));
|
||||
}
|
||||
|
||||
});
|
||||
table.add(image);
|
||||
|
||||
|
@ -9,7 +9,7 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.effect.Puddle;
|
||||
import io.anuke.mindustry.entities.effect.Rubble;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
@ -298,7 +298,7 @@ public class Block extends BaseBlock implements Content{
|
||||
}
|
||||
}
|
||||
|
||||
DamageArea.dynamicExplosion(x, y, flammability, explosiveness, power, tilesize * size/2f, tempColor);
|
||||
Damage.dynamicExplosion(x, y, flammability, explosiveness, power, tilesize * size/2f, tempColor);
|
||||
if(!tile.floor().solid && !tile.floor().liquid){
|
||||
Rubble.create(tile.drawx(), tile.drawy(), size);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.anuke.mindustry.world.blocks.types.power;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.content.fx.BlockFx;
|
||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
@ -138,7 +138,7 @@ public class NuclearReactor extends LiquidBurnerGenerator {
|
||||
});
|
||||
}
|
||||
|
||||
DamageArea.damage(tile.worldx(), tile.worldy(), explosionRadius * tilesize, explosionDamage * 4);
|
||||
Damage.damage(tile.worldx(), tile.worldy(), explosionRadius * tilesize, explosionDamage * 4);
|
||||
|
||||
|
||||
for(int i = 0; i < 20; i ++){
|
||||
|
Loading…
Reference in New Issue
Block a user