Changed power generation system, made generator blocks explode

This commit is contained in:
Anuken
2017-11-02 18:42:42 -04:00
parent 6c390b16e4
commit 5e16fbffc9
14 changed files with 183 additions and 114 deletions

View File

@@ -12,9 +12,26 @@ import io.anuke.ucore.util.Mathf;
public class EffectCreator{ public class EffectCreator{
static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f); static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f);
static Color lightOrange = Color.valueOf("f68021");
public static void create(){ public static void create(){
Effects.create("generatorexplosion", 28, e -> {
Angles.randLenVectors(e.id, 16, 10f + e.ifract()*8f, (x, y)->{
float size = e.fract()*12f + 1f;
Draw.color(Color.WHITE, lightOrange, e.ifract());
Draw.rect("circle", e.x + x, e.y + y, size, size);
Draw.reset();
});
});
Effects.create("shockwave", 10f, e -> {
Draw.color(Color.WHITE, Color.LIGHT_GRAY, e.ifract());
Draw.thick(e.fract()*2f + 0.2f);
Draw.circle(e.x, e.y, e.ifract()*28f);
Draw.reset();
});
Effects.create("shellsmoke", 21, e -> { Effects.create("shellsmoke", 21, e -> {
Angles.randLenVectors(e.id, 8, 1f + e.ifract()*16f, (x, y)->{ Angles.randLenVectors(e.id, 8, 1f + e.ifract()*16f, (x, y)->{
float size = 2f+e.fract()*5f; float size = 2f+e.fract()*5f;

View File

@@ -164,7 +164,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
} }
}, },
shot = new BulletType(2.4f, 2){ shot = new BulletType(2.4f, 2){
{lifetime=40;} {lifetime = 40;}
public void draw(Bullet b){ public void draw(Bullet b){
Draw.color(Color.GOLD); Draw.color(Color.GOLD);
Draw.rect("bullet", b.x, b.y, b.angle()); Draw.rect("bullet", b.x, b.y, b.angle());

View File

@@ -61,9 +61,13 @@ public class TileEntity extends Entity{
} }
public void collision(Bullet other){ public void collision(Bullet other){
Block block = tile.block(); damage(other.getDamage());
}
int amount = block.handleDamage(tile, other.getDamage()); public void damage(int damage){
if(dead) return;
int amount = tile.block().handleDamage(tile, damage);
health -= amount; health -= amount;
if(health <= 0) onDeath(); if(health <= 0) onDeath();
} }

View File

@@ -13,7 +13,7 @@ public enum Recipe{
steelwall(defense, DefenseBlocks.steelwall, stack(Item.steel, 2)), steelwall(defense, DefenseBlocks.steelwall, stack(Item.steel, 2)),
titaniumwall(defense, DefenseBlocks.titaniumwall, stack(Item.titanium, 2)), titaniumwall(defense, DefenseBlocks.titaniumwall, stack(Item.titanium, 2)),
duriumwall(defense, DefenseBlocks.diriumwall, stack(Item.dirium, 2)), duriumwall(defense, DefenseBlocks.diriumwall, stack(Item.dirium, 2)),
compositewall(defense, DefenseBlocks.compositewall, stack(Item.dirium, 2), stack(Item.titanium, 2), stack(Item.steel, 2), stack(Item.iron, 2)), //compositewall(defense, DefenseBlocks.compositewall, stack(Item.dirium, 2), stack(Item.titanium, 2), stack(Item.steel, 2), stack(Item.iron, 2)),
titaniumwalllarge(defense, DefenseBlocks.titaniumwalllarge, stack(Item.titanium, 8)), titaniumwalllarge(defense, DefenseBlocks.titaniumwalllarge, stack(Item.titanium, 8)),
duriumwalllarge(defense, DefenseBlocks.diriumwalllarge, stack(Item.dirium, 8)), duriumwalllarge(defense, DefenseBlocks.diriumwalllarge, stack(Item.dirium, 8)),
healturret(defense, DefenseBlocks.repairturret, stack(Item.iron, 30)), healturret(defense, DefenseBlocks.repairturret, stack(Item.iron, 30)),

View File

@@ -2,11 +2,13 @@ package io.anuke.mindustry.world;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.util.Bits; import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Mathf;
public class Tile{ public class Tile{
@@ -43,6 +45,21 @@ public class Tile{
return (T)entity; return (T)entity;
} }
public void damageNearby(int rad, int amount, float falloff){
//TODO damage falloff?
for(int dx = -rad; dx <= rad; dx ++){
for(int dy = -rad; dy <= rad; dy ++){
float dst = Vector2.dst(dx, dy, 0, 0);
if(dst > rad || (dx == 0 && dy == 0)) continue;
Tile other = World.tile(x + dx, y + dy);
if(other.entity != null){
other.entity.damage((int)(amount * Mathf.lerp(1f-dst/rad, 1f, falloff)));
}
}
}
}
public int id(){ public int id(){
return x + y * World.worldsize; return x + y * World.worldsize;
} }

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.world.blocks.types.defense; package io.anuke.mindustry.world.blocks.types.defense;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World; import io.anuke.mindustry.world.World;
@@ -50,8 +51,10 @@ public class RepairTurret extends Turret{
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
if(entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){ if(entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){
Tile targetTile = entity.blockTarget.tile;
Vector2 offset = targetTile.block().getPlaceOffset();
float x = tile.worldx(), y = tile.worldy(); float x = tile.worldx(), y = tile.worldy();
float x2 = entity.blockTarget.x, y2 = entity.blockTarget.y; float x2 = entity.blockTarget.x + offset.x, y2 = entity.blockTarget.y + offset.y;
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f)); Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
Draw.alpha(0.3f); Draw.alpha(0.3f);

View File

@@ -17,6 +17,7 @@ public class ShieldedWallBlock extends PowerBlock{
public ShieldedWallBlock(String name) { public ShieldedWallBlock(String name) {
super(name); super(name);
voltage = 0.00001f;
} }
@Override @Override

View File

@@ -5,9 +5,10 @@ import io.anuke.mindustry.world.blocks.types.production.Generator;
public class PowerBooster extends Generator{ public class PowerBooster extends Generator{
//TODO
public PowerBooster(String name) { public PowerBooster(String name) {
super(name); super(name);
drawRadius = true;
explosive = false;
} }
@Override @Override
@@ -15,6 +16,9 @@ public class PowerBooster extends Generator{
distributePower(tile); distributePower(tile);
} }
@Override
public void drawOver(Tile tile){}
@Override @Override
public boolean acceptsPower(Tile tile){ public boolean acceptsPower(Tile tile){
PowerEntity entity = tile.entity(); PowerEntity entity = tile.entity();

View File

@@ -1,20 +1,11 @@
package io.anuke.mindustry.world.blocks.types.distribution; package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World; import io.anuke.mindustry.world.blocks.types.production.Generator;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
public class PowerLaser extends PowerBlock{ public class PowerLaser extends Generator{
public int laserRange = 6;
public float powerAmount = 0.03f; public float powerAmount = 0.03f;
public Color color = Color.valueOf("e54135"); public Color color = Color.valueOf("e54135");
@@ -22,66 +13,19 @@ public class PowerLaser extends PowerBlock{
super(name); super(name);
rotate = true; rotate = true;
solid = true; solid = true;
} explosive = false;
laserDirections = 1;
@Override
public void drawOver(Tile tile){
PowerEntity entity = tile.entity();
if(entity.power > powerAmount){
drawLaserTo(tile, tile.rotation);
}
} }
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
distributeLaserPower(tile);
}
@Override
public boolean acceptsPower(Tile tile){
PowerEntity entity = tile.entity(); PowerEntity entity = tile.entity();
Tile target = target(tile, tile.rotation);
if(target == null) return; return entity.power + 0.001f <= powerCapacity;
PowerAcceptor p = (PowerAcceptor)target.block();
if(p.acceptsPower(target) && entity.power >= powerAmount){
entity.power -= (powerAmount - p.addPower(target, powerAmount));
}
}
protected void drawLaserTo(Tile tile, int rotation){
Tile target = target(tile, rotation);
if(target != null){
Angles.translation(rotation * 90, 6f);
Draw.color(Color.GRAY, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f));
Draw.alpha(1f);
float r = 0f;
Draw.laser("laser", "laserend",
tile.worldx() + Angles.x() + Mathf.range(r), tile.worldy() + Angles.y() + Mathf.range(r),
target.worldx() - Angles.x() + Mathf.range(r), target.worldy() - Angles.y() + Mathf.range(r),
0.7f + Mathf.sin(Timers.time(), 2f, 0.1f*0));
Draw.color();
}
}
protected Tile target(Tile tile, int rotation){
if(rotation < 0)
rotation += 4;
rotation %= 4;
GridPoint2 point = Geometry.getD4Points()[rotation];
int i = 0;
for(i = 1; i < laserRange; i ++){
Tile other = World.tile(tile.x + i * point.x, tile.y + i * point.y);
if(other != null && other.block() instanceof PowerAcceptor){
return other;
}
}
return null;
} }
} }

View File

@@ -1,39 +1,17 @@
package io.anuke.mindustry.world.blocks.types.distribution; package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
public class PowerLaserRouter extends PowerLaser{ public class PowerLaserRouter extends PowerLaser{
public PowerLaserRouter(String name) { public PowerLaserRouter(String name) {
super(name); super(name);
} laserDirections = 3;
@Override
public void drawOver(Tile tile){
PowerEntity entity = tile.entity();
if(entity.power > powerAmount){
for(int i = -1; i <= 1; i ++){
drawLaserTo(tile, tile.rotation + i);
}
}
} }
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
PowerEntity entity = tile.entity(); distributeLaserPower(tile);
for(int i = -1; i <= 1; i ++){
Tile target = target(tile, tile.rotation + i);
if(target == null) return;
PowerAcceptor p = (PowerAcceptor)target.block();
if(p.acceptsPower(target) && entity.power >= powerAmount/3f){
entity.power -= (powerAmount/3f - p.addPower(target, powerAmount/3f));
}
}
} }
} }

View File

@@ -1,5 +1,7 @@
package io.anuke.mindustry.world.blocks.types.production; package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
@@ -8,28 +10,133 @@ import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor; import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.mindustry.world.blocks.types.PowerBlock; import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
public class Generator extends PowerBlock{ public class Generator extends PowerBlock{
public static final int powerTime = 2; public static final int powerTime = 2;
public int laserRange = 6;
public int laserDirections = 4;
public int powerRange = 4; public int powerRange = 4;
public float powerSpeed = 0.2f; public float powerSpeed = 0.03f;
public boolean explosive = true;
public boolean drawRadius = false;
public Generator(String name) { public Generator(String name) {
super(name); super(name);
explosionEffect = "generatorexplosion";
}
@Override
public void onDestroyed(Tile tile){
if(explosive){
float x = tile.worldx(), y = tile.worldy();
Effects.effect("shellsmoke", x, y);
Effects.effect("blastsmoke", x, y);
Timers.run(Mathf.random(8f + Mathf.random(6f)), () -> {
Effects.shake(6f, 8f, x, y);
Effects.effect(explosionEffect, x, y);
Effects.effect("shockwave", x, y);
Timers.run(12f + Mathf.random(20f), () -> {
tile.damageNearby(3, 40, 0f);
});
Effects.sound(explosionSound, x, y);
});
}else{
super.onDestroyed(tile);
}
} }
@Override @Override
public void drawPixelOverlay(Tile tile){ public void drawPixelOverlay(Tile tile){
super.drawPixelOverlay(tile); super.drawPixelOverlay(tile);
if(drawRadius){
Draw.color("yellow"); Draw.color("yellow");
Draw.dashcircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize); Draw.dashcircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
Draw.reset(); Draw.reset();
} }
}
@Override
public void drawOver(Tile tile){
PowerEntity entity = tile.entity();
if(entity.power > powerSpeed){
for(int i = 0; i < laserDirections; i++){
drawLaserTo(tile, (tile.rotation + i) - laserDirections/2);
}
}
}
@Override
public boolean acceptsPower(Tile tile){
return false;
}
protected void distributeLaserPower(Tile tile){
PowerEntity entity = tile.entity();
for(int i = 0; i < laserDirections; i++){
Tile target = laserTarget(tile, (tile.rotation + i) - laserDirections/2);
if(target == null) continue;
PowerAcceptor p = (PowerAcceptor) target.block();
if(p.acceptsPower(target) && entity.power >= powerSpeed){
float accepted = p.addPower(target, powerSpeed);
entity.power -= (accepted);
}
}
}
protected void drawLaserTo(Tile tile, int rotation){
Tile target = laserTarget(tile, rotation);
if(target != null){
Angles.translation(rotation * 90, 6f);
Draw.color(Color.GRAY, Color.WHITE, 0.902f + Mathf.sin(Timers.time(), 1.7f, 0.08f));
Draw.alpha(1f);
float r = 0f;
Draw.laser("laser", "laserend", tile.worldx() + Angles.x() + Mathf.range(r), tile.worldy() + Angles.y() + Mathf.range(r), target.worldx() - Angles.x() + Mathf.range(r), target.worldy() - Angles.y() + Mathf.range(r), 0.7f + Mathf.sin(Timers.time(), 2f, 0.1f * 0));
Draw.color();
}
}
protected Tile laserTarget(Tile tile, int rotation){
if(rotation < 0)
rotation += 4;
rotation %= 4;
GridPoint2 point = Geometry.getD4Points()[rotation];
int i = 0;
for(i = 1; i < laserRange; i++){
Tile other = World.tile(tile.x + i * point.x, tile.y + i * point.y);
if(other != null && other.block() instanceof PowerAcceptor){
return other;
}
}
return null;
}
//TODO better distribution
protected void distributePower(Tile tile){ protected void distributePower(Tile tile){
if(!Timers.get(tile, "generate", powerTime)){ if(!Timers.get(tile, "generate", powerTime)){
return; return;
@@ -51,8 +158,7 @@ public class Generator extends PowerBlock{
if(Vector2.dst(x, y, 0, 0) < powerRange){ if(Vector2.dst(x, y, 0, 0) < powerRange){
Tile dest = World.tile(tile.x + x, tile.y + y); Tile dest = World.tile(tile.x + x, tile.y + y);
if(dest != null && dest.block() instanceof PowerAcceptor && if(dest != null && dest.block() instanceof PowerAcceptor && ((PowerAcceptor) dest.block()).acceptsPower(dest)){
((PowerAcceptor)dest.block()).acceptsPower(dest)){
if(i == 1){ if(i == 1){
PowerAcceptor block = (PowerAcceptor) dest.block(); PowerAcceptor block = (PowerAcceptor) dest.block();
@@ -61,7 +167,7 @@ public class Generator extends PowerBlock{
float amount = block.addPower(dest, transmission); float amount = block.addPower(dest, transmission);
p.power -= amount; p.power -= amount;
}else{ }else{
acceptors ++; acceptors++;
} }
} }
} }
@@ -74,9 +180,4 @@ public class Generator extends PowerBlock{
} }
} }
} }
@Override
public boolean acceptsPower(Tile tile){
return false;
}
} }

View File

@@ -41,7 +41,7 @@ public class ItemPowerGenerator extends Generator{
entity.removeItem(generateItem, 1); entity.removeItem(generateItem, 1);
} }
distributePower(tile); distributeLaserPower(tile);
} }

View File

@@ -46,7 +46,7 @@ public class LiquidItemPowerGenerator extends LiquidPowerGenerator{
Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y); Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y);
} }
distributePower(tile); distributeLaserPower(tile);
} }

View File

@@ -58,7 +58,7 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y); Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y);
} }
distributePower(tile); distributeLaserPower(tile);
} }