chargeShootEffect / Effect startDelay

This commit is contained in:
Anuken
2021-09-29 22:39:33 -04:00
parent efb9df7b1b
commit 6f6590d5bb
6 changed files with 33 additions and 15 deletions

View File

@@ -120,7 +120,7 @@ public interface Platform{
}else{
ui.loadAnd(() -> {
try{
Fi result = Core.files.local(name+ "." + extension);
Fi result = Core.files.local(name + "." + extension);
writer.write(result);
platform.shareFile(result);
}catch(Throwable e){

View File

@@ -30,6 +30,8 @@ public class Effect{
public float lifetime = 50f;
/** Clip size. */
public float clip;
/** Time delay before the effect starts */
public float startDelay;
/** Amount added to rotation */
public float baseRotation;
/** If true, parent unit is data are followed. */
@@ -58,6 +60,11 @@ public class Effect{
all.add(this);
}
public Effect startDelay(float d){
startDelay = d;
return this;
}
public void init(){}
public Effect followParent(boolean follow){
@@ -168,21 +175,29 @@ public class Effect{
effect.init();
}
EffectState entity = EffectState.create();
entity.effect = effect;
entity.rotation = effect.baseRotation + rotation;
entity.data = data;
entity.lifetime = effect.lifetime;
entity.set(x, y);
entity.color.set(color);
if(effect.followParent && data instanceof Posc p){
entity.parent = p;
entity.rotWithParent = effect.rotWithParent;
if(effect.startDelay <= 0f){
inst(effect, x, y, rotation, color, data);
}else{
Time.runTask(effect.startDelay, () -> inst(effect, x, y, rotation, color, data));
}
entity.add();
}
}
private static void inst(Effect effect, float x, float y, float rotation, Color color, Object data){
EffectState entity = EffectState.create();
entity.effect = effect;
entity.rotation = effect.baseRotation + rotation;
entity.data = data;
entity.lifetime = effect.lifetime;
entity.set(x, y);
entity.color.set(color);
if(effect.followParent && data instanceof Posc p){
entity.parent = p;
entity.rotWithParent = effect.rotWithParent;
}
entity.add();
}
public static void decal(TextureRegion region, float x, float y, float rotation){
decal(region, x, y, rotation, 3600f, Pal.rubble);
}

View File

@@ -49,6 +49,8 @@ public class BulletType extends Content implements Cloneable{
public Effect despawnEffect = Fx.hitBulletSmall;
/** Effect created when shooting. */
public Effect shootEffect = Fx.shootSmall;
/** Effect created when charging completes; only usable in single-shot weapons with a firstShotDelay / shotDelay. */
public Effect chargeShootEffect = Fx.none;
/** Extra smoke effect created when shooting. */
public Effect smokeEffect = Fx.shootSmallSmoke;
/** Sound made when hitting something or getting removed.*/

View File

@@ -76,7 +76,7 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
//sort counts in descending order
Seq<Entry<Block>> entries = floorc.entries().toArray();
entries.sort(e -> -e.value);
//remove all blocks occuring < 30 times - unimportant
//remove all blocks occurring < 30 times - unimportant
entries.removeAll(e -> e.value < 30);
Block[] floors = new Block[entries.size];
@@ -84,7 +84,7 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
floors[i] = entries.get(i).key;
}
//TODO bad code
//bad contains() code, but will likely never be fixed
boolean hasSnow = floors.length > 0 && (floors[0].name.contains("ice") || floors[0].name.contains("snow"));
boolean hasRain = floors.length > 0 && !hasSnow && content.contains(Liquids.water) && !floors[0].name.contains("sand");
boolean hasDesert = floors.length > 0 && !hasSnow && !hasRain && floors[0] == Blocks.sand;

View File

@@ -350,6 +350,7 @@ public class Weapon implements Cloneable{
if(!continuous){
shootSound.at(shootX, shootY, Mathf.random(soundPitchMin, soundPitchMax));
}
ammo.chargeShootEffect.at(shootX + unit.x - baseX, shootY + unit.y - baseY, rotation, parentize ? unit : null);
});
}else{
unit.vel.add(Tmp.v1.trns(rotation + 180f, ammo.recoil));