Ejemplo n.º 1
0
    public void Update()
    {
        PathfindingComponent pathFindingInterface = m_entity.PathfindingInterface;

        if (pathFindingInterface != null)
        {
            if (!pathFindingInterface.IsPathComplete)
            {
                Point3d  targetRoomPosition   = pathFindingInterface.CurrentWaypoint.StepPoint;
                Point2d  targetPixelPosition  = GameConstants.ConvertRoomPositionToPixelPosition(targetRoomPosition);
                Point2d  currentPixelPosition = GameConstants.ConvertRoomPositionToPixelPosition(m_entity.Position);
                Vector2d offsetToTarget       = targetPixelPosition - currentPixelPosition;

                // Throttle full speed at the target
                m_throttle.Copy(offsetToTarget);
                m_throttle.Normalize();

                // Always face the direction we're moving
                m_facing.Copy(offsetToTarget);
                m_facing.NormalizeWithDefault(Vector2d.WORLD_DOWN);
            }
            else
            {
                // Leave the facing alone, clear the throttle
                m_throttle.Copy(Vector2d.ZERO_VECTOR);
            }
        }
        else
        {
            Reset();
        }
    }
Ejemplo n.º 2
0
    public EnergyTankWidget(WidgetGroup parentGroup, EnergyTankWidgetStyle style, EnergyTankData energyTankData) :
        base(
            parentGroup,
            style.Width,
            style.Height,
            GameConstants.ConvertRoomPositionToPixelPosition(energyTankData.position).x,
            GameConstants.ConvertRoomPositionToPixelPosition(energyTankData.position).y) // Gross
    {
        m_style = style;

        m_title = new LabelWidget(
            this,
            m_style.LabelWidth,
            m_style.LabelHeight,
            (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
            m_style.Height,                                       // local y
            "0");                                                 // text
        m_title.Alignment = TextAnchor.UpperCenter;

        // Create the sprite game object
        m_spriteObject =
            GameObject.Instantiate(
                Resources.Load <GameObject>("Gfx/Sprites/Items/EnergyTank/EnergyTank_sprite")) as GameObject;
        m_spriteAnimator = m_spriteObject.GetComponent <Animator>();
        UpdateWorldPosition();

        // Set the initial animation controller parameters
        UpdateState(energyTankData);
    }
Ejemplo n.º 3
0
    public void SnapTo(Point3d point, float angle)
    {
        Point2d pixelPosition = GameConstants.ConvertRoomPositionToPixelPosition(point);

        // Update the character data
        _energyTankData.position.Set(point);

        // Snap our position
        _position.Set(point);
        _energyTankWidget.SetLocalPosition(pixelPosition.x, pixelPosition.y);
    }
Ejemplo n.º 4
0
    public CharacterWidget(WidgetGroup parentGroup, CharacterWidgetStyle style, CharacterData characterData) :
        base(
            parentGroup,
            style.Width,
            style.Height,
            GameConstants.ConvertRoomPositionToPixelPosition(characterData.PositionInRoom).x,
            GameConstants.ConvertRoomPositionToPixelPosition(characterData.PositionInRoom).y) // Gross
    {
        m_style = style;

        m_title =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                -m_style.BoundsHeight - style.LabelHeight,            // local y
                characterData.character_name);                        // text
        m_title.Alignment = TextAnchor.UpperCenter;

        m_energy =
            new LabelWidget(
                this,
                m_style.LabelWidth,                                   // width
                m_style.LabelHeight,                                  // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                0,                                                    // local y
                "");                                                  // text
        m_energy.Alignment = TextAnchor.UpperCenter;
        this.Energy        = characterData.energy;

        // Create the sprite game object
        {
            // TODO: Add this back in once we have sprites for each class
            //string archetype = GameConstants.GetArchetypeString(characterData.archetype);
            string archetype      = "Warrior";
            string gameObjectPath = "Gfx/Sprites/Players/" + archetype + "/" + archetype + "_sprite";

            m_spriteObject =
                GameObject.Instantiate(
                    Resources.Load <GameObject>(gameObjectPath)) as GameObject;
            m_spriteAnimator = m_spriteObject.GetComponent <Animator>();

            UpdateWorldPosition();
        }

        // Set the initial animation controller parameters
        m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, -1.0f);
        m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false);
    }
Ejemplo n.º 5
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();
    }
Ejemplo n.º 6
0
    public MobWidget(WidgetGroup parentGroup, MobWidgetStyle style, MobData mobData) :
        base(
            parentGroup,
            style.Width,
            style.Height,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).x,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).y) // Gross
    {
        MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        m_style = style;

        m_title =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                -m_style.BoundsHeight - style.LabelHeight,            // local y
                mobType.Label);                                       // text
        m_title.Alignment = TextAnchor.UpperCenter;

        m_energy =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                0,                                                    // local y
                "");                                                  // text
        m_energy.Alignment = TextAnchor.UpperCenter;
        this.Energy        = mobData.energy;

        // Create the sprite game object
        {
            string archetype      = mobType.Name;
            string gameObjectPath = "Gfx/Sprites/Enemies/" + archetype + "/" + archetype + "_sprite";

            m_spriteObject =
                GameObject.Instantiate(
                    Resources.Load <GameObject>(gameObjectPath)) as GameObject;
            m_spriteAnimator = m_spriteObject.GetComponent <Animator>();

            UpdateWorldPosition();
        }

        // Create the dialog label
        m_dialog =
            new LabelWidget(
                this,
                style.DialogWidth,                                     // width
                style.DialogHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.DialogWidth / 2.0f), // local x
                m_title.LocalY - style.DialogHeight,                   // local y
                "");                                                   // text
        m_dialog.FontSize  = 14;
        m_dialog.Color     = Color.red;
        m_dialog.Alignment = TextAnchor.UpperCenter;
        m_dialog.Visible   = false;

        // Set the initial animation controller parameters
        m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, -1.0f);
        m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false);

        // Create the vision cone
        m_visionCone =
            new VisionConeWidget(
                this,
                mobType.Name + mobData.mob_id.ToString(),
                mobType.VisionConeDistance,
                mobType.VisionConeAngleDegrees,
                0.0f,
                0.0f,
                0.0f);
        m_visionCone.ConeFacing = MathConstants.GetAngleForDirection(MathConstants.eDirection.down);
    }
Ejemplo n.º 7
0
    private void DebugDrawTestVisibility()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point3d startWorldPos = entity.Position;

            Point2d endPixelPos = GetMousePixelPosition();
            Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos);

            // Draw the target nav cell
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos);
                NavRef endNavRef   = navMesh.ComputeNavRefAtPoint(endWorldPos);

                if (startNavRef.IsValid && endNavRef.IsValid)
                {
                    bool  canSee     = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef);
                    Color debugColor = canSee ? Color.green : Color.red;

                    // Draw a box around the nav cell
                    {
                        Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex);
                        Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos);
                        float   halfWidth         = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                        Vector3 boxUL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxUR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxLR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);
                        Vector3 boxLL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);

                        Debug.DrawLine(boxUL, boxUR, debugColor);
                        Debug.DrawLine(boxUR, boxLR, debugColor);
                        Debug.DrawLine(boxLR, boxLL, debugColor);
                        Debug.DrawLine(boxLL, boxUL, debugColor);
                    }

                    // Update the visibility status label
                    _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE";
                    _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y);
                    _visibilityStatusLabel.Color   = debugColor;
                    _visibilityStatusLabel.Visible = true;

                    // Render the ray-cast line
                    {
                        Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos);
                        Vector3 endVertex   = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos);

                        Debug.DrawLine(startVertex, endVertex, debugColor);
                    }
                }
            }
        }
    }
Ejemplo n.º 8
0
    private void DebugDrawTestPath()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point2d mousePixelPos = GetMousePixelPosition();
            Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos);

            // Draw the target nav cell
            string targetLabel = "";
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos);

                if (navRef.IsValid)
                {
                    Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex);
                    Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos);
                    float   halfWidth      = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                    Vector3 boxUL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxUR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxLR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f);
                    Vector3 boxLL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f);

                    Debug.DrawLine(boxUL, boxUR, Color.blue);
                    Debug.DrawLine(boxUR, boxLR, Color.blue);
                    Debug.DrawLine(boxLR, boxLL, Color.blue);
                    Debug.DrawLine(boxLL, boxUL, Color.blue);

                    targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString();
                }

                // Attempt to compute a path from the active player to the mouse
                _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos);

                // Update the path status label
                {
                    if (_pathComputer.ResultCode == PathComputer.eResult.success)
                    {
                        _pathStatusLabel.Text  = "VALID" + targetLabel;
                        _pathStatusLabel.Color = Color.green;
                    }
                    else
                    {
                        _pathStatusLabel.Text  = _pathComputer.ResultCode + targetLabel;
                        _pathStatusLabel.Color = Color.red;
                    }

                    _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y);
                    _pathStatusLabel.Visible = true;
                }

                // Render the raw path
                for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++)
                {
                    Point3d previousPoint      = _pathComputer.FinalPath[stepIndex - 1].StepPoint;
                    Point3d currentPoint       = _pathComputer.FinalPath[stepIndex].StepPoint;
                    Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint);
                    Vector3 currentPixelPoint  = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint);

                    Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green);
                }
            }
        }
    }
    public static Vector3 ConvertRoomPositionToVertexPosition(Point3d roomPosition)
    {
        Point2d pixelPosition = GameConstants.ConvertRoomPositionToPixelPosition(roomPosition);

        return(ConvertPixelPositionToVertexPosition(pixelPosition.x, pixelPosition.y, roomPosition.z));
    }
 public static Point2d ConvertRoomPositionToScreenPosition(Point3d roomPosition)
 {
     return(ConvertPixelPositionToScreenPosition(GameConstants.ConvertRoomPositionToPixelPosition(roomPosition)));
 }