mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-06 07:30:35 +07:00
Charge Progress (#6947)
This commit is contained in:
parent
4a6600b94d
commit
968651d9ed
@ -22,16 +22,17 @@ public abstract class DrawPart{
|
|||||||
/** Parameters for drawing a part in draw(). */
|
/** Parameters for drawing a part in draw(). */
|
||||||
public static class PartParams{
|
public static class PartParams{
|
||||||
//TODO document
|
//TODO document
|
||||||
public float warmup, reload, smoothReload, heat, recoil, life;
|
public float warmup, reload, smoothReload, heat, recoil, life, charge;
|
||||||
public float x, y, rotation;
|
public float x, y, rotation;
|
||||||
public int sideOverride = -1, sideMultiplier = 1;
|
public int sideOverride = -1, sideMultiplier = 1;
|
||||||
|
|
||||||
public PartParams set(float warmup, float reload, float smoothReload, float heat, float recoil, float x, float y, float rotation){
|
public PartParams set(float warmup, float reload, float smoothReload, float heat, float recoil, float charge, float x, float y, float rotation){
|
||||||
this.warmup = warmup;
|
this.warmup = warmup;
|
||||||
this.reload = reload;
|
this.reload = reload;
|
||||||
this.heat = heat;
|
this.heat = heat;
|
||||||
this.recoil = recoil;
|
this.recoil = recoil;
|
||||||
this.smoothReload = smoothReload;
|
this.smoothReload = smoothReload;
|
||||||
|
this.charge = charge;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
@ -65,6 +66,8 @@ public abstract class DrawPart{
|
|||||||
smoothReload = p -> p.smoothReload,
|
smoothReload = p -> p.smoothReload,
|
||||||
/** Weapon warmup, 0 when not firing, 1 when actively shooting. Not equivalent to heat. */
|
/** Weapon warmup, 0 when not firing, 1 when actively shooting. Not equivalent to heat. */
|
||||||
warmup = p -> p.warmup,
|
warmup = p -> p.warmup,
|
||||||
|
/** Weapon charge, 0 when beginning to charge, 1 when finished */
|
||||||
|
charge = p -> p.charge,
|
||||||
/** Weapon recoil with no curve applied. */
|
/** Weapon recoil with no curve applied. */
|
||||||
recoil = p -> p.recoil,
|
recoil = p -> p.recoil,
|
||||||
/** Weapon heat, 1 when just fired, 0, when it has cooled down (duration depends on weapon) */
|
/** Weapon heat, 1 when just fired, 0, when it has cooled down (duration depends on weapon) */
|
||||||
|
@ -127,7 +127,7 @@ public class RegionPart extends DrawPart{
|
|||||||
float sign = (i == 1 ? -1 : 1) * params.sideMultiplier;
|
float sign = (i == 1 ? -1 : 1) * params.sideMultiplier;
|
||||||
Tmp.v1.set((x + mx) * sign, y + my).rotate(params.rotation - 90);
|
Tmp.v1.set((x + mx) * sign, y + my).rotate(params.rotation - 90);
|
||||||
|
|
||||||
childParam.set(params.warmup, params.reload, params.smoothReload, params.heat, params.recoil, params.x + Tmp.v1.x, params.y + Tmp.v1.y, i * sign + mr * sign + params.rotation);
|
childParam.set(params.warmup, params.reload, params.smoothReload, params.heat, params.recoil, params.charge, params.x + Tmp.v1.x, params.y + Tmp.v1.y, i * sign + mr * sign + params.rotation);
|
||||||
childParam.sideMultiplier = params.sideMultiplier;
|
childParam.sideMultiplier = params.sideMultiplier;
|
||||||
childParam.life = params.life;
|
childParam.life = params.life;
|
||||||
childParam.sideOverride = i;
|
childParam.sideOverride = i;
|
||||||
@ -174,4 +174,4 @@ public class RegionPart extends DrawPart{
|
|||||||
child.getOutlines(out);
|
child.getOutlines(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@ public class WeaponMount{
|
|||||||
public float heat;
|
public float heat;
|
||||||
/** lerps to 1 when shooting, 0 when not */
|
/** lerps to 1 when shooting, 0 when not */
|
||||||
public float warmup;
|
public float warmup;
|
||||||
|
/** is the weapon actively charging */
|
||||||
|
public boolean charging;
|
||||||
|
/** counts up to 1 when charging, 0 when not */
|
||||||
|
public float charge;
|
||||||
/** lerps to reload time */
|
/** lerps to reload time */
|
||||||
public float smoothReload;
|
public float smoothReload;
|
||||||
/** aiming position in world coordinates */
|
/** aiming position in world coordinates */
|
||||||
|
@ -1104,9 +1104,9 @@ public class UnitType extends UnlockableContent{
|
|||||||
|
|
||||||
WeaponMount first = unit.mounts.length > part.weaponIndex ? unit.mounts[part.weaponIndex] : null;
|
WeaponMount first = unit.mounts.length > part.weaponIndex ? unit.mounts[part.weaponIndex] : null;
|
||||||
if(first != null){
|
if(first != null){
|
||||||
DrawPart.params.set(first.warmup, first.reload / weapons.first().reload, first.smoothReload, first.heat, first.recoil, unit.x, unit.y, unit.rotation);
|
DrawPart.params.set(first.warmup, first.reload / weapons.first().reload, first.smoothReload, first.heat, first.recoil, first.charge, unit.x, unit.y, unit.rotation);
|
||||||
}else{
|
}else{
|
||||||
DrawPart.params.set(0f, 0f, 0f, 0f, 0f, unit.x, unit.y, unit.rotation);
|
DrawPart.params.set(0f, 0f, 0f, 0f, 0f, 0f, unit.x, unit.y, unit.rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unit instanceof Scaled s){
|
if(unit instanceof Scaled s){
|
||||||
|
@ -178,8 +178,6 @@ public class Weapon implements Cloneable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Unit unit, WeaponMount mount){
|
public void draw(Unit unit, WeaponMount mount){
|
||||||
if(!region.found()) return;
|
|
||||||
|
|
||||||
//apply layer offset, roll it back at the end
|
//apply layer offset, roll it back at the end
|
||||||
float z = Draw.z();
|
float z = Draw.z();
|
||||||
Draw.z(z + layerOffset);
|
Draw.z(z + layerOffset);
|
||||||
@ -200,7 +198,7 @@ public class Weapon implements Cloneable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(parts.size > 0){
|
if(parts.size > 0){
|
||||||
DrawPart.params.set(mount.warmup, mount.reload / reload, mount.smoothReload, mount.heat, mount.recoil, wx, wy, weaponRotation + 90);
|
DrawPart.params.set(mount.warmup, mount.reload / reload, mount.smoothReload, mount.heat, mount.recoil, mount.charge, wx, wy, weaponRotation + 90);
|
||||||
DrawPart.params.sideMultiplier = flipSprite ? -1 : 1;
|
DrawPart.params.sideMultiplier = flipSprite ? -1 : 1;
|
||||||
|
|
||||||
for(int i = 0; i < parts.size; i++){
|
for(int i = 0; i < parts.size; i++){
|
||||||
@ -213,7 +211,7 @@ public class Weapon implements Cloneable{
|
|||||||
|
|
||||||
Draw.xscl = -Mathf.sign(flipSprite);
|
Draw.xscl = -Mathf.sign(flipSprite);
|
||||||
|
|
||||||
Draw.rect(region, wx, wy, weaponRotation);
|
if(region.found()) Draw.rect(region, wx, wy, weaponRotation);
|
||||||
|
|
||||||
if(cellRegion.found()){
|
if(cellRegion.found()){
|
||||||
Draw.color(unit.type.cellColor(unit));
|
Draw.color(unit.type.cellColor(unit));
|
||||||
@ -255,6 +253,7 @@ public class Weapon implements Cloneable{
|
|||||||
mount.recoil = Mathf.approachDelta(mount.recoil, 0, unit.reloadMultiplier / recoilTime);
|
mount.recoil = Mathf.approachDelta(mount.recoil, 0, unit.reloadMultiplier / recoilTime);
|
||||||
mount.warmup = Mathf.lerpDelta(mount.warmup, (can && mount.shoot) || (continuous && mount.bullet != null) ? 1f : 0f, shootWarmupSpeed);
|
mount.warmup = Mathf.lerpDelta(mount.warmup, (can && mount.shoot) || (continuous && mount.bullet != null) ? 1f : 0f, shootWarmupSpeed);
|
||||||
mount.smoothReload = Mathf.lerpDelta(mount.smoothReload, mount.reload / reload, smoothReloadSpeed);
|
mount.smoothReload = Mathf.lerpDelta(mount.smoothReload, mount.reload / reload, smoothReloadSpeed);
|
||||||
|
mount.charge = mount.charging && shoot.firstShotDelay > 0 ? Mathf.approachDelta(mount.charge, 1, 1 / shoot.firstShotDelay) : 0;
|
||||||
|
|
||||||
//rotate if applicable
|
//rotate if applicable
|
||||||
if(rotate && (mount.rotate || mount.shoot) && can){
|
if(rotate && (mount.rotate || mount.shoot) && can){
|
||||||
@ -388,6 +387,7 @@ public class Weapon implements Cloneable{
|
|||||||
unit.apply(shootStatus, shootStatusDuration);
|
unit.apply(shootStatus, shootStatusDuration);
|
||||||
|
|
||||||
if(shoot.firstShotDelay > 0){
|
if(shoot.firstShotDelay > 0){
|
||||||
|
mount.charging = true;
|
||||||
chargeSound.at(shootX, shootY, Mathf.random(soundPitchMin, soundPitchMax));
|
chargeSound.at(shootX, shootY, Mathf.random(soundPitchMin, soundPitchMax));
|
||||||
bullet.chargeEffect.at(shootX, shootY, rotation, bullet.keepVelocity || parentizeEffects ? unit : null);
|
bullet.chargeEffect.at(shootX, shootY, rotation, bullet.keepVelocity || parentizeEffects ? unit : null);
|
||||||
}
|
}
|
||||||
@ -398,13 +398,14 @@ public class Weapon implements Cloneable{
|
|||||||
}else{
|
}else{
|
||||||
bullet(unit, mount, xOffset, yOffset, angle, mover);
|
bullet(unit, mount, xOffset, yOffset, angle, mover);
|
||||||
}
|
}
|
||||||
mount.totalShots ++;
|
mount.totalShots++;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bullet(Unit unit, WeaponMount mount, float xOffset, float yOffset, float angleOffset, Mover mover){
|
protected void bullet(Unit unit, WeaponMount mount, float xOffset, float yOffset, float angleOffset, Mover mover){
|
||||||
if(!unit.isAdded()) return;
|
if(!unit.isAdded()) return;
|
||||||
|
|
||||||
|
mount.charging = false;
|
||||||
float
|
float
|
||||||
xSpread = Mathf.range(xRand),
|
xSpread = Mathf.range(xRand),
|
||||||
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : baseRotation),
|
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : baseRotation),
|
||||||
|
@ -200,7 +200,7 @@ public class Turret extends ReloadTurret{
|
|||||||
public Seq<AmmoEntry> ammo = new Seq<>();
|
public Seq<AmmoEntry> ammo = new Seq<>();
|
||||||
public int totalAmmo;
|
public int totalAmmo;
|
||||||
public float curRecoil, heat, logicControlTime = -1;
|
public float curRecoil, heat, logicControlTime = -1;
|
||||||
public float shootWarmup;
|
public float shootWarmup, charge;
|
||||||
public int totalShots;
|
public int totalShots;
|
||||||
//turrets need to shoot once for 'visual reload' to be valid, otherwise they seem stuck at reload 0 when placed.
|
//turrets need to shoot once for 'visual reload' to be valid, otherwise they seem stuck at reload 0 when placed.
|
||||||
public boolean visualReloadValid;
|
public boolean visualReloadValid;
|
||||||
@ -348,8 +348,9 @@ public class Turret extends ReloadTurret{
|
|||||||
|
|
||||||
wasShooting = false;
|
wasShooting = false;
|
||||||
|
|
||||||
curRecoil = Math.max(curRecoil - Time.delta / recoilTime , 0);
|
curRecoil = Mathf.approachDelta(curRecoil, 0, 1 / recoilTime);
|
||||||
heat = Math.max(heat - Time.delta / cooldownTime, 0);
|
heat = Mathf.approachDelta(heat, 0, 1 / cooldownTime);
|
||||||
|
charge = charging() ? Mathf.approachDelta(charge, 1, 1 / shoot.firstShotDelay) : 0;
|
||||||
|
|
||||||
unit.tile(this);
|
unit.tile(this);
|
||||||
unit.rotation(rotation);
|
unit.rotation(rotation);
|
||||||
|
@ -70,7 +70,7 @@ public class DrawTurret extends DrawBlock{
|
|||||||
float progress = tb.visualReloadValid ? tb.progress() : 1f;
|
float progress = tb.visualReloadValid ? tb.progress() : 1f;
|
||||||
|
|
||||||
//TODO no smooth reload
|
//TODO no smooth reload
|
||||||
var params = DrawPart.params.set(build.warmup(), 1f - progress, 1f - progress, tb.heat, tb.curRecoil, tb.x + tb.recoilOffset.x, tb.y + tb.recoilOffset.y, tb.rotation);
|
var params = DrawPart.params.set(build.warmup(), 1f - progress, 1f - progress, tb.heat, tb.curRecoil, tb.charge, tb.x + tb.recoilOffset.x, tb.y + tb.recoilOffset.y, tb.rotation);
|
||||||
|
|
||||||
for(var part : parts){
|
for(var part : parts){
|
||||||
part.draw(params);
|
part.draw(params);
|
||||||
|
Loading…
Reference in New Issue
Block a user