Skip to content

Commit 02d56d2

Browse files
committed
Merge branch 'mining-beam-weapon' of https://github.com/MEEPofFaith/Mindustry into MEEPofFaith-mining-beam-weapon
2 parents e57e476 + 3e8a40b commit 02d56d2

File tree

3 files changed

+86
-10
lines changed

3 files changed

+86
-10
lines changed

core/src/mindustry/type/UnitType.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ public class UnitType extends UnlockableContent implements Senseable{
113113
buildSpeed = -1f,
114114
/** Minimum distance from this unit that weapons can target. Prevents units from firing "inside" the unit. */
115115
aimDst = -1f,
116-
/** Visual offset of build beam from front. */
116+
/** Visual offset of the build beam from the front. */
117117
buildBeamOffset = 3.8f,
118+
/** Visual offset of the mining beam from the front. Defaults to half the hitsize. */
119+
mineBeamOffset = Float.NEGATIVE_INFINITY,
118120
/** WIP: Units of low priority will always be ignored in favor of those with higher priority, regardless of distance. */
119121
targetPriority = 0f,
120122
/** Elevation of shadow drawn under this (ground) unit. Visual only. */
@@ -236,6 +238,8 @@ public class UnitType extends UnlockableContent implements Senseable{
236238
squareShape = false,
237239
/** if true, this unit will draw its building beam towards blocks. */
238240
drawBuildBeam = true,
241+
/** if true, this unit will draw its mining beam towards blocks */
242+
drawMineBeam = true,
239243
/** if false, the team indicator/cell is not drawn. */
240244
drawCell = true,
241245
/** if false, carried items are not drawn. */
@@ -803,6 +807,8 @@ public void init(){
803807
}).layer(Layer.debris);
804808
}
805809

810+
if(mineBeamOffset == Float.NEGATIVE_INFINITY) mineBeamOffset = hitSize / 2;
811+
806812
for(Ability ab : abilities){
807813
ab.init(this);
808814
}
@@ -1226,7 +1232,6 @@ public void draw(Unit unit){
12261232
if(unit.inFogTo(Vars.player.team())) return;
12271233

12281234
unit.drawBuilding();
1229-
12301235
drawMining(unit);
12311236

12321237
boolean isPayload = !unit.isAdded();
@@ -1339,25 +1344,29 @@ public Color shieldColor(Unit unit){
13391344
return shieldColor == null ? unit.team.color : shieldColor;
13401345
}
13411346

1342-
13431347
public void drawMining(Unit unit){
1348+
if(drawMineBeam){
1349+
float focusLen = mineBeamOffset + Mathf.absin(Time.time, 1.1f, 0.5f);
1350+
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
1351+
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
1352+
1353+
drawMiningBeam(unit, px, py);
1354+
}
1355+
}
1356+
1357+
public void drawMiningBeam(Unit unit, float px, float py){
13441358
if(!unit.mining()) return;
1345-
float focusLen = unit.hitSize / 2f + Mathf.absin(Time.time, 1.1f, 0.5f);
13461359
float swingScl = 12f, swingMag = tilesize / 8f;
13471360
float flashScl = 0.3f;
13481361

1349-
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
1350-
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
1351-
13521362
float ex = unit.mineTile.worldx() + Mathf.sin(Time.time + 48, swingScl, swingMag);
13531363
float ey = unit.mineTile.worldy() + Mathf.sin(Time.time + 48, swingScl + 2f, swingMag);
13541364

13551365
Draw.z(Layer.flyingUnit + 0.1f);
13561366

13571367
Draw.color(Color.lightGray, Color.white, 1f - flashScl + Mathf.absin(Time.time, 0.5f, flashScl));
13581368

1359-
Draw.alpha(Renderer.unitLaserOpacity);
1360-
Drawf.laser(mineLaserRegion, mineLaserEndRegion, px, py, ex, ey, 0.75f);
1369+
Drawf.laser(Core.atlas.find("minelaser"), Core.atlas.find("minelaser-end"), px, py, ex, ey, 0.75f);
13611370

13621371
if(unit.isLocal()){
13631372
Lines.stroke(1f, Pal.accent);

core/src/mindustry/type/weapons/BuildWeapon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class BuildWeapon extends Weapon{
1212

1313
public BuildWeapon(){
14-
14+
super();
1515
}
1616

1717
public BuildWeapon(String name){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package mindustry.type.weapons;
2+
3+
import arc.graphics.g2d.*;
4+
import arc.math.*;
5+
import arc.util.*;
6+
import mindustry.entities.bullet.*;
7+
import mindustry.entities.units.*;
8+
import mindustry.gen.*;
9+
import mindustry.type.*;
10+
11+
public class MineWeapon extends Weapon{
12+
public MineWeapon(){
13+
super();
14+
}
15+
16+
public MineWeapon(String name){
17+
super(name);
18+
}
19+
20+
{
21+
rotate = true;
22+
noAttack = true;
23+
predictTarget = false;
24+
display = false;
25+
bullet = new BulletType();
26+
useAttackRange = false;
27+
}
28+
29+
@Override
30+
public void update(Unit unit, WeaponMount mount){
31+
mount.shoot = false;
32+
mount.rotate = true;
33+
34+
//always aim at build plan
35+
if(unit.mining()){
36+
mount.aimX = unit.mineTile().drawx();
37+
mount.aimY = unit.mineTile().drawy();
38+
}else{
39+
//aim for front
40+
float weaponRotation = unit.rotation - 90 + baseRotation;
41+
mount.aimX = unit.x + Angles.trnsx(unit.rotation - 90, x, y) + Angles.trnsx(weaponRotation, this.shootX, this.shootY);
42+
mount.aimY = unit.y + Angles.trnsy(unit.rotation - 90, x, y) + Angles.trnsy(weaponRotation, this.shootX, this.shootY);
43+
}
44+
45+
super.update(unit, mount);
46+
}
47+
48+
@Override
49+
public void draw(Unit unit, WeaponMount mount){
50+
super.draw(unit, mount);
51+
52+
if(unit.mining()){
53+
float
54+
z = Draw.z(),
55+
rotation = unit.rotation - 90,
56+
weaponRotation = rotation + (rotate ? mount.rotation : 0),
57+
wx = unit.x + Angles.trnsx(rotation, x, y) + Angles.trnsx(weaponRotation, 0, -mount.recoil),
58+
wy = unit.y + Angles.trnsy(rotation, x, y) + Angles.trnsy(weaponRotation, 0, -mount.recoil),
59+
sY = shootY + Mathf.absin(Time.time, 1.1f, 0.5f),
60+
px = wx + Angles.trnsx(weaponRotation, shootX, sY),
61+
py = wy + Angles.trnsy(weaponRotation, shootX, sY);
62+
63+
unit.type.drawMiningBeam(unit, px, py);
64+
Draw.z(z);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)