Better bullet aiming
This commit is contained in:
@@ -304,13 +304,7 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
|
|
||||||
Effect.shake(hitShake, hitShake, b);
|
Effect.shake(hitShake, hitShake, b);
|
||||||
|
|
||||||
if(fragBullet != null){
|
createFrags(b, x, y);
|
||||||
for(int i = 0; i < fragBullets; i++){
|
|
||||||
float len = Mathf.random(1f, 7f);
|
|
||||||
float a = b.rotation() + Mathf.range(fragCone/2) + fragAngle;
|
|
||||||
fragBullet.create(b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax), Mathf.random(fragLifeMin, fragLifeMax));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(puddleLiquid != null && puddles > 0){
|
if(puddleLiquid != null && puddles > 0){
|
||||||
for(int i = 0; i < puddles; i++){
|
for(int i = 0; i < puddles; i++){
|
||||||
@@ -328,6 +322,14 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
Damage.applySuppression(b.team, b.x, b.y, suppressionRange, suppressionDuration, 0f, suppressionEffectChance, new Vec2(b.x, b.y));
|
Damage.applySuppression(b.team, b.x, b.y, suppressionRange, suppressionDuration, 0f, suppressionEffectChance, new Vec2(b.x, b.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createSplashDamage(b, x, y);
|
||||||
|
|
||||||
|
for(int i = 0; i < lightning; i++){
|
||||||
|
Lightning.create(b, lightningColor, lightningDamage < 0 ? damage : lightningDamage, b.x, b.y, b.rotation() + Mathf.range(lightningCone/2) + lightningAngle, lightningLength + Mathf.random(lightningLengthRand));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createSplashDamage(Bullet b, float x, float y){
|
||||||
if(splashDamageRadius > 0 && !b.absorbed){
|
if(splashDamageRadius > 0 && !b.absorbed){
|
||||||
Damage.damage(b.team, x, y, splashDamageRadius, splashDamage * b.damageMultiplier(), false, collidesAir, collidesGround, scaledSplashDamage, b);
|
Damage.damage(b.team, x, y, splashDamageRadius, splashDamage * b.damageMultiplier(), false, collidesAir, collidesGround, scaledSplashDamage, b);
|
||||||
|
|
||||||
@@ -346,12 +348,19 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
indexer.eachBlock(null, x, y, splashDamageRadius, other -> other.team != b.team, other -> Fires.create(other.tile));
|
indexer.eachBlock(null, x, y, splashDamageRadius, other -> other.team != b.team, other -> Fires.create(other.tile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < lightning; i++){
|
public void createFrags(Bullet b, float x, float y){
|
||||||
Lightning.create(b, lightningColor, lightningDamage < 0 ? damage : lightningDamage, b.x, b.y, b.rotation() + Mathf.range(lightningCone/2) + lightningAngle, lightningLength + Mathf.random(lightningLengthRand));
|
if(fragBullet != null){
|
||||||
|
for(int i = 0; i < fragBullets; i++){
|
||||||
|
float len = Mathf.random(1f, 7f);
|
||||||
|
float a = b.rotation() + Mathf.range(fragCone / 2) + fragAngle;
|
||||||
|
fragBullet.create(b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax), Mathf.random(fragLifeMin, fragLifeMax));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Called when the bullet reaches the end of its lifetime or is destroyed by something external. */
|
/** Called when the bullet reaches the end of its lifetime or is destroyed by something external. */
|
||||||
public void despawned(Bullet b){
|
public void despawned(Bullet b){
|
||||||
if(despawnHit){
|
if(despawnHit){
|
||||||
@@ -408,28 +417,40 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
|
|
||||||
public void update(Bullet b){
|
public void update(Bullet b){
|
||||||
updateTrail(b);
|
updateTrail(b);
|
||||||
|
updateHoming(b);
|
||||||
|
updateWeaving(b);
|
||||||
|
updateTrailEffects(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateHoming(Bullet b){
|
||||||
if(homingPower > 0.0001f && b.time >= homingDelay){
|
if(homingPower > 0.0001f && b.time >= homingDelay){
|
||||||
|
float realAimX = b.aimX < 0 ? b.x : b.aimX;
|
||||||
|
float realAimY = b.aimY < 0 ? b.y : b.aimY;
|
||||||
|
|
||||||
Teamc target;
|
Teamc target;
|
||||||
//home in on allies if possible
|
//home in on allies if possible
|
||||||
if(heals()){
|
if(heals()){
|
||||||
target = Units.closestTarget(null, b.x, b.y, homingRange,
|
target = Units.closestTarget(null, realAimX, realAimY, homingRange,
|
||||||
e -> e.checkTarget(collidesAir, collidesGround) && e.team != b.team && !b.hasCollided(e.id),
|
e -> e.checkTarget(collidesAir, collidesGround) && e.team != b.team && !b.hasCollided(e.id),
|
||||||
t -> collidesGround && (t.team != b.team || t.damaged()) && !b.hasCollided(t.id)
|
t -> collidesGround && (t.team != b.team || t.damaged()) && !b.hasCollided(t.id)
|
||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
target = Units.closestTarget(b.team, b.x, b.y, homingRange, e -> e.checkTarget(collidesAir, collidesGround) && !b.hasCollided(e.id), t -> collidesGround && !b.hasCollided(t.id));
|
target = Units.closestTarget(b.team, realAimX, realAimY, homingRange, e -> e.checkTarget(collidesAir, collidesGround) && !b.hasCollided(e.id), t -> collidesGround && !b.hasCollided(t.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(target != null){
|
if(target != null){
|
||||||
b.vel.setAngle(Angles.moveToward(b.rotation(), b.angleTo(target), homingPower * Time.delta * 50f));
|
b.vel.setAngle(Angles.moveToward(b.rotation(), b.angleTo(target), homingPower * Time.delta * 50f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateWeaving(Bullet b){
|
||||||
if(weaveMag != 0){
|
if(weaveMag != 0){
|
||||||
b.vel.rotateRadExact((float)Math.sin((b.time + Math.PI * weaveScale/2f) / weaveScale) * weaveMag * (weaveRandom ? (Mathf.randomSeed(b.id, 0, 1) == 1 ? -1 : 1) : 1f) * Time.delta * Mathf.degRad);
|
b.vel.rotateRadExact((float)Math.sin((b.time + Math.PI * weaveScale/2f) / weaveScale) * weaveMag * (weaveRandom ? (Mathf.randomSeed(b.id, 0, 1) == 1 ? -1 : 1) : 1f) * Time.delta * Mathf.degRad);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTrailEffects(Bullet b){
|
||||||
if(trailChance > 0){
|
if(trailChance > 0){
|
||||||
if(Mathf.chanceDelta(trailChance)){
|
if(Mathf.chanceDelta(trailChance)){
|
||||||
trailEffect.at(b.x, b.y, trailRotation ? b.rotation() : trailParam, trailColor);
|
trailEffect.at(b.x, b.y, trailRotation ? b.rotation() : trailParam, trailColor);
|
||||||
@@ -562,6 +583,8 @@ public class BulletType extends Content implements Cloneable{
|
|||||||
bullet.originX = x;
|
bullet.originX = x;
|
||||||
bullet.originY = y;
|
bullet.originY = y;
|
||||||
bullet.aimTile = world.tileWorld(aimX, aimY);
|
bullet.aimTile = world.tileWorld(aimX, aimY);
|
||||||
|
bullet.aimX = aimX;
|
||||||
|
bullet.aimY = aimY;
|
||||||
bullet.initVel(angle, speed * velocityScl);
|
bullet.initVel(angle, speed * velocityScl);
|
||||||
if(backMove){
|
if(backMove){
|
||||||
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
|
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
|||||||
//setting this variable to true prevents lifetime from decreasing for a frame.
|
//setting this variable to true prevents lifetime from decreasing for a frame.
|
||||||
transient boolean keepAlive;
|
transient boolean keepAlive;
|
||||||
transient @Nullable Tile aimTile;
|
transient @Nullable Tile aimTile;
|
||||||
|
transient float aimX, aimY;
|
||||||
transient float originX, originY;
|
transient float originX, originY;
|
||||||
transient @Nullable Mover mover;
|
transient @Nullable Mover mover;
|
||||||
transient boolean absorbed, hit;
|
transient boolean absorbed, hit;
|
||||||
|
|||||||
@@ -1136,7 +1136,8 @@ public class Mods implements Loadable{
|
|||||||
|
|
||||||
/** Mod metadata information.*/
|
/** Mod metadata information.*/
|
||||||
public static class ModMeta{
|
public static class ModMeta{
|
||||||
public String name, displayName, author, description, subtitle, version, main, minGameVersion = "0", repo;
|
public String name, minGameVersion = "0";
|
||||||
|
public @Nullable String displayName, author, description, subtitle, version, main, repo;
|
||||||
public Seq<String> dependencies = Seq.with();
|
public Seq<String> dependencies = Seq.with();
|
||||||
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
|
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
|
||||||
public boolean hidden;
|
public boolean hidden;
|
||||||
@@ -1166,7 +1167,7 @@ public class Mods implements Loadable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString(){
|
||||||
return "ModMeta{" +
|
return "ModMeta{" +
|
||||||
"name='" + name + '\'' +
|
"name='" + name + '\'' +
|
||||||
", author='" + author + '\'' +
|
", author='" + author + '\'' +
|
||||||
|
|||||||
Reference in New Issue
Block a user