Exemple #1
0
 protected internal void DrawChar(SpriteBatch batch, float x, float y, RectBox glyph,
                                  RectBox cropping, LColor color)
 {
     batch.Draw(texture, x + cropping.x, y + cropping.y, glyph.GetWidth(),
                glyph.GetHeight(), glyph.GetX(), glyph.GetY(),
                glyph.GetWidth(), glyph.GetHeight(), color);
 }
Exemple #2
0
        /// <summary>
        /// 检查矩形与圆形是否发生了碰撞
        /// </summary>
        ///
        /// <param name="rect1"></param>
        /// <param name="rect2"></param>
        /// <returns></returns>
        public static bool IsRectToCirc(RectBox rect1, RectBox rect2)
        {
            float radius     = rect2.GetWidth() / 2;
            Point middle     = GetMiddlePoint(rect2);
            Point upperLeft  = new Point(rect1.GetMinX(), rect1.GetMinY());
            Point upperRight = new Point(rect1.GetMaxX(), rect1.GetMinY());
            Point downLeft   = new Point(rect1.GetMinX(), rect1.GetMaxY());
            Point downRight  = new Point(rect1.GetMaxX(), rect1.GetMaxY());
            bool  collided   = true;

            if (!IsPointToLine(upperLeft, upperRight, middle, radius))
            {
                if (!IsPointToLine(upperRight, downRight, middle, radius))
                {
                    if (!IsPointToLine(upperLeft, downLeft, middle, radius))
                    {
                        if (!IsPointToLine(downLeft, downRight, middle, radius))
                        {
                            collided = false;
                        }
                    }
                }
            }
            return(collided);
        }
Exemple #3
0
        /// <summary>
        /// 判断两个圆形是否发生了碰撞
        /// </summary>
        ///
        /// <param name="rect1"></param>
        /// <param name="rect2"></param>
        /// <returns></returns>
        public static bool IsCircToCirc(RectBox rect1, RectBox rect2)
        {
            Point middle1  = GetMiddlePoint(rect1);
            Point middle2  = GetMiddlePoint(rect2);
            float distance = middle1.DistanceTo(middle2);
            float radius1  = rect1.GetWidth() / 2;
            float radius2  = rect2.GetWidth() / 2;

            return((distance - radius2) < radius1);
        }
Exemple #4
0
 public WaitSprite(int s, int w, int h)
 {
     this.style   = s;
     this.wait    = new DrawWait(s, w, h);
     this.delay   = new LTimer(120);
     this.alpha   = 1.0F;
     this.visible = true;
     if (s > 1)
     {
         int width  = w / 2;
         int height = h / 2;
         cycle = NewSample(s - 2, width, height);
         RectBox limit = cycle.GetCollisionBox();
         SetLocation(
             (w - ((limit.GetWidth() == 0) ? 20 : limit.GetWidth())) / 2,
             (h - ((limit.GetHeight() == 0) ? 20 : limit.GetHeight())) / 2);
     }
     Update(0);
 }
Exemple #5
0
        public void OnCreate(bool m_landscape, bool m_fullscreen)
        {
            if (!m_landscape)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = m_landscape;

            this.CheckDisplayMode();

            //下列代码修正屏幕大小为LSetting设定尺寸

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (m_landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (m_landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!m_landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!m_landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (m_mode != LMode.Max)
            {
                if (m_landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (m_landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (m_mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (m_mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (m_mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (m_mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1f;
                LSystem.scaleHeight = 1f;
            }

            if (LSystem.screenRect == null)
            {
                LSystem.screenRect = new RectBox(0, 0, width, height);
            }
            else
            {
                LSystem.screenRect.SetBounds(0, 0, width, height);
            }

            //PS:width与height为期望的游戏画布大小,而maxWidth和maxHeight为实际的手机屏幕大小

            graphics.PreferredBackBufferFormat = m_displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (m_landscape)
            {
                graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            }
            else
            {
                graphics.SupportedOrientations = DisplayOrientation.Portrait;
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = false;
            graphics.PreferMultiSampling            = true;
            graphics.PreparingDeviceSettings       += new EventHandler <PreparingDeviceSettingsEventArgs>(Inner_deviceSettings);
#if WINDOWS
            graphics.IsFullScreen = false;
            IsMouseVisible        = true;
#elif XBOX || WINDOWS_PHONE
            //全屏
            if (m_fullscreen)
            {
                graphics.IsFullScreen = true;
            }
            else
            {
                graphics.IsFullScreen = false;
            }
#endif
            base.IsFixedTimeStep = false;

            graphics.ApplyChanges();
        }
Exemple #6
0
        public void Initialization(bool l,
                                   bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape  = l;
            this.fullScreen = f;
            this.mode       = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1;
                LSystem.scaleHeight = 1;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (landscape)
            {
                graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            }
            else
            {
                graphics.SupportedOrientations = DisplayOrientation.Portrait;
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferMultiSampling            = true;


#if WINDOWS
            graphics.IsFullScreen = false;
            IsMouseVisible        = true;
#elif XBOX || WINDOWS_PHONE
            //全屏
            graphics.IsFullScreen = true;
#endif


            graphics.ApplyChanges();

            base.IsFixedTimeStep = false;

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            SetSleepTime(1);

            LSystem.screenActivity = this;
            LSystem.screenProcess  = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();
            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
            .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());
        }
Exemple #7
0
        protected virtual void UpdateViewSize(bool landscape, int width, int height, LMode mode)
        {
            RectBox d = GetScreenDimension();

            this.maxWidth  = MathUtils.Max((int)d.GetWidth(), 1);
            this.maxHeight = MathUtils.Max((int)d.GetHeight(), 1);

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.zoomWidth  = width;
                    this.zoomHeight = height;
                }
                else
                {
                    this.zoomWidth  = height;
                    this.zoomHeight = width;
                }
            }
            else
            {
                if (landscape)
                {
                    this.zoomWidth  = maxWidth >= width ? width : maxWidth;
                    this.zoomHeight = maxHeight >= height ? height : maxHeight;
                }
                else
                {
                    this.zoomWidth  = maxWidth >= height ? height : maxWidth;
                    this.zoomHeight = maxHeight >= width ? width : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = FitLimitSize(zoomWidth, zoomHeight, maxWidth, maxHeight);
                maxWidth  = res.width;
                maxHeight = res.height;
                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else if (mode == LMode.Ratio)
            {
                float userAspect = (float)zoomWidth / (float)zoomHeight;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else if (mode == LMode.MaxRatio)
            {
                float userAspect = (float)zoomWidth / (float)zoomHeight;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)zoomHeight / (float)zoomWidth;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else
            {
                LSystem.SetScaleWidth(1f);
                LSystem.SetScaleHeight(1f);
            }
            UpdateViewSizeData(mode);
        }
Exemple #8
0
        public override void Update(long elapsedTime)
        {
            if (moveJump < 0)
            {
                if (this.moveY > -(moveJump))
                {
                    this.moveY = -moveJump;
                }
            }
            else
            {
                if (this.moveY > (moveJump))
                {
                    this.moveY = moveJump;
                }
            }
            original.SetLocation(offsetX + (original.GetX() + this.moveX), offsetY
                                 + (original.GetY() + this.moveY));
            if (moveJump < 0)
            {
                this.moveY += g;
            }
            else
            {
                this.moveY -= g;
            }

            if (moveJump > 0)
            {
                if (original.GetY() + original.GetHeight() > original
                    .GetContainerHeight() + original.GetHeight())
                {
                    isComplete = true;
                }
            }
            else if (original.GetY() + original.GetHeight() < 0)
            {
                isComplete = true;
            }
            bool isLimit = original.IsBounded();

            if (isLimit)
            {
                RectBox rect       = original.GetRectBox();
                int     limitWidth = (int)(original.GetContainerWidth() - rect
                                           .GetWidth());
                int limitHeight = (int)rect.GetHeight();
                if (original.GetX() > limitWidth)
                {
                    original.SetLocation(offsetX + limitWidth,
                                         offsetY + original.GetY());
                    isComplete = true;
                }
                else if (original.GetX() < 0)
                {
                    original.SetLocation(offsetX, offsetY + original.GetY());
                    isComplete = true;
                }
                if (original.GetY() < 0)
                {
                    original.SetLocation(offsetX + original.GetX(), offsetY
                                         + limitHeight);
                    isComplete = true;
                }
                else if (original.GetY() > original.GetHeight() - limitHeight)
                {
                    original.SetLocation(offsetX + original.GetX(), offsetY
                                         + (original.GetContainerHeight() - limitHeight));
                    isComplete = true;
                }
            }
        }
Exemple #9
0
        public void Initialization(bool l,
                                   bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape  = l;
            this.fullScreen = f;
            this.mode       = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1;
                LSystem.scaleHeight = 1;
            }

            if (landscape)
            {
                GamePage.Orientation           = Microsoft.Phone.Controls.PageOrientation.Landscape | Microsoft.Phone.Controls.PageOrientation.LandscapeLeft | Microsoft.Phone.Controls.PageOrientation.LandscapeRight;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Landscape;
            }
            else
            {
                GamePage.Orientation           = Microsoft.Phone.Controls.PageOrientation.Portrait | Microsoft.Phone.Controls.PageOrientation.PortraitDown | Microsoft.Phone.Controls.PageOrientation.PortraitUp;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Portrait;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (GamePage != null)
            {
                UIElementRenderer = new UIElementRenderer(GamePage, maxWidth, maxHeight);
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = true;

            graphics.ApplyChanges();

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            LSystem.screenActivity = this;
            LSystem.screenProcess  = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();

            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
            .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());

            if (GamePage != null)
            {
                GamePage.Background = null;
                GamePage.Foreground = null;
                GamePage.Style      = null;
                GamePage.AllowDrop  = false;
                GamePage.Visibility = System.Windows.Visibility.Collapsed;

                /*System.Windows.Interop.Settings settings = new System.Windows.Interop.Settings();
                 * settings.EnableFrameRateCounter = true;
                 * settings.EnableCacheVisualization = true;
                 * settings.EnableRedrawRegions = true;
                 * settings.MaxFrameRate = maxFrames;
                 * System.Windows.Media.BitmapCache cache = new System.Windows.Media.BitmapCache();
                 * cache.RenderAtScale = 1;
                 * GamePage.CacheMode = cache;*/
                GamePage.Opacity = 1f;
            }
        }
Exemple #10
0
        private void Load(Stream ins, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc        = XMLParser.Parse(ins);
                XMLElement  docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                              "Only orthogonal maps supported, found " + orient);
                }

                width      = docElement.GetIntAttribute("width", 0);
                height     = docElement.GetIntAttribute("height", 0);
                tileWidth  = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = docElement
                                          .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List <XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string     name        = propElement.GetAttribute("name", null);
                        string     value_ren   = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List <XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet       = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List <XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer   layer     = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List <XMLElement> objectGroupNodes = docElement
                                                     .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement   current_4   = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth  = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }
Exemple #11
0
 public void UpdateCamera()
 {
     if (follow != null &&
         !moveRect.Contains(follow.GetX() + follow.GetWidth() / 2,
                            follow.GetY() + follow.GetHeight() / 2))
     {
         float targetCX = follow.GetX() - (this.renderWidth / 2);
         float targetCY = follow.GetY() - (this.renderHeight / 2);
         if (maxSpeed != null)
         {
             if (MathUtils.Abs(targetCX - cameraX) > maxSpeed.x)
             {
                 if (targetCX > cameraX)
                 {
                     cameraX += maxSpeed.x * 2;
                 }
                 else
                 {
                     cameraX -= maxSpeed.x * 2;
                 }
             }
             else
             {
                 cameraX = targetCX;
             }
             if (MathUtils.Abs(targetCY - cameraY) > maxSpeed.y)
             {
                 if (targetCY > cameraY)
                 {
                     cameraY += maxSpeed.y * 2;
                 }
                 else
                 {
                     cameraY -= maxSpeed.y * 2;
                 }
             }
             else
             {
                 cameraY = targetCY;
             }
         }
         else
         {
             cameraX = targetCX;
             cameraY = targetCY;
         }
     }
     if (cameraX < 0)
     {
         cameraX = 0;
     }
     if (cameraX + renderWidth > cameraRect.GetWidth())
     {
         cameraX = cameraRect.GetWidth() - renderWidth + 1;
     }
     if (cameraY < 0)
     {
         cameraY = 0;
     }
     if (cameraY + renderHeight > cameraRect.GetHeight())
     {
         cameraY = cameraRect.GetHeight() - renderHeight + 1;
     }
     visibleRect.SetBounds(cameraX - horBorderPixel, cameraY
                           - vertBorderPixel, renderWidth + horBorderPixel, renderHeight
                           + vertBorderPixel);
     moveRect.SetBounds(cameraX + horBorderPixel / 2 - speedX, cameraY
                        + vertBorderPixel / 2, renderWidth - horBorderPixel + speedY,
                        renderHeight - vertBorderPixel);
 }