WIP tank unit type
This commit is contained in:
@@ -11,9 +11,7 @@ import mindustry.world.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class EntityCollisions{
|
||||
//range for tile collision scanning
|
||||
private static final int r = 1;
|
||||
//move in 1-unit chunks
|
||||
//move in 1-unit chunks (can this be made more efficient?)
|
||||
private static final float seg = 1f;
|
||||
|
||||
//tile collisions
|
||||
@@ -42,10 +40,12 @@ public class EntityCollisions{
|
||||
if(Math.abs(deltax) < 0.0001f & Math.abs(deltay) < 0.0001f) return;
|
||||
|
||||
boolean movedx = false;
|
||||
entity.hitboxTile(r1);
|
||||
int r = Math.max(Math.round(r1.width / tilesize), 1);
|
||||
|
||||
while(Math.abs(deltax) > 0 || !movedx){
|
||||
movedx = true;
|
||||
moveDelta(entity, Math.min(Math.abs(deltax), seg) * Mathf.sign(deltax), 0, true, solidCheck);
|
||||
moveDelta(entity, Math.min(Math.abs(deltax), seg) * Mathf.sign(deltax), 0, r, true, solidCheck);
|
||||
|
||||
if(Math.abs(deltax) >= seg){
|
||||
deltax -= seg * Mathf.sign(deltax);
|
||||
@@ -58,7 +58,7 @@ public class EntityCollisions{
|
||||
|
||||
while(Math.abs(deltay) > 0 || !movedy){
|
||||
movedy = true;
|
||||
moveDelta(entity, 0, Math.min(Math.abs(deltay), seg) * Mathf.sign(deltay), false, solidCheck);
|
||||
moveDelta(entity, 0, Math.min(Math.abs(deltay), seg) * Mathf.sign(deltay), r, false, solidCheck);
|
||||
|
||||
if(Math.abs(deltay) >= seg){
|
||||
deltay -= seg * Mathf.sign(deltay);
|
||||
@@ -68,7 +68,7 @@ public class EntityCollisions{
|
||||
}
|
||||
}
|
||||
|
||||
public void moveDelta(Hitboxc entity, float deltax, float deltay, boolean x, SolidPred solidCheck){
|
||||
public void moveDelta(Hitboxc entity, float deltax, float deltay, int r, boolean x, SolidPred solidCheck){
|
||||
entity.hitboxTile(r1);
|
||||
entity.hitboxTile(r2);
|
||||
r1.x += deltax;
|
||||
|
||||
@@ -69,6 +69,9 @@ abstract class HitboxComp implements Posc, Sized, QuadTreeObject{
|
||||
public void hitboxTile(Rect rect){
|
||||
//tile hitboxes are never bigger than a tile, otherwise units get stuck
|
||||
float size = Math.min(hitSize * 0.66f, 7.9f);
|
||||
//TODO: better / more accurate version is
|
||||
//float size = hitSize * 0.85f;
|
||||
//- for tanks?
|
||||
rect.setCentered(x, y, size, size);
|
||||
}
|
||||
}
|
||||
|
||||
63
core/src/mindustry/entities/comp/TankComp.java
Normal file
63
core/src/mindustry/entities/comp/TankComp.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package mindustry.entities.comp;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.environment.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component
|
||||
abstract class TankComp implements Posc, Flyingc, Hitboxc, Unitc, ElevationMovec{
|
||||
@Import float x, y, hitSize;
|
||||
@Import UnitType type;
|
||||
|
||||
transient float treadTime;
|
||||
transient boolean walked;
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
//trigger animation only when walking manually
|
||||
if(walked || net.client()){
|
||||
float len = deltaLen();
|
||||
treadTime += len;
|
||||
walked = false;
|
||||
}
|
||||
|
||||
//TODO treads should create dust, see MechComp
|
||||
}
|
||||
|
||||
@Replace
|
||||
@Override
|
||||
public @Nullable Floor drownFloor(){
|
||||
//tanks can only drown when all the nearby floors are deep
|
||||
//TODO implement properly
|
||||
if(hitSize >= 12 && canDrown()){
|
||||
for(Point2 p : Geometry.d8){
|
||||
Floor f = world.floorWorld(x + p.x * tilesize, y + p.y * tilesize);
|
||||
if(!f.isDeep()){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return canDrown() ? floorOn() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveAt(Vec2 vector, float acceleration){
|
||||
//mark walking state when moving in a controlled manner
|
||||
if(!vector.isZero()){
|
||||
walked = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void approach(Vec2 vector){
|
||||
//mark walking state when moving in a controlled manner
|
||||
if(!vector.isZero(0.001f)){
|
||||
walked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user