Implemented lightning turret

This commit is contained in:
Anuken 2018-04-06 15:14:19 -04:00
parent 2191437f39
commit d67402e6aa
6 changed files with 96 additions and 9 deletions

View File

@ -1,5 +1,5 @@
#Autogenerated file. Do not modify.
#Fri Apr 06 10:14:01 EDT 2018
#Fri Apr 06 15:12:13 EDT 2018
version=release
androidBuildCode=856
name=Mindustry

View File

@ -16,6 +16,8 @@ public class AmmoTypes {
lancerLaser = new AmmoType(TurretBullets.lancerLaser),
lightning = new AmmoType(TurretBullets.lightning),
oil = new AmmoType(Liquids.oil, TurretBullets.oilShot, 0.3f, 1f),
water = new AmmoType(Liquids.water, TurretBullets.waterShot, 0.3f, 1f),

View File

@ -107,8 +107,18 @@ public class WeaponBlocks{
heatColor = Color.RED;
}},
teslaturret = new PowerTurret("teslaturret"){{
teslaturret = new LaserTurret("teslaturret"){{
shootType = AmmoTypes.lightning;
reload = 100f;
chargeTime = 70f;
shootShake = 1f;
chargeMaxDelay = 30f;
chargeEffects = 7;
shootEffect = ShootFx.lightningShoot;
chargeEffect = ShootFx.lancerLaserCharge;
chargeBeginEffect = ShootFx.lancerLaserChargeBegin;
heatColor = Color.RED;
recoil = 3f;
}},
liquidturret = new LiquidTurret("liquidturret") {{

View File

@ -173,6 +173,8 @@ public class TurretBullets {
lightning = new BulletType(0.001f, 5) {
{
lifetime = 1;
despawneffect = Fx.none;
hiteffect = BulletFx.hitLancer;
}
@Override
@ -182,7 +184,7 @@ public class TurretBullets {
@Override
public void init(Bullet b) {
new Lightning(b.team, b, b.x, b.y, b.angle(), 30);
new Lightning(b.team, hiteffect, damage, b.x, b.y, b.angle(), 40).add();
}
};

View File

@ -186,5 +186,16 @@ public class ShootFx {
Draw.color();
Fill.circle(e.x, e.y, e.fin() * 2f);
}),
lightningShoot= new Effect(12f, e -> {
Draw.color(Color.WHITE, Palette.lancerLaser, e.fin());
Lines.stroke(e.fout() * 1.2f + 0.5f);
Angles.randLenVectors(e.id, 7, 25f * e.finpow(), e.rotation, 50f, (x, y) -> {
Lines.lineAngle(e.x + x, e.y + y, Mathf.atan2(x, y), e.fin()*5f + 2f);
});
Draw.reset();
});
}

View File

@ -1,28 +1,76 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.game.Team;
import io.anuke.ucore.entities.Entity;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
public class Lightning extends Entity {
private Array<Vector2> lines = new Array<Vector2>();
public class Lightning extends TimedEntity {
private static Array<SolidEntity> entities = new Array<>();
private static Rectangle rect = new Rectangle();
private static float wetDamageMultiplier = 2;
private Array<Vector2> lines = new Array<>();
private float angle;
public Lightning(Team team, Effect effect, int damage, float x, float y, float targetAngle, int length){
this.x = x;
this.y = y;
this.lifetime = 10f;
this.angle = targetAngle;
public Lightning(Team team, SolidEntity damager, float x, float y, float angle, int length){
float step = 3f;
float range = 6f;
float attractRange = 20f;
entities.clear();
Units.getNearbyEnemies(team, rect, entities::add);
for(int i = 0; i < length; i ++){
lines.add(new Vector2(x, y));
float fx = x, fy = y;
float x2 = x + Angles.trnsx(angle, step);
float y2 = y + Angles.trnsy(angle, step);
float fangle = angle;
angle += Mathf.range(30f);
rect.setSize(attractRange).setCenter(x, y);
Units.getNearbyEnemies(team, rect, entity -> {
float dst = entity.distanceTo(x2, y2);
if(dst < attractRange) {
angle = Mathf.slerp(angle, Angles.angle(x2, y2, entity.x, entity.y), (attractRange - dst) / attractRange / 4f);
}
Rectangle hitbox = entity.hitbox.getRect(entity.x, entity.y, range);
if(hitbox.contains(x2, y2) || hitbox.contains(fx, fy)){
int result = damage;
if(entity.status.current() == StatusEffects.wet)
result = (int)(result * wetDamageMultiplier);
entity.damage(result);
Effects.effect(effect, x2, y2, fangle);
}
});
if(Mathf.chance(0.1)){
new Lightning(team, damager, x2, y2, angle + Mathf.range(100f), length/2).add();
new Lightning(team, effect, damage, x2, y2, angle + Mathf.range(100f), length/3).add();
}
x = x2;
@ -31,4 +79,18 @@ public class Lightning extends Entity {
lines.add(new Vector2(x, y));
}
@Override
public void draw() {
float lx = x, ly = y;
Draw.color(Palette.lancerLaser, Color.WHITE, fin());
for(int i = 0; i < lines.size; i ++){
Vector2 v = lines.get(i);
Lines.stroke(fout() * 3f + 1f-(float)i/lines.size);
Lines.line(lx, ly, v.x, v.y);
lx = v.x;
ly = v.y;
}
Draw.color();
}
}