Implemented fire

This commit is contained in:
Anuken
2018-04-15 17:12:09 -04:00
parent 6007e511ba
commit 3adc599278
8 changed files with 134 additions and 14 deletions
@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.world.Block;
@@ -29,6 +30,8 @@ public class TileEntity extends Entity{
public boolean dead = false;
public boolean added;
public Fire fire;
public PowerModule power;
public InventoryModule inventory;
public LiquidModule liquid;
@@ -50,6 +53,14 @@ public class TileEntity extends Entity{
return this;
}
public boolean hasFire(){
return fire != null;
}
public void setFire(){
this.fire = new Fire(tile).add();
}
public void write(DataOutputStream stream) throws IOException{
@@ -1,10 +1,66 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.content.fx.EnvironmentFx;
import io.anuke.mindustry.entities.TileEntity;
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.util.Geometry;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.effectGroup;
import static io.anuke.mindustry.Vars.world;
public class Fire extends TimedEntity {
private Tile tile;
private float flammability = -1;
public Fire(Tile tile){
this.tile = tile;
lifetime = 1000f;
}
@Override
public void update() {
super.update();
TileEntity entity = tile.target().entity;
boolean damage = entity != null;
if(!damage){
time += Timers.delta()*8;
}else if (flammability < 0){
flammability = tile.block().getFlammability(tile);
}
if(damage) {
lifetime += Mathf.clamp(flammability / 8f, 0f, 0.6f) * Timers.delta();
if (flammability > 1f && Mathf.chance(0.03 * Timers.delta() * Mathf.clamp(flammability/5f, 0.3f, 2f))) {
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();
//}
}
}
if(Mathf.chance(0.1 * Timers.delta())){
Effects.effect(EnvironmentFx.fire, tile.worldx() + Mathf.range(4f), tile.worldy() + Mathf.range(4f));
if(damage){
entity.damage(0.4f);
}
}
if(Mathf.chance(0.05 * Timers.delta())){
Effects.effect(EnvironmentFx.smoke, tile.worldx() + Mathf.range(4f), tile.worldy() + Mathf.range(4f));
}
}
@Override
public Fire add(){
@@ -2,6 +2,8 @@ package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
@@ -9,33 +11,41 @@ import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.effectGroup;
import static io.anuke.mindustry.Vars.world;
public class Fireball extends TimedEntity {
private float rotation;
private float speed = 0.3f;
private float speed;
private Color color;
public Fireball(float x, float y, Color color, float rotation){
set(x, y);
this.rotation = rotation;
this.color = color;
lifetime = 70f;
speed += Mathf.random(1f);
lifetime = 40f + Mathf.random(40f);
speed = 0.3f + Mathf.random(2f);
}
@Override
public void update() {
super.update();
float speed = this.speed - fin()*0.1f;
float speed = this.speed * fout();
x += Angles.trnsx(rotation, speed);
y += Angles.trnsy(rotation, speed);
if(Mathf.chance(0.04 * Timers.delta())){
Tile tile = world.tileWorld(x, y);
if(tile != null){
new Fire(tile).add();
}
}
}
@Override
public void draw() {
Draw.color(Palette.lightFlame, color, Color.GRAY, fin());
Fill.circle(x, y, 3f * fout() + 0.5f);
Fill.circle(x, y, 3f * fout());
Draw.reset();
}