1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-11 08:15:35 +03:00

Multi-tread support for tanks

This commit is contained in:
Anuken 2022-01-30 17:10:04 -05:00
parent 3f8a7f591a
commit 7c22478618
14 changed files with 62 additions and 31 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -517,3 +517,4 @@
63186=red-stone-boulder|block-red-stone-boulder-ui
63185=red-diamond-wall|block-red-diamond-wall-ui
63184=crystal-orbs|block-crystal-orbs-ui
63183=conquer|unit-conquer-ui

Binary file not shown.

View File

@ -11,6 +11,7 @@ import mindustry.entities.*;
import mindustry.entities.abilities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@ -72,7 +73,7 @@ public class UnitTypes{
public static @EntityDef({Unitc.class, BuildingTetherc.class, Payloadc.class}) UnitType manifold, assemblyDrone;
//tank
public static @EntityDef({Unitc.class, Tankc.class}) UnitType vanquish;
public static @EntityDef({Unitc.class, Tankc.class}) UnitType vanquish, conquer;
//endregion
@ -2436,7 +2437,7 @@ public class UnitTypes{
health = 9000;
armor = 20f;
areaDamage = 12f;
treadRect = new Rect(22f, 16f, 28f, 130f);
treadRects = new Rect[]{new Rect(22, 16, 28, 130)};
weapons.add(new Weapon("vanquish-weapon"){{
layerOffset = 0.0001f;
@ -2499,6 +2500,20 @@ public class UnitTypes{
}
}};
conquer = new TankUnitType("conquer"){{
hitSize = 44f;
treadPullOffset = 1;
speed = 0.48f;
health = 20000;
armor = 25f;
areaDamage = 22f;
rotateSpeed = 0.9f;
treadRects = new Rect[]{new Rect(27, 152, 56, 73), new Rect(24, 51, 29, 17), new Rect(59, 18, 39, 19)};
decals.add(new UnitDecal("conquer-glow", 0, 0, 0, -1, Pal.turretHeat.cpy()){{
blending = Blending.additive;
}});
}};
//endregion
//region erekir - mech

View File

@ -32,9 +32,10 @@ abstract class TankComp implements Posc, Flyingc, Hitboxc, Unitc, ElevationMovec
//dust
if(walked && !headless){
treadEffectTime += Time.delta;
if(treadEffectTime >= 6f){
if(treadEffectTime >= 6f && type.treadRects.length > 0){
var treadRegion = type.treadRegion;
var treadRect = type.treadRect;
//first rect should always be at the back
var treadRect = type.treadRects[0];
float xOffset = (treadRegion.width/2f - (treadRect.x + treadRect.width/2f)) / 4f;
float yOffset = (treadRegion.height/2f - (treadRect.y + treadRect.height/2f)) / 4f;

View File

@ -9,6 +9,7 @@ public class UnitDecal{
public float x, y, rotation;
public float layer = Layer.flyingUnit + 1f;
public float xScale = 1f, yScale = 1f;
public Blending blending = Blending.normal;
public Color color = Color.white;
public UnitDecal(String region, float x, float y, float rotation, float layer, Color color){

View File

@ -119,7 +119,7 @@ public class UnitType extends UnlockableContent{
public boolean mechStepParticles = false;
public Color mechLegColor = Pal.darkMetal;
public Rect treadRect = new Rect();
public Rect[] treadRects = {};
public int treadFrames = 18;
public int treadPullOffset = 0;
@ -176,7 +176,8 @@ public class UnitType extends UnlockableContent{
public Seq<Weapon> weapons = new Seq<>();
public TextureRegion baseRegion, legRegion, region, shadowRegion, cellRegion,
softShadowRegion, jointRegion, footRegion, legBaseRegion, baseJointRegion, outlineRegion, treadRegion;
public TextureRegion[] wreckRegions, segmentRegions, segmentOutlineRegions, treadRegions;
public TextureRegion[] wreckRegions, segmentRegions, segmentOutlineRegions;
public TextureRegion[][] treadRegions;
protected float buildTime = -1f;
protected @Nullable ItemStack[] totalRequirements, cachedRequirements, firstRequirements;
@ -524,9 +525,11 @@ public class UnitType extends UnlockableContent{
footRegion = Core.atlas.find(name + "-foot");
treadRegion = Core.atlas.find(name + "-treads");
if(treadRegion.found()){
treadRegions = new TextureRegion[treadFrames];
for(int i = 0; i < treadFrames; i++){
treadRegions[i] = Core.atlas.find(name + "-treads" + i);
treadRegions = new TextureRegion[treadRects.length][treadFrames];
for(int r = 0; r < treadRects.length; r++){
for(int i = 0; i < treadFrames; i++){
treadRegions[r][i] = Core.atlas.find(name + "-treads" + r + "-" + i);
}
}
}
legBaseRegion = Core.atlas.find(name + "-leg-base", name + "-leg");
@ -767,10 +770,12 @@ public class UnitType extends UnlockableContent{
if(decals.size > 0){
float base = unit.rotation - 90;
for(var d : decals){
Draw.z(d.layer);
Draw.blend(d.blending);
Draw.z(d.layer <= 0f ? z : d.layer);
Draw.scl(d.xScale, d.yScale);
Draw.color(d.color);
Draw.rect(d.region, unit.x + Angles.trnsx(base, d.x, d.y), unit.y + Angles.trnsy(base, d.x, d.y), base + d.rotation);
Draw.blend();
}
Draw.reset();
Draw.z(z);
@ -995,13 +1000,16 @@ public class UnitType extends UnlockableContent{
if(treadRegion.found()){
int frame = (int)(unit.treadTime()) % treadFrames;
var region = treadRegions[frame];
float xOffset = treadRegion.width/2f - (treadRect.x + treadRect.width/2f);
float yOffset = treadRegion.height/2f - (treadRect.y + treadRect.height/2f);
for(int i = 0; i < treadRects.length; i ++){
var region = treadRegions[i][frame];
var treadRect = treadRects[i];
float xOffset = treadRegion.width/2f - (treadRect.x + treadRect.width/2f);
float yOffset = treadRegion.height/2f - (treadRect.y + treadRect.height/2f);
for(int i : Mathf.signs){
Tmp.v1.set(xOffset * i, yOffset).rotate(unit.rotation - 90);
Draw.rect(region, unit.x + Tmp.v1.x / 4f, unit.y + Tmp.v1.y / 4f, treadRect.width / 4f, region.height / 4f, unit.rotation - 90);
for(int side : Mathf.signs){
Tmp.v1.set(xOffset * side, yOffset).rotate(unit.rotation - 90);
Draw.rect(region, unit.x + Tmp.v1.x / 4f, unit.y + Tmp.v1.y / 4f, treadRect.width / 4f, region.height / 4f, unit.rotation - 90);
}
}
}
}

View File

@ -24,4 +24,4 @@ android.useAndroidX=true
#used for slow jitpack builds; TODO see if this actually works
org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000
archash=a066e32504
archash=16d2626649

View File

@ -521,22 +521,27 @@ public class Generators{
//generate tank animation
if(sample instanceof Tankc){
Pixmap pix = get(type.treadRegion);
//slice is always 1 pixel wide
Pixmap slice = pix.crop((int)type.treadRect.x, (int)type.treadRect.y, 1, (int)type.treadRect.height);
int frames = type.treadFrames;
for(int i = 0; i < frames; i++){
int pullOffset = type.treadPullOffset;
Pixmap frame = new Pixmap(slice.width, slice.height);
for(int y = 0; y < slice.height; y++){
int idx = y + i;
if(idx >= slice.height){
idx -= slice.height;
idx += pullOffset;
}
frame.setRaw(0, y, slice.getRaw(0, idx));
for(int r = 0; r < type.treadRects.length; r++){
Rect treadRect = type.treadRects[r];
//slice is always 1 pixel wide
Pixmap slice = pix.crop((int)treadRect.x, (int)treadRect.y, 1, (int)treadRect.height);
int frames = type.treadFrames;
for(int i = 0; i < frames; i++){
int pullOffset = type.treadPullOffset;
Pixmap frame = new Pixmap(slice.width, slice.height);
for(int y = 0; y < slice.height; y++){
int idx = y + i;
if(idx >= slice.height){
idx -= slice.height;
idx += pullOffset;
idx = Mathf.mod(idx, slice.height);
}
frame.setRaw(0, y, slice.getRaw(0, idx));
}
save(frame, type.name + "-treads" + r + "-" + i);
}
save(frame, type.name + "-treads" + i);
}
}