Bullet cleanup
This commit is contained in:
@@ -92,15 +92,17 @@ public class Damage{
|
||||
}
|
||||
};
|
||||
|
||||
world.raycastEachWorld(x, y, x + tr.x, y + tr.y, (cx, cy) -> {
|
||||
collider.get(cx, cy);
|
||||
if(large){
|
||||
for(Point2 p : Geometry.d4){
|
||||
collider.get(cx + p.x, cy + p.y);
|
||||
if(hitter.type.collidesGround){
|
||||
world.raycastEachWorld(x, y, x + tr.x, y + tr.y, (cx, cy) -> {
|
||||
collider.get(cx, cy);
|
||||
if(large){
|
||||
for(Point2 p : Geometry.d4){
|
||||
collider.get(cx + p.x, cy + p.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
rect.setPosition(x, y).setSize(tr.x, tr.y);
|
||||
float x2 = tr.x + x, y2 = tr.y + y;
|
||||
@@ -123,6 +125,8 @@ public class Damage{
|
||||
rect.height += expand * 2;
|
||||
|
||||
Cons<Unit> cons = e -> {
|
||||
if(!e.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround)) return;
|
||||
|
||||
e.hitbox(hitrect);
|
||||
Rect other = hitrect;
|
||||
other.y -= expand;
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
@@ -21,22 +22,28 @@ public class Lightning{
|
||||
private static boolean bhit = false;
|
||||
private static int lastSeed = 0;
|
||||
|
||||
/** Create a lighting branch at a location. Use Team.none to damage everyone. */
|
||||
/** Create a lighting branch at a location. Use Team.derelict to damage everyone. */
|
||||
public static void create(Team team, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
createLightingInternal(lastSeed++, team, color, damage, x, y, targetAngle, length);
|
||||
createLightingInternal(null, lastSeed++, team, color, damage, x, y, targetAngle, length);
|
||||
}
|
||||
|
||||
/** Create a lighting branch at a location. Uses bullet parameters. */
|
||||
public static void create(Bullet bullet, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
createLightingInternal(bullet, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length);
|
||||
}
|
||||
|
||||
//TODO remote method
|
||||
//@Remote(called = Loc.server, unreliable = true)
|
||||
private static void createLightingInternal(int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
|
||||
private static void createLightingInternal(Bullet hitter, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
|
||||
random.setSeed(seed);
|
||||
hit.clear();
|
||||
|
||||
BulletType bulletType = hitter != null && !hitter.type.collidesAir ? Bullets.damageLightningGround : Bullets.damageLightning;
|
||||
Seq<Vec2> lines = new Seq<>();
|
||||
bhit = false;
|
||||
|
||||
for(int i = 0; i < length / 2; i++){
|
||||
Bullets.damageLightning.create(null, team, x, y, 0f, damage, 1f, 1f, null);
|
||||
bulletType.create(null, team, x, y, 0f, damage, 1f, 1f, hitter);
|
||||
lines.add(new Vec2(x + Mathf.range(3f), y + Mathf.range(3f)));
|
||||
|
||||
if(lines.size > 1){
|
||||
@@ -61,7 +68,7 @@ public class Lightning{
|
||||
entities.clear();
|
||||
if(hit.size < maxChain){
|
||||
Units.nearbyEnemies(team, rect, u -> {
|
||||
if(!hit.contains(u.id())){
|
||||
if(!hit.contains(u.id()) && (hitter == null || u.checkTarget(hitter.type.collidesAir, hitter.type.collidesGround))){
|
||||
entities.add(u);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -109,6 +109,10 @@ public abstract class BulletType extends Content{
|
||||
despawnEffect = Fx.hitBulletSmall;
|
||||
}
|
||||
|
||||
public BulletType(){
|
||||
this(1f, 1f);
|
||||
}
|
||||
|
||||
/** Returns maximum distance the bullet this bullet type has can travel. */
|
||||
public float range(){
|
||||
return speed * lifetime * (1f - drag);
|
||||
@@ -153,7 +157,7 @@ public abstract class BulletType extends Content{
|
||||
}
|
||||
|
||||
for(int i = 0; i < lightning; i++){
|
||||
Lightning.create(b.team, Pal.surge, lightningDamage < 0 ? damage : lightningDamage, b.x, b.y, Mathf.random(360f), lightningLength);
|
||||
Lightning.create(b, Pal.surge, lightningDamage < 0 ? damage : lightningDamage, b.x, b.y, Mathf.random(360f), lightningLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ public class LightningBulletType extends BulletType{
|
||||
|
||||
@Override
|
||||
public void init(Bullet b){
|
||||
Lightning.create(b.team, lightningColor, damage, b.x, b.y, b.rotation(), lightningLength + Mathf.random(lightningLengthRand));
|
||||
Lightning.create(b, lightningColor, damage, b.x, b.y, b.rotation(), lightningLength + Mathf.random(lightningLengthRand));
|
||||
}
|
||||
}
|
||||
|
||||
47
core/src/mindustry/entities/bullet/ShrapnelBulletType.java
Normal file
47
core/src/mindustry/entities/bullet/ShrapnelBulletType.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package mindustry.entities.bullet;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
public class ShrapnelBulletType extends BulletType{
|
||||
public float length = 100f;
|
||||
public float width = 20f;
|
||||
public Color fromColor = Color.white, toColor = Pal.lancerLaser;
|
||||
|
||||
public int serrations = 7;
|
||||
public float serrationLenScl = 10f, serrationWidth = 4f, serrationSpacing = 8f, serrationSpaceOffset = 80f;
|
||||
|
||||
public ShrapnelBulletType(){
|
||||
speed = 0.01f;
|
||||
hitEffect = Fx.hitLancer;
|
||||
shootEffect = smokeEffect = Fx.lightningShoot;
|
||||
lifetime = 10f;
|
||||
despawnEffect = Fx.none;
|
||||
pierce = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Bullet b){
|
||||
Damage.collideLine(b, b.team, hitEffect, b.x, b.y, b.rotation(), length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Bullet b){
|
||||
Draw.color(fromColor, toColor, b.fin());
|
||||
for(int i = 0; i < serrations; i++){
|
||||
Tmp.v1.trns(b.rotation(), i * serrationSpacing);
|
||||
float sl = Mathf.clamp(b.fout() - 0.5f) * (serrationSpaceOffset - i * serrationLenScl);
|
||||
Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, serrationWidth, sl, b.rotation() + 90);
|
||||
Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, serrationWidth, sl, b.rotation() - 90);
|
||||
}
|
||||
Drawf.tri(b.x, b.y, width * b.fout(), (length + 50), b.rotation());
|
||||
Drawf.tri(b.x, b.y, width * b.fout(), 10f, b.rotation() + 180f);
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user