Collisions, lots of bugfixes
This commit is contained in:
@@ -3,7 +3,6 @@ package mindustry.entities;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
@@ -223,6 +222,8 @@ public class EntityCollisions{
|
||||
sc.hitbox(r1);
|
||||
if(r2.overlaps(r1)){
|
||||
checkCollide(solid, sc);
|
||||
//break out of loop when this object hits something
|
||||
if(!solid.isAdded()) return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -56,16 +56,30 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
||||
return damage * damageMultiplier();
|
||||
}
|
||||
|
||||
@Replace
|
||||
@Override
|
||||
public boolean collides(Hitboxc other){
|
||||
return type.collides && (other instanceof Teamc && ((Teamc)other).team() != team()) && !(other instanceof Flyingc && ((Flyingc)other).isFlying() && !type.collidesAir);
|
||||
}
|
||||
|
||||
@MethodPriority(100)
|
||||
@Override
|
||||
public void collision(Hitboxc other, float x, float y){
|
||||
if(!type.pierce) remove();
|
||||
type.hit(this, x, y);
|
||||
|
||||
if(other instanceof Healthc){
|
||||
Healthc h = (Healthc)other;
|
||||
h.damage(damage);
|
||||
}
|
||||
|
||||
if(other instanceof Unitc){
|
||||
Unitc unit = (Unitc)other;
|
||||
unit.vel().add(Tmp.v3.set(other.x(), other.y()).sub(x, y).setLength(type.knockback / unit.mass()));
|
||||
unit.apply(type.status, type.statusDuration);
|
||||
}
|
||||
|
||||
//must be last.
|
||||
if(!type.pierce) remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,10 +25,6 @@ abstract class HealthComp implements Entityc{
|
||||
hitTime -= Time.delta() / hitDuration;
|
||||
}
|
||||
|
||||
float hitAlpha(){
|
||||
return hitTime / hitDuration;
|
||||
}
|
||||
|
||||
void killed(){
|
||||
//implement by other components
|
||||
}
|
||||
@@ -53,6 +49,7 @@ abstract class HealthComp implements Entityc{
|
||||
|
||||
void damage(float amount){
|
||||
health -= amount;
|
||||
hitTime = 1f;
|
||||
if(health <= 0 && !dead){
|
||||
kill();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,12 @@ abstract class HitboxComp implements Posc, QuadTreeObject{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(){
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
}
|
||||
|
||||
void updateLastPosition(){
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
@@ -35,8 +41,7 @@ abstract class HitboxComp implements Posc, QuadTreeObject{
|
||||
}
|
||||
|
||||
boolean collides(Hitboxc other){
|
||||
return Intersector.overlapsRect(x - hitSize/2f, y - hitSize/2f, hitSize, hitSize,
|
||||
other.x() - other.hitSize()/2f, other.y() - other.hitSize()/2f, other.hitSize(), other.hitSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,6 +73,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
|
||||
}
|
||||
|
||||
public void team(Team team){
|
||||
this.team = team;
|
||||
if(unit != null){
|
||||
unit.team(team);
|
||||
}
|
||||
|
||||
@@ -150,8 +150,6 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
float flammability = item().flammability * stack().amount;
|
||||
Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, bounds() / 2f, Pal.darkFlame);
|
||||
|
||||
//TODO cleanup
|
||||
//ScorchDecal.create(getX(), getY());
|
||||
Effects.scorch(x, y, (int)(hitSize() / 5));
|
||||
Fx.explosion.at(this);
|
||||
Effects.shake(2f, 2f, this);
|
||||
@@ -159,9 +157,8 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
|
||||
Events.fire(new UnitDestroyEvent(this));
|
||||
|
||||
//TODO implement suicide bomb trigger
|
||||
//if(explosiveness > 7f && this == player){
|
||||
// Events.fire(Trigger.suicideBomb);
|
||||
//}
|
||||
if(explosiveness > 7f && isLocal()){
|
||||
Events.fire(Trigger.suicideBomb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +155,8 @@ public class UnitDef extends UnlockableContent{
|
||||
}
|
||||
|
||||
public void drawWeapons(Unitc unit){
|
||||
Draw.mixcol(Color.white, unit.hitTime());
|
||||
|
||||
for(WeaponMount mount : unit.mounts()){
|
||||
Weapon weapon = mount.weapon;
|
||||
|
||||
@@ -173,10 +175,12 @@ public class UnitDef extends UnlockableContent{
|
||||
rotation);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
public void drawBody(Unitc unit){
|
||||
Draw.mixcol(Color.white, unit.hitAlpha());
|
||||
Draw.mixcol(Color.white, unit.hitTime());
|
||||
|
||||
Draw.rect(region, unit, unit.rotation() - 90);
|
||||
|
||||
@@ -196,7 +200,7 @@ public class UnitDef extends UnlockableContent{
|
||||
}
|
||||
|
||||
public void drawLegs(Legsc unit){
|
||||
Draw.mixcol(Color.white, unit.hitAlpha());
|
||||
Draw.mixcol(Color.white, unit.hitTime());
|
||||
|
||||
float ft = Mathf.sin(unit.walkTime(), 6f, 2f + unit.hitSize() / 15f);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user