Fixed bugs with enemies not getting put on paths correctly
This commit is contained in:
@@ -130,12 +130,12 @@ public class Control extends Module{
|
||||
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
//TODO remove this debugging
|
||||
for(int i = 1; i < 60; i ++){
|
||||
UCore.log("\n\n--WAVE " + i);
|
||||
printEnemies(i);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -105,9 +105,14 @@ public class Enemy extends DestructibleEntity{
|
||||
|
||||
node = cindex;
|
||||
|
||||
//node = 0;
|
||||
int x2 = path[node].x, y2 = path[node].y;
|
||||
|
||||
//set(World.spawnpoints.get(spawn).worldx(), World.spawnpoints.get(spawn).worldy());
|
||||
if(World.raycast(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize), x2, y2) != null){
|
||||
Timers.run(Mathf.random(10f), ()->{
|
||||
set(x2 * Vars.tilesize, y2 * Vars.tilesize);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
public class World{
|
||||
public static int worldsize = 128;
|
||||
@@ -274,4 +275,42 @@ public class World{
|
||||
texture.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Input is in block coordinates, not world coordinates.
|
||||
* @return null if no collisions found, block position otherwise.
|
||||
*/
|
||||
public static Vector2 raycast(int x0f, int y0f, int x1f, int y1f){
|
||||
int x0 = (int)x0f;
|
||||
int y0 = (int)y0f;
|
||||
int x1 = (int)x1f;
|
||||
int y1 = (int)y1f;
|
||||
int dx = Math.abs(x1 - x0);
|
||||
int dy = Math.abs(y1 - y0);
|
||||
|
||||
int sx = x0 < x1 ? 1 : -1;
|
||||
int sy = y0 < y1 ? 1 : -1;
|
||||
|
||||
int err = dx - dy;
|
||||
int e2;
|
||||
while(true){
|
||||
|
||||
if(solid(x0, y0)){
|
||||
return Tmp.v3.set(x0, y0);
|
||||
}
|
||||
if(x0 == x1 && y0 == y1) break;
|
||||
|
||||
e2 = 2 * err;
|
||||
if(e2 > -dy){
|
||||
err = err - dy;
|
||||
x0 = x0 + sx;
|
||||
}
|
||||
|
||||
if(e2 < dx){
|
||||
err = err + dx;
|
||||
y0 = y0 + sy;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user