Browse Source

calculate NPC physics-box correctly

master
Colin McMillen 4 years ago
parent
commit
36a72b938f
  1. 9
      Shared/NPC.cs

9
Shared/NPC.cs

@ -28,7 +28,7 @@ namespace SemiColinGames {
int desiredX = npc.Position.X + (int) (moveSpeed * npc.Facing * modelTime);
int testPoint = desiredX + 12 * npc.Facing;
// TODO: define the box modularly & correctly.
AABB npcBox = new AABB(new Vector2(testPoint, npc.Position.Y), new Vector2(1, 33));
AABB npcBox = new AABB(new Vector2(testPoint, npc.Position.Y), new Vector2(1, 25));
Debug.AddRect(npcBox, Color.Cyan);
bool foundBox = false;
foreach (AABB box in world.CollisionTargets) {
@ -49,13 +49,16 @@ namespace SemiColinGames {
public class NPC {
private const int spriteWidth = 96;
private const int spriteHeight = 81;
private const int spriteCenterYOffset = 2;
private const int spriteCenterYOffset = 10;
private readonly Vector2 eyeOffset = new Vector2(4, -3);
private readonly FSM<NPC> fsm;
private AABB physicsBox;
private readonly Vector2 halfSize = new Vector2(12, 24);
public NPC(Point position, int facing) {
Position = position;
physicsBox = new AABB(position.ToVector2(), halfSize);
Facing = facing;
fsm = new FSM<NPC>(new Dictionary<string, IState<NPC>> {
{ "idle", new IdleState() },
@ -93,6 +96,8 @@ namespace SemiColinGames {
public void Update(float modelTime, World world) {
fsm.Update(this, modelTime, world);
physicsBox = new AABB(Position.ToVector2(), halfSize);
Debug.AddRect(physicsBox, Color.White);
}
public void Draw(SpriteBatch spriteBatch) {

Loading…
Cancel
Save