Esempio n. 1
0
        };                                                                                                                               //Color.BlueViolet

        /// <summary>
        /// Briefly shows standard blinking on-screen rectangle.
        /// </summary>
        public static void ShowOsdRect(RECT r, bool limitToScreen = false)
        {
            var osr = CreateOsdRect();

            r.Inflate(2, 2);             //2 pixels inside, 2 outside
            if (limitToScreen)
            {
                var k = AScreen.Of(r).Bounds;
                r.Intersect(k);
            }
            osr.Rect = r;
            osr.Show();

            int i = 0;

            ATimer.Every(250, t => {
                if (i++ < 5)
                {
                    osr.Color = (i & 1) != 0 ? 0xFFFFFF00 : 0xFF8A2BE2;
                }
                else
                {
                    t.Stop();
                    osr.Dispose();
                }
            });
        }
Esempio n. 2
0
    bool CheckMove(RECT next)
    {
        bool _left  = next.X < chara.X;
        bool _right = next.X > chara.X;
        bool _up    = next.Y < chara.Y;
        bool _down  = next.Y > chara.Y;

        bool  hitFlag = false;
        bool  moved   = true;
        float firstX  = float.NaN;

        for (int i = 0; i < tile.Length; i++)
        {
            if (tile[i].Intersects(ref next))
            {
                hitFlag = true;

                RECT intersect;
                RECT.Intersect(ref tile[i], ref next, out intersect);
                // 稍微凸起的地面
                if (intersect.Bottom == next.Bottom && next.Y <= chara.Y)
                {
                    if (intersect.Height < CLIMB_THRESHOLD)
                    {
                        // 防止大坡度时走得太快
                        if (float.IsNaN(firstX))
                        {
                            // 上楼梯
                            next.Y -= intersect.Height;

                            firstX = next.X - intersect.Width;
                            i      = -1;
                            continue;
                        }
                        else
                        {
                            next.X = firstX;
                            break;
                        }
                    }
                }
                if (_down)
                {
                    // 向下移动时向上挤出
                    //next.Y -= intersect.Height;
                    next.Y = intersect.Y - next.Height;
                    if (next.Y > chara.Y)
                    {
                        continue;
                    }
                }
                if (_right)
                {
                    // 向右移动时向左挤出
                    //next.X -= intersect.Width;
                    next.X = intersect.X - next.Width;
                    if (next.X > chara.X)
                    {
                        continue;
                    }
                }
                if (_left)
                {
                    // 向左移动时向右挤出
                    //next.X += intersect.Width;
                    next.X = intersect.Right;
                    if (next.X < chara.X)
                    {
                        continue;
                    }
                }
                if (_up)
                {
                    // 向上移动时向下挤出
                    //next.Y += intersect.Height;
                    next.Y = intersect.Bottom;
                    if (next.Y < chara.Y)
                    {
                        continue;
                    }
                }

                moved = false;
                break;
            }
        }

        if (moved)
        {
            if (next.X <= 0)
            {
                next.X = 0;
            }
            if (next.X >= mapWidth - chara.Width)
            {
                next.X = mapWidth - chara.Width;
            }

            chara = next;

            // 地图跟随移动
            var gsize     = Entry.GRAPHICS.GraphicsSize.X;
            var gsizeHalf = Entry.GRAPHICS.GraphicsSize.X * 0.5f;
            if (next.X <= gsizeHalf)
            {
                offset.M31 = 0;
            }
            else if (next.X >= mapWidth - gsizeHalf)
            {
                offset.M31 = gsize - mapWidth;
            }
            else
            {
                offset.M31 = gsizeHalf - next.X;
            }
        }

        if (_down && (!moved || hitFlag))
        {
            jumpSpeed.X = 0;
            jumpSpeed.Y = 0;
        }

        return(moved);
    }