From 396c087072b964ac3eca72f8be57f0108a96d343 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 16 Jan 2022 22:53:58 -0500 Subject: [PATCH] Experimenting with abilities --- .../sprites/units/bulwark-armor.png | Bin 0 -> 1393 bytes core/assets/icons/icons.properties | 1 + core/assets/logicids.dat | Bin 3934 -> 3950 bytes core/assets/shaders/unitarmor.frag | 30 +++++++++++ core/assets/shaders/unitbuild.frag | 31 ++--------- core/src/mindustry/content/Blocks.java | 17 ++++-- core/src/mindustry/content/UnitTypes.java | 9 ++-- .../entities/abilities/ArmorPlateAbility.java | 49 ++++++++++++++++++ core/src/mindustry/graphics/Shaders.java | 20 +++++++ 9 files changed, 122 insertions(+), 35 deletions(-) create mode 100644 core/assets-raw/sprites/units/bulwark-armor.png create mode 100644 core/assets/shaders/unitarmor.frag create mode 100644 core/src/mindustry/entities/abilities/ArmorPlateAbility.java diff --git a/core/assets-raw/sprites/units/bulwark-armor.png b/core/assets-raw/sprites/units/bulwark-armor.png new file mode 100644 index 0000000000000000000000000000000000000000..1057bdee6707874ef1e7b53254fa819e4eae8a86 GIT binary patch literal 1393 zcmaKs`#%#30L2x}Vrs)oLYYfU$|FT+ZHB14-+9hEZKPzML^r~^o5#(oOv!s~-tAh$ zblv7-@|^cuh&!*DSCZtqf55%x^Ev1H%Q?TEXLdH0QW6RhA|fJER@X2N2aG>(ArNqo zDOJ$+101^NV2Ku~>{4715jmn|g+VzH@>cRjo)_tW%x~`RBZHNLJk1Ch}s9d9W)zHrBtYPW*xA^m_V^REE#;1_={*}N$de^vGMK8r9 zD(2-#sj96NouO_!;r*bFj|uBV*tR(`nTJ)B?7AA*Rx!0D_*I#ggQo<5tPMd(ui(zx zv0Y5vRx(|8uF;snple6Pa3#W}ef$s2k)A&dp^V8wTOk5d&&RJ1N)`pP=ZC6w84&!(E22WSz z#21E;JVN)Zaf=_N1$*u2Hw#Iwc4-p-=`uKD4o2d^spZNPTxpWMq4j>dtK^fS&HZ9` z)s9Cb`Mrs0a@yotV^Iu7M>Fq7Pw9+I?b1HdYw8}ZegFE)RiE>!xMRiz4w3Y}qC?23 zXvJ3E;`Y`kPxW@-zK1;2g|C3xyI^A4Y1-^kH-O$0oVkPHFML~+H0o|TX8?bc0kmFN zGVAAljvEx>;D)mU(K#*Hix5oziLT)e1c2$<;SJ~GieQPIWNd`HDuMK7C`b!IIWYv9 zM-#!#L|iy!gp)pB-i&oqVoml1m9_{gz}{!dUsX#tFUKlhWY6qowlmRoP3De`^z&*z zJI81B4x|-4n>ODUUON z2sT#eO<}DnG}((~-H_yJh1R77KafSKg-yj7W%>DpL8#QC3EKct6zxmq&5sp8$Ea)=d!1886rW;>r z;!APV$h-KmP>c{!9KyQP0JN@Iwd`hBuwrE6bATSBZYVM6L8nFd4Mj}!f8&3_GHtB& zp(xxfdD4^JaAlbQV{{0HOYs(BtQRzn0viJP67ZgZ|Dujbr$BUzcM3o~dRswj&$5|L zz?S4}!Zs152lteM18#ZD;4Z@(^&bU;b%%ST!*dMK$B8J?+(P9}jV`vwHud?b+TJ$ngLzotX1g^=J;g%ov^5A4=T21dauyiZW>=ekFOf@N)PR(} zN}B;bWMb1}*R$D0ynr9-Gh`0yES!7UAg@iDuBC~LS5m>&$g^+R*CvADGPNZ6UWo#O zKTk;4Jg9Vu~e010XLOE{&+ayXPusv7T5am9N57ifmZh@B;GpH`r(Oy-qX|K(7v>oLprsoo!-VgA+63-H+IN*(*95DcKjoTx6)n3hN6E zX=o#wjXuNBiJk5^l0vgfJv(^QU2R-unD=>N#Ex0U@Uyy{jL?44Dc1vytt`GzTi2|1 u7p*VsF8Kw9*38XMTnjSKKlI-Z_gpB>l#Mtk2WjK|Te32@!BnDs 0.01){ + float f = step(abs(sin(coords.y*3.0 + u_time)), 0.9); + c.a *= f; + //c.rgb = mix(c.rgb, u_color.rgb, f * u_color.a); + } + + // c.a *= (1.0-coords.y); + + gl_FragColor = c * v_color; +} diff --git a/core/assets/shaders/unitbuild.frag b/core/assets/shaders/unitbuild.frag index d4657060da..9f4386aba7 100644 --- a/core/assets/shaders/unitbuild.frag +++ b/core/assets/shaders/unitbuild.frag @@ -1,5 +1,3 @@ -#define step 3.0 - uniform sampler2D u_texture; uniform float u_time; @@ -12,40 +10,17 @@ uniform vec2 u_texsize; varying vec4 v_color; varying vec2 v_texCoords; -bool id(vec4 v){ - return v.a > 0.1; -} - -bool id(vec2 coords, vec4 base){ - vec4 target = texture2D(u_texture, coords); - return target.a < 0.1 || (coords.x < u_uv.x || coords.y < u_uv.y || coords.x > u_uv2.x || coords.y > u_uv2.y); -} - -bool cont(vec2 T, vec2 v){ - vec4 base = texture2D(u_texture, T); - return base.a > 0.1 && - (id(T + vec2(0, step) * v, base) || id(T + vec2(0, -step) * v, base) || - id(T + vec2(step, 0) * v, base) || id(T + vec2(-step, 0) * v, base) || - id(T + vec2(step, step) * v, base) || id(T + vec2(-step, -step) * v, base) || - id(T + vec2(step, -step) * v, base) || id(T + vec2(-step, step) * v, base)); -} - void main(){ - vec2 coords = (v_texCoords.xy - u_uv) / (u_uv2 - u_uv); - vec2 t = v_texCoords.xy; + vec2 coords = (v_texCoords - u_uv) / (u_uv2 - u_uv); vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y); - vec4 c = texture2D(u_texture, v_texCoords.xy); + vec4 c = texture2D(u_texture, v_texCoords); float alpha = c.a; c.a *= u_progress; if(c.a > 0.01){ - float f = abs(sin(coords.x*2.0 + u_time)); - if(f > 0.9) - f = 1.0; - else - f = 0.0; + float f = step(abs(sin(coords.x*2.0 + u_time)), 0.9); c = mix(c, u_color, f * u_color.a); } diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 3bc530df58..3436c3fad6 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -3295,7 +3295,7 @@ public class Blocks{ tankAssembler = new UnitAssembler("tank-assembler"){{ requirements(Category.units, with(Items.graphite, 10)); size = 5; - plans.add(new AssemblerUnitPlan(UnitTypes.vanquish, 60f * 10f, BlockStack.list(Blocks.thoriumWallLarge, 4, Blocks.duct, 2))); + plans.add(new AssemblerUnitPlan(UnitTypes.vanquish, 60f * 10f, BlockStack.list(Blocks.tungstenWallLarge, 5, Blocks.duct, 2))); consumes.power(2f); areaSize = 13; @@ -3307,7 +3307,7 @@ public class Blocks{ shipAssembler = new UnitAssembler("ship-assembler"){{ requirements(Category.units, with(Items.graphite, 10)); size = 5; - plans.add(new AssemblerUnitPlan(UnitTypes.quell, 60f * 4f, BlockStack.list(Blocks.thoriumWallLarge, 4, Blocks.duct, 2))); + plans.add(new AssemblerUnitPlan(UnitTypes.quell, 60f * 4f, BlockStack.list(Blocks.tungstenWallLarge, 5, Blocks.plasmaBore, 2))); consumes.power(2f); areaSize = 13; @@ -3316,7 +3316,18 @@ public class Blocks{ }}; - //TODO mech assembler + //TODO requirements + mechAssembler = new UnitAssembler("mech-assembler"){{ + requirements(Category.units, with(Items.graphite, 10)); + size = 5; + plans.add(new AssemblerUnitPlan(UnitTypes.bulwark, 60f * 4f, BlockStack.list(Blocks.tungstenWallLarge, 5, Blocks.duct, 2))); + consumes.power(2f); + areaSize = 13; + + //TODO unit production is rarely continuous, can be double + consumes.liquid(Liquids.gallium, 1f / 60f); + + }}; basicAssemblerModule = new UnitAssemblerModule("basic-assembler-module"){{ requirements(Category.units, with(Items.graphite, 10)); diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index cece9e8a2d..c4c5bfd7d3 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -2455,7 +2455,7 @@ public class UnitTypes{ sprite = "missile-large"; width = 9.5f; height = 15f; - lifetime = 32f; + lifetime = 30f; hitSize = 6f; shootEffect = Fx.shootTitan; smokeEffect = Fx.shootSmokeTitan; @@ -2509,7 +2509,8 @@ public class UnitTypes{ outlineColor = Pal.darkOutline; envDisabled = Env.space; - //TODO shield ability + //TODO shield ability looks bad + //abilities.add(new ArmorPlateAbility()); rotateSpeed = 2.7f; @@ -2549,7 +2550,7 @@ public class UnitTypes{ velocityRnd = 0.33f; heatColor = Color.red; - bullet = new MissileBulletType(4.2f, 30){{ + bullet = new MissileBulletType(4.2f, 34){{ homingPower = 0.2f; weaveMag = 4; weaveScale = 4; @@ -2557,7 +2558,7 @@ public class UnitTypes{ //TODO better shootEffect = Fx.shootBig2; smokeEffect = Fx.shootSmokeTitan; - splashDamage = 50f; + splashDamage = 40f; splashDamageRadius = 30f; frontColor = Color.white; hitSound = Sounds.none; diff --git a/core/src/mindustry/entities/abilities/ArmorPlateAbility.java b/core/src/mindustry/entities/abilities/ArmorPlateAbility.java new file mode 100644 index 0000000000..f20e3b855d --- /dev/null +++ b/core/src/mindustry/entities/abilities/ArmorPlateAbility.java @@ -0,0 +1,49 @@ +package mindustry.entities.abilities; + +import arc.*; +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; +import arc.util.*; +import mindustry.gen.*; +import mindustry.graphics.*; + +public class ArmorPlateAbility extends Ability{ + public TextureRegion plateRegion; + public Color color = Color.valueOf("d1efff"); + + public float healthMultiplier = 0.2f; + public float z = Layer.effect; + + protected float warmup; + + @Override + public void update(Unit unit){ + super.update(unit); + + warmup = Mathf.lerpDelta(warmup, unit.isShooting() ? 1f : 0f, 0.1f); + unit.healthMultiplier += warmup * healthMultiplier; + } + + @Override + public void draw(Unit unit){ + if(warmup > 0.001f){ + if(plateRegion == null){ + plateRegion = Core.atlas.find(unit.type.name + "-armor", unit.type.region); + } + + Draw.draw(z <= 0 ? Draw.z() : z, () -> { + Shaders.armor.region = plateRegion; + Shaders.armor.progress = warmup; + Shaders.armor.time = -Time.time / 20f; + + Draw.color(color); + Draw.shader(Shaders.armor); + Draw.rect(Shaders.armor.region, unit.x, unit.y, unit.rotation - 90f); + Draw.shader(); + + Draw.reset(); + }); + } + } +} diff --git a/core/src/mindustry/graphics/Shaders.java b/core/src/mindustry/graphics/Shaders.java index 9868dc1da3..b74c70fdaf 100644 --- a/core/src/mindustry/graphics/Shaders.java +++ b/core/src/mindustry/graphics/Shaders.java @@ -19,6 +19,7 @@ public class Shaders{ public static @Nullable ShieldShader shield; public static BuildBeamShader buildBeam; public static UnitBuildShader build; + public static UnitArmorShader armor; public static DarknessShader darkness; public static LightShader light; public static SurfaceShader water, mud, tar, slag, cryofluid, space, caustics, arkycite; @@ -42,6 +43,7 @@ public class Shaders{ } buildBeam = new BuildBeamShader(); build = new UnitBuildShader(); + armor = new UnitArmorShader(); darkness = new DarknessShader(); light = new LightShader(); water = new SurfaceShader("water"); @@ -200,6 +202,24 @@ public class Shaders{ } } + public static class UnitArmorShader extends LoadShader{ + public float progress, time; + public TextureRegion region; + + public UnitArmorShader(){ + super("unitarmor", "default"); + } + + @Override + public void apply(){ + setUniformf("u_time", time); + setUniformf("u_progress", progress); + setUniformf("u_uv", region.u, region.v); + setUniformf("u_uv2", region.u2, region.v2); + setUniformf("u_texsize", region.texture.width, region.texture.height); + } + } + public static class BlockBuildShader extends LoadShader{ public float progress; public TextureRegion region = new TextureRegion();