Better leg unit death explosion

This commit is contained in:
Anuken 2022-02-01 23:21:57 -05:00
parent 69f59ff803
commit a138b7b9a8
9 changed files with 65 additions and 19 deletions

View File

@ -2360,5 +2360,20 @@ public class Fx{
}
Lines.endLine();
}).followParent(false).rotWithParent(false);
}).followParent(false).rotWithParent(false),
legDestroy = new Effect(90f, 100f, e -> {
if(!(e.data instanceof LegDestroyData data)) return;
rand.setSeed(e.id);
e.lifetime = rand.random(70f, 130f);
Tmp.v1.trns(rand.random(360f), rand.random(data.region.width / 8f) * e.finpow());
float ox = Tmp.v1.x, oy = Tmp.v1.y;
alpha(e.foutpowdown());
stroke(data.region.height * scl);
line(data.region, data.a.x + ox, data.a.y + oy, data.b.x + ox, data.b.y + oy, false);
}).layer(Layer.groundUnit + 5f);
}

View File

@ -52,7 +52,6 @@ public class Planets{
landCloudColor = Color.valueOf("ed6542");
atmosphereColor = Color.valueOf("f07218");
defaultEnv = Env.scorching | Env.terrestrial;
drillOverlay = Blocks.air;
startSector = 10;
atmosphereRadIn = 0.02f;
atmosphereRadOut = 0.3f;

View File

@ -0,0 +1,15 @@
package mindustry.entities;
import arc.graphics.g2d.*;
import arc.math.geom.*;
public class LegDestroyData{
public Vec2 a, b;
public TextureRegion region;
public LegDestroyData(Vec2 a, Vec2 b, TextureRegion region){
this.a = a;
this.b = b;
this.region = region;
}
}

View File

@ -15,6 +15,8 @@ import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.blocks.environment.*;
import static mindustry.Vars.*;
@Component
abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
private static final Vec2 straightVec = new Vec2();
@ -57,6 +59,31 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
resetLegs(1f);
}
@MethodPriority(-1)
@Override
public void destroy(){
if(!isAdded() || Vars.headless) return;
float legExplodeRad = type.legRegion.height / 4f / 1.45f;
//create effects for legs being destroyed
for(int i = 0; i < legs.length; i++){
Leg l = legs[i];
Vec2 base = legOffset(Tmp.v1, i).add(x, y);
Tmp.v2.set(l.base).sub(l.joint).inv().setLength(type.legExtension);
for(Vec2 vec : new Vec2[]{base, l.joint, l.base}){
Damage.dynamicExplosion(vec.x, vec.y, 0f, 0f, 0f, legExplodeRad, state.rules.damageExplosions, false, team, type.deathExplosionEffect);
}
Fx.legDestroy.at(base.x, base.y, 0f, new LegDestroyData(base.cpy(), l.joint, type.legRegion));
Fx.legDestroy.at(l.joint.x, l.joint.y, 0f, new LegDestroyData(l.joint.cpy().add(Tmp.v2), l.base, type.legBaseRegion));
}
}
public void resetLegs(){
resetLegs(type.legLength);
}
@ -89,7 +116,6 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
baseRotation = rotation;
}
float rot = baseRotation;
float legLength = type.legLength;
//set up initial leg positions

View File

@ -506,7 +506,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
float power = item().charge * Mathf.pow(stack().amount, 1.11f) * 160f;
if(!spawnedByCore){
Damage.dynamicExplosion(x, y, flammability, explosiveness, power, bounds() / 2f, state.rules.damageExplosions, item().flammability > 1, team, type.deathExplosionEffect);
Damage.dynamicExplosion(x, y, flammability, explosiveness, power, (bounds() + type.legLength/1.7f) / 2f, state.rules.damageExplosions, item().flammability > 1, team, type.deathExplosionEffect);
}else{
type.deathExplosionEffect.at(x, y, bounds() / 2f / 8f);
}

View File

@ -30,7 +30,6 @@ import mindustry.world.blocks.ConstructBlock.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.blocks.legacy.*;
import mindustry.world.blocks.power.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.sandbox.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.blocks.storage.CoreBlock.*;
@ -421,20 +420,20 @@ public class Schematics implements Loadable{
/** Places the last launch loadout at the coordinates and fills it with the launch resources. */
public static void placeLaunchLoadout(int x, int y){
placeLoadout(universe.getLastLoadout(), x, y, state.rules.defaultTeam, state.rules.sector == null ? Blocks.air : state.rules.sector.planet.drillOverlay);
placeLoadout(universe.getLastLoadout(), x, y, state.rules.defaultTeam);
if(world.tile(x, y).build == null) throw new RuntimeException("No core at loadout coordinates!");
world.tile(x, y).build.items.add(universe.getLaunchResources());
}
public static void placeLoadout(Schematic schem, int x, int y){
placeLoadout(schem, x, y, state.rules.defaultTeam, Blocks.oreCopper);
placeLoadout(schem, x, y, state.rules.defaultTeam);
}
public static void placeLoadout(Schematic schem, int x, int y, Team team, Block resource){
placeLoadout(schem, x, y, team, resource, true);
public static void placeLoadout(Schematic schem, int x, int y, Team team){
placeLoadout(schem, x, y, team, true);
}
public static void placeLoadout(Schematic schem, int x, int y, Team team, Block resource, boolean check){
public static void placeLoadout(Schematic schem, int x, int y, Team team, boolean check){
Stile coreTile = schem.tiles.find(s -> s.block instanceof CoreBlock);
Seq<Tile> seq = new Seq<>();
if(coreTile == null) throw new IllegalArgumentException("Loadout schematic has no core tile!");
@ -465,10 +464,6 @@ public class Schematics implements Loadable{
tile.build.configureAny(config);
}
if(st.block instanceof Drill && resource != Blocks.air){
tile.getLinkedTiles(t -> t.setOverlay(resource));
}
if(tile.build instanceof CoreBuild cb){
state.teams.registerCore(cb);
}

View File

@ -56,7 +56,7 @@ public class BaseGenerator{
for(Tile tile : cores){
tile.clearOverlay();
Schematics.placeLoadout(coreschem.schematic, tile.x, tile.y, team, coreschem.required instanceof Item ? bases.ores.get((Item)coreschem.required) : Blocks.oreCopper, false);
Schematics.placeLoadout(coreschem.schematic, tile.x, tile.y, team, false);
//fill core with every type of item (even non-material)
Building entity = tile.build;

View File

@ -9,14 +9,12 @@ import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.noise.*;
import mindustry.content.*;
import mindustry.content.TechTree.*;
import mindustry.ctype.*;
import mindustry.graphics.*;
import mindustry.graphics.g3d.*;
import mindustry.graphics.g3d.PlanetGrid.*;
import mindustry.maps.generators.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
@ -68,8 +66,6 @@ public class Planet extends UnlockableContent{
public boolean accessible = true;
/** Environment flags for sectors on this planet. */
public int defaultEnv = Env.terrestrial | Env.spores | Env.groundOil | Env.groundWater | Env.oxygen;
/** Default block placed under drills upon launching. */
public Block drillOverlay = Blocks.oreCopper;
/** If true, a day/night cycle is simulated. */
public boolean updateLighting = true;
/** Day/night cycle parameters. */