|
@@ -1,8 +1,9 @@
|
|
|
package me.hammerle.supersnuvi.entity;
|
|
|
|
|
|
+import me.hammerle.supersnuvi.entity.animator.EntityAnimator;
|
|
|
+import me.hammerle.supersnuvi.entity.ai.EntityController;
|
|
|
import java.util.LinkedList;
|
|
|
import me.hammerle.supersnuvi.gamelogic.Level;
|
|
|
-import me.hammerle.supersnuvi.javafx.Image;
|
|
|
import me.hammerle.supersnuvi.rendering.Game;
|
|
|
import me.hammerle.supersnuvi.tiles.Location;
|
|
|
import me.hammerle.supersnuvi.util.CollisionBox;
|
|
@@ -39,7 +40,9 @@ public class Entity
|
|
|
private final double maxHealth;
|
|
|
private double health;
|
|
|
|
|
|
- private Image image;
|
|
|
+ private EntityAnimator animator;
|
|
|
+
|
|
|
+ private EntityController controller;
|
|
|
|
|
|
private final Level level;
|
|
|
|
|
@@ -59,8 +62,8 @@ public class Entity
|
|
|
this.height = height;
|
|
|
this.maxHealth = health;
|
|
|
this.health = health;
|
|
|
-
|
|
|
- image = Utils.getColoredImage(0, 0, 0, 255, (int) width, (int) height);
|
|
|
+ this.animator = new EntityAnimator(this);
|
|
|
+ this.controller = new EntityController(this);
|
|
|
}
|
|
|
|
|
|
public Level getLevel()
|
|
@@ -68,12 +71,41 @@ public class Entity
|
|
|
return level;
|
|
|
}
|
|
|
|
|
|
+ //--------------------------------------------------------------------------
|
|
|
+ // utility
|
|
|
+ //--------------------------------------------------------------------------
|
|
|
+
|
|
|
+ public final double squaredDistance(Entity other)
|
|
|
+ {
|
|
|
+ return (posX - other.posX) * (posX - other.posX) + (posY - other.posY) * (posY - other.posY);
|
|
|
+ }
|
|
|
+
|
|
|
+ public final double signedDistanceX(Entity other)
|
|
|
+ {
|
|
|
+ if(posX < other.posX)
|
|
|
+ {
|
|
|
+ return Math.min(0.0, posX + width - other.posX);
|
|
|
+ }
|
|
|
+ return Math.max(0.0, posX - (other.posX + other.width));
|
|
|
+ }
|
|
|
+
|
|
|
+ //--------------------------------------------------------------------------
|
|
|
+ // controller - either ai or player
|
|
|
+ //--------------------------------------------------------------------------
|
|
|
+
|
|
|
+ public final void setController(EntityController controller)
|
|
|
+ {
|
|
|
+ this.controller = controller;
|
|
|
+ }
|
|
|
+
|
|
|
//--------------------------------------------------------------------------
|
|
|
// ticking
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
- public void tick()
|
|
|
+ public final void tick()
|
|
|
{
|
|
|
+ controller.tick();
|
|
|
+
|
|
|
inWater = false;
|
|
|
|
|
|
if(isAffectedByGravity())
|
|
@@ -104,9 +136,9 @@ public class Entity
|
|
|
LinkedList<CollisionBox> list = level.getMovementBoxesAt(this, getBox());
|
|
|
if(!list.isEmpty())
|
|
|
{
|
|
|
- System.out.println(getBox());
|
|
|
- list.forEach(s -> System.out.println(s));
|
|
|
- System.out.println("WELL");
|
|
|
+ //System.out.println(getBox());
|
|
|
+ //list.forEach(s -> System.out.println(s));
|
|
|
+ //System.out.println("WELL");
|
|
|
posX = prevPosX;
|
|
|
posY = prevPrevY;
|
|
|
}
|
|
@@ -130,6 +162,8 @@ public class Entity
|
|
|
motionX = 0.0;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ animator.tick();
|
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
@@ -187,11 +221,6 @@ public class Entity
|
|
|
this.friction = friction;
|
|
|
}
|
|
|
|
|
|
- public boolean isRunning()
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
//--------------------------------------------------------------------------
|
|
|
// collision stuff
|
|
|
//--------------------------------------------------------------------------
|
|
@@ -517,12 +546,14 @@ public class Entity
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void onCollideWithTile(Location loc, Face face)
|
|
|
+ public final void onCollideWithTile(Location loc, Face face)
|
|
|
{
|
|
|
+ controller.onCollideWithTile(loc, face);
|
|
|
}
|
|
|
|
|
|
- public void onCollideWithEntity(Entity ent, Face face)
|
|
|
+ public final void onCollideWithEntity(Entity ent, Face face)
|
|
|
{
|
|
|
+ controller.onCollideWithEntity(ent, face);
|
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
@@ -644,19 +675,14 @@ public class Entity
|
|
|
return posY + height;
|
|
|
}
|
|
|
|
|
|
- public void setImage(Image image)
|
|
|
+ public final void setAnimator(EntityAnimator animator)
|
|
|
{
|
|
|
- this.image = image;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean drawImageFlipped()
|
|
|
- {
|
|
|
- return false;
|
|
|
+ this.animator = animator;
|
|
|
}
|
|
|
|
|
|
- public Image getImage()
|
|
|
+ public EntityAnimator getAnimator()
|
|
|
{
|
|
|
- return image;
|
|
|
+ return animator;
|
|
|
}
|
|
|
|
|
|
public double getRenderOffsetX()
|