diff --git a/core/assets/maps/test3.png b/core/assets/maps/test3.png index aa0b384025..34e5a233de 100644 Binary files a/core/assets/maps/test3.png and b/core/assets/maps/test3.png differ diff --git a/core/assets/shaders/outline.fragment b/core/assets/shaders/outline.fragment index 3bd3c1c9ce..2ac6ef52be 100644 --- a/core/assets/shaders/outline.fragment +++ b/core/assets/shaders/outline.fragment @@ -30,6 +30,6 @@ void main() { if(any){ gl_FragColor = u_color; }else{ - gl_FragColor = texture2D(u_texture, T); + gl_FragColor = texture2D(u_texture, T) * v_color; } } diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index ad34385288..84a235031e 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -46,6 +46,8 @@ public class Vars{ public static boolean infiniteAmmo = false; //whether to show paths of enemies public static boolean showPaths = true; + //if false, player is always hidden + public static boolean showPlayer = true; //number of save slots-- increasing may lead to layout issues //TODO named save slots, possibly with a scroll dialog public static final int saveSlots = 8; diff --git a/core/src/io/anuke/mindustry/ai/Pathfind.java b/core/src/io/anuke/mindustry/ai/Pathfind.java index 4937c13805..22d7dcb58d 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfind.java +++ b/core/src/io/anuke/mindustry/ai/Pathfind.java @@ -10,7 +10,9 @@ import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.enemies.Enemy; import io.anuke.mindustry.world.SpawnPoint; import io.anuke.mindustry.world.Tile; +import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Angles; +import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Tmp; public class Pathfind{ @@ -30,7 +32,6 @@ public class Pathfind{ return vector.set(enemy.x, enemy.y); }else if(enemy.node == -2){ enemy.node = -1; - enemy.findClosestNode(); } Tile[] path = enemy.path; @@ -43,7 +44,7 @@ public class Pathfind{ if(enemy.node > 1) enemy.node = enemy.node - 1; }else{ - //what's the problem, then? + //must be blocked by a playermade block } enemy.idletime = 0; @@ -100,6 +101,7 @@ public class Pathfind{ if(point.finder.search(point.request, ms * 2)){ smoother.smoothPath(point.path); point.pathTiles = point.path.nodes.toArray(Tile.class); + point.tempTiles = point.path.nodes.toArray(Tile.class); } } } @@ -112,6 +114,7 @@ public class Pathfind{ point.path.clear(); point.pathTiles = null; + point.tempTiles = null; point.request = new PathFinderRequest(point.start, Vars.control.getCore(), heuristic, point.path); point.request.statusChanged = true; //IMPORTANT! @@ -128,22 +131,44 @@ public class Pathfind{ } enemy.path = Vars.control.getSpawnPoints().get(enemy.spawn).pathTiles; - Tile[] path = enemy.path; - Tile closest = null; - float ldst = 0f; - int cindex = -1; - for(int i = 0; i < path.length; i ++){ - Tile tile = path[i]; - float dst = Vector2.dst(tile.worldx(), tile.worldy(), enemy.x, enemy.y); - - if(closest == null || dst < ldst){ - ldst = dst; - closest = tile; + int closest = findClosest(enemy.path, 0, enemy.x, enemy.y); + closest = findClosest(enemy.path, closest + 1, enemy.x, enemy.y); + //closest ++; + + closest = Mathf.clamp(closest, 1, enemy.path.length-1); + Tile end = enemy.path[closest]; + enemy.node = closest; + + //if the enemy can't get to this node, teleport to it + if(enemy.node < enemy.path.length - 2 && Vars.world.raycastWorld(enemy.x, enemy.y, end.worldx(), end.worldy()) != null){ + Timers.run(Mathf.random(20f), () -> enemy.set(end.worldx(), end.worldy())); + } + } + + private static int findClosest(Tile[] tiles, int offset, float x, float y){ + int cindex = -1; + float dst = Float.MAX_VALUE; + + for(int i = offset; i < tiles.length; i ++){ + Tile tile = tiles[i]; + if(Vector2.dst(tile.worldx(), tile.worldy(), x, y) < dst){ + dst = Vector2.dst(tile.worldx(), tile.worldy(), x, y); cindex = i; } } - enemy.node = Math.max(cindex, 1); + + return cindex; + } + + private static int indexOf(Tile tile, Tile[] tiles){ + int i = -1; + for(int j = 0; j < tiles.length; j ++){ + if(tiles[j] == tile){ + return j; + } + } + return i; } private static boolean onLine(Vector2 vector, float x1, float y1, float x2, float y2){ diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index cccd55a5a3..a4cdbe7a6c 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -270,6 +270,11 @@ public class Renderer extends RendererModule{ Graphics.begin(); Draw.reset(); + + if(Vars.showPaths){ + drawPaths(); + } + int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2) + 2; int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2; @@ -383,6 +388,20 @@ public class Renderer extends RendererModule{ cbatch.dispose(); cbatch = new CacheBatch(256 * 256 * 3); } + + void drawPaths(){ + Draw.color(Color.RED); + for(SpawnPoint point : control.spawnpoints){ + if(point.pathTiles != null){ + for(int i = 1; i < point.pathTiles.length; i ++){ + Draw.line(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), + point.pathTiles[i].worldx(), point.pathTiles[i].worldy()); + Draw.circle(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), 6f); + } + } + } + Draw.reset(); + } void renderPixelOverlay(){ @@ -503,7 +522,7 @@ public class Renderer extends RendererModule{ drawHealth(entity); } - if(!Vars.android) + if(!Vars.android && Vars.showPlayer) drawHealth(player); } diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index 38a4df9b3c..dfdaabbd33 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -112,10 +112,10 @@ public class UI extends SceneModule{ Draw.color(); TextureRegion back = Draw.region("background"); - float backscl = 4f; + float backscl = 4.5f; - Draw.alpha(0.8f); - Core.batch.draw(back, w/2 - back.getRegionWidth()*backscl/2, h/2 - back.getRegionHeight()*backscl/2, + Draw.alpha(0.7f); + Core.batch.draw(back, w/2 - back.getRegionWidth()*backscl/2 +240f, h/2 - back.getRegionHeight()*backscl/2 + 250f, back.getRegionWidth()*backscl, back.getRegionHeight()*backscl); float logoscl = (int)Unit.dp.inPixels(7); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 09b687c297..3421334dbf 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -56,6 +56,8 @@ public class Player extends DestructibleEntity{ @Override public void draw(){ + if(!Vars.showPlayer) return; + if(Vars.snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){ Draw.rect("mech-"+mech.name(), (int)x, (int)y, direction.angle()-90); }else{ diff --git a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java index cb22aefc7f..1d3572a1be 100644 --- a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java +++ b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java @@ -18,7 +18,7 @@ import io.anuke.ucore.util.Tmp; public class Enemy extends DestructibleEntity{ public final static Color[] tierColors = { Color.valueOf("ffe451"), Color.valueOf("f48e20"), Color.valueOf("ff6757"), Color.valueOf("ff2d86") }; public final static int maxtier = 4; - public final static float maxIdle = 60*3f; + public final static float maxIdle = 60*1.5f; protected float speed = 0.4f; protected float reload = 32; @@ -142,11 +142,16 @@ public class Enemy extends DestructibleEntity{ Bullet out = new Bullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation).add(); out.damage = (int) (damage * Vars.multiplier); } - + + /* public void findClosestNode(){ int index = 0; int cindex = -1; float dst = Float.MAX_VALUE; + UCore.log("Finding closest."); + + Tile[] clone = path.clone(); + UCore.log(clone.length); //find closest node index for(Tile tile : path){ @@ -171,7 +176,7 @@ public class Enemy extends DestructibleEntity{ set(x2 * Vars.tilesize, y2 * Vars.tilesize); }); } - } + }*/ @Override public void added(){ @@ -221,7 +226,7 @@ public class Enemy extends DestructibleEntity{ xvelocity = (x - lastx) / Timers.delta(); yvelocity = (y - lasty) / Timers.delta(); - float minv = 0.001f; + float minv = 0.0001f; if(xvelocity < minv && yvelocity < minv && node > 0){ idletime += Timers.delta(); @@ -248,6 +253,12 @@ public class Enemy extends DestructibleEntity{ Draw.color(); Draw.rect(region, x, y, this.angle - 90); + if(Vars.showPaths){ + Draw.color(Color.PURPLE); + Draw.line(x, y, x + xvelocity*10f, y + yvelocity*10f); + Draw.color(); + } + Graphics.flush(); } diff --git a/core/src/io/anuke/mindustry/ui/MindustrySettingsDialog.java b/core/src/io/anuke/mindustry/ui/MindustrySettingsDialog.java index f4a13053a1..a0f2ee6d12 100644 --- a/core/src/io/anuke/mindustry/ui/MindustrySettingsDialog.java +++ b/core/src/io/anuke/mindustry/ui/MindustrySettingsDialog.java @@ -21,7 +21,7 @@ public class MindustrySettingsDialog extends SettingsDialog{ content().remove(); buttons().remove(); - ScrollPane pane = new ScrollPane(content()); + ScrollPane pane = new ScrollPane(content(), "clear"); pane.setFadeScrollBars(false); row(); diff --git a/core/src/io/anuke/mindustry/world/SpawnPoint.java b/core/src/io/anuke/mindustry/world/SpawnPoint.java index 9735946ecd..94a0293203 100644 --- a/core/src/io/anuke/mindustry/world/SpawnPoint.java +++ b/core/src/io/anuke/mindustry/world/SpawnPoint.java @@ -8,6 +8,7 @@ import io.anuke.mindustry.ai.SmoothGraphPath; public class SpawnPoint{ public Tile start; public Tile[] pathTiles; + public Tile[] tempTiles; public PathFinder finder; public SmoothGraphPath path = new SmoothGraphPath(); public PathFinderRequest request; diff --git a/core/src/io/anuke/mindustry/world/World.java b/core/src/io/anuke/mindustry/world/World.java index 5769a500b2..48a761e4da 100644 --- a/core/src/io/anuke/mindustry/world/World.java +++ b/core/src/io/anuke/mindustry/world/World.java @@ -68,6 +68,12 @@ public class World extends Module{ return tile == null || tile.solid(); } + public boolean passable(int x, int y){ + Tile tile = tile(x, y); + + return tile != null && tile.passable(); + } + public boolean wallSolid(int x, int y){ Tile tile = tile(x, y); return tile == null || tile.block().solid; @@ -462,7 +468,7 @@ public class World extends Module{ int e2; while(true){ - if(solid(x0, y0)){ + if(!passable(x0, y0)){ return Tmp.g1.set(x0, y0); } if(x0 == x1 && y0 == y1) break; diff --git a/desktop/mindustry-saves/0.mins b/desktop/mindustry-saves/0.mins index 0a4475541e..d6822e9442 100644 Binary files a/desktop/mindustry-saves/0.mins and b/desktop/mindustry-saves/0.mins differ diff --git a/desktop/mindustry-saves/1.mins b/desktop/mindustry-saves/1.mins index 86411f17c3..c9e88d8c67 100644 Binary files a/desktop/mindustry-saves/1.mins and b/desktop/mindustry-saves/1.mins differ diff --git a/desktop/mindustry-saves/7.mins b/desktop/mindustry-saves/7.mins index c4c689f225..ea53bde8d4 100644 Binary files a/desktop/mindustry-saves/7.mins and b/desktop/mindustry-saves/7.mins differ