Beispiel #1
0
        //Private void DrawBitmap(ref g As Graphics, ref Source As Bitmap, Angle As Double, X As Integer, Y As Integer, Optional center As Boolean = False)
        //    if( center = False )
        //        X += Math.Floor(Source.Width * 0.5)
        //        Y += Math.Floor(Source.Height * 0.5)
        //    }
        //    //Dim p As Bitmap = Rotate(Angle, Source)
        //    //X -= Math.Floor(p.Width * 0.5)
        //    //Y -= Math.Floor(p.Height * 0.5)
        //    //g.DrawImage(p, X, Y)
        //}

        public unsafe void DrawRotatedImage(double Angle, ref Bitsmap Img, int X, int Y)
        {
            do
            {
                if (Angle > 90)
                {
                    Angle -= 90;
                    Img.Bit.RotateFlip(RotateFlipType.Rotate90FlipNone);
                }
                else if (Angle < 0)
                {
                    Angle += 90;
                    Img.Bit.RotateFlip(RotateFlipType.Rotate270FlipNone);
                }
            } while (Angle <= 0 || Angle >= 90);
            Angle = Angle * (Math.PI / 180); // Radians

            for (int iY = 0; iY < Img.Height; iY++)
            {
                for (int iX = 0; iX < Img.Width; iX++)
                {
                    // Rotate iX iY to get new coordinates
                    double h   = Math.Sqrt((iY * iY) + (iX * iX));
                    double Ang = Math.Atan2(iY, iX);
                    Ang += Angle;
                    int nX = (int)(Math.Cos(Ang) * h);
                    int nY = (int)(Math.Sin(Ang) * h);

                    // Set pixel
                    int *p  = (int *)(BLoc + ((nX + X) * 4) + ((nY + Y) * Stride));
                    int *po = (int *)(Img.BLoc + (iX * 4) + (iY * Img.Stride));
                    *    p  = *po;
                }
            }
        }
Beispiel #2
0
        public unsafe void DrawImage(ref Bitsmap img, int X, int Y)
        {
            int dWidth  = img.Width;
            int dHeight = img.Height;

            // Change X, Y, Width, and Height based on Bit's size, as needed. (Don't try to change pixels that don't exist.)
            if (X >= Width || Y >= Height)
            {
                return; // Nothing to fill!
            }
            int leftCutOff = 0;
            int topCutOff  = 0;

            if (X < 0)
            {
                dWidth    += X;
                leftCutOff = -X;
                X          = 0;
            }
            if (Y < 0)
            {
                dHeight  += Y;
                topCutOff = -Y;
                Y         = 0;
            }
            if (dWidth + X > Width)
            {
                dWidth = Width - X;
            }

            if (dHeight + Y > Height)
            {
                dHeight = Height - Y;
            }

            if (dWidth <= 0 || dHeight <= 0)
            {
                return;
            }

            // Copy rows of bits
            IntPtr ptrMe    = BLoc + (X * 4) + (Y * Stride);
            int    ItStride = img.Width * 4;
            int    copyLen  = dWidth * 1;

            int[]  newItBytes = new int[copyLen];
            IntPtr ItPtr      = img.BLoc;

            ItPtr += (leftCutOff * 4);
            ItPtr += (topCutOff * img.Stride);

            for (int iY = 0; iY < dHeight; iY++)
            {
                Marshal.Copy(ItPtr, newItBytes, 0, copyLen);
                Marshal.Copy(newItBytes, 0, ptrMe, copyLen);
                //CopyIntArray((int*)ItPtr, (int*)ptrMe, copyLen);
                ptrMe += Stride;
                ItPtr += ItStride;
            }
        }
        public void Resize(int displayWidth, int displayHeight)
        {
            img = new Bitsmap(displayWidth, displayHeight);
            MG  = Graphics.FromImage(img.Bit);
            map.ResizeView(displayWidth, displayHeight);

            ReDraw();
        }
Beispiel #4
0
        public void Draw(Bitsmap graphics)
        {
            //Matrix old = graphics.Transform;

            //graphics.Transform = Matrix;
            graphics.DrawImageA(ref _bitmap, 0, 0);

            //graphics.Transform = old;
        }
Beispiel #5
0
        public Bitsmap Clone()
        {
            Bitsmap c      = new Bitsmap(Width, Height);
            int     intLen = Len / 4;

            int[] temp = new int[intLen];
            Marshal.Copy(BLoc, temp, 0, intLen);
            Marshal.Copy(temp, 0, c.BLoc, intLen);

            return(c);
        }
        //private Sprite _sprite;

        public Game_ART(int displayWidth = 540, int displayHeight = 405)
        {
            //_sprite = new Sprite(General.ZapPic.Bit);
            img = new Bitsmap(displayWidth, displayHeight);
            MG  = Graphics.FromImage(img.Bit);

            map       = new Map(null, displayWidth, displayHeight);
            Players   = new List <LocalCharacter>();
            recording = new Recording();
            AddPlayer(true);

            // Set-up
            targetFPS = 27;
            if (map == null)
            {
                map = new Map(null);
            }

            StartGame();
        }
Beispiel #7
0
        public unsafe void DrawImageA(ref Bitsmap img, int X, int Y)
        {
            int dWidth  = img.Width;
            int dHeight = img.Height;

            // Change X, Y, Width, and Height based on Bit's size, as needed. (Don't try to change pixels that don't exist.)
            if (X >= Width || Y >= Height)
            {
                return; // Nothing to fill!
            }
            int leftCutOff = 0;
            int topCutOff  = 0;

            if (X < 0)
            {
                dWidth    += X;
                leftCutOff = -X;
                X          = 0;
            }
            if (Y < 0)
            {
                dHeight  += Y;
                topCutOff = -Y;
                Y         = 0;
            }
            if (dWidth + X > Width)
            {
                dWidth = Width - X;
            }

            if (dHeight + Y > Height)
            {
                dHeight = Height - Y;
            }

            if (dWidth <= 0 || dHeight <= 0)
            {
                return;
            }

            // Copy/blend bytes
            int    ItStride = img.Width * 4;
            IntPtr ItPtr    = img.BLoc;

            ItPtr += (leftCutOff * 4);
            ItPtr += (topCutOff * img.Stride);
            IntPtr ptrMe = BLoc + (X * 4) + (Y * Stride);

            ItPtr += (leftCutOff * 4);
            ItPtr += (topCutOff * img.Stride);

            for (int iY = 0; iY < dHeight; iY++)
            {
                byte *pMe = (byte *)ptrMe;
                byte *pIt = (byte *)ItPtr;
                for (int iX = 0; iX < dWidth; iX++)
                {
                    // Values for loop
                    double a      = (double)pIt[3] / 255.0;
                    double alpha1 = 1 - a;

                    // newC = (1 - A)*oldC + ovrCA
                    pMe[0] = (byte)(pMe[0] * alpha1 + pIt[0] * a);
                    pMe[1] = (byte)(pMe[1] * alpha1 + pIt[1] * a);
                    pMe[2] = (byte)(pMe[2] * alpha1 + pIt[2] * a);

                    pMe += 4;
                    pIt += 4;
                }
                ptrMe += Stride;
                ItPtr += ItStride;
            }
        }