mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-26 07:37:54 +07:00
Fully implemented teleporters
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -14,7 +14,7 @@ varying vec4 v_color;
|
|||||||
varying vec2 v_texCoord;
|
varying vec2 v_texCoord;
|
||||||
|
|
||||||
const float tau = 6.28318530717958647692;
|
const float tau = 6.28318530717958647692;
|
||||||
const float tscl = 0.5;
|
const float tscl = 0.4;
|
||||||
|
|
||||||
// Gamma correction
|
// Gamma correction
|
||||||
#define GAMMA (2.2)
|
#define GAMMA (2.2)
|
||||||
@ -34,8 +34,7 @@ float srand(vec2 co){
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 Noise(ivec2 x ){
|
vec4 Noise(ivec2 x ){
|
||||||
vec2 uv = (vec2(x)+0.5)/256.0;
|
return vec4(srand((vec2(x)+0.5)/256.0));
|
||||||
return vec4(srand(uv), srand(uv + vec2(10.0, 0.0)), srand(uv + vec2(10.0, 0.0)), srand(uv + vec2(10.0, 10.0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Fri Apr 06 21:25:35 EDT 2018
|
#Sat Apr 07 19:29:57 EDT 2018
|
||||||
version=release
|
version=release
|
||||||
androidBuildCode=864
|
androidBuildCode=864
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
|
@ -24,6 +24,7 @@ public class Blocks {
|
|||||||
space = new Floor("space") {{
|
space = new Floor("space") {{
|
||||||
variants = 0;
|
variants = 0;
|
||||||
drawLayer = DrawLayer.space;
|
drawLayer = DrawLayer.space;
|
||||||
|
solid = true;
|
||||||
}},
|
}},
|
||||||
|
|
||||||
deepwater = new Floor("deepwater") {{
|
deepwater = new Floor("deepwater") {{
|
||||||
|
@ -8,6 +8,7 @@ import io.anuke.ucore.graphics.Draw;
|
|||||||
import io.anuke.ucore.graphics.Fill;
|
import io.anuke.ucore.graphics.Fill;
|
||||||
import io.anuke.ucore.graphics.Lines;
|
import io.anuke.ucore.graphics.Lines;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
@ -213,5 +214,27 @@ public class BlockFx {
|
|||||||
Fill.poly(e.x + x, e.y + y, 4, 0.5f+e.fout()*2f, 45);
|
Fill.poly(e.x + x, e.y + y, 4, 0.5f+e.fout()*2f, 45);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
});
|
});
|
||||||
|
}),
|
||||||
|
teleport = new Effect(60, e -> {
|
||||||
|
Draw.color(e.color);
|
||||||
|
Lines.stroke(e.fin()*2f);
|
||||||
|
Lines.circle(e.x, e.y, 7f + e.fout()*8f);
|
||||||
|
|
||||||
|
Angles.randLenVectors(e.id, 20, 6f + 20f * e.fout(), (x, y) -> {
|
||||||
|
Lines.lineAngle(e.x + x, e.y + y, Mathf.atan2(x, y), e.fin()*4f + 1f);
|
||||||
|
});
|
||||||
|
|
||||||
|
Draw.reset();
|
||||||
|
}),
|
||||||
|
teleportOut = new Effect(20, e -> {
|
||||||
|
Draw.color(e.color);
|
||||||
|
Lines.stroke(e.fout()*2f);
|
||||||
|
Lines.circle(e.x, e.y, 7f + e.fin()*8f);
|
||||||
|
|
||||||
|
Angles.randLenVectors(e.id, 20, 4f + 20f * e.fin(), (x, y) -> {
|
||||||
|
Lines.lineAngle(e.x + x, e.y + y, Mathf.atan2(x, y), e.fslope()*4f + 1f);
|
||||||
|
});
|
||||||
|
|
||||||
|
Draw.reset();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import static io.anuke.mindustry.Vars.mapExtension;
|
|||||||
|
|
||||||
public class Maps implements Disposable{
|
public class Maps implements Disposable{
|
||||||
/**List of all built-in maps.*/
|
/**List of all built-in maps.*/
|
||||||
private static final String[] defaultMapNames = {"test", "space", "hole"};
|
private static final String[] defaultMapNames = {"test", "trinity"};
|
||||||
/**Tile format version.*/
|
/**Tile format version.*/
|
||||||
private static final int version = 0;
|
private static final int version = 0;
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
import io.anuke.mindustry.content.UnitTypes;
|
||||||
|
import io.anuke.mindustry.content.fx.BlockFx;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||||
import io.anuke.mindustry.content.UnitTypes;
|
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
@ -53,7 +53,7 @@ public class DebugFragment implements Fragment {
|
|||||||
row();
|
row();
|
||||||
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
|
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
|
||||||
row();
|
row();
|
||||||
new button("effect", () -> Effects.effect(ExplosionFx.explosion, player));
|
new button("effect", () -> Effects.effect(BlockFx.teleport, player));
|
||||||
row();
|
row();
|
||||||
new button("wave", () -> state.wavetime = 0f);
|
new button("wave", () -> state.wavetime = 0f);
|
||||||
row();
|
row();
|
||||||
|
@ -3,11 +3,12 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
import io.anuke.mindustry.content.fx.Fx;
|
import io.anuke.mindustry.content.fx.BlockFx;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.types.PowerBlock;
|
import io.anuke.mindustry.world.blocks.types.PowerBlock;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
import io.anuke.ucore.core.Effects.Effect;
|
import io.anuke.ucore.core.Effects.Effect;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
@ -28,6 +29,8 @@ public class Teleporter extends PowerBlock{
|
|||||||
Color.PURPLE, Color.GOLD, Color.PINK, Color.LIGHT_GRAY};
|
Color.PURPLE, Color.GOLD, Color.PINK, Color.LIGHT_GRAY};
|
||||||
public static final int colors = colorArray.length;
|
public static final int colors = colorArray.length;
|
||||||
|
|
||||||
|
protected int timerTeleport = timers++;
|
||||||
|
|
||||||
private static ObjectSet<Tile>[] teleporters = new ObjectSet[colors];
|
private static ObjectSet<Tile>[] teleporters = new ObjectSet[colors];
|
||||||
private static Color color = new Color();
|
private static Color color = new Color();
|
||||||
private static byte lastColor = 0;
|
private static byte lastColor = 0;
|
||||||
@ -35,8 +38,10 @@ public class Teleporter extends PowerBlock{
|
|||||||
private Array<Tile> removal = new Array<>();
|
private Array<Tile> removal = new Array<>();
|
||||||
private Array<Tile> returns = new Array<>();
|
private Array<Tile> returns = new Array<>();
|
||||||
|
|
||||||
protected float warmupTime = 80f;
|
protected float warmupTime = 60f;
|
||||||
protected Effect teleportEffect = Fx.none;
|
protected float teleportMax = 400f;
|
||||||
|
protected Effect teleportEffect = BlockFx.teleport;
|
||||||
|
protected Effect teleportOutEffect = BlockFx.teleportOut;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
for(int i = 0; i < colors; i ++){
|
for(int i = 0; i < colors; i ++){
|
||||||
@ -51,7 +56,7 @@ public class Teleporter extends PowerBlock{
|
|||||||
health = 80;
|
health = 80;
|
||||||
powerCapacity = 30f;
|
powerCapacity = 30f;
|
||||||
size = 3;
|
size = 3;
|
||||||
itemCapacity = 150;
|
itemCapacity = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,45 +82,39 @@ public class Teleporter extends PowerBlock{
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Tile tile){
|
public void draw(Tile tile){
|
||||||
TeleporterEntity entity = tile.entity();
|
TeleporterEntity entity = tile.entity();
|
||||||
|
float time = entity.time;
|
||||||
|
|
||||||
super.draw(tile);
|
super.draw(tile);
|
||||||
|
|
||||||
Color target = colorArray[entity.color];
|
Draw.color(getColor(tile, 0));
|
||||||
float ss = 0.5f;
|
|
||||||
float bs = 0.2f;
|
|
||||||
|
|
||||||
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, 0));
|
|
||||||
Draw.rect("teleporter-top", tile.drawx(), tile.drawy());
|
Draw.rect("teleporter-top", tile.drawx(), tile.drawy());
|
||||||
|
|
||||||
//Draw.color(Palette.portal);
|
Draw.color(getColor(tile, 0));
|
||||||
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, 0));
|
|
||||||
|
|
||||||
Fill.circle(tile.drawx(), tile.drawy(), 7f + Mathf.absin(Timers.time()+55, 8f, 1f));
|
Fill.circle(tile.drawx(), tile.drawy(), 7f + Mathf.absin(time+55, 8f, 1f));
|
||||||
|
|
||||||
//Draw.color(Palette.portalDark);
|
Draw.color(getColor(tile, -1));
|
||||||
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, -bs));
|
|
||||||
|
|
||||||
Fill.circle(tile.drawx(), tile.drawy(), 2f + Mathf.absin(Timers.time(), 7f, 3f));
|
Fill.circle(tile.drawx(), tile.drawy(), 2f + Mathf.absin(time, 7f, 3f));
|
||||||
|
|
||||||
for(int i = 0; i < 11; i ++){
|
for(int i = 0; i < 11; i ++){
|
||||||
Lines.swirl(tile.drawx(), tile.drawy(),
|
Lines.swirl(tile.drawx(), tile.drawy(),
|
||||||
2f + i/3f + Mathf.sin(Timers.time() - i *75, 20f + i, 3f),
|
2f + i/3f + Mathf.sin(time - i *75, 20f + i, 3f),
|
||||||
0.3f + Mathf.sin(Timers.time() + i *33, 10f + i, 0.1f),
|
0.3f + Mathf.sin(time + i *33, 10f + i, 0.1f),
|
||||||
Timers.time() * (1f + Mathf.randomSeedRange(i + 1, 1f)) + Mathf.randomSeedRange(i, 360f));
|
time * (1f + Mathf.randomSeedRange(i + 1, 1f)) + Mathf.randomSeedRange(i, 360f));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw.color(Palette.portalLight);
|
Draw.color(getColor(tile, 1));
|
||||||
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, bs));
|
|
||||||
|
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Lines.circle(tile.drawx(), tile.drawy(), 7f + Mathf.absin(Timers.time()+55, 8f, 1f));
|
Lines.circle(tile.drawx(), tile.drawy(), 7f + Mathf.absin(time+55, 8f, 1f));
|
||||||
Lines.stroke(1f);
|
Lines.stroke(1f);
|
||||||
|
|
||||||
for(int i = 0; i < 11; i ++){
|
for(int i = 0; i < 11; i ++){
|
||||||
Lines.swirl(tile.drawx(), tile.drawy(),
|
Lines.swirl(tile.drawx(), tile.drawy(),
|
||||||
3f + i/3f + Mathf.sin(Timers.time() + i *93, 20f + i, 3f),
|
3f + i/3f + Mathf.sin(time + i *93, 20f + i, 3f),
|
||||||
0.2f + Mathf.sin(Timers.time() + i *33, 10f + i, 0.1f),
|
0.2f + Mathf.sin(time + i *33, 10f + i, 0.1f),
|
||||||
Timers.time() * (1f + Mathf.randomSeedRange(i + 1, 1f)) + Mathf.randomSeedRange(i, 360f));
|
time * (1f + Mathf.randomSeedRange(i + 1, 1f)) + Mathf.randomSeedRange(i, 360f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
@ -131,8 +130,39 @@ public class Teleporter extends PowerBlock{
|
|||||||
tryDump(tile);
|
tryDump(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entity.inventory.totalItems() == itemCapacity && entity.power.amount >= powerCapacity){
|
if(entity.teleporting){
|
||||||
|
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 2f, 0.01f);
|
||||||
|
}else{
|
||||||
|
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.04f);
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.time += Timers.delta()*entity.speedScl;
|
||||||
|
|
||||||
|
if(entity.inventory.totalItems() == itemCapacity && entity.power.amount >= powerCapacity &&
|
||||||
|
entity.timer.get(timerTeleport, teleportMax)){
|
||||||
|
Array<Tile> testLinks = findLinks(tile);
|
||||||
|
|
||||||
|
if(testLinks.size == 0) return;
|
||||||
|
|
||||||
|
entity.teleporting = true;
|
||||||
|
|
||||||
|
Effects.effect(teleportEffect, getColor(tile, 0), tile.drawx(), tile.drawy());
|
||||||
|
Timers.run(warmupTime, () -> {
|
||||||
|
Array<Tile> links = findLinks(tile);
|
||||||
|
|
||||||
|
for(Tile other : links){
|
||||||
|
int canAccept = itemCapacity - other.entity.inventory.totalItems();
|
||||||
|
int total = entity.inventory.totalItems();
|
||||||
|
if(total == 0) break;
|
||||||
|
Effects.effect(teleportOutEffect, getColor(tile, 0), other.drawx(), other.drawy());
|
||||||
|
for(int i = 0; i < canAccept && i < total; i ++){
|
||||||
|
other.entity.inventory.addItem(entity.inventory.takeItem(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Effects.effect(teleportOutEffect, getColor(tile, 0), tile.drawx(), tile.drawy());
|
||||||
|
entity.power.amount = 0f;
|
||||||
|
entity.teleporting = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +210,16 @@ public class Teleporter extends PowerBlock{
|
|||||||
public TileEntity getEntity(){
|
public TileEntity getEntity(){
|
||||||
return new TeleporterEntity();
|
return new TeleporterEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Color getColor(Tile tile, int shift){
|
||||||
|
TeleporterEntity entity = tile.entity();
|
||||||
|
|
||||||
|
Color target = colorArray[entity.color];
|
||||||
|
float ss = 0.5f;
|
||||||
|
float bs = 0.2f;
|
||||||
|
|
||||||
|
return Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, shift * bs + (entity.speedScl - 1f)/3f);
|
||||||
|
}
|
||||||
|
|
||||||
private Array<Tile> findLinks(Tile tile){
|
private Array<Tile> findLinks(Tile tile){
|
||||||
TeleporterEntity entity = tile.entity();
|
TeleporterEntity entity = tile.entity();
|
||||||
@ -209,6 +249,9 @@ public class Teleporter extends PowerBlock{
|
|||||||
|
|
||||||
public static class TeleporterEntity extends TileEntity{
|
public static class TeleporterEntity extends TileEntity{
|
||||||
public byte color = 0;
|
public byte color = 0;
|
||||||
|
public boolean teleporting;
|
||||||
|
public float speedScl = 1f;
|
||||||
|
public float time;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutputStream stream) throws IOException{
|
public void write(DataOutputStream stream) throws IOException{
|
||||||
|
@ -12,6 +12,7 @@ import java.util.Arrays;
|
|||||||
public class InventoryModule extends BlockModule{
|
public class InventoryModule extends BlockModule{
|
||||||
public int[] items = new int[Item.getAllItems().size];
|
public int[] items = new int[Item.getAllItems().size];
|
||||||
|
|
||||||
|
//TODO optimize!
|
||||||
public int totalItems(){
|
public int totalItems(){
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for(int i = 0; i < items.length; i ++){
|
for(int i = 0; i < items.length; i ++){
|
||||||
@ -20,6 +21,16 @@ public class InventoryModule extends BlockModule{
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Item takeItem(){
|
||||||
|
for(int i = 0; i < items.length; i ++){
|
||||||
|
if(items[i] > 0){
|
||||||
|
items[i] --;
|
||||||
|
return Item.getByID(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public int getItem(Item item){
|
public int getItem(Item item){
|
||||||
return items[item.id];
|
return items[item.id];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user