From 0a7e40bd23c211fd51c7d79c8f836d10eea4d378 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 2 Jul 2020 10:44:31 -0400 Subject: [PATCH] Merged wall classes --- core/src/mindustry/content/Blocks.java | 12 ++-- core/src/mindustry/world/Build.java | 5 +- .../world/blocks/defense/DeflectorWall.java | 69 ------------------- .../world/blocks/defense/SurgeWall.java | 28 -------- .../mindustry/world/blocks/defense/Wall.java | 69 +++++++++++++++++++ gradle.properties | 2 +- 6 files changed, 80 insertions(+), 105 deletions(-) delete mode 100644 core/src/mindustry/world/blocks/defense/DeflectorWall.java delete mode 100644 core/src/mindustry/world/blocks/defense/SurgeWall.java diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index b127ed7407..40be769a5b 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -749,26 +749,30 @@ public class Blocks implements ContentList{ size = 2; }}; - phaseWall = new DeflectorWall("phase-wall"){{ + phaseWall = new Wall("phase-wall"){{ requirements(Category.defense, with(Items.phasefabric, 6)); health = 150 * wallHealthMultiplier; + flashWhite = deflect = true; }}; - phaseWallLarge = new DeflectorWall("phase-wall-large"){{ + phaseWallLarge = new Wall("phase-wall-large"){{ requirements(Category.defense, ItemStack.mult(phaseWall.requirements, 4)); health = 150 * 4 * wallHealthMultiplier; size = 2; + flashWhite = deflect = true; }}; - surgeWall = new SurgeWall("surge-wall"){{ + surgeWall = new Wall("surge-wall"){{ requirements(Category.defense, with(Items.surgealloy, 6)); health = 230 * wallHealthMultiplier; + lightningChance = 0.05f; }}; - surgeWallLarge = new SurgeWall("surge-wall-large"){{ + surgeWallLarge = new Wall("surge-wall-large"){{ requirements(Category.defense, ItemStack.mult(surgeWall.requirements, 4)); health = 230 * 4 * wallHealthMultiplier; size = 2; + lightningChance = 0.05f; }}; door = new Door("door"){{ diff --git a/core/src/mindustry/world/Build.java b/core/src/mindustry/world/Build.java index d9c38c1a7f..3578826bbe 100644 --- a/core/src/mindustry/world/Build.java +++ b/core/src/mindustry/world/Build.java @@ -114,8 +114,7 @@ public class Build{ return type.bounds(x, y, Tmp.r1).grow(0.01f).contains(tile.block.bounds(tile.centerX(), tile.centerY(), Tmp.r2)); } - //TODO should water blocks be placeable here? - if(/*!type.requiresWater && */!contactsShallows(tile.x, tile.y, type)){ + if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type)){ return false; } @@ -142,7 +141,7 @@ public class Build{ return true; }else{ return tile.interactable(team) - && contactsShallows(tile.x, tile.y, type) + && (contactsShallows(tile.x, tile.y, type) || type.requiresWater) && (!tile.floor().isDeep() || type.floating || type.requiresWater) && tile.floor().placeableOn && (!type.requiresWater || tile.floor().liquidDrop == Liquids.water) diff --git a/core/src/mindustry/world/blocks/defense/DeflectorWall.java b/core/src/mindustry/world/blocks/defense/DeflectorWall.java deleted file mode 100644 index ae2d9e8834..0000000000 --- a/core/src/mindustry/world/blocks/defense/DeflectorWall.java +++ /dev/null @@ -1,69 +0,0 @@ -package mindustry.world.blocks.defense; - -import arc.graphics.*; -import arc.graphics.g2d.*; -import arc.math.*; -import arc.math.geom.*; -import arc.util.*; -import mindustry.gen.*; - -import static mindustry.Vars.tilesize; - -public class DeflectorWall extends Wall{ - public static final float hitTime = 10f; - - protected float maxDamageDeflect = 10f; - protected Rect rect = new Rect(); - protected Rect rect2 = new Rect(); - - public DeflectorWall(String name){ - super(name); - } - - public class DeflectorEntity extends Building{ - public float hit; - - @Override - public void draw(){ - super.draw(); - - if(hit < 0.0001f) return; - - Draw.color(Color.white); - Draw.alpha(hit * 0.5f); - Draw.blend(Blending.additive); - Fill.rect(x, y, tilesize * size, tilesize * size); - Draw.blend(); - Draw.reset(); - - hit = Mathf.clamp(hit - Time.delta() / hitTime); - } - - @Override - public boolean collision(Bullet bullet){ - super.collision(bullet); - - //doesn't reflect powerful bullets - if(bullet.damage() > maxDamageDeflect) return true; - - //translate bullet back to where it was upon collision - bullet.trns(-bullet.vel().x, -bullet.vel().y); - - float penX = Math.abs(x - bullet.x()), penY = Math.abs(y - bullet.y()); - - if(penX > penY){ - bullet.vel().x *= -1; - }else{ - bullet.vel().y *= -1; - } - - bullet.owner(this); - bullet.team(team); - bullet.time(bullet.time() + 1f); - - hit = 1f; - - return false; - } - } -} diff --git a/core/src/mindustry/world/blocks/defense/SurgeWall.java b/core/src/mindustry/world/blocks/defense/SurgeWall.java deleted file mode 100644 index becf1b46e9..0000000000 --- a/core/src/mindustry/world/blocks/defense/SurgeWall.java +++ /dev/null @@ -1,28 +0,0 @@ -package mindustry.world.blocks.defense; - -import arc.math.*; -import mindustry.entities.*; -import mindustry.gen.*; -import mindustry.graphics.*; - -public class SurgeWall extends Wall{ - public float lightningChance = 0.05f; - public float lightningDamage = 20f; - public int lightningLength = 17; - - public SurgeWall(String name){ - super(name); - } - - public class SurgeEntity extends Building{ - @Override - public boolean collision(Bullet bullet){ - - if(Mathf.chance(lightningChance)){ - Lightning.create(team(), Pal.surge, lightningDamage, x, y, bullet.rotation() + 180f, lightningLength); - } - - return super.collision(bullet); - } - } -} diff --git a/core/src/mindustry/world/blocks/defense/Wall.java b/core/src/mindustry/world/blocks/defense/Wall.java index 6411640356..f3002bf3e0 100644 --- a/core/src/mindustry/world/blocks/defense/Wall.java +++ b/core/src/mindustry/world/blocks/defense/Wall.java @@ -1,15 +1,29 @@ package mindustry.world.blocks.defense; import arc.*; +import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; +import arc.util.*; +import mindustry.entities.*; import mindustry.gen.*; +import mindustry.graphics.*; import mindustry.world.*; import mindustry.world.meta.*; +import static mindustry.Vars.*; + public class Wall extends Block{ public int variants = 0; + public float lightningChance = -0.001f; + public float lightningDamage = 20f; + public int lightningLength = 17; + + public float maxDamageDeflect = 10f; + public boolean flashWhite; + public boolean deflect; + public Wall(String name){ super(name); solid = true; @@ -43,6 +57,7 @@ public class Wall extends Block{ } public class WallEntity extends Building{ + public float hit; @Override public void draw(){ @@ -51,6 +66,60 @@ public class Wall extends Block{ }else{ Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], x, y); } + + //draw flashing white overlay if enabled + if(flashWhite){ + if(hit < 0.0001f) return; + + Draw.color(Color.white); + Draw.alpha(hit * 0.5f); + Draw.blend(Blending.additive); + Fill.rect(x, y, tilesize * size, tilesize * size); + Draw.blend(); + Draw.reset(); + + hit = Mathf.clamp(hit - Time.delta() / 10f); + } + } + + @Override + public boolean collision(Bullet bullet){ + super.collision(bullet); + + hit = 1f; + + //create lightning if necessary + if(lightningChance > 0){ + if(Mathf.chance(lightningChance)){ + Lightning.create(team(), Pal.surge, lightningDamage, x, y, bullet.rotation() + 180f, lightningLength); + } + } + + //deflect bullets if necessary + if(deflect){ + //doesn't reflect powerful bullets + if(bullet.damage() > maxDamageDeflect) return true; + + //translate bullet back to where it was upon collision + bullet.trns(-bullet.vel().x, -bullet.vel().y); + + float penX = Math.abs(x - bullet.x()), penY = Math.abs(y - bullet.y()); + + if(penX > penY){ + bullet.vel().x *= -1; + }else{ + bullet.vel().y *= -1; + } + + bullet.owner(this); + bullet.team(team); + bullet.time(bullet.time() + 1f); + + //disable bullet collision by returning false + return false; + } + + return true; } } } diff --git a/gradle.properties b/gradle.properties index 3c456302d4..5b62b2b054 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=95c135917655b61d636292ba9dfd05766019c1d8 +archash=5e12ee82715df10aa81012c6b9db0865d47ceb16