예제 #1
0
        public PlayerShot(EPointF pntStart)
        {
            this.Velocity = new EPointF(0, -4);
            this.Loc      = pntStart;

            string anim = "PlayerShot";

            if (!EH.Instance.CastLib.FrameSets.Exists(anim))
            {
                PicRef.CreatePicRefs("SpaceInv\\PlayerShot", 2, 2);
            }
            Endogine.Animation.BhAnimator an = new Endogine.Animation.BhAnimator(this, anim);

            this.Color = GameMain.Instance.m_clrOffwhite;
            //TODO: never disposed properly
        }
예제 #2
0
        public Bitmap LoadIntoBitmap(string a_sFilename)         //, ref string actualFilename)
        {
            //string sOrg = a_sFilename; //for debugging
            //a_sFilename = m_endogine.CastLib.FindFile(a_sFilename);
            a_sFilename = AppSettings.Instance.FindFile(a_sFilename);
            if (a_sFilename.Length == 0)
            {
                if (true)                 // || m_endogine.CastLib.UseDummiesForFilesNotFound)
                {
                    //TODO: generalized dummy function
                    a_sFilename = m_endogine.CastLib.DirectoryPath + "Cross.bmp";
                }
            }

            System.IO.FileInfo finfo = new System.IO.FileInfo(a_sFilename);

            Name         = finfo.Name.Replace(finfo.Extension, "");
            FileFullName = a_sFilename;


            if (!finfo.Exists)
            {
                throw new System.IO.FileNotFoundException("Member file not found: " + a_sFilename);
            }


            //TODO: only allow >= 24 bpp PixelFormat.Format8bppIndexed - otherwise convert!

            Bitmap bmpDst        = null;
            bool   bStandardLoad = true;

            if (a_sFilename.IndexOf(".gif") > 0)
            {
                Image img = System.Drawing.Image.FromFile(a_sFilename);
                System.Drawing.Imaging.FrameDimension oDimension = new System.Drawing.Imaging.FrameDimension(img.FrameDimensionsList[0]);
                int nNumFrames = img.GetFrameCount(oDimension);

                //calc how big the destination bitmap must be (make it as square as possible)
                //TODO: it's OK if there's a few uninhabited tiles at end?
                int nNumFramesOnX = (int)Math.Sqrt(nNumFrames);
                for (; nNumFramesOnX > 0; nNumFramesOnX--)
                {
                    if (nNumFrames / nNumFramesOnX * nNumFramesOnX == nNumFrames)
                    {
                        break;
                    }
                }

                bmpDst = new Bitmap(
                    img.Size.Width * nNumFramesOnX, img.Size.Height * nNumFrames / nNumFramesOnX,
                    PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(bmpDst);

                if (nNumFrames > 1)
                {
                    bStandardLoad = false;
                    //TODO: let picRefs handle the generation animation...
                    for (int i = 0; i < nNumFrames; i++)
                    {
                        int x = i % nNumFramesOnX;
                        int y = i / nNumFramesOnX;
                        img.SelectActiveFrame(oDimension, i);
                        ERectangle rctDst = new ERectangle(x * img.Size.Width, y * img.Size.Height, img.Size.Width, img.Size.Height);
                        g.DrawImageUnscaled(img, rctDst.X, rctDst.Y, rctDst.Width, rctDst.Height);
                    }
                    g.Dispose();
                    this.m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height);

                    this.m_bGotAnimation = true;
                    PicRef.CreatePicRefs(this, nNumFramesOnX, nNumFrames);
                    //AnimateWithinSize = new EPoint(img.Size.Width, img.Size.Height);
                }
                img.Dispose();
            }

            if (!bStandardLoad)
            {
            }
            else
            {
                bmpDst = (Bitmap)System.Drawing.Bitmap.FromFile(a_sFilename);
            }

            m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height);

            m_bmpThumbnail = new Bitmap(32, 32, PixelFormat.Format24bppRgb);
            Graphics g2 = Graphics.FromImage(m_bmpThumbnail);

            g2.DrawImage(bmpDst, 0, 0, m_bmpThumbnail.Width, m_bmpThumbnail.Height);
            g2.Dispose();

            this.LoadResourceFile(a_sFilename);

            return(bmpDst);
        }
예제 #3
0
        private void LoadResourceFile(string sPicFile)
        {
            System.IO.FileInfo finfo    = new System.IO.FileInfo(sPicFile);
            string             sResInfo = finfo.FullName.Replace(finfo.Extension, "") + ".xml";

            //TODO: switch to XmlSerializer!

            if (!System.IO.File.Exists(sResInfo))
            {
                return;
            }

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(sResInfo);
            System.Xml.XmlNode node = doc.FirstChild.SelectSingleNode("RegPoint");
            if (node != null)
            {
                this.m_pntRegPoint = this.ParseRegPoint(Serialization.XmlHelper.GetValueOrInnerText(node), this.Size);
                //this.m_pntRegPoint = new EPoint(Serialization.XmlHelper.GetValueOrInnerText(node));
            }


            node = doc.FirstChild.SelectSingleNode("NumFramesTotal");
            int numFramesTotal = 0;

            if (node != null)
            {
                numFramesTotal = Convert.ToInt32(Serialization.XmlHelper.GetValueOrInnerText(node));
            }

            int numFramesOnX = 0;

            node = doc.FirstChild.SelectSingleNode("NumFramesOnX");
            if (node != null)
            {
                numFramesOnX = Convert.ToInt32(Serialization.XmlHelper.GetValueOrInnerText(node)); //GetValueOrInnerText
            }
            List <PicRef> picRefs = null;

            if (numFramesTotal > 0)
            {
                this.m_bGotAnimation = true;
                picRefs = PicRef.CreatePicRefs(sPicFile, numFramesOnX, numFramesTotal);
            }
            else
            {
                picRefs = new List <PicRef>();
                PicRef pr = PicRef.Create((MemberSpriteBitmap)this, this.Name);
                pr.SourceRectangle = new ERectangle(0, 0, this.Size.X, this.Size.Y);
                picRefs.Add(pr);
            }

            node = doc.FirstChild.SelectSingleNode("RegPoint");
            if (node != null)
            {
                if (picRefs != null)
                {
                    EPoint ptReg = this.ParseRegPoint(Serialization.XmlHelper.GetValueOrInnerText(node), picRefs[0].SourceRectangle.Size);
                    foreach (PicRef pr in picRefs)
                    {
                        pr.Offset = ptReg;
                    }
                }
            }

            node = doc.FirstChild.SelectSingleNode("Animations");
            //TODO: add to animations library
            //if (node!=null)
            //    this._animations = Endogine.Animation.AnimationHelpers.ParseAnimations(node);
            //TODO: optionally load animations from other files.
        }