Collisions, lots of bugfixes

This commit is contained in:
Anuken
2020-02-10 09:58:00 -05:00
parent fbadb9f4aa
commit 0ad8408ba9
7 changed files with 35 additions and 16 deletions
@@ -3,7 +3,6 @@ package mindustry.entities;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.world.*; import mindustry.world.*;
@@ -223,6 +222,8 @@ public class EntityCollisions{
sc.hitbox(r1); sc.hitbox(r1);
if(r2.overlaps(r1)){ if(r2.overlaps(r1)){
checkCollide(solid, sc); 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(); 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 @Override
public void collision(Hitboxc other, float x, float y){ public void collision(Hitboxc other, float x, float y){
if(!type.pierce) remove();
type.hit(this, x, y); type.hit(this, x, y);
if(other instanceof Healthc){
Healthc h = (Healthc)other;
h.damage(damage);
}
if(other instanceof Unitc){ if(other instanceof Unitc){
Unitc unit = (Unitc)other; Unitc unit = (Unitc)other;
unit.vel().add(Tmp.v3.set(other.x(), other.y()).sub(x, y).setLength(type.knockback / unit.mass())); unit.vel().add(Tmp.v3.set(other.x(), other.y()).sub(x, y).setLength(type.knockback / unit.mass()));
unit.apply(type.status, type.statusDuration); unit.apply(type.status, type.statusDuration);
} }
//must be last.
if(!type.pierce) remove();
} }
@Override @Override
@@ -25,10 +25,6 @@ abstract class HealthComp implements Entityc{
hitTime -= Time.delta() / hitDuration; hitTime -= Time.delta() / hitDuration;
} }
float hitAlpha(){
return hitTime / hitDuration;
}
void killed(){ void killed(){
//implement by other components //implement by other components
} }
@@ -53,6 +49,7 @@ abstract class HealthComp implements Entityc{
void damage(float amount){ void damage(float amount){
health -= amount; health -= amount;
hitTime = 1f;
if(health <= 0 && !dead){ if(health <= 0 && !dead){
kill(); kill();
} }
@@ -17,6 +17,12 @@ abstract class HitboxComp implements Posc, QuadTreeObject{
} }
@Override
public void add(){
lastX = x;
lastY = y;
}
void updateLastPosition(){ void updateLastPosition(){
lastX = x; lastX = x;
lastY = y; lastY = y;
@@ -35,8 +41,7 @@ abstract class HitboxComp implements Posc, QuadTreeObject{
} }
boolean collides(Hitboxc other){ boolean collides(Hitboxc other){
return Intersector.overlapsRect(x - hitSize/2f, y - hitSize/2f, hitSize, hitSize, return true;
other.x() - other.hitSize()/2f, other.y() - other.hitSize()/2f, other.hitSize(), other.hitSize());
} }
@Override @Override
@@ -73,6 +73,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
} }
public void team(Team team){ public void team(Team team){
this.team = team;
if(unit != null){ if(unit != null){
unit.team(team); unit.team(team);
} }
@@ -150,8 +150,6 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
float flammability = item().flammability * stack().amount; float flammability = item().flammability * stack().amount;
Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, bounds() / 2f, Pal.darkFlame); Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, bounds() / 2f, Pal.darkFlame);
//TODO cleanup
//ScorchDecal.create(getX(), getY());
Effects.scorch(x, y, (int)(hitSize() / 5)); Effects.scorch(x, y, (int)(hitSize() / 5));
Fx.explosion.at(this); Fx.explosion.at(this);
Effects.shake(2f, 2f, 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)); Events.fire(new UnitDestroyEvent(this));
//TODO implement suicide bomb trigger if(explosiveness > 7f && isLocal()){
//if(explosiveness > 7f && this == player){ Events.fire(Trigger.suicideBomb);
// Events.fire(Trigger.suicideBomb); }
//}
} }
} }
+6 -2
View File
@@ -155,6 +155,8 @@ public class UnitDef extends UnlockableContent{
} }
public void drawWeapons(Unitc unit){ public void drawWeapons(Unitc unit){
Draw.mixcol(Color.white, unit.hitTime());
for(WeaponMount mount : unit.mounts()){ for(WeaponMount mount : unit.mounts()){
Weapon weapon = mount.weapon; Weapon weapon = mount.weapon;
@@ -173,10 +175,12 @@ public class UnitDef extends UnlockableContent{
rotation); rotation);
} }
} }
Draw.reset();
} }
public void drawBody(Unitc unit){ public void drawBody(Unitc unit){
Draw.mixcol(Color.white, unit.hitAlpha()); Draw.mixcol(Color.white, unit.hitTime());
Draw.rect(region, unit, unit.rotation() - 90); Draw.rect(region, unit, unit.rotation() - 90);
@@ -196,7 +200,7 @@ public class UnitDef extends UnlockableContent{
} }
public void drawLegs(Legsc unit){ 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); float ft = Mathf.sin(unit.walkTime(), 6f, 2f + unit.hitSize() / 15f);