1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 14:56:10 +03:00

Added syncable bullets

This commit is contained in:
Anuken 2018-06-04 18:32:03 -04:00
parent 2a5118326a
commit 210967cfef
7 changed files with 52 additions and 10 deletions

View File

@ -101,7 +101,7 @@ public class TurretBullets implements ContentList {
@Override
public void init(Bullet b) {
DamageArea.collideLine(b, b.team, hiteffect, b.x, b.y, b.angle(), length);
DamageArea.collideLine(b, b.getTeam(), hiteffect, b.x, b.y, b.angle(), length);
}
@Override
@ -168,7 +168,7 @@ public class TurretBullets implements ContentList {
@Override
public void init(Bullet b) {
Lightning.create(b.team, hiteffect, Palette.lancerLaser, damage, b.x, b.y, b.angle(), 30);
Lightning.create(b.getTeam(), hiteffect, Palette.lancerLaser, damage, b.x, b.y, b.angle(), 30);
}
};
}

View File

@ -3,24 +3,30 @@ package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pools;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TeamTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.net.Interpolator;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.impl.BulletEntity;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.entities.trait.VelocityTrait;
import io.anuke.ucore.entities.impl.BulletEntity;
import io.anuke.ucore.util.Timer;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.world;
public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait{
private static Vector2 vector = new Vector2();
private Interpolator interpolator = new Interpolator();
private Team team;
public Timer timer = new Timer(3);
public Team team;
public static Bullet create(BulletType type, TeamTrait owner, float x, float y, float angle){
return create(type, owner, owner.getTeam(), x, y, angle);
@ -46,12 +52,39 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait{
return create(type, parent.owner, parent.team, x, y, angle);
}
private Bullet(){}
/**Internal use only!*/
public Bullet(){}
public boolean collidesTiles(){
return true; //TODO make artillery and such not do this
}
@Override
public boolean doSync(){
return type.syncable;
}
@Override
public Interpolator getInterpolator() {
return interpolator;
}
@Override
public void write(ByteBuffer data) {
data.putFloat(x);
data.putFloat(y);
data.put((byte)team.ordinal());
data.put((byte)type.id);
}
@Override
public void read(ByteBuffer data, long time) {
x = data.getFloat();
y = data.getFloat();
team = Team.values()[data.get()];
type = BulletType.getByID(data.get());
}
@Override
public Team getTeam() {
return team;

View File

@ -22,6 +22,8 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
public float statusIntensity = 0.5f;
/**What fraction of armor is pierced, 0-1*/
public float armorPierce = 0f;
/**Whether to sync this bullet to clients.*/
public boolean syncable;
public BulletType(float speed, float damage){
this.id = lastid ++;

View File

@ -158,11 +158,13 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
public void write(ByteBuffer data) {
data.putFloat(x);
data.putFloat(y);
data.put((byte)item.id);
}
@Override
public void read(ByteBuffer data, long time) {
x = data.getFloat();
y = data.getFloat();
item = Item.getByID(data.get());
}
}

View File

@ -14,6 +14,10 @@ public interface SyncTrait extends Entity {
return threads.isEnabled() && threads.getFPS() <= Gdx.graphics.getFramesPerSecond() / 2f;
}
default boolean doSync(){
return true;
}
default void setNet(float x, float y){
set(x, y);
getInterpolator().target.set(x, y);

View File

@ -190,8 +190,8 @@ public class DesktopInput extends InputHandler{
mode = placing;
} else {
//only begin shooting if there's no cursor event
if(!tileTapped(cursor) && player.getPlaceQueue().size == 0 && !tryBeginMine(cursor)
&& player.getMineTile() == null && !tryTapPlayer(worldx, worldy) && !droppingItem){
if(!tileTapped(cursor) && player.getPlaceQueue().size == 0 && !tryTapPlayer(worldx, worldy) && !droppingItem &&
!tryBeginMine(cursor) && player.getMineTile() == null){
shooting = true;
}
}

View File

@ -26,7 +26,7 @@ import static io.anuke.mindustry.Vars.*;
public abstract class InputHandler extends InputAdapter{
/**Used for dropping items.*/
final float playerSelectRange = 16f;
final float playerSelectRange = mobile ? 17f : 11f;
/**Maximum line length.*/
final int maxLength = 100;
final Translator stackTrns = new Translator();
@ -152,6 +152,7 @@ public abstract class InputHandler extends InputAdapter{
boolean canMine(Tile tile){
return tile.floor().drops != null && tile.floor().drops.item.hardness <= player.mech.drillPower
&& player.inventory.canAcceptItem(tile.floor().drops.item)
&& tile.block() == Blocks.air && player.distanceTo(tile.worldx(), tile.worldy()) <= Player.mineDistance;
}
@ -191,7 +192,7 @@ public abstract class InputHandler extends InputAdapter{
}
public void tryDropItems(Tile tile, float x, float y){
if(!droppingItem || !player.inventory.hasItem() || !tile.block().hasItems){
if(!droppingItem || !player.inventory.hasItem() || !tile.block().hasItems || canTapPlayer(x, y)){
droppingItem = false;
return;
}