Merge branch 'MEEPofFaith-mining-beam-weapon'

This commit is contained in:
Anuken 2025-02-09 11:19:47 -05:00
commit 925bfad30f
3 changed files with 85 additions and 8 deletions

View File

@ -113,8 +113,10 @@ public class UnitType extends UnlockableContent implements Senseable{
buildSpeed = -1f,
/** Minimum distance from this unit that weapons can target. Prevents units from firing "inside" the unit. */
aimDst = -1f,
/** Visual offset of build beam from front. */
/** Visual offset of the build beam from the front. */
buildBeamOffset = 3.8f,
/** Visual offset of the mining beam from the front. Defaults to half the hitsize. */
mineBeamOffset = Float.NEGATIVE_INFINITY,
/** WIP: Units of low priority will always be ignored in favor of those with higher priority, regardless of distance. */
targetPriority = 0f,
/** Elevation of shadow drawn under this (ground) unit. Visual only. */
@ -236,6 +238,8 @@ public class UnitType extends UnlockableContent implements Senseable{
squareShape = false,
/** if true, this unit will draw its building beam towards blocks. */
drawBuildBeam = true,
/** if true, this unit will draw its mining beam towards blocks */
drawMineBeam = true,
/** if false, the team indicator/cell is not drawn. */
drawCell = true,
/** if false, carried items are not drawn. */
@ -803,6 +807,8 @@ public class UnitType extends UnlockableContent implements Senseable{
}).layer(Layer.debris);
}
if(mineBeamOffset == Float.NEGATIVE_INFINITY) mineBeamOffset = hitSize / 2;
for(Ability ab : abilities){
ab.init(this);
}
@ -1226,7 +1232,6 @@ public class UnitType extends UnlockableContent implements Senseable{
if(unit.inFogTo(Vars.player.team())) return;
unit.drawBuilding();
drawMining(unit);
boolean isPayload = !unit.isAdded();
@ -1339,16 +1344,21 @@ public class UnitType extends UnlockableContent implements Senseable{
return shieldColor == null ? unit.team.color : shieldColor;
}
public void drawMining(Unit unit){
if(drawMineBeam){
float focusLen = mineBeamOffset + Mathf.absin(Time.time, 1.1f, 0.5f);
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
drawMiningBeam(unit, px, py);
}
}
public void drawMiningBeam(Unit unit, float px, float py){
if(!unit.mining()) return;
float focusLen = unit.hitSize / 2f + Mathf.absin(Time.time, 1.1f, 0.5f);
float swingScl = 12f, swingMag = tilesize / 8f;
float flashScl = 0.3f;
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
float ex = unit.mineTile.worldx() + Mathf.sin(Time.time + 48, swingScl, swingMag);
float ey = unit.mineTile.worldy() + Mathf.sin(Time.time + 48, swingScl + 2f, swingMag);

View File

@ -11,7 +11,7 @@ import mindustry.type.*;
public class BuildWeapon extends Weapon{
public BuildWeapon(){
super();
}
public BuildWeapon(String name){

View File

@ -0,0 +1,67 @@
package mindustry.type.weapons;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.entities.bullet.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
public class MineWeapon extends Weapon{
public MineWeapon(){
super();
}
public MineWeapon(String name){
super(name);
}
{
rotate = true;
noAttack = true;
predictTarget = false;
display = false;
bullet = new BulletType();
useAttackRange = false;
}
@Override
public void update(Unit unit, WeaponMount mount){
mount.shoot = false;
mount.rotate = true;
//always aim at build plan
if(unit.mining()){
mount.aimX = unit.mineTile().drawx();
mount.aimY = unit.mineTile().drawy();
}else{
//aim for front
float weaponRotation = unit.rotation - 90 + baseRotation;
mount.aimX = unit.x + Angles.trnsx(unit.rotation - 90, x, y) + Angles.trnsx(weaponRotation, this.shootX, this.shootY);
mount.aimY = unit.y + Angles.trnsy(unit.rotation - 90, x, y) + Angles.trnsy(weaponRotation, this.shootX, this.shootY);
}
super.update(unit, mount);
}
@Override
public void draw(Unit unit, WeaponMount mount){
super.draw(unit, mount);
if(unit.mining()){
float
z = Draw.z(),
rotation = unit.rotation - 90,
weaponRotation = rotation + (rotate ? mount.rotation : 0),
wx = unit.x + Angles.trnsx(rotation, x, y) + Angles.trnsx(weaponRotation, 0, -mount.recoil),
wy = unit.y + Angles.trnsy(rotation, x, y) + Angles.trnsy(weaponRotation, 0, -mount.recoil),
sY = shootY + Mathf.absin(Time.time, 1.1f, 0.5f),
px = wx + Angles.trnsx(weaponRotation, shootX, sY),
py = wy + Angles.trnsy(weaponRotation, shootX, sY);
unit.type.drawMiningBeam(unit, px, py);
Draw.z(z);
}
}
}