Beispiel #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);
 }
Beispiel #2
0
        public SideDisplayBox(GraphicsDevice graphicsDevice, SpriteFont textFont, Vector2 pos, float width)
        {
            this.width    = (int)width;
            this.pos      = pos;
            this.textFont = textFont;

            playerNameBox = new RectBox(graphicsDevice,
                                        this.pos,
                                        this.width, nameBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, playerNameBox.GetBottom()),
                                new Vector2(pos.X + width, playerNameBox.GetBottom()),
                                5, Color.White);

            characterSpriteBox = new RectBox(graphicsDevice,
                                             new Vector2(pos.X, playerNameBox.GetBottom()),
                                             this.width, spriteBoxHeight);

            divisorB = new Line(graphicsDevice,
                                new Vector2(pos.X, characterSpriteBox.GetBottom()),
                                new Vector2(pos.X + width, characterSpriteBox.GetBottom()),
                                5, Color.White);

            characterInfoBox = new RectBox(graphicsDevice,
                                           new Vector2(pos.X, characterSpriteBox.GetBottom()),
                                           this.width, infoBoxHeight);

            dimensions = new Vector2(width,
                                     playerNameBox.GetHeight() + characterSpriteBox.GetHeight() + characterInfoBox.GetHeight());
        }
Beispiel #3
0
        public ActionLogBox(GraphicsDevice graphicsDevice, int capacity, SpriteFont textFont, Vector2 pos)
        {
            this.pos      = pos;
            this.textFont = textFont;

            //generate a colourless pixel to draw colour blocks with.
            emptyRect = UiTools.GeneratePixelTexture(graphicsDevice);


            textBox = new RectBox(graphicsDevice,
                                  this.pos,
                                  width, textBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, textBox.GetBottom()),
                                new Vector2(pos.X + width, textBox.GetBottom()),
                                5, Color.White);

            actionBoxes = new RectBox[capacity];

            for (int i = 0; i < capacity; i++)
            {
                actionBoxes[i] = new RectBox(graphicsDevice,
                                             new Vector2(
                                                 pos.X,
                                                 (i == 0)? textBox.GetBottom() : actionBoxes[i - 1].GetBottom()),
                                             width, actionBoxHeight);
            }


            dimensions = new Vector2(width,
                                     textBox.GetHeight() + capacity * actionBoxHeight);
        }
Beispiel #4
0
        public UnitShopBox(UnitShop parent, GraphicsDevice graphicsDevice, int capacity, Vector2 pos)
        {
            this.pos = pos;

            textBox = new RectBox(graphicsDevice,
                                  this.pos,
                                  width, textBoxHeight);

            divisorA = new Line(graphicsDevice,
                                new Vector2(pos.X, textBox.GetBottom()),
                                new Vector2(pos.X + width, textBox.GetBottom()),
                                5, Color.White);

            unitBoxes = new UnitShopButton[capacity];

            for (int i = 0; i < capacity; i++)
            {
                unitBoxes[i] = new UnitShopButton(i, graphicsDevice,
                                                  new Vector2(
                                                      pos.X,
                                                      (i == 0) ? textBox.GetBottom() : unitBoxes[i - 1].GetBottom()),
                                                  width, unitBoxHeight);
                unitBoxes[i].buttonPressed += parent.SellEntry;
            }

            dimensions = new Vector2(width,
                                     textBox.GetHeight() + capacity * unitBoxHeight);
        }
Beispiel #5
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);
 }
Beispiel #6
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();
        }
Beispiel #7
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());
        }
Beispiel #8
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);
        }
Beispiel #9
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;
                }
            }
        }
Beispiel #10
0
        public void Draw(SpriteBatch spriteBatch, BattleTurn.ActionArgs[] actions, Player[] players, DrawParams textures)
        {
            //pass in the information about actions -- draw for each one. This information does not need to be stored here too.


            //draw underlying alpha box for the box containing text.
            textBox.Draw(spriteBatch);
            //calculate the size of the text
            Vector2 nameSize = textFont.MeasureString(text);
            //calculate the position where the text needs to be drawn to be central
            //  to the text box.
            Vector2 namePos = textBox.GetCentrePos() - 0.5f * new Vector2(nameSize.X, nameSize.Y);

            //draw the text
            spriteBatch.DrawString(textFont, text, namePos, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);

            foreach (RectBox box in actionBoxes)
            {
                box.Draw(spriteBatch);
            }

            //draw respective information about each action
            for (int i = 0; i < actions.Length; i++)
            {
                BattleTurn.ActionArgs action = actions[i];
                RectBox boxDrawingTo         = actionBoxes[i];
                Vector2 boxPos = boxDrawingTo.GetPos();

                Color boxColor = (action.ActingUnit.OwnerId == 3) ?
                                 Color.Gray :
                                 players.Where(player => player.Id == action.ActingUnit.OwnerId).First().Colour; //set the color to Ai color/player color


                //draw a coloured block to specify which player the acting unit belongs to.
                //Using a single pixel texture instead of a non-disposable object (say my RectBox class for instance)
                // eliminates memory leak issues.
                spriteBatch.Draw(emptyRect, new Rectangle(boxDrawingTo.GetPos().ToPoint(), new Point(10, actionBoxHeight)), color: boxColor);

                Texture2D actingUnitSprite = action.ActingUnit.GetSprite(textures.unitSprites);


                //draw the units involved in each action, and the icons displaying the type of action.
                if (action.IsAttack)
                {
                    //draw the attacking unit
                    spriteBatch.Draw(actingUnitSprite,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(actingUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw the attack icon
                    spriteBatch.Draw(textures.attackIcon,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2),
                                     scale: iconScaleVector
                                     );

                    //draw the target unit
                    Texture2D targetUnitSprite = action.TargetUnit.GetSprite(textures.unitSprites);
                    spriteBatch.Draw(targetUnitSprite,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(targetUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw the defense icon
                    spriteBatch.Draw(textures.defenseIcon,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - iconScale * new Vector2(textures.defenseIcon.Width, 0),
                                     scale: iconScaleVector
                                     );

                    //draw the skull icon if the target unit died as a result of the action.
                    if (action.TargetFainted)
                    {
                        spriteBatch.Draw(textures.skullIcon,
                                         position: boxPos + new Vector2(3.5f * width / 5, boxDrawingTo.GetHeight() / 2) - iconScale / 2 * UiTools.BoundsToVector(textures.skullIcon.Bounds),
                                         scale: iconScaleVector * 2
                                         );
                    }
                }
                else if (action.IsMove)
                {
                    //draw acting unit
                    spriteBatch.Draw(actingUnitSprite,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(actingUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw move icon
                    spriteBatch.Draw(textures.moveIcon,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2),
                                     scale: iconScaleVector
                                     );

                    //draw target unit
                    Texture2D targetUnitSprite = action.TargetUnit.GetSprite(textures.unitSprites);
                    spriteBatch.Draw(targetUnitSprite,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(targetUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw targetting icon
                    spriteBatch.Draw(textures.targetIcon,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - iconScale * new Vector2(textures.targetIcon.Width, 0),
                                     scale: iconScaleVector
                                     );
                }
                else //(No move)
                {
                    //Draw the unit trying to act
                    spriteBatch.Draw(actingUnitSprite,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(actingUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //Draw no act icon (cant move)
                    spriteBatch.Draw(textures.noMoveIcon,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2),
                                     scale: iconScaleVector
                                     );
                }
            }

            //draw dividing line
            divisorA.Draw(spriteBatch);
        }
Beispiel #11
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;
            }
        }
Beispiel #12
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);
            }
        }
Beispiel #13
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);
 }