mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-03 14:14:03 +07:00
Build weapon
This commit is contained in:
parent
37ba8ac66b
commit
3efbf58ab5
@ -2680,7 +2680,7 @@ public class UnitTypes{
|
||||
targetAir = false;
|
||||
mineSpeed = 8f;
|
||||
mineTier = 3;
|
||||
buildSpeed = 1.4f;
|
||||
buildSpeed = 2f;
|
||||
drag = 0.06f;
|
||||
speed = 2.6f;
|
||||
rotateSpeed = 3f;
|
||||
@ -2702,21 +2702,23 @@ public class UnitTypes{
|
||||
new UnitEngine(49 / 4f, -62 / 4f, es, 315f)
|
||||
);
|
||||
|
||||
Vec2[] positions = {new Vec2(30f, 50f), new Vec2(60f, -15f)};
|
||||
Vec2[] positions = {/*new Vec2(30f, 50f), */new Vec2(60f, -15f)};
|
||||
int i = 0;
|
||||
|
||||
for(var pos : positions){
|
||||
int fi = i;
|
||||
weapons.add(new Weapon("incite-weapon"){{
|
||||
//TODO change to BuildWeapon properly, remove standard build beam and rotation
|
||||
weapons.add(new BuildWeapon("incite-weapon"){{
|
||||
rotate = true;
|
||||
reload = fi == 0 ? 25f : 35f;
|
||||
rotateSpeed = 4f;
|
||||
rotateSpeed = 7f;
|
||||
x = pos.x/4f;
|
||||
y = pos.y/4f;
|
||||
shootY = 5.75f;
|
||||
recoil = 2f;
|
||||
rotationLimit = 90f;
|
||||
layerOffset = -0.01f;
|
||||
|
||||
drawBuildBeam = false;
|
||||
rotateToBuilding = false;
|
||||
|
||||
bullet = new BasicBulletType(5f, 17){{
|
||||
width = 7f;
|
||||
|
@ -35,7 +35,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
||||
|
||||
private transient BuildPlan lastActive;
|
||||
private transient int lastSize;
|
||||
private transient float buildAlpha = 0f;
|
||||
transient float buildAlpha = 0f;
|
||||
|
||||
public boolean canBuild(){
|
||||
return type.buildSpeed > 0 && buildSpeedMultiplier > 0;
|
||||
@ -257,13 +257,14 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
||||
}
|
||||
|
||||
public void drawBuilding(){
|
||||
//TODO make this more generic so it works with builder "weapons"
|
||||
boolean active = activelyBuilding();
|
||||
if(!active && lastActive == null) return;
|
||||
|
||||
Draw.z(Layer.flyingUnit);
|
||||
|
||||
BuildPlan plan = active ? buildPlan() : lastActive;
|
||||
Tile tile = world.tile(plan.x, plan.y);
|
||||
Tile tile = plan.tile();
|
||||
var core = team.core();
|
||||
|
||||
if(tile == null || !within(plan, state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange)){
|
||||
@ -278,14 +279,32 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
||||
Draw.z(Layer.flyingUnit);
|
||||
}
|
||||
|
||||
if(type.drawBuildBeam){
|
||||
float focusLen = type.buildBeamOffset + Mathf.absin(Time.time, 3f, 0.6f);
|
||||
float px = x + Angles.trnsx(rotation, focusLen);
|
||||
float py = y + Angles.trnsy(rotation, focusLen);
|
||||
|
||||
drawBuildingBeam(px, py);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawBuildingBeam(float px, float py){
|
||||
boolean active = activelyBuilding();
|
||||
if(!active && lastActive == null) return;
|
||||
|
||||
Draw.z(Layer.flyingUnit);
|
||||
|
||||
BuildPlan plan = active ? buildPlan() : lastActive;
|
||||
Tile tile = world.tile(plan.x, plan.y);
|
||||
|
||||
if(tile == null || !within(plan, state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange)){
|
||||
return;
|
||||
}
|
||||
|
||||
int size = plan.breaking ? active ? tile.block().size : lastSize : plan.block.size;
|
||||
float tx = plan.drawx(), ty = plan.drawy();
|
||||
|
||||
Lines.stroke(1f, plan.breaking ? Pal.remove : Pal.accent);
|
||||
float focusLen = type.buildBeamOffset + Mathf.absin(Time.time, 3f, 0.6f);
|
||||
float px = x + Angles.trnsx(rotation, focusLen);
|
||||
float py = y + Angles.trnsy(rotation, focusLen);
|
||||
|
||||
Draw.z(Layer.buildBeam);
|
||||
|
||||
Draw.alpha(buildAlpha);
|
||||
|
@ -136,7 +136,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
|
||||
/** @return where the unit wants to look at. */
|
||||
public float prefRotation(){
|
||||
if(activelyBuilding()){
|
||||
if(activelyBuilding() && type.rotateToBuilding){
|
||||
return angleTo(buildPlan());
|
||||
}else if(mineTile != null){
|
||||
return angleTo(mineTile);
|
||||
|
@ -401,6 +401,16 @@ public class BlockRenderer{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO remove
|
||||
Draw.z(Layer.overlayUI);
|
||||
Lines.stroke(1f, Color.green);
|
||||
|
||||
blockTree.intersect(camera.bounds(Tmp.r1), tile -> {
|
||||
Lines.rect(tile.getHitbox(Tmp.r2));
|
||||
});
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
static class BlockQuadtree extends QuadTree<Tile>{
|
||||
|
@ -80,6 +80,8 @@ public class UnitType extends UnlockableContent{
|
||||
public float payloadCapacity = 8;
|
||||
public float aimDst = -1f;
|
||||
public float buildBeamOffset = 3.8f;
|
||||
public boolean drawBuildBeam = true;
|
||||
public boolean rotateToBuilding = true;
|
||||
public int commandLimit = 8;
|
||||
public float commandRadius = 150f;
|
||||
public float visualElevation = -1f;
|
||||
|
63
core/src/mindustry/type/weapons/BuildWeapon.java
Normal file
63
core/src/mindustry/type/weapons/BuildWeapon.java
Normal file
@ -0,0 +1,63 @@
|
||||
package mindustry.type.weapons;
|
||||
|
||||
import arc.math.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** Purely visual turret. Does not shoot anything. */
|
||||
public class BuildWeapon extends Weapon{
|
||||
|
||||
public BuildWeapon(){
|
||||
|
||||
}
|
||||
|
||||
public BuildWeapon(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
{
|
||||
rotate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Unit unit, WeaponMount mount){
|
||||
//no
|
||||
mount.shoot = false;
|
||||
//yes
|
||||
mount.rotate = true;
|
||||
|
||||
//always aim at build plan
|
||||
if(unit.activelyBuilding()){
|
||||
mount.aimX = unit.buildPlan().drawx();
|
||||
mount.aimY = unit.buildPlan().drawy();
|
||||
}else{
|
||||
//aim for front
|
||||
float weaponRotation = unit.rotation - 90;
|
||||
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.activelyBuilding()){
|
||||
|
||||
float
|
||||
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),
|
||||
px = wx + Angles.trnsx(weaponRotation, this.shootX, this.shootY),
|
||||
py = wy + Angles.trnsy(weaponRotation, this.shootX, this.shootY);
|
||||
|
||||
unit.drawBuildingBeam(px, py);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user