Ejemplo n.º 1
0
 public PicRef this[char c]
 {
     get
     {
         if (this._definedCharacters.IndexOf(c) == -1)
         {
             this._definedCharacters += c.ToString();
         }
         return(PicRef.Get(GetPrefix(this._font) + "_" + c.ToString()));
     }
 }
Ejemplo n.º 2
0
        public Player(GameMain a_gameMain)
        {
            m_gameMain = a_gameMain;

            this.Name     = "Player";
            m_fAngleStep  = (float)(5.0 * Math.PI / 180);
            MemberName    = "Ship";
            this.RegPoint = (this.Member.Size.ToEPointF() * 0.5f).ToEPoint();

            #region Set up particle system (for thrusters)
            m_particleSystem = new Endogine.ParticleSystem.ParticleEmitter();
            //m_particleSystem.Parent = this;
            m_particleSystem.LocZ = LocZ - 1;

            SortedList aColors = new SortedList();
            aColors.Add(0.0, System.Drawing.Color.FromArgb(255, 255, 0));
            aColors.Add(0.5, System.Drawing.Color.FromArgb(255, 0, 0));
            aColors.Add(1.0, System.Drawing.Color.FromArgb(0, 0, 0));
            m_particleSystem.SetColorList(aColors);

            SortedList aSizes = new SortedList();
            aSizes.Add(0.0, 1.0);
            aSizes.Add(1.0, 0.0);
            m_particleSystem.SetSizeList(aSizes);

            m_particleSystem.MaxParticles            = 100;
            m_particleSystem.NumNewParticlesPerFrame = 0;

            m_fThrustParticles = 2;

            m_particleSystem.Gravity  = 0;
            m_particleSystem.Speed    = 5;
            m_particleSystem.SizeFact = 0.3f;

            m_particleSystem.ParticlePicRef = PicRef.GetOrCreate("Particle");
            m_particleSystem.SourceRect     = new ERectangle(0, 0, 10, 10);
            m_particleSystem.RegPoint       = new EPoint(5, 5);
            m_particleSystem.LocZ           = 100;
            #endregion

            #region Keys setup
            m_keysSteering = new KeysSteering();
            this.m_keysSteering.AddKeyPreset(KeysSteering.KeyPresets.ArrowsSpace);
            this.m_keysSteering.AddKeyPreset(KeysSteering.KeyPresets.awsdCtrlShift);
            this.m_keysSteering.AddPair("left", "right");
            this.m_keysSteering.AddPair("up", "down");
            //m_keysSteering.ReceiveEndogineKeys(m_endogine);
            m_keysSteering.KeyEvent += new KeyEventHandler(m_keysSteering_KeyEvent);
            #endregion
        }
Ejemplo n.º 3
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
        }
Ejemplo n.º 4
0
        public int GetKerningBetween(char c1, char c2)
        {
            PicRef p1 = this[c1];

            if (p1 == null)
            {
                return(0);
            }
            PicRef p2 = this[c2];

            if (p2 == null)
            {
                return(0);
            }
            int kern = CalcKerningBetween(this.GetProfile(c1), this.GetProfile(c2), p1.Offset.Y - p2.Offset.Y);

            return(kern);
        }
Ejemplo n.º 5
0
        public GameMain()
        {
            Instance = this;

            string path = AppSettings.Instance.GetPath("Media") + "SpaceInv";

            AppSettings.Instance.AddPath("Media", path);
            PicRef.ScanDirectory(path);

            this.m_clrOffwhite = System.Drawing.Color.FromArgb(214, 181, 140);

            this.m_interfaceSprites = new ArrayList();

            this.m_score = new Score();

            this.m_livesLeft = new LivesLeft();

            Sprite sp = new Sprite();

            sp.SetGraphics("Screen");
            sp.LocZ = 500;
            sp.Ink  = RasterOps.ROPs.AddPin;
            this.m_interfaceSprites.Add(sp);

            this.AddColorizers();


            this.m_covers = new ArrayList();
            Cover cover;

            for (int nCoverNum = 0; nCoverNum < 4; nCoverNum++)
            {
                cover     = new Cover();
                cover.Loc = new EPointF(170 + 90 + (nCoverNum - 1) * 90, 369);
                this.m_covers.Add(cover);
            }

            ERectangleF rctPlayArea = ERectangleF.FromLTRB(155, 20, 550, 400);          //new ERectangleF(145,10,350,200); //155 550

            this.m_invadersGrid = new InvadersGrid();

            //ERectangleF rctPlayerConstraints = rctPlayArea+ERectangleF.FromLTRB(-10,0,-55,0);
            this.m_player = new Player();
        }
Ejemplo n.º 6
0
        public List <EPointF> GenerateLocList(string text, int maxWidth, float kerningStrength, float lineSpacingFactor)
        {
            List <EPointF> locs = new List <EPointF>();

            //TODO: only works for certain charsets!!
            int bottomOfG  = this['g'].SourceRectangle.Height - this['g'].Offset.Y;
            int topOfAuml  = -this['Å'].Offset.Y;
            int lineHeight = bottomOfG - topOfAuml;

            lineHeight = (int)(lineSpacingFactor * lineHeight);

            float   extraSpace = 0;
            EPointF loc        = new EPointF(0, 0);

            for (int i = 0; i < text.Length; i++)
            {
                PicRef p = this[text[i]];
                if (p == null)
                {
                    loc.X += 0.2f * lineHeight; //TODO: define space width!
                    locs.Add(loc.Copy());
                    loc.X += extraSpace;
                }
                else
                {
                    int kern = 0;
                    if (i > 0)
                    {
                        kern = this.GetKerningBetween(text[i - 1], text[i]);
                    }
                    loc.X -= kerningStrength * kern;
                    locs.Add(loc.Copy());
                    loc.X += (int)p.SourceRectangle.Width + extraSpace;
                }
                if (loc.X > maxWidth)
                {
                    //TODO: go back to last whitespace or hypen and break there
                    loc.Y += lineHeight;
                    loc.X  = 0;
                }
            }
            return(locs);
        }
Ejemplo n.º 7
0
        public static Dictionary <char, int[, ]> CreatePicRefs(Font font, string characters, List <object> pensAndBrushes)
        {
            Bitmap[]     bitmaps = FontGenerator.Generate(font, characters, pensAndBrushes);
            ERectangle[] rects;
            EPoint[]     offsets;

            Bitmap bmpLarge = Endogine.BitmapHelpers.TexturePacking.TreePack(bitmaps, out rects, out offsets);             //.PackBitmapsIntoOneLarge(trimmedBmps, null, out node);

            Dictionary <char, int[, ]> profiles = new Dictionary <char, int[, ]>();

            for (int i = 0; i < bitmaps.Length; i++)
            {
                Bitmap bmp = bitmaps[i];
                int[,] profile = GetProfile(bmp);
                profiles.Add(characters[i], profile);
            }

            MemberSpriteBitmap mb   = new MemberSpriteBitmap(bmpLarge);
            string             name = GetPrefix(font);

            mb.Name = name;

            string[] names = new string[characters.Length];
            for (int i = 0; i < characters.Length; i++)
            {
                names[i] = ((int)characters[i]).ToString();
            }

            //bmpLarge.Save("_fonttest.png");
            //Endogine.BitmapHelpers.TexturePacking.CreateDocFromRectsAndOffsets(rects, offsets, names).Save("_fonttest.xml");

            for (int i = 0; i < bitmaps.Length; i++)
            {
                PicRef pic = new PicRef(name + "_" + characters.Substring(i, 1), mb);
                pic.Offset          = new EPoint(0, offsets[i].Y);       //Ignore the X offset
                pic.SourceRectangle = rects[i];
                //EH.Instance.CastLib.Pictures.AddPicture(pic);
            }

            return(profiles);
        }
Ejemplo n.º 8
0
        private void miParticle_Click(object sender, System.EventArgs e)
        {
            if (m_particleControl == null)
            {
                //MemberSpriteBitmap mbParticle = (MemberSpriteBitmap)EndogineHub.Instance.CastLib.GetOrCreate("Particle");
                //mbParticle.CenterRegPoint();

                m_particleSystem = new FunParticleSystem();
                m_particleSystem.ParticlePicRef = PicRef.GetOrCreate("Particle");
                m_particleSystem.Ink            = RasterOps.ROPs.AddPin;        //Difference looks nice (only works properly in GDI mode);
                m_particleSystem.SourceRect     = new ERectangle(0, 0, 50, 50); //how big is the emitter
                m_particleSystem.LocZ           = 100;

                m_particleControl = new ParticleControl(m_particleSystem);
            }
            else
            {
                m_particleControl.Dispose();
                m_particleControl = null;

                m_particleSystem.Dispose();
            }
        }
Ejemplo n.º 9
0
        public override void EnterFrame()
        {
            if (m_explosion != null)
            {
                m_nExplodingFrame++;
                if (m_nExplodingFrame <= 5)
                {
                    m_explosion.NumNewParticlesPerFrame = 1.0f * (1.0f - (float)m_nExplodingFrame / 5);
                }
                m_explosion.Loc = this.Loc;

//				m_explosion.Dispose();
//				m_explosion = null;
            }
            if (m_smoke != null)
            {
                m_smoke.Loc = this.Loc;
            }

            if (!m_bDying)
            {
                if (m_keysSteering.GetKeyActive("up"))
                {
                    this.Velocity -= m_pntGravity * 2;
                }
            }
            this.Velocity += m_pntGravity;

            base.EnterFrame();

            if (GameMain.Instance.CaveWalls.CheckCollision(this) || GameMain.Instance.Obstacles.CheckCollision(this))
            {
                if (m_explosion == null)
                {
                    m_explosion                 = new Endogine.ParticleSystem.ParticleEmitter();
                    m_explosion.Rect            = new ERectangleF(0, 0, 20, 20);
                    m_explosion.SprayangleRange = (float)Math.PI * 2;
                    m_explosion.AddedVelocity.X = this.Velocity.X;
                    m_explosion.Speed           = 5;
                    m_explosion.Gravity         = m_pntGravity.Y;
                    //MemberSpriteBitmap mbParticle = (MemberSpriteBitmap)EndogineHub.Instance.CastLib.GetOrCreate("Particle");
                    //mbParticle.CenterRegPoint();
                    m_explosion.ParticlePicRef = PicRef.GetOrCreate("Particle");

                    SortedList aColors = new SortedList();
                    aColors.Add(0.0, System.Drawing.Color.FromArgb(255, 255, 0));
                    aColors.Add(0.5, System.Drawing.Color.FromArgb(255, 0, 0));
                    aColors.Add(1.0, System.Drawing.Color.FromArgb(0, 0, 0));
                    m_explosion.SetColorList(aColors);

                    SortedList aSizes = new SortedList();
                    aSizes.Add(0.0, 0.3);
                    m_explosion.SetSizeList(aSizes);

                    m_explosion.NumNewParticlesPerFrame = 10;
                }
                m_explosion.Loc = this.Loc;
                if (m_nExplodingFrame > 6)
                {
                    m_explosion.NumNewParticlesPerFrame = 10;
                }
                m_nExplodingFrame = 1;

                this.LocY       -= this.Velocity.Y * 2;
                this.Velocity.Y *= -0.7f;

                if (!m_bDying)
                {
                    m_bDying = true;

                    m_smoke = new Endogine.ParticleSystem.ParticleEmitter();
                    m_smoke.ParticlePicRef          = PicRef.GetOrCreate("Particle");
                    m_smoke.Rect                    = new ERectangleF(0, 0, 20, 20);
                    m_smoke.SprayangleRange         = (float)Math.PI * 2;
                    m_smoke.AddedVelocity.Y         = -1;
                    m_smoke.Speed                   = 0;
                    m_smoke.Gravity                 = 0;
                    m_smoke.NumNewParticlesPerFrame = 0.4f;

                    SortedList aColors = new SortedList();
                    aColors.Add(0.0, System.Drawing.Color.FromArgb(127, 127, 127));
                    aColors.Add(1.0, System.Drawing.Color.FromArgb(0, 0, 0));
                    m_smoke.SetColorList(aColors);

                    SortedList aSizes = new SortedList();
                    aSizes.Add(0.0, 1.0);
                    m_smoke.SetSizeList(aSizes);
                }
            }
        }
Ejemplo n.º 10
0
        public static Dictionary<char, int[, ]> CreatePicRefs(Font font, string characters, List<object> pensAndBrushes)
        {
            Bitmap[] bitmaps = FontGenerator.Generate(font, characters, pensAndBrushes);
            ERectangle[] rects;
            EPoint[] offsets;

            Bitmap bmpLarge = Endogine.BitmapHelpers.TexturePacking.TreePack(bitmaps, out rects, out offsets); //.PackBitmapsIntoOneLarge(trimmedBmps, null, out node);

            Dictionary<char, int[,]> profiles = new Dictionary<char, int[,]>();
            for (int i=0; i<bitmaps.Length; i++)
            {
                Bitmap bmp = bitmaps[i];
                int[,] profile = GetProfile(bmp);
                profiles.Add(characters[i], profile);
            }

            MemberSpriteBitmap mb = new MemberSpriteBitmap(bmpLarge);
            string name = GetPrefix(font);
            mb.Name = name;

            string[] names = new string[characters.Length];
            for (int i=0; i<characters.Length;i++)
                names[i] = ((int)characters[i]).ToString();

            //bmpLarge.Save("_fonttest.png");
            //Endogine.BitmapHelpers.TexturePacking.CreateDocFromRectsAndOffsets(rects, offsets, names).Save("_fonttest.xml");

            for (int i=0; i<bitmaps.Length; i++)
            {
                PicRef pic = new PicRef(name+"_"+characters.Substring(i,1), mb);
                pic.Offset = new EPoint(0,offsets[i].Y); //Ignore the X offset
                pic.SourceRectangle = rects[i];
                //EH.Instance.CastLib.Pictures.AddPicture(pic);
            }

            return profiles;
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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.
        }