Ejemplo n.º 1
0
        /// <summary>
        /// Draw a cricle, which optionally fades out towards the edges. Only sets cell backgrounds
        /// </summary>
        public static void DrawCircle(TCODConsole console, Vector2 center, float radius, TCODColor color, bool fade = true)
        {
            TCODColor currentCol;
            Vector2   pos;
            int       e = (int)(center.x + radius);
            int       w = (int)(center.x - radius);
            int       n = (int)(center.y - radius);
            int       s = (int)(center.y + radius);

            // small optimization so that the distance doesnt have to be calculated for each tile
            float radSqr = radius * radius;

            for (int x = w; x <= e; x++)
            {
                for (int y = n; y <= s; y++)
                {
                    pos.x = x;
                    pos.y = y;

                    float sqrDist = (center - pos).SqrMagnitude();
                    if (sqrDist > radSqr)
                    {
                        continue;
                    }

                    float mag = fade ? 1.0f - (sqrDist / radSqr) : 1.0f;

                    currentCol = console.getCharBackground(x, y);
                    console.setCharBackground(x, y, CrossFadeColor(color, currentCol, mag));
                }
            }
        }
Ejemplo n.º 2
0
 public override void DrawNewFrame(TCODConsole screen)
 {
     if (m_enabled)
     {
         foreach (Point p in m_playerFOV)
         {
             int screenPlacementX = m_mapUpCorner.X + p.X + 1;
             int screenPlacementY = m_mapUpCorner.Y + p.Y + 1;
             if (IsDrawableTile(screenPlacementX, screenPlacementY))
                 screen.setCharBackground(screenPlacementX, screenPlacementY, ColorPresets.DarkRed);
         }
         foreach (ICharacter c in m_monsterFOV.Keys)
         {
             foreach (Point p in m_monsterFOV[c])
             {
                 int screenPlacementX = m_mapUpCorner.X + p.X + 1;
                 int screenPlacementY = m_mapUpCorner.Y + p.Y + 1;
                 if (IsDrawableTile(screenPlacementX, screenPlacementY))
                 {
                     TCODColor currentColor = screen.getCharBackground(screenPlacementX, screenPlacementY);
                     screen.setCharBackground(screenPlacementX, screenPlacementY, TCODColor.Interpolate(currentColor, GetColorForMonster(c), .6f));
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        private void ColorSquare(TCODConsole screen, Point p, double strength, TCODColor color)
        {
            int screenPlacementX = m_mapUpCorner.X + p.X + 1;
            int screenPlacementY = m_mapUpCorner.Y + p.Y + 1;

            if (IsDrawableTile(screenPlacementX, screenPlacementY))
            {
                TCODColor attackColor = TCODColor.Interpolate(ColorPresets.Black, color, (float)strength);
                TCODColor currentColor = screen.getCharBackground(screenPlacementX, screenPlacementY);
                TCODColor newColor = TCODColor.Interpolate(currentColor, attackColor, .5f);
                screen.setCharBackground(screenPlacementX, screenPlacementY, newColor);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws a line on the console from start to end
        /// </summary>
        public static void DrawLine(TCODConsole console, Vector2 from, Vector2 to, TCODColor color, bool fade = true)
        {
            if (from == to)
            {
                return;
            }

            Vector2 delta     = from - to;
            int     absDeltax = Math.Abs(delta.X);
            int     absDeltay = Math.Abs(delta.Y);
            int     signx     = Math.Sign(delta.x);
            int     signy     = Math.Sign(delta.y);
            int     error     = 0;

            int       x = to.X;
            int       y = to.Y;
            Vector2   current;
            TCODColor currentBg;

            // Is the line x or y dominant
            if (absDeltax > absDeltay)
            {
                error = absDeltay * 2 - absDeltax;
                do
                {
                    if (error >= 0)
                    {
                        y     += signy;
                        error -= absDeltax * 2;
                    }

                    x     += signx;
                    error += absDeltay * 2;

                    if (x == from.x && y == from.y)
                    {
                        break;
                    }

                    current = new Vector2(x - to.x, y - to.y);
                    float mag = fade ? current.SqrMagnitude() / (to - from).SqrMagnitude() : 1.0f;
                    currentBg = console.getCharBackground(x, y);


                    console.setCharBackground(x, y, CrossFadeColor(color, currentBg, mag));
                } while(x != from.x || y != from.y);
            }
            else
            {
                error = absDeltax * 2 - absDeltay;
                do
                {
                    if (error >= 0)
                    {
                        x     += signx;
                        error -= absDeltay * 2;
                    }

                    y     += signy;
                    error += absDeltax * 2;

                    if (x == from.x && y == from.y)
                    {
                        break;
                    }

                    current = new Vector2(x - to.x, y - to.y);
                    float mag = fade ? current.SqrMagnitude() / (to - from).SqrMagnitude() : 1.0f;
                    currentBg = console.getCharBackground(x, y);

                    console.setCharBackground(x, y, CrossFadeColor(color, currentBg, mag));
                } while(x != from.x || y != from.y);
            }
        }
Ejemplo n.º 5
0
        private void DrawTabBar(TCODConsole screen)
        {
            const int HorizontalTabOffset = 2;
            screen.rect(UpperLeft + 1, UpperLeft + 1, SkillTreeWidth - 2, HorizontalTabOffset - 1, true);

            screen.putChar(UpperLeft, UpperLeft + HorizontalTabOffset, (int)TCODSpecialCharacter.TeeEast);
            screen.putChar(UpperLeft + SkillTreeWidth - 1, UpperLeft + HorizontalTabOffset, (int)TCODSpecialCharacter.TeeWest);
            screen.hline(UpperLeft + 1, UpperLeft + HorizontalTabOffset, SkillTreeWidth - 2);

            int x = UpperLeft + 2;
            int y = UpperLeft + HorizontalTabOffset - 1;
            foreach (string name in m_skillTreeTabs.Keys)
            {
                int xOffset = name == "Water" ? 1 : 0;
                screen.print(x + xOffset, y, name);
                x += name.Length + 1;

                if (name != "Water")
                {
                    screen.putChar(x, y, (int)TCODSpecialCharacter.VertLine);

                    // This is a bit of a hack. We don't want to overwrite the color'ed background title of the frame, so we check first
                    // This can break if libtcod changes that background title color
                    if (!screen.getCharBackground(x, y - 1).Equal(new TCODColor(211, 211, 211)))
                        screen.putChar(x, y - 1, (int)TCODSpecialCharacter.TeeSouth);

                    screen.putChar(x, y + 1, (int)TCODSpecialCharacter.TeeNorth);
                }
                x += 2;

                if (m_currentTabName == name)
                {
                    int lengthReductionToDueTee = name == "Water" ? 0 : 2;
                    for (int i = x - 4 - name.Length; i < x - lengthReductionToDueTee; i++)
                    {
                        screen.setCharBackground(i, y, TCODColor.grey);
                    }
                }
            }
        }