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)59eQNH>5m2OE$)Y?pW%NO2Z;L>4nJa0`PlBg3pY z5H=O_J`cuLeiXdp%=DKj8?B_a`AL=45_&F_I6-ivjdN7pj4%6iuX;uoRxpO zLP94lYLk@cKmT{ls%Z~ar&lw@_aA>;?HHMt$H?fwAi%)FfI*${*unbt#`nKZ&tET9 zb=bOS|F5}%t_lb2yKg>v->>4N@vH9Se;L=NfH$w#rLu53)nCl^7U+tNZVD)P&d_Cd zB7K( z6~ZbE=L8(Mp5!qLIWRRaXxwI-#bNMSW`l3t4OPZ_1@mi8@TZeUS;|(U&Y6 zxV(V0WSAq92ZO)?1&@YHwxzc@17?2RC*&Zlz`)UvmCndAfnhGYPH}@+!y_h-#=_?e zoC?73nUc%AoHK!M0>cVDhp8eK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ch)Lx3QhjL4?U8qx(Y>QS%8x`V2 zoEOwesMYR}?op!W_Z$_@;?q2YJcFosm%~D{&{LB@eXTSstz|G!2!l@eaT@vQg7R54 z>K3X(pGCvs$z6t4G^Bf^7~TGRI6e_Jf0hA_!)|-ayu!KKNZhZ z9APUstHQ72O3XyOrk+0vR^kth?kjuxGQ;yZjH1%enPw;1n&+tyhsdDHO07$=5#Hsn zP6RR%l34|4A9S3B7lgwd>iKEtK$ptEqKG6#*E=|vK;q`B2QgKile(>L_v z5SCbwqJHX~M`N8@N{P0irXYuP6FPky8gX~W2&ZsuuCL1mexUhL!NG`Y3UXY5MdLh0 zC!sEa4lrZPVYLQRBGxWOrcJ4lL`%elddXU|kg3@Q41Q4_0xoKbJt3YxIyFeHvFV=# z?6r3Kl>MQkHi5VXCrS6I145cQPa!4;bm4GK$F~v$9&s3I)^UuZT}%No!8DYHeKpO4 zz=~UxycF(iP?{1&UH)>_nOV7$rninn$Ah zNi+_kOd<~a1_H^1rC-~}xv`M0DgM4#4I?9cti)-1gDV<`_WkczT1+PQ<}XAn@yh3$ z<-%(;?j!w5QxT%DVa_kXXJSNvbR0E&RPC3pbGR$ZU(9%XfsB(T)hlNEA^KkbgChcu z;`uqRIeFiAWs=#amJYLx%T7GK{AV%t5CiSiU!G%)WAp2AW7a>>sy|pd8Y5)V`GpML z-WATg*Z3^Jj>Pdl4ia0`aX%?R+EgZQU6v(gzt6y`cbR$pjDzw4-HTU_iwY_7(fW-C z$Qdv0h4f)OK<<)B0Xj3=|5&OBi9$nr&0nY4G9+QTezRU}Y{Tq@4;~%CCgx#0p4D2g zA;Q|oH@K{4Q1H?-1=AE|VaTXFb 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()); }