Major refactoring; implemented multi-frame pathfinding

This commit is contained in:
Anuken
2017-11-26 18:59:03 -05:00
parent 25952985dd
commit 07ac552495
60 changed files with 767 additions and 498 deletions
@@ -2,8 +2,8 @@ package io.anuke.mindustry.entities;
import static io.anuke.mindustry.Vars.tilesize;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.entities.*;
import io.anuke.ucore.util.Mathf;
@@ -29,7 +29,7 @@ public class Bullet extends BulletEntity{
int tilex = Mathf.scl2(x, tilesize);
int tiley = Mathf.scl2(y, tilesize);
Tile tile = World.tile(tilex, tiley);
Tile tile = Vars.world.tile(tilex, tiley);
TileEntity targetEntity = null;
if(tile != null){
@@ -5,7 +5,6 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.util.Mathf;
@@ -29,7 +28,7 @@ public class DamageArea{
int trad = (int)(radius / Vars.tilesize);
for(int dx = -trad; dx <= trad; dx ++){
for(int dy= -trad; dy <= trad; dy ++){
Tile tile = World.tile(Mathf.scl2(x, Vars.tilesize) + dx, Mathf.scl2(y, Vars.tilesize) + dy);
Tile tile = Vars.world.tile(Mathf.scl2(x, Vars.tilesize) + dx, Mathf.scl2(y, Vars.tilesize) + dy);
if(tile != null && tile.entity != null && Vector2.dst(dx, dy, 0, 0) <= trad){
int amount = calculateDamage(x, y, tile.worldx(), tile.worldy(), radius, damage);
tile.entity.damage(amount);
@@ -6,7 +6,6 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
@@ -36,7 +35,7 @@ public class EMP extends TimedEntity{
for(int dx = -radius; dx <= radius; dx ++){
for(int dy = -radius; dy <= radius; dy ++){
if(Vector2.dst(dx, dy, 0, 0) < radius){
Tile tile = World.tile(worldx + dx, worldy + dy);
Tile tile = Vars.world.tile(worldx + dx, worldy + dy);
if(tile != null && tile.block().destructible){
array.add(tile);
@@ -5,14 +5,12 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.effect.Fx;
import io.anuke.mindustry.entities.effect.Shaders;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.*;
import io.anuke.ucore.util.Mathf;
@@ -57,15 +55,17 @@ public class Enemy extends DestructibleEntity{
}
void move(){
boolean nearCore = distanceTo(World.core.worldx(), World.core.worldy()) <= range - 18f;
Tile core = Vars.control.getCore();
boolean nearCore = distanceTo(core.worldx(), core.worldy()) <= range - 18f;
Vector2 vec;
if(nearCore){
vec = Tmp.v2.setZero();
target = World.core.entity;
target = core.entity;
}else{
vec = Pathfind.find(this);
vec = Vars.world.pathfinder().find(this);
vec.sub(x, y).setLength(speed);
}
@@ -94,8 +94,13 @@ public class Enemy extends DestructibleEntity{
move(vec.x * Timers.delta(), vec.y * Timers.delta());
updateTargeting(nearCore);
}
void updateTargeting(boolean nearCore){
if(Timers.get(this, "target", 15) && !nearCore){
target = World.findTileTarget(x, y, null, range, false);
target = Vars.world.findTileTarget(x, y, null, range, false);
//no tile found
if(target == null){
@@ -126,7 +131,7 @@ public class Enemy extends DestructibleEntity{
}
public void findClosestNode(){
Pathfind.find(this);
Vars.world.pathfinder().find(this);
int index = 0;
int cindex = -1;
@@ -150,7 +155,7 @@ public class Enemy extends DestructibleEntity{
int x2 = path[node].x, y2 = path[node].y;
//if the enemy can't move to that node right now, set its position to it
if(World.raycast(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize), x2, y2) != null){
if(Vars.world.raycast(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize), x2, y2) != null){
Timers.run(Mathf.random(15f), () -> {
set(x2 * Vars.tilesize, y2 * Vars.tilesize);
});
@@ -1,11 +1,11 @@
package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.effect.Shaders;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.graphics.Hue;
@@ -28,12 +28,7 @@ public class HealerEnemy extends Enemy{
}
@Override
void move(){
Vector2 vec = Pathfind.find(this);
vec.sub(x, y).setLength(speed);
move(vec.x*Timers.delta(), vec.y*Timers.delta());
void updateTargeting(boolean nearCore){
if(Timers.get(this, "target", 15)){
target = Entities.getClosest(Entities.getGroup(Enemy.class),
x, y, range, e -> e instanceof Enemy && e != this && ((Enemy)e).healthfrac() < 1f);
@@ -62,12 +57,14 @@ public class HealerEnemy extends Enemy{
Angles.translation(this.angleTo(enemy), 5f);
Graphics.shader();
if(enemy != null && enemy.health < enemy.maxhealth){
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 13f));
Draw.alpha(0.9f);
Draw.laser("laser", "laserend", x + Angles.x(), y + Angles.y(), enemy.x - Angles.x()/1.5f, enemy.y - Angles.y()/1.5f);
Draw.color();
}
Graphics.shader(Shaders.outline);
}
}