New lightning mechanics

This commit is contained in:
Anuken
2018-10-09 19:49:46 -04:00
parent 0bae421fbc
commit faa1fee1c0
11 changed files with 97 additions and 34 deletions
@@ -96,7 +96,7 @@ public class Mechs implements ContentList{
Effects.shake(1f, 1f, player); Effects.shake(1f, 1f, player);
Effects.effect(UnitFx.landShock, player); Effects.effect(UnitFx.landShock, player);
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
Timers.run(Mathf.random(8f), () -> Lightning.create(player.getTeam(), BulletFx.hitLancer, player.getTeam().color, 17f, player.x, player.y, Mathf.random(360f), 14)); Timers.run(Mathf.random(8f), () -> Lightning.create(player.getTeam(), player.getTeam().color, 17f, player.x, player.y, Mathf.random(360f), 14));
} }
} }
} }
@@ -254,7 +254,7 @@ public class Mechs implements ContentList{
float scl = scld(player); float scl = scld(player);
if(Mathf.chance(Timers.delta() * (0.15*scl))){ if(Mathf.chance(Timers.delta() * (0.15*scl))){
Effects.effect(BulletFx.hitLancer, Palette.lancerLaser, player.x, player.y); Effects.effect(BulletFx.hitLancer, Palette.lancerLaser, player.x, player.y);
Lightning.create(player.getTeam(), BulletFx.hitLancer, Palette.lancerLaser, 10f, Lightning.create(player.getTeam(), Palette.lancerLaser, 10f,
player.x + player.getVelocity().x, player.y + player.getVelocity().y, player.rotation, 14); player.x + player.getVelocity().x, player.y + player.getVelocity().y, player.rotation, 14);
} }
} }
@@ -112,15 +112,18 @@ public class TurretBlocks extends BlockList implements ContentList{
heatColor = Color.RED; heatColor = Color.RED;
size = 2; size = 2;
health = 320; health = 320;
targetAir = false;
}}; }};
arc = new PowerTurret("arc"){{ arc = new PowerTurret("arc"){{
shootType = AmmoTypes.arc; shootType = AmmoTypes.arc;
reload = 34f; reload = 60f;
shootShake = 1f; shootShake = 1f;
shootCone = 40f;
rotatespeed = 8f;
powerUsed = 5f; powerUsed = 5f;
powerCapacity = 30f; powerCapacity = 30f;
range = 60f; range = 130f;
shootEffect = ShootFx.lightningShoot; shootEffect = ShootFx.lightningShoot;
heatColor = Color.RED; heatColor = Color.RED;
recoil = 1f; recoil = 1f;
@@ -43,7 +43,7 @@ public class FlakBullets extends BulletList implements ContentList{
super.despawned(b); super.despawned(b);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Lightning.create(b.getTeam(), BulletFx.hitLancer, Palette.surge, damage, b.x, b.y, Mathf.random(360f), 12); Lightning.create(b.getTeam(), Palette.surge, damage, b.x, b.y, Mathf.random(360f), 12);
} }
} }
}; };
@@ -67,7 +67,7 @@ public class MissileBullets extends BulletList implements ContentList{
super.hit(b); super.hit(b);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Lightning.create(b.getTeam(), BulletFx.hitLancer, Palette.surge, damage, b.x, b.y, Mathf.random(360f), 14); Lightning.create(b.getTeam(), Palette.surge, damage, b.x, b.y, Mathf.random(360f), 14);
} }
} }
}; };
@@ -27,11 +27,20 @@ import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.world; import static io.anuke.mindustry.Vars.world;
public class TurretBullets extends BulletList implements ContentList{ public class TurretBullets extends BulletList implements ContentList{
public static BulletType fireball, basicFlame, lancerLaser, burstLaser, meltdownLaser, fuseShot, waterShot, cryoShot, lavaShot, oilShot, lightning, driverBolt, healBullet, arc; public static BulletType fireball, basicFlame, lancerLaser, burstLaser, meltdownLaser,
fuseShot, waterShot, cryoShot, lavaShot, oilShot, lightning, driverBolt, healBullet, arc, damageLightning;
@Override @Override
public void load(){ public void load(){
damageLightning = new BulletType(0.0001f, 0f){
{
lifetime = Lightning.lifetime;
hiteffect = BulletFx.hitLancer;
despawneffect = Fx.none;
}
};
healBullet = new BulletType(5.2f, 13){ healBullet = new BulletType(5.2f, 13){
float healAmount = 21f; float healAmount = 21f;
@@ -276,11 +285,12 @@ public class TurretBullets extends BulletList implements ContentList{
} }
}; };
lightning = new BulletType(0.001f, 14){ lightning = new BulletType(0.001f, 12f){
{ {
lifetime = 1; lifetime = 1f;
despawneffect = Fx.none; despawneffect = Fx.none;
hiteffect = BulletFx.hitLancer; hiteffect = BulletFx.hitLancer;
keepVelocity = false;
} }
@Override @Override
@@ -289,11 +299,11 @@ public class TurretBullets extends BulletList implements ContentList{
@Override @Override
public void init(Bullet b){ public void init(Bullet b){
Lightning.create(b.getTeam(), hiteffect, Palette.lancerLaser, damage, b.x, b.y, b.angle(), 30); Lightning.create(b.getTeam(), Palette.lancerLaser, damage, b.x, b.y, b.angle(), 30);
} }
}; };
arc = new BulletType(0.001f, 7){ arc = new BulletType(0.001f, 30){
{ {
lifetime = 1; lifetime = 1;
despawneffect = Fx.none; despawneffect = Fx.none;
@@ -306,7 +316,7 @@ public class TurretBullets extends BulletList implements ContentList{
@Override @Override
public void init(Bullet b){ public void init(Bullet b){
Lightning.create(b.getTeam(), hiteffect, Palette.lancerLaser, damage, b.x, b.y, b.angle(), 28); Lightning.create(b.getTeam(), Palette.lancerLaser, damage, b.x, b.y, b.angle(), 34);
} }
}; };
@@ -34,7 +34,7 @@ public class Damage{
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){ public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){
for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i++){ for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i++){
int branches = 5 + Mathf.clamp((int) (power / 30), 1, 20); int branches = 5 + Mathf.clamp((int) (power / 30), 1, 20);
Timers.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.none, Fx.none, Palette.power, 3, Timers.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.none, Palette.power, 3,
x, y, Mathf.random(360f), branches + Mathf.range(2))); x, y, Mathf.random(360f), branches + Mathf.range(2)));
} }
@@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote; import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.entities.Unit; import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.entities.traits.AbsorbTrait; import io.anuke.mindustry.entities.traits.AbsorbTrait;
import io.anuke.mindustry.entities.traits.SyncTrait; import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TeamTrait; import io.anuke.mindustry.entities.traits.TeamTrait;
@@ -133,6 +134,10 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
return super.getDamage() * ((Unit) owner).getDamageMultipler(); return super.getDamage() * ((Unit) owner).getDamageMultipler();
} }
if(owner instanceof Lightning && data instanceof Float){
return (Float)data;
}
return super.getDamage(); return super.getDamage();
} }
@@ -1,10 +1,16 @@
package io.anuke.mindustry.entities.effect; package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntSet;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote; import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.content.bullets.TurretBullets;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.traits.SyncTrait; import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
@@ -17,17 +23,24 @@ import io.anuke.ucore.entities.trait.PosTrait;
import io.anuke.ucore.entities.trait.TimeTrait; import io.anuke.ucore.entities.trait.TimeTrait;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Pooling; import io.anuke.ucore.util.*;
import io.anuke.ucore.util.SeedRandom;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import static io.anuke.mindustry.Vars.bulletGroup; import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.fontScale;
public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, TimeTrait{ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, TimeTrait{
public static final float lifetime = 10f;
private static final SeedRandom random = new SeedRandom();
private static final Rectangle rect = new Rectangle();
private static final Array<Unit> entities = new Array<>();
private static final IntSet hit = new IntSet();
private static final int maxChain = 8;
private static final float hitRange = 30f;
private static int lastSeed = 0; private static int lastSeed = 0;
private static SeedRandom random = new SeedRandom();
private Array<PosTrait> lines = new Array<>(); private Array<PosTrait> lines = new Array<>();
private Color color = Palette.lancerLaser; private Color color = Palette.lancerLaser;
@@ -37,25 +50,52 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
} }
/**Create a lighting branch at a location. Use Team.none to damage everyone.*/ /**Create a lighting branch at a location. Use Team.none to damage everyone.*/
public static void create(Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){ public static void create(Team team, Color color, float damage, float x, float y, float targetAngle, int length){
Call.createLighting(lastSeed++, team, effect, color, damage, x, y, targetAngle, length); Call.createLighting(lastSeed++, team, color, damage, x, y, targetAngle, length);
} }
/**Do not invoke!*/ /**Do not invoke!*/
@Remote(called = Loc.server) @Remote(called = Loc.server)
public static void createLighting(int seed, Team team, Color color, float damage, float x, float y, int length){ public static void createLighting(int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
Lightning l = Pooling.obtain(Lightning.class, Lightning::new); Lightning l = Pooling.obtain(Lightning.class, Lightning::new);
Float dmg = damage;
l.x = x; l.x = x;
l.y = y; l.y = y;
l.color = color; l.color = color;
l.add(); l.add();
for (int i = 0; i < length; i++) {
Effect
}
random.setSeed(seed); random.setSeed(seed);
hit.clear();
for (int i = 0; i < length/2; i++) {
Bullet.create(TurretBullets.damageLightning, l, team, x, y, 0f, 1f, 1f, dmg);
l.lines.add(new Translator(x + Mathf.range(3f), y + Mathf.range(3f)));
rect.setSize(hitRange).setCenter(x, y);
entities.clear();
if(hit.size < maxChain){
Units.getNearbyEnemies(team, rect, u -> {
if(!hit.contains(u.getID())){
entities.add(u);
}
});
}
Unit furthest = Geometry.findFurthest(x, y, entities);
if(furthest != null){
hit.add(furthest.getID());
x = furthest.x;
y = furthest.y;
}else{
rotation += random.range(20f);
x += Angles.trnsx(rotation, hitRange/2f);
y += Angles.trnsy(rotation, hitRange/2f);
}
}
} }
@Override @Override
@@ -71,11 +111,12 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
@Override @Override
public float lifetime(){ public float lifetime(){
return 10; return lifetime;
} }
@Override @Override
public void reset(){ public void reset(){
super.reset();
color = Palette.lancerLaser; color = Palette.lancerLaser;
lines.clear(); lines.clear();
} }
@@ -91,20 +132,25 @@ public class Lightning extends TimedEntity implements DrawTrait, SyncTrait, Time
float lx = x, ly = y; float lx = x, ly = y;
Draw.color(color, Color.WHITE, fin()); Draw.color(color, Color.WHITE, fin());
for(int i = 0; i < lines.size; i++){ for(int i = 0; i < lines.size; i++){
Vector2 v = lines.get(i); PosTrait v = lines.get(i);
Lines.stroke(fout() * 3f * (1.5f - (float) i / lines.size)); float f = (float) i / lines.size;
Lines.stroke(fout() * 3f * (1.5f - f));
Lines.stroke(Lines.getStroke() * 4f); Lines.stroke(Lines.getStroke() * 4f);
Draw.alpha(0.3f); Draw.alpha(0.3f);
Lines.line(lx, ly, v.x, v.y); Lines.line(lx, ly, v.getX(), v.getY());
Lines.stroke(Lines.getStroke()/4f); Lines.stroke(Lines.getStroke()/4f);
Draw.alpha(1f); Draw.alpha(1f);
Lines.line(lx, ly, v.x, v.y); Lines.line(lx, ly, v.getX(), v.getY());
lx = v.x; Lines.stroke(3f * fout() * (1f - f));
ly = v.y; // Lines.lineAngleCenter(lx, ly, Angles.angle(lx, ly, v.getX(), v.getY()) + 90f, 20f);
lx = v.getX();
ly = v.getY();
} }
Draw.color(); Draw.color();
} }
@@ -15,6 +15,7 @@ import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect; import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator; import io.anuke.ucore.util.Translator;
@@ -1,6 +1,5 @@
package io.anuke.mindustry.world.blocks.defense; package io.anuke.mindustry.world.blocks.defense;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.entities.Unit; import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.effect.Lightning; import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.graphics.Layer; import io.anuke.mindustry.graphics.Layer;
@@ -47,7 +46,7 @@ public class ShockMine extends Block{
public void unitOn(Tile tile, Unit unit){ public void unitOn(Tile tile, Unit unit){
if(unit.getTeam() != tile.getTeam() && tile.entity.timer.get(timerDamage, cooldown)){ if(unit.getTeam() != tile.getTeam() && tile.entity.timer.get(timerDamage, cooldown)){
for(int i = 0; i < tendrils; i++){ for(int i = 0; i < tendrils; i++){
Lightning.create(tile.getTeam(), BulletFx.hitLancer, tile.getTeam().color, damage, tile.drawx(), tile.drawy(), Mathf.random(360f), length); Lightning.create(tile.getTeam(), tile.getTeam().color, damage, tile.drawx(), tile.drawy(), Mathf.random(360f), length);
} }
tile.entity.damage(tileDamage); tile.entity.damage(tileDamage);
} }
@@ -1,6 +1,5 @@
package io.anuke.mindustry.world.blocks.defense; package io.anuke.mindustry.world.blocks.defense;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.effect.Lightning; import io.anuke.mindustry.entities.effect.Lightning;
@@ -20,7 +19,7 @@ public class SurgeWall extends Wall{
public void handleBulletHit(TileEntity entity, Bullet bullet){ public void handleBulletHit(TileEntity entity, Bullet bullet){
super.handleBulletHit(entity, bullet); super.handleBulletHit(entity, bullet);
if(Mathf.chance(lightningChance)){ if(Mathf.chance(lightningChance)){
Lightning.create(entity.getTeam(), BulletFx.hitLancer, Palette.surge, lightningDamage, bullet.x, bullet.y, bullet.angle() + 180f, lightningLength); Lightning.create(entity.getTeam(), Palette.surge, lightningDamage, bullet.x, bullet.y, bullet.angle() + 180f, lightningLength);
} }
} }
} }