selectable objects in practice
parent
30ae31e913
commit
a77f3f9158
|
|
@ -8,6 +8,7 @@ import static xyz.valnet.engine.util.Math.lerp;
|
|||
|
||||
import xyz.valnet.engine.graphics.Drawing;
|
||||
import xyz.valnet.engine.math.Vector2f;
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.Tile;
|
||||
import xyz.valnet.hadean.pathfinding.AStarPathfinder;
|
||||
|
|
@ -17,7 +18,7 @@ import xyz.valnet.hadean.pathfinding.Path;
|
|||
import xyz.valnet.hadean.scenes.GameScene;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
public class Pawn extends GameObject {
|
||||
public class Pawn extends GameObject implements ISelectable {
|
||||
|
||||
private float x = 0.5f, y = 0.5f;
|
||||
private float dx, dy;
|
||||
|
|
@ -26,7 +27,7 @@ public class Pawn extends GameObject {
|
|||
|
||||
private Path path;
|
||||
|
||||
private final float speed = 50f;
|
||||
private final float speed = 70f;
|
||||
|
||||
private Camera camera;
|
||||
private Terrain terrain;
|
||||
|
|
@ -125,5 +126,18 @@ public class Pawn extends GameObject {
|
|||
y = nextNode.y + 0.5f;
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector4f getWorldBox() {
|
||||
if(path != null && !path.isComplete()) {
|
||||
float t = counter / speed;
|
||||
Node n = path.peek();
|
||||
float x1 = lerp(x - 0.5f, n.x, t);
|
||||
float y1 = lerp(y - 0.5f, n.y, t);
|
||||
return new Vector4f(x1, y1, x1 + 1, y1 + 1);
|
||||
} else {
|
||||
return new Vector4f(x - 0.5f, y - 0.5f, x + 0.5f, y + 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package xyz.valnet.hadean.gameobjects;
|
||||
|
||||
import xyz.valnet.engine.math.Vector4f;
|
||||
import xyz.valnet.engine.scenegraph.GameObject;
|
||||
import xyz.valnet.hadean.util.Assets;
|
||||
|
||||
public class Tree extends GameObject implements ITileThing {
|
||||
public class Tree extends GameObject implements ITileThing, ISelectable {
|
||||
private Camera camera;
|
||||
|
||||
private int x, y;
|
||||
|
|
@ -26,4 +27,9 @@ public class Tree extends GameObject implements ITileThing {
|
|||
public boolean isWalkable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector4f getWorldBox() {
|
||||
return new Vector4f(x - 1, y - 2, x + 2, y + 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue