Added deflector walls
This commit is contained in:
@@ -21,7 +21,8 @@ public class Recipes implements ContentList{
|
||||
new Recipe(defense, DefenseBlocks.diriumwall, new ItemStack(Items.surgealloy, 12 * 4));
|
||||
new Recipe(defense, DefenseBlocks.door, new ItemStack(Items.steel, 3), new ItemStack(Items.iron, 3 * 4));
|
||||
new Recipe(defense, DefenseBlocks.largedoor, new ItemStack(Items.steel, 3 * 4), new ItemStack(Items.iron, 3 * 4 * 4));
|
||||
new Recipe(defense, DefenseBlocks.titaniumshieldwall, new ItemStack(Items.titanium, 16));
|
||||
new Recipe(defense, DefenseBlocks.deflectorwall, new ItemStack(Items.titanium, 1));
|
||||
new Recipe(defense, DefenseBlocks.deflectorwalllarge, new ItemStack(Items.titanium, 1));
|
||||
|
||||
new Recipe(distribution, DistributionBlocks.conveyor, new ItemStack(Items.iron, 1));
|
||||
new Recipe(distribution, DistributionBlocks.steelconveyor, new ItemStack(Items.steel, 1));
|
||||
|
||||
@@ -4,11 +4,11 @@ import io.anuke.mindustry.content.fx.BlockFx;
|
||||
import io.anuke.mindustry.type.ContentList;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.Wall;
|
||||
import io.anuke.mindustry.world.blocks.defense.DeflectorWall;
|
||||
import io.anuke.mindustry.world.blocks.defense.Door;
|
||||
import io.anuke.mindustry.world.blocks.defense.ShieldedWallBlock;
|
||||
|
||||
public class DefenseBlocks extends BlockList implements ContentList {
|
||||
public static Block stonewall, ironwall, steelwall, titaniumwall, diriumwall, compositewall, steelwalllarge, titaniumwalllarge, diriumwalllarge, titaniumshieldwall, door, largedoor;
|
||||
public static Block stonewall, ironwall, steelwall, titaniumwall, diriumwall, steelwalllarge, titaniumwalllarge, diriumwalllarge, door, largedoor, deflectorwall, deflectorwalllarge;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
@@ -34,10 +34,6 @@ public class DefenseBlocks extends BlockList implements ContentList {
|
||||
health = 190 * wallHealthMultiplier;
|
||||
}};
|
||||
|
||||
compositewall = new Wall("compositewall") {{
|
||||
health = 270 * wallHealthMultiplier;
|
||||
}};
|
||||
|
||||
steelwalllarge = new Wall("steelwall-large") {{
|
||||
health = 110 * 4 * wallHealthMultiplier;
|
||||
size = 2;
|
||||
@@ -53,10 +49,15 @@ public class DefenseBlocks extends BlockList implements ContentList {
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
titaniumshieldwall = new ShieldedWallBlock("titaniumshieldwall") {{
|
||||
deflectorwall = new DeflectorWall("deflector-wall") {{
|
||||
health = 150 * wallHealthMultiplier;
|
||||
}};
|
||||
|
||||
deflectorwalllarge = new DeflectorWall("deflector-wall-large") {{
|
||||
health = 150 * 4 * wallHealthMultiplier;
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
door = new Door("door") {{
|
||||
health = 90 * wallHealthMultiplier;
|
||||
}};
|
||||
|
||||
@@ -113,7 +113,7 @@ public class TileEntity extends BaseEntity implements TargetTrait {
|
||||
}
|
||||
|
||||
public void collision(Bullet other){
|
||||
damage(other.getDamage());
|
||||
tile.block().handleBulletHit(this, other);
|
||||
}
|
||||
|
||||
public void damage(float damage){
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
private static Vector2 vector = new Vector2();
|
||||
|
||||
private Team team;
|
||||
private boolean supressCollision;
|
||||
|
||||
public Timer timer = new Timer(3);
|
||||
|
||||
@@ -73,7 +74,11 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
public Bullet(){}
|
||||
|
||||
public boolean collidesTiles(){
|
||||
return type.collidesTiles; //TODO make artillery and such not do this
|
||||
return type.collidesTiles;
|
||||
}
|
||||
|
||||
public void supressCollision(){
|
||||
supressCollision = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,7 +146,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
public void update(){
|
||||
super.update();
|
||||
|
||||
if (type.hitTiles && collidesTiles()) {
|
||||
if (type.hitTiles && collidesTiles() && !supressCollision) {
|
||||
world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> {
|
||||
|
||||
Tile tile = world.tile(x, y);
|
||||
@@ -150,8 +155,11 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
|
||||
if (tile.entity != null && tile.entity.collide(this) && !tile.entity.isDead() && tile.entity.tile.getTeam() != team) {
|
||||
tile.entity.collision(this);
|
||||
remove();
|
||||
type.hit(this);
|
||||
|
||||
if(!supressCollision){
|
||||
type.hit(this);
|
||||
remove();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -159,6 +167,8 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
supressCollision = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.annotations.Annotations.ReadClass;
|
||||
import io.anuke.annotations.Annotations.WriteClass;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.entities.traits.CarriableTrait;
|
||||
import io.anuke.mindustry.entities.traits.CarryTrait;
|
||||
@@ -23,6 +24,7 @@ import io.anuke.ucore.entities.Entities;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
@@ -51,12 +53,23 @@ public class TypeIO {
|
||||
}
|
||||
|
||||
@ReadClass(Unit.class)
|
||||
public static Unit writeUnit(ByteBuffer buffer){
|
||||
public static Unit readUnit(ByteBuffer buffer){
|
||||
byte gid = buffer.get();
|
||||
int id = buffer.getInt();
|
||||
return (Unit)Entities.getGroup(gid).getByID(id);
|
||||
}
|
||||
|
||||
@WriteClass(Bullet.class)
|
||||
public static void writeBullet(ByteBuffer buffer, Bullet bullet){
|
||||
buffer.putInt(bullet.getID());
|
||||
}
|
||||
|
||||
@ReadClass(Bullet.class)
|
||||
public static Bullet readBullet(ByteBuffer buffer){
|
||||
int id = buffer.getInt();
|
||||
return (Bullet)bulletGroup.getByID(id);
|
||||
}
|
||||
|
||||
@WriteClass(CarriableTrait.class)
|
||||
public static void writeCarriable(ByteBuffer buffer, CarriableTrait unit){
|
||||
if(unit == null){
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.effect.Puddle;
|
||||
import io.anuke.mindustry.entities.effect.Rubble;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
@@ -237,6 +238,10 @@ public class Block extends BaseBlock implements UnlockableContent{
|
||||
public float handleDamage(Tile tile, float amount){
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void handleBulletHit(TileEntity entity, Bullet bullet){
|
||||
entity.damage(bullet.getDamage());
|
||||
}
|
||||
|
||||
public void update(Tile tile){}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package io.anuke.mindustry.world.blocks.defense;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Wall;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class DeflectorWall extends Wall {
|
||||
static final float hitTime = 10f;
|
||||
|
||||
public DeflectorWall(String name) {
|
||||
super(name);
|
||||
update = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
DeflectorEntity entity = tile.entity();
|
||||
|
||||
if(entity.hit < 0.0001f) return;
|
||||
|
||||
Graphics.setAdditiveBlending();
|
||||
|
||||
Draw.color(Color.WHITE);
|
||||
Draw.alpha(entity.hit * 0.5f);
|
||||
Draw.rect("blank", tile.drawx(), tile.drawy(), tilesize * size, tilesize * size);
|
||||
Draw.reset();
|
||||
|
||||
entity.hit = Mathf.clamp(entity.hit - Timers.delta()/hitTime);
|
||||
|
||||
Graphics.setNormalBlending();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBulletHit(TileEntity entity, Bullet bullet){
|
||||
super.handleBulletHit(entity, bullet);
|
||||
|
||||
float penX = Math.abs(entity.x - bullet.x), penY = Math.abs(entity.y - bullet.y);
|
||||
|
||||
if(penX < tilesize/2f * size) {
|
||||
bullet.getVelocity().x *= -1;
|
||||
}
|
||||
|
||||
if(penY < tilesize/2f * size){
|
||||
bullet.getVelocity().y *= -1;
|
||||
}
|
||||
|
||||
bullet.updateVelocity(BulletType.getByID(bullet.getTypeID()).drag);
|
||||
bullet.supressCollision();
|
||||
|
||||
((DeflectorEntity)entity).hit = 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new DeflectorEntity();
|
||||
}
|
||||
|
||||
static class DeflectorEntity extends TileEntity{
|
||||
public float hit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user