Exemple #1
0
    public CharacterEntity(int characterId)
    {
        SessionData sessionData = SessionData.GetInstance();

        m_characterId   = characterId;
        m_characterData = sessionData.CurrentGameData.GetCharacterById(m_characterId);

        m_position = new Point3d(m_characterData.x, m_characterData.y, m_characterData.z);
        m_facing   = MathConstants.GetUnitVectorForAngle(m_characterData.angle);

        m_characterWidget      = null;
        m_pathfindingComponent = null;
        m_steeringComponent    = null;
    }
    public MobEntity(int characterId)
    {
        SessionData sessionData = SessionData.GetInstance();

        m_mobId   = characterId;
        m_mobData = sessionData.CurrentGameData.CurrentRoom.GetMobById(m_mobId);

        m_position    = new Point3d(m_mobData.x, m_mobData.y, m_mobData.z);
        m_facing      = MathConstants.GetUnitVectorForAngle(m_mobData.angle);
        m_dialogTimer = -1.0f;

        m_mobWidget            = null;
        m_pathfindingComponent = null;
        m_steeringComponent    = null;
    }
        public static bool IsPointInMobVisionCone(
            Mob mob,
            Point3d point)
        {
            MobType mobType = mob.MobType;

            Vector2d mobToPoint   = (point - mob.Position).ToVector2d();
            Vector2d facingVector = MathConstants.GetUnitVectorForAngle(mob.Angle);

            float cosHalfAngle                   = (float)Math.Cos(mob.MobType.VisionCone.GetHalfAngle());
            float cosAngleToProp                 = facingVector.Dot(mobToPoint);
            float pointDistanceSquared           = Point2d.DistanceSquared(point, mob.Position);
            float minVisionCircleDistanceSquared = WorldConstants.ROOM_TILE_SIZE * WorldConstants.ROOM_TILE_SIZE;
            float minVisionConeDistanceSquared   = (float)(mobType.VisionCone.distance * mobType.VisionCone.distance);

            bool isInVisionCone =
                (pointDistanceSquared <= minVisionCircleDistanceSquared) ||
                ((cosAngleToProp > cosHalfAngle) && (pointDistanceSquared <= minVisionConeDistanceSquared));

            return(isInVisionCone);
        }
Exemple #4
0
    public void SnapTo(Point3d point, float angle)
    {
        Point2d pixelPosition = GameConstants.ConvertRoomPositionToPixelPosition(point);

        // Update the character data
        m_characterData.x     = point.x;
        m_characterData.y     = point.y;
        m_characterData.z     = point.z;
        m_characterData.angle = angle;

        // Snap our position
        m_position.Set(point);
        m_facing = MathConstants.GetUnitVectorForAngle(angle);
        m_characterWidget.SetLocalPosition(pixelPosition.x, pixelPosition.y);

        // Snap out facing and go to idle
        m_characterWidget.UpdateAnimation(m_facing, Vector2d.ZERO_VECTOR);

        // Forget about any path we were running
        m_pathfindingComponent.ClearPath();
    }
Exemple #5
0
    public void RequestMoveTo(
        Point3d point,
        float angle,
        PathComputer.OnPathComputedCallback onPathComputed)
    {
        // Set our new destination.
        // The position will update as we move along our path
        m_pathfindingComponent.SubmitPathRequest(
            point,
            MathConstants.GetUnitVectorForAngle(angle),
            (PathComputer pathResult) =>
        {
            if (pathResult == null)
            {
                // No result means we stopped in out tracks
                m_characterData.x     = Position.x;
                m_characterData.y     = Position.y;
                m_characterData.z     = Position.z;
                m_characterData.angle = angle;

                onPathComputed(PathComputer.eResult.success);
            }
            else
            {
                if (pathResult.ResultCode == PathComputer.eResult.success)
                {
                    // Set the character data immediately to the destination
                    m_characterData.x     = point.x;
                    m_characterData.y     = point.y;
                    m_characterData.z     = point.z;
                    m_characterData.angle = angle;
                }

                onPathComputed(pathResult.ResultCode);
            }
        });
    }