From 12aa8c406b493369f2cf047b0c39207e27048f5e Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 11 Nov 2017 13:55:38 -0500 Subject: [PATCH] Implemented enemy avoidance --- build.gradle | 2 +- core/assets/maps/test.png | Bin 5403 -> 714 bytes .../mindustry/entities/enemies/Enemy.java | 22 +++++++++++++++--- .../io/anuke/mindustry/ui/LevelDialog.java | 8 +++---- core/src/io/anuke/mindustry/world/Block.java | 3 +-- .../io/anuke/mindustry/world/Generator.java | 7 +++--- .../world/blocks/types/production/Drill.java | 6 +++-- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index be164223a8..3d396aa0a3 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,7 @@ project(":core") { apply plugin: "java" dependencies { - compile 'com.github.anuken:ucore:91e4e11010' + compile 'com.github.anuken:ucore:c498e5920a' compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-ai:1.8.1" } diff --git a/core/assets/maps/test.png b/core/assets/maps/test.png index aec9f3a5dbeeed4c96e728ce376ecf5e0678eb2e..070058cda45b8afc056829b330f0b751323f790a 100644 GIT binary patch delta 688 zcmbQOb&A!qGr-TCmrII^fq{Y7)59f*fq|g`ggMw47#I%QC7xzrVBjq9h%9Dc;1&j9 zMuu5)Bp4VN*h@TpUD+RUa|=mx)`ec!J~3Lop2@}2#WAGf*4x{GdCd+yu7OgOt|{I( z^>SAJ?FtEG=114>{d-4bzu7zvB?hhS zjm}Ixe^v;qFq{)`;ChnBEabq{z@TxPZ5D^YXPFJYbvINQ?-k6iIgzW@kPDJhUB4a-?v zHn0gTG@kg>sos0T?_Jydm^@gS1R5D!UTn2Jy2kv#oPdCaQ${tj8dUf3&e`iK^D}3o z$fNhYvlJ!!x?+D-HoQ4`;nA(QWXD~V3zu$T@lbPqeMHG&(#(b7tCbEsaQZSYki#Hi zw?(yv>Vcz1F?(AD6cTf`AE{^ literal 5403 zcmeAS@N?(olHy`uV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sEhayGVirK!~~Ec zhj3;l27_Rb6`-c@1BZQo_~YWCMYlkozCRO`jc5-0On$$G5n8Y)=u8Kh4%5z%P;!rz z1(YwLx#@<7=22(3EXYfsY$(y3&x|3+0CG99VGYavXut)Via0?!;e5B}u?`@=fQ(^z zDg^3sfLz$HAchHI2GoHdd635z*ze<)0Hu5e1qKvFA9|uqK~*Qzn+N{wNoL$L3*P(y zNx@4Vq*9?_*`J3`ksSaIYmiOg%60K)Hc&J%G}N)NFeDs-IsJe~3{yimFVq~Cr>AFv zjNk=p3pmZd#9)vOa&QL22PsfuuLY$C2j+(9Y#<%4<)MKJ^DIMy_zyN%m@*vt__W@E zfkBKPWTXQRGY7+gcZ};n**U@tXYNl{=GO#c#U_5Y;O@N_cB}<=)0s{k&TEPsE60^o+9u9_vcgH9HZTSjH?%G^) zq8%6*TJ8ls6S-#Jz`&5g5b+0Hu$p^|hQQG` zf($Xw!`EJ2eBcZFAy8q~Rd}Yd_(_BF4n~F_+fUwMUSQmK;|>GEjr2DqTjuCFFfe2= z_|${a^u~qijN2YoGce5aF~2X`@RHx<5gWsSp2dG>7UneM?PO%A*vc5gx8UQCPS9T*svM6WP9FpFJ) zfx&b6S_y+MAZ5pX&fdTRcIW~Yh6MFGAp>v>gF+dW5=Oh3SV99*MuIaCG2sNwvY>p= z0LnIm0vRPQ6QNmw!G;N5;J`B-A)7#@A1OAW6;uR$kJLmX%1tB&D!8y4WNsoNu27Va z68!KomBesDu@HN8fue*|H-SogB8){*f?^?x3^-QdUWG+3t=)uSAptj$nsq?tlNwGS hJ*0#a5pG)Zh5I?TqWB?~qwJs&Lr+&fmvv4FO#sVOi0J?T diff --git a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java index 2e32bc8c3a..0f6533049e 100644 --- a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java +++ b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.entities.enemies; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.reflect.ClassReflection; import io.anuke.mindustry.Shaders; @@ -15,6 +16,7 @@ import io.anuke.mindustry.world.World; import io.anuke.ucore.core.*; import io.anuke.ucore.entities.*; import io.anuke.ucore.util.Mathf; +import io.anuke.ucore.util.Tmp; public class Enemy extends DestructibleEntity{ public final static Color[] tierColors = {Color.YELLOW, Color.ORANGE, Color.RED, Color.MAGENTA}; @@ -59,6 +61,22 @@ public class Enemy extends DestructibleEntity{ Vector2 vec = Pathfind.find(this); vec.sub(x, y).setLength(speed); + Array entities = Entities.getNearby(x, y, range); + + Vector2 shift = Tmp.v3.setZero(); + float shiftRange = hitbox.width + 3f; + + for(SolidEntity other : entities){ + float dst = other.distanceTo(this); + if(other != this && other instanceof Enemy && dst < shiftRange){ + float scl = Mathf.clamp(1.4f - dst/shiftRange); + shift.add((x - other.x) * scl, (y - other.y) * scl); + } + } + + shift.nor(); + vec.add(shift.scl(0.5f)); + move(vec.x*Timers.delta(), vec.y*Timers.delta()); if(Timers.get(this, "target", 15)){ @@ -66,9 +84,7 @@ public class Enemy extends DestructibleEntity{ //no tile found if(target == null){ - target = Entities.getClosest(x, y, range, e->{ - return e instanceof Player; - }); + target = Entities.getClosest(entities, x, y, range, e -> e instanceof Player); } } diff --git a/core/src/io/anuke/mindustry/ui/LevelDialog.java b/core/src/io/anuke/mindustry/ui/LevelDialog.java index 5d9c0b8725..b14daa2e84 100644 --- a/core/src/io/anuke/mindustry/ui/LevelDialog.java +++ b/core/src/io/anuke/mindustry/ui/LevelDialog.java @@ -35,7 +35,7 @@ public class LevelDialog extends FloatingDialog{ for(int i = 0; i < Map.values().length; i ++){ Map map = Map.values()[i]; - if(!map.visible) continue; + if(!map.visible && !Vars.debug) continue; if(i % maxwidth == 0){ maps.row(); @@ -48,18 +48,18 @@ public class LevelDialog extends FloatingDialog{ .pad(3f).units(Unit.dp); inset.pack(); - float images = Unit.dp.inPixels(154); + float images = 154f; ImageButton image = new ImageButton(new TextureRegion(World.getTexture(map)), "togglemap"); image.row(); - image.add(inset).width(images+6); + image.add(inset).width(images+6).units(Unit.dp); image.clicked(()->{ selectedMap = map; hide(); Vars.control.playMap(selectedMap); }); image.getImageCell().size(images); - maps.add(image).width(Unit.dp.inPixels(170)).pad(4f).units(Unit.dp); + maps.add(image).width(170).pad(4f).units(Unit.dp); } content().add(pane); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index f68e834dd1..d3326d2730 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -203,9 +203,8 @@ public class Block{ } //update the tile entity through the draw method, only if it's an entity without updating - //TODO enable if(destructible && !update && !GameState.is(State.paused)){ - // tile.entity.update(); + tile.entity.update(); } } diff --git a/core/src/io/anuke/mindustry/world/Generator.java b/core/src/io/anuke/mindustry/world/Generator.java index ffacd1996b..c4c5e537af 100644 --- a/core/src/io/anuke/mindustry/world/Generator.java +++ b/core/src/io/anuke/mindustry/world/Generator.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.world; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.ObjectMap; import io.anuke.mindustry.Vars; @@ -94,9 +95,9 @@ public class Generator{ } //preformance debugging - //if(Vector2.dst(pixmap.getWidth()/2, pixmap.getHeight()/2, x, y) < 40){ - // block = DefenseBlocks.stonewall; - //} + if(Vector2.dst(pixmap.getWidth()/2, pixmap.getHeight()/2, x, y) < 30){ + // block = Mathf.choose(ProductionBlocks.stonedrill, DistributionBlocks.conveyor); + } World.tile(x, y).setBlock(block); World.tile(x, y).setFloor(floor); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/Drill.java b/core/src/io/anuke/mindustry/world/blocks/types/production/Drill.java index 54231cf0d4..5821145308 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/Drill.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/Drill.java @@ -12,18 +12,20 @@ public class Drill extends Block{ protected Block resource; protected Item result; protected int time = 5; + protected int capacity = 5; public Drill(String name) { super(name); update = true; + //update = false; + //destructible = true; solid = true; } @Override public void update(Tile tile){ - //drills can only hold up to 10 items at a time - if(tile.floor() == resource && Timers.get(tile, "drill", 60 * time) && tile.entity.totalItems() < 10){ + if(tile.floor() == resource && Timers.get(tile, "drill", 60 * time) && tile.entity.totalItems() < capacity){ offloadNear(tile, result); Effects.effect("spark", tile.worldx(), tile.worldy()); }