This commit is contained in:
Anuken
2020-02-06 11:37:22 -05:00
parent a11f6efe0a
commit 6a99a3922e
46 changed files with 2155 additions and 1871 deletions

View File

@@ -0,0 +1,76 @@
package mindustry.entities.def;
import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@Component
abstract class HealthComp implements Entityc{
static final float hitDuration = 9f;
float health, maxHealth, hitTime;
boolean dead;
boolean isValid(){
return !dead && isAdded();
}
float healthf(){
return health / maxHealth;
}
@Override
public void update(){
hitTime -= Time.delta() / hitDuration;
}
void killed(){
//implement by other components
}
void kill(){
health = 0;
dead = true;
}
void heal(){
dead = false;
health = maxHealth;
}
boolean damaged(){
return health <= maxHealth - 0.0001f;
}
void damage(float amount){
health -= amount;
if(health <= 0 && !dead){
dead = true;
killed();
}
}
void damage(float amount, boolean withEffect){
float pre = hitTime;
damage(amount);
if(!withEffect){
hitTime = pre;
}
}
void damageContinuous(float amount){
damage(amount * Time.delta(), hitTime <= -20 + hitDuration);
}
void clampHealth(){
health = Mathf.clamp(health, 0, maxHealth);
}
void heal(float amount){
health += amount;
clampHealth();
}
}