Improved fireballs and general block explosions

This commit is contained in:
Anuken
2018-04-15 20:06:38 -04:00
parent 3adc599278
commit cb569be3b3
9 changed files with 99 additions and 16 deletions

View File

@@ -98,6 +98,10 @@ public abstract class Unit extends SyncEntity {
velocity.scl(Mathf.clamp(1f-drag* floor.dragMultiplier* Timers.delta()));
}
public void applyEffect(StatusEffect effect, float intensity){
status.handleApply(this, effect, intensity);
}
public void damagePeriodic(float amount){
damage(amount * Timers.delta(), Timers.get(this, "damageeffect", 20));
}

View File

@@ -14,9 +14,7 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Physics;
import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
import static io.anuke.mindustry.Vars.*;
public class DamageArea{
private static Rectangle rect = new Rectangle();
@@ -65,6 +63,24 @@ public class DamageArea{
Units.getNearbyEnemies(team, rect, cons);
}
/**Damages all entities and blocks in a radius that are enemies of the team.*/
public static void damageUnits(Team team, float x, float y, float size, float damage, Consumer<Unit> acceptor) {
Consumer<Unit> cons = entity -> {
if (!entity.hitbox.getRect(entity.x, entity.y).overlaps(rect)) {
return;
}
entity.damage(damage);
acceptor.accept(entity);
};
rect.setSize(size * 2).setCenter(x, y);
if (team != null) {
Units.getNearbyEnemies(team, rect, cons);
} else {
Units.getNearby(rect, cons);
}
}
/**Damages everything in a radius.*/
public static void damage(float x, float y, float radius, float damage){
damage(null, x, y, radius, damage);
@@ -78,7 +94,8 @@ public class DamageArea{
}
float amount = calculateDamage(x, y, entity.x, entity.y, radius, damage);
entity.damage(amount);
entity.velocity.add(tr.set(entity.x - x, entity.y - y).setLength(Mathf.clamp(damage/2f, 0, 6)));
//TODO better velocity displacement
entity.velocity.add(tr.set(entity.x - x, entity.y - y).setLength(damage*2f));
};
rect.setSize(radius *2).setCenter(x, y);

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.EnvironmentFx;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.Tile;
@@ -11,6 +12,7 @@ import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.effectGroup;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Fire extends TimedEntity {
@@ -43,9 +45,6 @@ public class Fire extends TimedEntity {
GridPoint2 p = Mathf.select(Geometry.d4);
Tile other = world.tile(tile.x + p.x, tile.y + p.y);
new Fire(other).add();
//if(other != null && other.target().entity != null && !other.entity.hasFire()){
//other.entity.setFire();
//}
}
}
@@ -55,6 +54,7 @@ public class Fire extends TimedEntity {
if(damage){
entity.damage(0.4f);
}
DamageArea.damageUnits(null, tile.worldx(), tile.worldy(), tilesize, 3f, unit -> unit.applyEffect(StatusEffects.burning, 0.8f));
}
if(Mathf.chance(0.05 * Timers.delta())){

View File

@@ -1,8 +1,10 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.fx.EnvironmentFx;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.graphics.Draw;
@@ -22,8 +24,8 @@ public class Fireball extends TimedEntity {
set(x, y);
this.rotation = rotation;
this.color = color;
lifetime = 40f + Mathf.random(40f);
speed = 0.3f + Mathf.random(2f);
lifetime = 30f + Mathf.random(40f);
speed = 0.6f + Mathf.random(2f);
}
@Override
@@ -40,6 +42,14 @@ public class Fireball extends TimedEntity {
new Fire(tile).add();
}
}
if(Mathf.chance(0.1 * Timers.delta())){
Effects.effect(EnvironmentFx.fireballsmoke, x, y);
}
if(Mathf.chance(0.1 * Timers.delta())){
Effects.effect(EnvironmentFx.ballfire, x, y);
}
}
@Override