Removed useless hitbox rects

This commit is contained in:
Anuken
2018-09-25 17:37:01 -04:00
parent 3ce16e0ed1
commit b9eb8a750b
10 changed files with 41 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.entities;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Queue;
import io.anuke.annotations.Annotations.Loc;
@@ -28,7 +29,6 @@ import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.storage.CoreBlock.CoreEntity;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Lines;
@@ -47,7 +47,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
private static final int timerShootRight = 1;
private static final float liftoffBoost = 0.2f;
//region instance variables, constructor
//region instance variables
public float baseRotation;
public float pointerX, pointerY;
@@ -75,11 +75,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
private Vector2 movement = new Translator();
private boolean moved;
public Player(){
hitbox.setSize(5);
hitboxTile.setSize(4f);
}
//endregion
//region unit and event overrides, utility methods
@@ -101,6 +96,16 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
player.onDeath();
}
@Override
public void getHitbox(Rectangle rectangle){
rectangle.setSize(5).setCenter(x, y);
}
@Override
public void getHitboxTile(Rectangle rectangle){
rectangle.setSize(4).setCenter(x, y);
}
@Override
public float getDrag(){
return mech.drag;

View File

@@ -40,7 +40,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
public static final float velocityPercision = 8f;
/**Maximum absolute value of a velocity vector component.*/
public static final float maxAbsVelocity = 127f / velocityPercision;
private static final Vector2 moveVector = new Vector2();
public UnitInventory inventory = new UnitInventory(this);

View File

@@ -64,7 +64,6 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
if(type.keepVelocity){
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait) owner).getVelocity() : Vector2.Zero);
}
bullet.hitbox.setSize(type.hitsize);
bullet.team = team;
bullet.type = type;

View File

@@ -114,6 +114,12 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT
return l;
}
@Override
public void getHitbox(Rectangle rectangle){}
@Override
public void getHitboxTile(Rectangle rectangle){}
@Override
public void absorb(){
activeFrame = 99;
@@ -183,7 +189,7 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT
Units.getNearbyEnemies(team, rect, unit -> {
unit.getHitbox(hitrect);
if(rect.overlaps(hitrect)){
unit.damage(damage * (unit.hasEffect(StatusEffects.wet) ? 2f : 1f));
unit.damage(damage * (unit.hasEffect(StatusEffects.wet) ? wetDamageMultiplier : 1f));
Effects.effect(effect, vec.x, vec.y, 0f);
}
});

View File

@@ -1,6 +1,5 @@
package io.anuke.mindustry.entities.traits;
import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.net.Interpolator;
import io.anuke.ucore.entities.trait.Entity;
@@ -8,15 +7,8 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.threads;
public interface SyncTrait extends Entity, TypeTrait{
/**Whether smoothing of entities is enabled when using multithreading; not yet implemented.*/
static boolean isSmoothing(){
return threads.isEnabled() && threads.getTPS() <= Gdx.graphics.getFramesPerSecond() / 2f;
}
/**Sets the position of this entity and updated the interpolator.*/
default void setNet(float x, float y){
set(x, y);

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities.units;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.Vars;
@@ -43,7 +44,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
protected static int timerIndex = 0;
protected static final int timerTarget = timerIndex++;
protected static final int timerShootLeft = timerIndex++;
protected static final int timerShootRight = timerIndex++;
@@ -364,8 +364,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
@Override
public void added(){
hitbox.setSize(type.hitsize);
hitboxTile.setSize(type.hitsizeTile);
state.set(getStartState());
health(maxHealth());
@@ -375,6 +373,16 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
}
@Override
public void getHitbox(Rectangle rectangle){
rectangle.setSize(type.hitsize).setCenter(x, y);
}
@Override
public void getHitboxTile(Rectangle rectangle){
rectangle.setSize(type.hitsizeTile).setCenter(x, y);
}
@Override
public EntityGroup targetGroup(){
return unitGroups[team.ordinal()];

View File

@@ -112,9 +112,9 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
@Override
public void onCommand(UnitCommand command){
state.set(command == UnitCommand.retreat ? retreat :
(command == UnitCommand.attack ? attack :
(command == UnitCommand.patrol ? patrol :
(null))));
command == UnitCommand.attack ? attack :
command == UnitCommand.patrol ? patrol :
null);
}
@Override

View File

@@ -98,9 +98,9 @@ public abstract class GroundUnit extends BaseUnit{
@Override
public void onCommand(UnitCommand command){
state.set(command == UnitCommand.retreat ? retreat :
(command == UnitCommand.attack ? attack :
(command == UnitCommand.patrol ? patrol :
(null))));
command == UnitCommand.attack ? attack :
command == UnitCommand.patrol ? patrol :
null);
}
@Override

View File

@@ -20,6 +20,7 @@ public class DeflectorWall extends Wall{
protected float maxDamageDeflect = 10f;
protected Rectangle rect = new Rectangle();
protected Rectangle rect2 = new Rectangle();
public DeflectorWall(String name){
super(name);
@@ -54,8 +55,10 @@ public class DeflectorWall extends Wall{
float penX = Math.abs(entity.x - bullet.x), penY = Math.abs(entity.y - bullet.y);
bullet.getHitbox(rect2);
Vector2 position = Physics.raycastRect(bullet.lastPosition().x, bullet.lastPosition().y, bullet.x, bullet.y,
rect.setCenter(entity.x, entity.y).setSize(size * tilesize + bullet.hitbox.width + bullet.hitbox.height));
rect.setCenter(entity.x, entity.y).setSize(size * tilesize + rect2.width + rect2.height));
if(position != null){
bullet.set(position.x, position.y);