Added shield shader, temporarily disabled dependencies and shield energy
This commit is contained in:
@@ -79,7 +79,7 @@ project(":core") {
|
|||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.anuken:ucore:989f9713fa'
|
//compile 'com.github.anuken:ucore:989f9713fa'
|
||||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
|
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
core/assets-raw/sprites/blocks/coalgenerator.png
Normal file
BIN
core/assets-raw/sprites/blocks/coalgenerator.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 313 B |
BIN
core/assets-raw/sprites/blocks/shieldgenerator.png
Normal file
BIN
core/assets-raw/sprites/blocks/shieldgenerator.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 262 B |
BIN
core/assets-raw/sprites/circle2.png
Normal file
BIN
core/assets-raw/sprites/circle2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
52
core/assets/shaders/shield.fragment
Normal file
52
core/assets/shaders/shield.fragment
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
precision mediump int;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
uniform vec4 u_color;
|
||||||
|
uniform vec2 u_texsize;
|
||||||
|
uniform float u_time;
|
||||||
|
uniform vec2 u_offset;
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
varying vec2 v_texCoord;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vec2 T = v_texCoord.xy;
|
||||||
|
vec2 coords = (T * u_texsize) + u_offset;
|
||||||
|
|
||||||
|
float si = 1.0 + sin(u_time / 20.0 + (coords.x + coords.y) / 30.0) / 10.0;
|
||||||
|
|
||||||
|
vec4 color = texture2D(u_texture, T) * vec4(si, si, si, 1.0);
|
||||||
|
|
||||||
|
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
||||||
|
|
||||||
|
bool any = false;
|
||||||
|
|
||||||
|
float thickness = 1.0;
|
||||||
|
float step = 1.0;
|
||||||
|
|
||||||
|
if(texture2D(u_texture, T).a < 0.1 &&
|
||||||
|
(texture2D(u_texture, T + vec2(0, step) * v).a > 0.1 || texture2D(u_texture, T + vec2(0, -step) * v).a > 0.1 ||
|
||||||
|
texture2D(u_texture, T + vec2(step, 0) * v).a > 0.1 || texture2D(u_texture, T + vec2(-step, 0) * v).a > 0.1))
|
||||||
|
any = true;
|
||||||
|
|
||||||
|
if(any){
|
||||||
|
gl_FragColor = u_color * vec4(si, si, si, 1.0);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
//coords.x = float(int(coords.x));
|
||||||
|
if(color.a > 0.1){
|
||||||
|
if(mod(coords.x + coords.y + sin(coords.x / 5.0) * 3.0 + sin(coords.y / 5.0) * 3.0 + u_time / 4.0, 10.0) < 2.0){
|
||||||
|
color *= 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
color.a = 0.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 36 KiB |
@@ -59,6 +59,13 @@ public class EffectCreator{
|
|||||||
Draw.reset();
|
Draw.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Effects.create("generate", 11, e -> {
|
||||||
|
Draw.color(Hue.mix(Color.ORANGE, Color.YELLOW, e.ifract()));
|
||||||
|
Draw.thickness(1f);
|
||||||
|
Draw.spikes(e.x, e.y, e.ifract() * 5f, 2, 8);
|
||||||
|
Draw.reset();
|
||||||
|
});
|
||||||
|
|
||||||
Effects.create("spark", 10, e -> {
|
Effects.create("spark", 10, e -> {
|
||||||
Draw.thickness(1f);
|
Draw.thickness(1f);
|
||||||
Draw.color(Hue.mix(Color.WHITE, Color.GRAY, e.ifract()));
|
Draw.color(Hue.mix(Color.WHITE, Color.GRAY, e.ifract()));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.Input.Buttons;
|
import com.badlogic.gdx.Input.Buttons;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ public class Renderer extends RendererModule{
|
|||||||
pixelate();
|
pixelate();
|
||||||
|
|
||||||
Graphics.addSurface("shadow", Core.cameraScale);
|
Graphics.addSurface("shadow", Core.cameraScale);
|
||||||
|
Graphics.addSurface("shield", Core.cameraScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -118,8 +120,14 @@ public class Renderer extends RendererModule{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(){
|
public void draw(){
|
||||||
|
Graphics.surface("shield");
|
||||||
|
Graphics.surface();
|
||||||
|
|
||||||
renderTiles();
|
renderTiles();
|
||||||
Entities.draw();
|
Entities.draw();
|
||||||
|
|
||||||
|
drawShield();
|
||||||
|
|
||||||
renderPixelOverlay();
|
renderPixelOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +140,24 @@ public class Renderer extends RendererModule{
|
|||||||
camera.position.set(player.x, player.y, 0);
|
camera.position.set(player.x, player.y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawShield(){
|
||||||
|
Texture texture = Graphics.getSurface("shield").texture();
|
||||||
|
Shaders.shield.color.set(Color.SKY);
|
||||||
|
|
||||||
|
Tmp.tr2.setRegion(texture);
|
||||||
|
Shaders.shield.region = Tmp.tr2;
|
||||||
|
|
||||||
|
Graphics.end();
|
||||||
|
Graphics.shader(Shaders.shield);
|
||||||
|
Graphics.setScreen();
|
||||||
|
|
||||||
|
Core.batch.draw(texture, 0, Gdx.graphics.getHeight(), Gdx.graphics.getWidth(), -Gdx.graphics.getHeight());
|
||||||
|
|
||||||
|
Graphics.shader();
|
||||||
|
Graphics.end();
|
||||||
|
Graphics.beginCam();
|
||||||
|
}
|
||||||
|
|
||||||
void renderTiles(){
|
void renderTiles(){
|
||||||
int chunksx = World.width() / chunksize, chunksy = World.height() / chunksize;
|
int chunksx = World.width() / chunksize, chunksy = World.height() / chunksize;
|
||||||
|
|
||||||
@@ -374,6 +400,7 @@ public class Renderer extends RendererModule{
|
|||||||
clampScale();
|
clampScale();
|
||||||
Graphics.getSurface("pixel").setScale(targetscale);
|
Graphics.getSurface("pixel").setScale(targetscale);
|
||||||
Graphics.getSurface("shadow").setScale(targetscale);
|
Graphics.getSurface("shadow").setScale(targetscale);
|
||||||
|
Graphics.getSurface("shield").setScale(targetscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scaleCamera(int amount){
|
public void scaleCamera(int amount){
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ package io.anuke.mindustry;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
import io.anuke.ucore.core.Core;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Shader;
|
import io.anuke.ucore.graphics.Shader;
|
||||||
import io.anuke.ucore.util.Tmp;
|
import io.anuke.ucore.util.Tmp;
|
||||||
|
|
||||||
public class Shaders{
|
public class Shaders{
|
||||||
public static final Outline outline = new Outline();
|
public static final Outline outline = new Outline();
|
||||||
|
public static final Shield shield = new Shield();
|
||||||
|
|
||||||
public static class Outline extends Shader{
|
public static class Outline extends Shader{
|
||||||
public Color color = new Color();
|
public Color color = new Color();
|
||||||
@@ -22,4 +25,21 @@ public class Shaders{
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Shield extends Shader{
|
||||||
|
public Color color = new Color();
|
||||||
|
|
||||||
|
public Shield(){
|
||||||
|
super("shield", "default");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(){
|
||||||
|
shader.setUniformf("u_color", color);
|
||||||
|
shader.setUniformf("u_time", Timers.time());
|
||||||
|
shader.setUniformf("u_offset", Tmp.v1.set(Core.camera.position.x, Core.camera.position.y));
|
||||||
|
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,56 @@
|
|||||||
package io.anuke.mindustry.entities.effect;
|
package io.anuke.mindustry.entities.effect;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.blocks.types.ShieldBlock;
|
||||||
|
import io.anuke.ucore.core.Draw;
|
||||||
|
import io.anuke.ucore.core.Graphics;
|
||||||
import io.anuke.ucore.entities.Entity;
|
import io.anuke.ucore.entities.Entity;
|
||||||
|
|
||||||
public class Shield extends Entity{
|
public class Shield extends Entity{
|
||||||
public boolean active;
|
public boolean active;
|
||||||
|
private final Tile tile;
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
|
public Shield(Tile tile){
|
||||||
|
this.tile = tile;
|
||||||
|
this.x = tile.worldx();
|
||||||
|
this.y = tile.worldy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float drawSize(){
|
||||||
|
return 150;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(){
|
||||||
|
if(!(tile.block() instanceof ShieldBlock)){
|
||||||
|
remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(){
|
||||||
|
Graphics.surface("shield", false);
|
||||||
|
Draw.color(Color.ROYAL);
|
||||||
|
Draw.thick(2f);
|
||||||
|
Draw.rect("circle2", (int)x + 0.5f, (int)y + 0.5f, 102f, 102f);
|
||||||
|
Draw.reset();
|
||||||
|
Graphics.surface();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
@Override
|
||||||
|
public void drawOver(){
|
||||||
|
Graphics.surface("shield", false);
|
||||||
|
Draw.thick(1f);
|
||||||
|
Draw.color(Color.SKY);
|
||||||
|
Draw.circle(x, y, ((Timers.time() + 50f) % 100f) / 2f);
|
||||||
|
Draw.circle(x, y, (Timers.time() % 100f) / 2f);
|
||||||
|
Draw.reset();
|
||||||
|
Graphics.surface();
|
||||||
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void added(){
|
public void added(){
|
||||||
active = true;
|
active = true;
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public enum Recipe{
|
|||||||
coalpurifier(production, ProductionBlocks.coalpurifier, stack(Item.steel, 10), stack(Item.iron, 10)),
|
coalpurifier(production, ProductionBlocks.coalpurifier, stack(Item.steel, 10), stack(Item.iron, 10)),
|
||||||
titaniumpurifier(production, ProductionBlocks.titaniumpurifier, stack(Item.steel, 30), stack(Item.iron, 30)),
|
titaniumpurifier(production, ProductionBlocks.titaniumpurifier, stack(Item.steel, 30), stack(Item.iron, 30)),
|
||||||
omnidrill(production, ProductionBlocks.omnidrill, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
omnidrill(production, ProductionBlocks.omnidrill, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||||
|
coalgenerator(production, ProductionBlocks.coalgenerator, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||||
|
shieldgenerator(production, WeaponBlocks.shieldgenerator, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||||
|
|
||||||
conduit(distribution, ProductionBlocks.conduit, stack(Item.steel, 1)),
|
conduit(distribution, ProductionBlocks.conduit, stack(Item.steel, 1)),
|
||||||
liquidrouter(distribution, ProductionBlocks.liquidrouter, stack(Item.steel, 2)),
|
liquidrouter(distribution, ProductionBlocks.liquidrouter, stack(Item.steel, 2)),
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class Block{
|
|||||||
tile.entity.addItem(item, 1);
|
tile.entity.addItem(item, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class Block{
|
|||||||
|
|
||||||
for(int j = 0; j < 4; j ++){
|
for(int j = 0; j < 4; j ++){
|
||||||
Tile other = tiles[i];
|
Tile other = tiles[i];
|
||||||
if(other != null && other.block().accept(item, other, tile)
|
if(other != null && other.block().acceptItem(item, other, tile)
|
||||||
//don't output to things facing this thing
|
//don't output to things facing this thing
|
||||||
&& !(other.block().rotate && (other.rotation + 2) % 4 == i)){
|
&& !(other.block().rotate && (other.rotation + 2) % 4 == i)){
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ public class Block{
|
|||||||
|
|
||||||
if(todump != null && item != todump) continue;
|
if(todump != null && item != todump) continue;
|
||||||
|
|
||||||
if(tile.entity.hasItem(item) && other != null && other.block().accept(item, other, tile) &&
|
if(tile.entity.hasItem(item) && other != null && other.block().acceptItem(item, other, tile) &&
|
||||||
//don't output to things facing this thing
|
//don't output to things facing this thing
|
||||||
!(other.block().rotate && (other.rotation + 2) % 4 == i)){
|
!(other.block().rotate && (other.rotation + 2) % 4 == i)){
|
||||||
other.block().handleItem(other, item, tile);
|
other.block().handleItem(other, item, tile);
|
||||||
@@ -144,7 +144,7 @@ public class Block{
|
|||||||
*/
|
*/
|
||||||
protected boolean offloadDir(Tile tile, Item item){
|
protected boolean offloadDir(Tile tile, Item item){
|
||||||
Tile other = tile.getNearby()[tile.rotation];
|
Tile other = tile.getNearby()[tile.rotation];
|
||||||
if(other != null && other.block().accept(item, other, tile)){
|
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||||
other.block().handleItem(other, item, tile);
|
other.block().handleItem(other, item, tile);
|
||||||
//other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f);
|
//other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class ProductionBlocks{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -75,12 +75,12 @@ public class ProductionBlocks{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
int dir = source.relativeTo(dest.x, dest.y);
|
int dir = source.relativeTo(dest.x, dest.y);
|
||||||
dir = (dir+4)%4;
|
dir = (dir+4)%4;
|
||||||
Tile to = dest.getNearby()[dir];
|
Tile to = dest.getNearby()[dir];
|
||||||
//uncomment the junction bit to disable giving items to other junctions
|
//uncomment the junction bit to disable giving items to other junctions
|
||||||
return to != null /*&& to.block() != junction*/ && to.block().accept(item, to, dest);
|
return to != null /*&& to.block() != junction*/ && to.block().acceptItem(item, to, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -199,7 +199,15 @@ public class ProductionBlocks{
|
|||||||
public String description(){
|
public String description(){
|
||||||
return "Mines 1 of any resource every "+time+" seconds.";
|
return "Mines 1 of any resource every "+time+" seconds.";
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
coalgenerator = new ItemPowerGenerator("coalgenerator"){
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
generateItem = Item.stone;
|
||||||
|
generateAmount = 4f;
|
||||||
|
powerCapacity = 40f;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import io.anuke.mindustry.entities.effect.TeslaOrb;
|
|||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.types.LaserTurret;
|
import io.anuke.mindustry.world.blocks.types.*;
|
||||||
import io.anuke.mindustry.world.blocks.types.RepairTurret;
|
|
||||||
import io.anuke.mindustry.world.blocks.types.Turret;
|
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
@@ -182,5 +180,9 @@ public class WeaponBlocks{
|
|||||||
reload = 20f;
|
reload = 20f;
|
||||||
health = 90;
|
health = 90;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
shieldgenerator = new ShieldBlock("shieldgenerator"){
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class Conveyor extends Block{
|
|||||||
ConveyorEntity entity = tile.entity();
|
ConveyorEntity entity = tile.entity();
|
||||||
|
|
||||||
Draw.rect(name() +
|
Draw.rect(name() +
|
||||||
(Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed && accept(Item.stone, tile, null) ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
|
(Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed && acceptItem(Item.stone, tile, null) ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90);
|
||||||
|
|
||||||
for(ItemPos pos : entity.convey){
|
for(ItemPos pos : entity.convey){
|
||||||
Tmp.v1.set(tilesize, 0).rotate(tile.rotation * 90);
|
Tmp.v1.set(tilesize, 0).rotate(tile.rotation * 90);
|
||||||
@@ -94,7 +94,7 @@ public class Conveyor extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
int direction = source == null ? 0 : Math.abs(source.relativeTo(dest.x, dest.y) - dest.rotation);
|
int direction = source == null ? 0 : Math.abs(source.relativeTo(dest.x, dest.y) - dest.rotation);
|
||||||
float minitem = dest.<ConveyorEntity>entity().minitem;
|
float minitem = dest.<ConveyorEntity>entity().minitem;
|
||||||
return ((direction == 0) && minitem > 0.05f) ||
|
return ((direction == 0) && minitem > 0.05f) ||
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class Crafter extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
boolean craft = false;
|
boolean craft = false;
|
||||||
for(Item req : requirements){
|
for(Item req : requirements){
|
||||||
if(item == req){
|
if(item == req){
|
||||||
|
|||||||
@@ -1,9 +1,65 @@
|
|||||||
package io.anuke.mindustry.world.blocks.types;
|
package io.anuke.mindustry.world.blocks.types;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.World;
|
||||||
|
import io.anuke.ucore.core.Draw;
|
||||||
|
|
||||||
public class Generator extends PowerBlock{
|
public class Generator extends PowerBlock{
|
||||||
|
public static final int powerTime = 8;
|
||||||
|
|
||||||
|
public int powerRange = 6;
|
||||||
|
public float powerSpeed = 1f;
|
||||||
|
|
||||||
public Generator(String name) {
|
public Generator(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawPixelOverlay(Tile tile){
|
||||||
|
super.drawPixelOverlay(tile);
|
||||||
|
|
||||||
|
Draw.color("yellow");
|
||||||
|
Draw.dashcircle(tile.worldx(), tile.worldy(), powerRange * Vars.tilesize);
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void distributePower(Tile tile){
|
||||||
|
PowerEntity p = tile.entity();
|
||||||
|
//TODO have two phases, where it checks nearby blocks first, then distributes it evenly
|
||||||
|
for(int x = -powerRange; x <= powerRange; x ++){
|
||||||
|
for(int y = -powerRange; y <= powerRange; y ++){
|
||||||
|
|
||||||
|
if(x == 0 && y == 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(p.power <= 0.0001f){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 block = (PowerAcceptor)dest.block();
|
||||||
|
|
||||||
|
float transmission = Math.min(powerSpeed, p.power);
|
||||||
|
|
||||||
|
if(p.power >= 0.0001f){
|
||||||
|
float amount = block.addPower(dest, transmission);
|
||||||
|
p.power -= amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//don't accept any power
|
||||||
|
@Override
|
||||||
|
public float addPower(Tile tile, float amount){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package io.anuke.mindustry.world.blocks.types;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
|
import io.anuke.mindustry.resource.Item;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
|
|
||||||
|
public class ItemPowerGenerator extends Generator{
|
||||||
|
public int itemCapacity = 20;
|
||||||
|
public Item generateItem;
|
||||||
|
public float generateAmount;
|
||||||
|
|
||||||
|
public ItemPowerGenerator(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawPixelOverlay(Tile tile){
|
||||||
|
super.drawPixelOverlay(tile);
|
||||||
|
|
||||||
|
TileEntity entity = tile.entity;
|
||||||
|
|
||||||
|
//TODO maybe don't draw it due to clutter
|
||||||
|
Vars.renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13 + 4, (float)entity.totalItems() / itemCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||||
|
return item == generateItem && tile.entity.totalItems() < itemCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Tile tile){
|
||||||
|
PowerEntity entity = tile.entity();
|
||||||
|
|
||||||
|
if(entity.hasItem(generateItem) && tryAddPower(tile, generateAmount)){
|
||||||
|
Effects.effect("generate", tile.entity);
|
||||||
|
entity.removeItem(generateItem, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Timers.get(tile, "power", powerTime)){
|
||||||
|
distributePower(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package io.anuke.mindustry.world.blocks.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
|
public interface PowerAcceptor{
|
||||||
|
/**Attempts to add some power to this block; returns the amount of power <i>not</i> accepted.*/
|
||||||
|
public float addPower(Tile tile, float amount);
|
||||||
|
}
|
||||||
@@ -1,10 +1,19 @@
|
|||||||
package io.anuke.mindustry.world.blocks.types;
|
package io.anuke.mindustry.world.blocks.types;
|
||||||
|
|
||||||
import io.anuke.mindustry.world.Block;
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public abstract class PowerBlock extends Block{
|
import com.badlogic.gdx.graphics.Color;
|
||||||
public float powerCapacity;
|
|
||||||
public float power;
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
|
import io.anuke.mindustry.world.Block;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
|
public abstract class PowerBlock extends Block implements PowerAcceptor{
|
||||||
|
public float powerCapacity = 10f;
|
||||||
|
|
||||||
public PowerBlock(String name) {
|
public PowerBlock(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
@@ -12,4 +21,55 @@ public abstract class PowerBlock extends Block{
|
|||||||
solid = true;
|
solid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawPixelOverlay(Tile tile){
|
||||||
|
PowerEntity entity = tile.entity();
|
||||||
|
|
||||||
|
float fract = (float)entity.power / powerCapacity;
|
||||||
|
if(fract > 0)
|
||||||
|
fract = Mathf.clamp(fract, 0.24f, 1f);
|
||||||
|
|
||||||
|
Vars.renderer.drawBar(Color.YELLOW, tile.worldx(), tile.worldy() + 13, fract);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Tries adding all the power with no remainder, returns success.*/
|
||||||
|
public boolean tryAddPower(Tile tile, float amount){
|
||||||
|
PowerEntity entity = tile.entity();
|
||||||
|
|
||||||
|
if(entity.power + amount <= powerCapacity){
|
||||||
|
entity.power += amount;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float addPower(Tile tile, float amount){
|
||||||
|
PowerEntity entity = tile.entity();
|
||||||
|
|
||||||
|
float canAccept = Math.min(powerCapacity - entity.power, amount);
|
||||||
|
|
||||||
|
entity.power += canAccept;
|
||||||
|
|
||||||
|
return canAccept;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity getEntity(){
|
||||||
|
return new PowerEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PowerEntity extends TileEntity{
|
||||||
|
public float power;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutputStream stream) throws IOException{
|
||||||
|
stream.writeFloat(power);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInputStream stream) throws IOException{
|
||||||
|
power = stream.readFloat();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class Purifier extends Conduit{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile tile, Tile source){
|
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||||
TileEntity entity = tile.entity();
|
TileEntity entity = tile.entity();
|
||||||
return item == input && entity.items.get(item, 0) < itemCapacity;
|
return item == input && entity.items.get(item, 0) < itemCapacity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class Router extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
int items = dest.entity.totalItems();
|
int items = dest.entity.totalItems();
|
||||||
return items < maxitems;
|
return items < maxitems;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.world.blocks.types;
|
|||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.effect.Shield;
|
import io.anuke.mindustry.entities.effect.Shield;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
|
||||||
|
|
||||||
public class ShieldBlock extends PowerBlock{
|
public class ShieldBlock extends PowerBlock{
|
||||||
public float shieldRadius = 40f;
|
public float shieldRadius = 40f;
|
||||||
@@ -18,20 +17,23 @@ public class ShieldBlock extends PowerBlock{
|
|||||||
ShieldEntity entity = tile.entity();
|
ShieldEntity entity = tile.entity();
|
||||||
|
|
||||||
if(entity.shield == null){
|
if(entity.shield == null){
|
||||||
entity.shield = new Shield();
|
entity.shield = new Shield(tile);
|
||||||
|
entity.shield.add();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(power > powerDrain * Timers.delta()){
|
/*
|
||||||
|
if(entity.power > powerDrain * Timers.delta()){
|
||||||
if(!entity.shield.active){
|
if(!entity.shield.active){
|
||||||
entity.shield.add();
|
entity.shield.add();
|
||||||
}
|
}
|
||||||
|
|
||||||
power -= powerDrain * Timers.delta();
|
entity.power -= powerDrain * Timers.delta();
|
||||||
}else{
|
}else{
|
||||||
if(entity.shield.active){
|
if(entity.shield.active){
|
||||||
entity.shield.remove();
|
entity.shield.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +41,7 @@ public class ShieldBlock extends PowerBlock{
|
|||||||
return new ShieldEntity();
|
return new ShieldEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ShieldEntity extends TileEntity{
|
static class ShieldEntity extends PowerEntity{
|
||||||
Shield shield;
|
Shield shield;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class Turret extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Item item, Tile dest, Tile source){
|
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||||
return item == ammo && dest.<TurretEntity>entity().ammo < maxammo;
|
return item == ammo && dest.<TurretEntity>entity().ammo < maxammo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user