diff --git a/core/assets-raw/sprites/laser.png b/core/assets-raw/sprites/laser.png index 25509df010..67651ee81c 100644 Binary files a/core/assets-raw/sprites/laser.png and b/core/assets-raw/sprites/laser.png differ diff --git a/core/assets-raw/sprites/laserend.png b/core/assets-raw/sprites/laserend.png index ce1df97dae..878827188f 100644 Binary files a/core/assets-raw/sprites/laserend.png and b/core/assets-raw/sprites/laserend.png differ diff --git a/core/assets/sprites/sprites.png b/core/assets/sprites/sprites.png index 5a5595a6c1..4735538a0b 100644 Binary files a/core/assets/sprites/sprites.png and b/core/assets/sprites/sprites.png differ diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/PowerLaser.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/PowerLaser.java new file mode 100644 index 0000000000..777549d682 --- /dev/null +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/PowerLaser.java @@ -0,0 +1,61 @@ +package io.anuke.mindustry.world.blocks.types.distribution; + +import com.badlogic.gdx.math.GridPoint2; + +import io.anuke.mindustry.Vars; +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.util.Angles; +import io.anuke.ucore.util.Geometry; + +public class PowerLaser extends PowerBlock{ + public int laserRange = 4; + public float powerAmount = 0.01f; + + public PowerLaser(String name) { + super(name); + rotate = true; + } + + @Override + public void drawOver(Tile tile){ + Tile target = target(tile); + + if(target != null){ + Draw.laser("laser", "laserend", tile.worldx(), tile.worldy(), target.worldx(), target.worldy()); + }else{ + Angles.translation(tile.rotation*90, laserRange*Vars.tilesize); + + Draw.laser("laser", "laserend", tile.worldx(), tile.worldy(), tile.worldx() + Angles.x(), tile.worldy() + Angles.y()); + } + } + + @Override + public void update(Tile tile){ + PowerEntity entity = tile.entity(); + Tile target = target(tile); + + PowerAcceptor p = (PowerAcceptor)target.block(); + if(p.acceptsPower(target) && entity.power >= powerAmount){ + entity.power -= (powerAmount - p.addPower(target, powerAmount)); + } + } + + private Tile target(Tile tile){ + GridPoint2 point = Geometry.getD4Points()[tile.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; + } +}