Beispiel #1
0
        public virtual bool rotateTo(float target, float speed = 1)
        {
            if (rotation == target)
            {
                return(true);
            }

            float diff = RadianHelper.diff(rotation, target);

            if (Math.Abs(diff) <= 0.01)
            {
                rotate(diff);
                spin = 0f;
                return(true);
            }

            spin = diff * speed;
            return(false);
        }
Beispiel #2
0
        public NamePlate(Vector2 position, float rotation, float radius, float scale, float maxWidth, string playerName, Color playerColour, int id = 0)
        {
            this.position     = position;
            smallScale        = scale;
            this.font         = ContentStore.font44pt;
            smallFontScale    = nameScale = scale / 4f;
            this.rotation     = RadianHelper.clip(rotation + ((float)Math.PI / 2f));
            rotation2         = RadianHelper.clip(this.rotation + (float)Math.PI);
            this.playerName   = playerName;
            this.playerColour = playerColour;
            this.ID           = id;

            int   iw        = 15;
            int   cw        = 12;
            float fullWidth = ((8f * cw) + (3f * iw)) * smallScale;
            float diff      = maxWidth / fullWidth;

            if (diff < 1f)
            {
                fullWidth      *= diff;
                smallFontScale *= diff;
                smallScale     *= diff;
            }
            float halfWidth = fullWidth / 2;

            Vector2 textSize = font.MeasureString(playerName) * nameScale;
            float   textDiff = maxWidth / textSize.X;

            if (textDiff < 1f)
            {
                nameScale *= textDiff;
                textSize  *= textDiff;
            }

            namePos  = namePos2 = position + new Vector2(0, radius);
            sIconPos = sIconPos2 = namePos + new Vector2(-halfWidth, textSize.Y);
            sTextPos = sTextPos2 = sIconPos + new Vector2(((1 * iw) + (0 * cw)) * smallScale, 0);
            bIconPos = bIconPos2 = sIconPos + new Vector2(((1 * iw) + (4 * cw)) * smallScale, 0);
            bTextPos = bTextPos2 = sIconPos + new Vector2(((2 * iw) + (4 * cw)) * smallScale, 0);
            wIconPos = wIconPos2 = sIconPos + new Vector2(((2 * iw) + (6 * cw)) * smallScale, 0);
            wTextPos = wTextPos2 = sIconPos + new Vector2(((3 * iw) + (6 * cw)) * smallScale, 0);

            namePos.X -= (textSize.X / 2f);
            namePos2   = namePos;

            rotateVector(ref namePos, position, this.rotation);
            rotateVector(ref sIconPos, position, this.rotation);
            rotateVector(ref sTextPos, position, this.rotation);
            rotateVector(ref bIconPos, position, this.rotation);
            rotateVector(ref bTextPos, position, this.rotation);
            rotateVector(ref wIconPos, position, this.rotation);
            rotateVector(ref wTextPos, position, this.rotation);

            rotateVector(ref namePos2, position, rotation2);
            rotateVector(ref sIconPos2, position, rotation2);
            rotateVector(ref sTextPos2, position, rotation2);
            rotateVector(ref bIconPos2, position, rotation2);
            rotateVector(ref bTextPos2, position, rotation2);
            rotateVector(ref wIconPos2, position, rotation2);
            rotateVector(ref wTextPos2, position, rotation2);
        }