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

View File

@ -15,6 +15,7 @@ public class StorageBlocks {
vault = new Vault("vault"){{
size = 3;
health = 600;
}},
unloader = new Unloader("unloader"){{

View File

@ -23,6 +23,26 @@ public class EnvironmentFx {
Draw.color();
}),
fire = new Effect(35f, e -> {
Draw.color(Palette.lightFlame, Palette.darkFlame, e.fin());
Angles.randLenVectors(e.id, 2, 2f + e.fin()*7f, (x, y) -> {
Fill.circle(e.x + x, e.y + y, 0.2f + e.fslope() * 1.5f);
});
Draw.color();
}),
smoke = new Effect(35f, e -> {
Draw.color(Color.GRAY);
Angles.randLenVectors(e.id, 1, 2f + e.fin()*7f, (x, y) -> {
Fill.circle(e.x + x, e.y + y, 0.2f + e.fslope() * 1.5f);
});
Draw.color();
}),
freezing = new Effect(40f, e -> {
Draw.color(Liquids.cryofluid.color);

View File

@ -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{

View File

@ -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(){

View File

@ -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();
}

View File

@ -3,12 +3,12 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import io.anuke.mindustry.content.UnitTypes;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.effect.Fireball;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.builders.button;
import io.anuke.ucore.scene.builders.label;
@ -18,6 +18,7 @@ import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Log.LogHandler;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
@ -55,7 +56,11 @@ public class DebugFragment implements Fragment {
row();
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
row();
new button("effect", () -> Effects.effect(BlockFx.teleport, player));
new button("effect", () -> {
for(int i = 0; i < 20; i ++){
new Fireball(player.x, player.y, Palette.darkFlame, Mathf.random(360f)).add();
}
});
row();
new button("wave", () -> state.wavetime = 0f);
row();

View File

@ -18,6 +18,7 @@ import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.DrawLayer;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.Item;
@ -214,7 +215,7 @@ public class Block extends BaseBlock {
float heat = 0f;
float power = 0f;
int units = 1;
tempColor.set(Color.WHITE);
tempColor.set(Palette.darkFlame);
if(hasInventory){
for(Item item : Item.getAllItems()){
@ -256,9 +257,9 @@ public class Block extends BaseBlock {
});
}
for(int i = 0; i < Mathf.clamp(flammability / 20, 0, 20); i ++){
Timers.run(i, () -> {
Fireball f = new Fireball(x, y, Mathf.choose(tempColor, Color.LIGHT_GRAY), Mathf.random(360f));
for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i ++){
Timers.run(i/2, () -> {
Fireball f = new Fireball(x, y, tempColor, Mathf.random(360f));
f.add();
});
}
@ -274,6 +275,22 @@ public class Block extends BaseBlock {
DamageArea.damage(x, y, Mathf.clamp(size * tilesize + explosiveness, 0, 60f), 5 + explosiveness);
}
public float getFlammability(Tile tile){
if(!hasInventory || tile.entity == null){
return 0;
}else{
float result = 0f;
for(Item item : Item.getAllItems()){
int amount = tile.entity.inventory.getItem(item);
result += item.flammability*amount;
}
if(hasLiquids){
result += tile.entity.liquid.amount * tile.entity.liquid.liquid.flammability/3f;
}
return result;
}
}
public TextureRegion[] getIcon(){
if(Draw.hasRegion(name + "-icon")){
return new TextureRegion[]{Draw.region(name + "-icon")};