Changed power generation system, made generator blocks explode
This commit is contained in:
@@ -12,9 +12,26 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class EffectCreator{
|
||||
static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f);
|
||||
static Color lightOrange = Color.valueOf("f68021");
|
||||
|
||||
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 -> {
|
||||
Angles.randLenVectors(e.id, 8, 1f + e.ifract()*16f, (x, y)->{
|
||||
float size = 2f+e.fract()*5f;
|
||||
|
||||
@@ -164,7 +164,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
}
|
||||
},
|
||||
shot = new BulletType(2.4f, 2){
|
||||
{lifetime=40;}
|
||||
{lifetime = 40;}
|
||||
public void draw(Bullet b){
|
||||
Draw.color(Color.GOLD);
|
||||
Draw.rect("bullet", b.x, b.y, b.angle());
|
||||
|
||||
@@ -61,9 +61,13 @@ public class TileEntity extends Entity{
|
||||
}
|
||||
|
||||
public void collision(Bullet other){
|
||||
Block block = tile.block();
|
||||
damage(other.getDamage());
|
||||
}
|
||||
|
||||
public void damage(int damage){
|
||||
if(dead) return;
|
||||
|
||||
int amount = block.handleDamage(tile, other.getDamage());
|
||||
int amount = tile.block().handleDamage(tile, damage);
|
||||
health -= amount;
|
||||
if(health <= 0) onDeath();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public enum Recipe{
|
||||
steelwall(defense, DefenseBlocks.steelwall, stack(Item.steel, 2)),
|
||||
titaniumwall(defense, DefenseBlocks.titaniumwall, stack(Item.titanium, 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)),
|
||||
duriumwalllarge(defense, DefenseBlocks.diriumwalllarge, stack(Item.dirium, 8)),
|
||||
healturret(defense, DefenseBlocks.repairturret, stack(Item.iron, 30)),
|
||||
|
||||
@@ -2,11 +2,13 @@ package io.anuke.mindustry.world;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
|
||||
public class Tile{
|
||||
@@ -43,6 +45,21 @@ public class Tile{
|
||||
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(){
|
||||
return x + y * World.worldsize;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
@@ -50,8 +51,10 @@ public class RepairTurret extends Turret{
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
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 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.alpha(0.3f);
|
||||
|
||||
@@ -17,6 +17,7 @@ public class ShieldedWallBlock extends PowerBlock{
|
||||
|
||||
public ShieldedWallBlock(String name) {
|
||||
super(name);
|
||||
voltage = 0.00001f;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,9 +5,10 @@ import io.anuke.mindustry.world.blocks.types.production.Generator;
|
||||
|
||||
public class PowerBooster extends Generator{
|
||||
|
||||
//TODO
|
||||
public PowerBooster(String name) {
|
||||
super(name);
|
||||
drawRadius = true;
|
||||
explosive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -15,6 +16,9 @@ public class PowerBooster extends Generator{
|
||||
distributePower(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
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;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Generator;
|
||||
|
||||
public class PowerLaser extends PowerBlock{
|
||||
public int laserRange = 6;
|
||||
public class PowerLaser extends Generator{
|
||||
public float powerAmount = 0.03f;
|
||||
public Color color = Color.valueOf("e54135");
|
||||
|
||||
@@ -22,66 +13,19 @@ public class PowerLaser extends PowerBlock{
|
||||
super(name);
|
||||
rotate = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
|
||||
if(entity.power > powerAmount){
|
||||
drawLaserTo(tile, tile.rotation);
|
||||
}
|
||||
explosive = false;
|
||||
laserDirections = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
distributeLaserPower(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
Tile target = target(tile, tile.rotation);
|
||||
|
||||
if(target == null) return;
|
||||
|
||||
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;
|
||||
return entity.power + 0.001f <= powerCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
|
||||
|
||||
public class PowerLaserRouter extends PowerLaser{
|
||||
|
||||
public PowerLaserRouter(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
laserDirections = 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
PowerEntity entity = tile.entity();
|
||||
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));
|
||||
}
|
||||
}
|
||||
distributeLaserPower(tile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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 io.anuke.mindustry.Vars;
|
||||
@@ -8,35 +10,140 @@ import io.anuke.mindustry.world.World;
|
||||
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.Effects;
|
||||
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 Generator extends PowerBlock{
|
||||
public static final int powerTime = 2;
|
||||
|
||||
public int laserRange = 6;
|
||||
public int laserDirections = 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) {
|
||||
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
|
||||
public void drawPixelOverlay(Tile tile){
|
||||
super.drawPixelOverlay(tile);
|
||||
|
||||
Draw.color("yellow");
|
||||
Draw.dashcircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
|
||||
Draw.reset();
|
||||
|
||||
if(drawRadius){
|
||||
Draw.color("yellow");
|
||||
Draw.dashcircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
|
||||
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){
|
||||
if(!Timers.get(tile, "generate", powerTime)){
|
||||
return;
|
||||
}
|
||||
|
||||
PowerEntity p = tile.entity();
|
||||
|
||||
|
||||
int acceptors = 0;
|
||||
float flow = 0f;
|
||||
|
||||
@@ -51,8 +158,7 @@ public class Generator extends PowerBlock{
|
||||
|
||||
if(Vector2.dst(x, y, 0, 0) < powerRange){
|
||||
Tile dest = World.tile(tile.x + x, tile.y + y);
|
||||
if(dest != null && dest.block() instanceof PowerAcceptor &&
|
||||
((PowerAcceptor)dest.block()).acceptsPower(dest)){
|
||||
if(dest != null && dest.block() instanceof PowerAcceptor && ((PowerAcceptor) dest.block()).acceptsPower(dest)){
|
||||
if(i == 1){
|
||||
PowerAcceptor block = (PowerAcceptor) dest.block();
|
||||
|
||||
@@ -61,22 +167,17 @@ public class Generator extends PowerBlock{
|
||||
float amount = block.addPower(dest, transmission);
|
||||
p.power -= amount;
|
||||
}else{
|
||||
acceptors ++;
|
||||
acceptors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO better distribution scheme
|
||||
if(i == 0 && acceptors > 0){
|
||||
flow = Mathf.clamp(p.power / acceptors, 0f, powerSpeed / acceptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPower(Tile tile){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ItemPowerGenerator extends Generator{
|
||||
entity.removeItem(generateItem, 1);
|
||||
}
|
||||
|
||||
distributePower(tile);
|
||||
distributeLaserPower(tile);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class LiquidItemPowerGenerator extends LiquidPowerGenerator{
|
||||
Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||
}
|
||||
|
||||
distributePower(tile);
|
||||
distributeLaserPower(tile);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
||||
Effects.effect(generateEffect, tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||
}
|
||||
|
||||
distributePower(tile);
|
||||
distributeLaserPower(tile);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user