public virtual void FollowTarget(Entity target) { float maxDistance = 240f; float distance = Vector2.Distance(GetConvertedPosition(), target.GetConvertedPosition()); followPosition.X = target.GetPosX() - GetPosX(); followPosition.Y = (target.GetPosZ() - GetPosZ()) + 91; followPosition.Normalize(); if (distance < maxDistance) { followPosition.X = 0; followPosition.Y = 0; if (this.InRangeZ(target, 130)) { SetAnimationState(Animation.State.ATTACK1); } else { SetAnimationState(Animation.State.STANCE); } } else { SetAnimationState(Animation.State.WALK_TOWARDS); } VelX(followPosition.X * 1.6f); VelZ(followPosition.Y * 2.1f); }
public static bool InBoundsZ(this Entity e1, Entity e2, float range) { return InRangeZ(e1, e2, range) && !(e1.GetPosZ() <= e2.GetPosZ() - range) && !(e1.GetPosZ() >= e2.GetPosZ() + range); }
public static bool InRangeZ(this Entity e1, Entity e2, float range) { return (GetDiff(e1.GetPosZ(), e2.GetPosZ()) <= range); }
public static bool InRangeZ(this Entity e1, Entity e2) { return (GetDiff(e1.GetPosZ(), e2.GetPosZ()) <= e2.GetDepth()); }
private void CheckBounds(Entity entity) { List<CLNS.BoundsBox> bboxes = entity.GetBoxes(CLNS.BoxType.BOUNDS_BOX).Cast<CLNS.BoundsBox>().ToList(); bboxes.AddRange(entity.GetCurrentBoxes(CLNS.BoxType.BOUNDS_BOX).Cast<CLNS.BoundsBox>().ToList()); CLNS.BoundsBox entityBox = null; int ePosY = (int)Math.Abs(entity.GetPosY()); int eGround = (int)Math.Abs(entity.GetGround()); bool onTop = false; foreach (Entity target in entities) { if (entity != target && target.IsEntity(Entity.EntityType.OBSTACLE)) { List<CLNS.BoundsBox> tboxes = target.GetBoxes(CLNS.BoxType.BOUNDS_BOX).Cast<CLNS.BoundsBox>().ToList(); tboxes.AddRange(target.GetCurrentBoxes(CLNS.BoxType.BOUNDS_BOX).Cast<CLNS.BoundsBox>().ToList()); CLNS.BoundsBox targetBox = null; bool hasCollided = false; int tPosY = (int)Math.Abs(target.GetPosY()); int tGround = (int)Math.Abs(target.GetGround()); foreach (CLNS.BoundsBox bb1 in bboxes) { foreach (CLNS.BoundsBox bb2 in tboxes) { if (entity.InBoundsZ(target, bb2.GetZdepth()) && bb1.GetRect().Intersects(bb2.GetRect())) { entityBox = bb1; targetBox = bb2; hasCollided = true; break; } } } if (hasCollided && entityBox != null && targetBox != null) { //Debug.WriteLine("TT tPosY: " + target.GetName() + ": " + tPosY); //Debug.WriteLine("E: " + entity.GetName() + " : " + (ePosY + entity.GetHeight())); //Problem with tposy not updating in time for comparison if (entityBox.GetRect().Intersects(targetBox.GetRect())) { int eHeight = (int)(entityBox.GetHeight() + eGround); int tHeight = (int)(targetBox.GetHeight() + tGround); Debug.WriteLine("tHeight: " + tHeight); if (entityBox.GetRect().InBoundsX(targetBox.GetRect(), 60) && entity.InBoundsZ(target, targetBox.GetZdepth() - 5) && entityBox.GetRect().TouchTop(targetBox.GetRect(), 10)) { onTop = true; } if (entityBox.GetRect().InBoundsX(targetBox.GetRect(), 60) && entity.InBoundsZ(target, targetBox.GetZdepth() - 5) && entityBox.GetRect().TouchTop(targetBox.GetRect(), 10) && entity.GetVelocity().Y > 1) { entity.SetGround(-(tHeight + 1)); } bool over = false; if (targetBox.GetRect().TouchTop(entityBox.GetRect(), 10) && tGround >= eGround) { over = true; } if (ePosY < tHeight - 10) { if (entity.InBoundsZ(target, targetBox.GetZdepth() - 5) && over == false) { float depth = entityBox.GetRect().GetHorizontalIntersectionDepth(targetBox.GetRect()); if (depth != 0) { if (!entity.IsLeft() && entityBox.GetRect().TouchLeft(targetBox.GetRect())) { entity.MoveX(depth + 5); entity.GetCollisionInfo().Right(); entity.VelX(0f); } else if (entity.IsLeft() && entityBox.GetRect().TouchRight(targetBox.GetRect())) { entity.MoveX(depth - 5); entity.GetCollisionInfo().Left(); entity.VelX(0f); } } } if (entity.GetDirZ() > 0 && entity.GetPosZ() <= target.GetPosZ()) { entity.VelZ(0f); entity.GetCollisionInfo().Top(); } else if (entity.GetDirZ() < 0 && entity.GetPosZ() >= target.GetPosZ()) { entity.VelZ(0f); entity.GetCollisionInfo().Bottom(); } } } } } } if ((onTop == false && entity.GetGround() != entity.GetGroundBase() && entity.HasLanded()) || (onTop == false && Math.Abs(entity.GetPosY()) != entity.GetGround() && !entity.IsToss())) { if (!entity.IsToss()) { entity.SetGround(entity.GetGroundBase()); entity.SetAnimationState(Animation.State.FALL1); entity.Toss(5); } } }