Exemplo n.º 1
0
 public void SetRendererPreDraw(ImageBuffer background, RendererBase rendererToDrawWith, Player playerToCenterOn)
 {
     rendererToDrawWith.PushTransform();
     Vector2D windowCenter = new Vector2D(screenWindow.Left + (screenWindow.Right - screenWindow.Left) / 2, screenWindow.Bottom + (screenWindow.Top - screenWindow.Bottom) / 2);
     Vector2D playerPos = playerToCenterOn.Position;
     Vector2D playfieldOffset = windowCenter - playerPos;
     if (playfieldOffset.x > screenWindow.Left)
     {
         playfieldOffset.x = screenWindow.Left;
     }
     if (playfieldOffset.x < -background.Width() + screenWindow.Right)
     {
         playfieldOffset.x = -background.Width() + screenWindow.Right;
     }
     if (playfieldOffset.y > screenWindow.Bottom)
     {
         playfieldOffset.y = screenWindow.Bottom;
     }
     if (playfieldOffset.y < -background.Height() + screenWindow.Top)
     {
         playfieldOffset.y = -background.Height() + screenWindow.Top;
     }
     Affine translation = Affine.NewTranslation(playfieldOffset);
     rendererToDrawWith.SetTransform(rendererToDrawWith.GetTransform() * translation);
     rendererToDrawWith.SetClippingRect(screenWindow);
 }
Exemplo n.º 2
0
            public void SetRendererPreDraw(ImageBuffer background, RendererBase rendererToDrawWith, Player playerToCenterOn)
            {
                rendererToDrawWith.PushTransform();
                Vector2D windowCenter    = new Vector2D(screenWindow.Left + (screenWindow.Right - screenWindow.Left) / 2, screenWindow.Bottom + (screenWindow.Top - screenWindow.Bottom) / 2);
                Vector2D playerPos       = playerToCenterOn.Position;
                Vector2D playfieldOffset = windowCenter - playerPos;

                if (playfieldOffset.x > screenWindow.Left)
                {
                    playfieldOffset.x = screenWindow.Left;
                }
                if (playfieldOffset.x < -background.Width() + screenWindow.Right)
                {
                    playfieldOffset.x = -background.Width() + screenWindow.Right;
                }
                if (playfieldOffset.y > screenWindow.Bottom)
                {
                    playfieldOffset.y = screenWindow.Bottom;
                }
                if (playfieldOffset.y < -background.Height() + screenWindow.Top)
                {
                    playfieldOffset.y = -background.Height() + screenWindow.Top;
                }
                Affine translation = Affine.NewTranslation(playfieldOffset);

                rendererToDrawWith.SetTransform(rendererToDrawWith.GetTransform() * translation);
                rendererToDrawWith.SetClippingRect(screenWindow);
            }
Exemplo n.º 3
0
 public void SetRendererPostDraw(RendererBase rendererToDrawWith)
 {
     rendererToDrawWith.SetClippingRect(new rect_d(0, 0, 800, 600));
     rendererToDrawWith.PopTransform();
 }
Exemplo n.º 4
0
 public void SetRendererPostDraw(RendererBase rendererToDrawWith)
 {
     rendererToDrawWith.SetClippingRect(new rect_d(0, 0, 800, 600));
     rendererToDrawWith.PopTransform();
 }
Exemplo n.º 5
0
        public override void OnDraw(RendererBase rendererToDrawWith)
        {
            ImageBuffer levelMap = playfield.LevelMap;
            int         offset;

            byte[] buffer = levelMap.GetBuffer(out offset);

            if (!haveDrawnWalls)
            {
                RendererBase backgroundRenderer = BackgroundImage.NewRenderer();
                rect_i       boundsI            = BackgroundImage.GetBoundingRect();
                rect_d       bounds             = new rect_d(boundsI.Left, boundsI.Bottom, boundsI.Right, boundsI.Top);
                backgroundRenderer.SetClippingRect(bounds);
                ImageSequence wallTileSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "WallTile");
                for (int y = 0; y < levelMap.Height(); y++)
                {
                    for (int x = 0; x < levelMap.Width(); x++)
                    {
                        if (buffer[levelMap.GetBufferOffsetXY(x, y)] == 0)
                        {
                            int index = 0;
                            // what type of wall
                            if (x < levelMap.Width() - 1 &&
                                buffer[levelMap.GetBufferOffsetXY(x + 1, y + 0)] == 0)
                            {
                                index |= 8;
                            }

                            if (y < levelMap.Height() - 1 &&
                                buffer[levelMap.GetBufferOffsetXY(x + 0, y + 1)] == 0)
                            {
                                index |= 4;
                            }

                            if (x > 0 &&
                                buffer[levelMap.GetBufferOffsetXY(x - 1, y + 0)] == 0)
                            {
                                index |= 2;
                            }

                            if (y > 0 &&
                                buffer[levelMap.GetBufferOffsetXY(x + 0, y - 1)] == 0)
                            {
                                index |= 1;
                            }

                            backgroundRenderer.Render(wallTileSequence.GetImageByIndex(index), x * 16, y * 16);
                        }
                    }
                }
                haveDrawnWalls = true;
            }

            //for (int i = 0; i < 1; i++)
            for (int i = 0; i < numPlayers; i++)
            {
                playerViews[i].SetRendererPreDraw(BackgroundImage, rendererToDrawWith, playfield.PlayerList[i]);

                rendererToDrawWith.Render(BackgroundImage, 0, 0);

                foreach (SequenceEntity aSequenceEntity in playfield.SequenceEntityList)
                {
                    aSequenceEntity.Draw(rendererToDrawWith);
                }

                foreach (Player aPlayer in playfield.PlayerList)
                {
                    aPlayer.Draw(rendererToDrawWith);
                }

                playfield.sword.Draw(rendererToDrawWith);
                playfield.key.Draw(rendererToDrawWith);
                playfield.shield.Draw(rendererToDrawWith);

                playerViews[i].SetRendererPostDraw(rendererToDrawWith);
            }

            ImageSequence hud = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), (playfield.PlayerList.Count).ToString() + "PlayerHUD");

            rendererToDrawWith.Render(hud.GetImageByIndex(0), 400, 300);

            foreach (Player aPlayer in playfield.PlayerList)
            {
                aPlayer.DrawScore(rendererToDrawWith);
            }

            rendererToDrawWith.Line(0.5, 300.5, 800.5, 300.5, new RGBA_Bytes(255, 20, 20));
            rendererToDrawWith.Line(400.5, 0.5, 400.5, 600.5, new RGBA_Bytes(255, 20, 20));

            base.OnDraw(rendererToDrawWith);
        }