示例#1
0
 /// <summary>
 /// A protected method to return a new particle pixel with the randomized color attributes.
 /// </summary>
 /// <returns>A new particle pixel with the new color values.</returns>
 protected override SdlDotNet.Particles.BaseParticle CreateParticle()
 {
     ParticlePixel p = new ParticlePixel();
     p.Color = Color.FromArgb(
         Random.Next(m_MinR, m_MaxR),
         Random.Next(m_MinG, m_MaxG),
         Random.Next(m_MinB, m_MaxB));
     return p;
 }
示例#2
0
        /// <summary>
        /// Run the application
        /// </summary>
        public void Go()
        {

            // Make the particle emitter.
            emit = new ParticleRectangleEmitter(particles);
            emit.Frequency = 50000; // 100000 every 1000 updates.
            emit.LifeFullMin = 20;
            emit.LifeFullMax = 50;
            emit.LifeMin = 10;
            emit.LifeMax = 30;
            emit.DirectionMin = -2; // shoot up in radians.
            emit.DirectionMax = -1;
            emit.ColorMin = Color.DarkBlue;
            emit.ColorMax = Color.LightBlue;
            emit.SpeedMin = 5;
            emit.SpeedMax = 20;
            emit.MaxSize = new SizeF(5, 5);
            emit.MinSize = new SizeF(1, 1);

            // Make the first particle (a pixel)
            ParticlePixel first = new ParticlePixel(Color.White, 100, 200, new Vector(0, 0, 0), -1);
            particles.Add(first); // Add it to the system

            if (File.Exists(Path.Combine(dataDirectory, "marble1.png")))
            {
                filePath = "";
            }

            // Make the second particle (an animated sprite)
            AnimationCollection anim = new AnimationCollection();
            SurfaceCollection surfaces = new SurfaceCollection();
            surfaces.Add(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png")), new Size(50, 50));
            anim.Add(surfaces, 1);
            AnimatedSprite marble = new AnimatedSprite(anim);
            marble.Animate = true;
            ParticleSprite second = new ParticleSprite(marble, 200, 200, new Vector(-7, -9, 0), 500);
            second.Life = -1;
            particles.Add(second); // Add it to the system

            // Add some manipulators to the particle system.
            ParticleGravity grav = new ParticleGravity(0.5f);
            particles.Manipulators.Add(grav); // Gravity of 0.5f
            particles.Manipulators.Add(new ParticleFriction(0.1f)); // Slow down particles
            particles.Manipulators.Add(vort); // A particle vortex fixed on the mouse
            particles.Manipulators.Add(new ParticleBoundary(SdlDotNet.Graphics.Video.Screen.Size)); // fix particles on screen.


            Events.Run();
        }
示例#3
0
        public void Draw()
        {
            //Clear screen (not very clean, must find a better way)
            ScreenManager.MainScreen.Fill (Color.Black);
            if (ConfigurationSettings.AppSettings ["AnimatedStarsBackground"] == "true") {
                //First draw the stars background
                pixels.Fill (Color.Black);
                lstPixels.Clear ();
                for (int i=0; i<512; i++) {

                    //move the star closer
                    starsZ [i] = (float)(starsZ [i] - (starsZV [i] * animationSpeed));

                    if ((starsScreenX [i] < 0 ||
                        starsScreenX [i] > ScreenManager.MainScreen.Width ||
                        starsScreenY [i] < 0 ||
                        starsScreenY [i] > ScreenManager.MainScreen.Height) ||
                        starsZ [i] < 1) {
                        starsX [i] = rand.Next (-1000, 1000);
                        starsY [i] = rand.Next (-1000, 1000);
                        starsZ [i] = rand.Next (400, 1000);
                        starsZV [i] = rand.Next (1, 8);
                    }

                    //calculate screen coordinates
                    starsScreenX [i] = Convert.ToInt32 (starsX [i] / starsZ [i] * 100 + (ScreenManager.MainScreen.Width / 2));
                    starsScreenY [i] = Convert.ToInt32 (starsY [i] / starsZ [i] * 100 + (ScreenManager.MainScreen.Height / 2));
                    string hexStarsColors = ConfigurationSettings.AppSettings ["HexaRGBStarsColor"];
                    string hexR = hexStarsColors.Substring (0, 2);
                    string hexG = hexStarsColors.Substring (2, 2);
                    string hexB = hexStarsColors.Substring (4, 2);

                    double maxR = Convert.ToDouble (int.Parse (hexR, System.Globalization.NumberStyles.HexNumber));
                    double maxV = Convert.ToDouble (int.Parse (hexG, System.Globalization.NumberStyles.HexNumber));
                    double maxB = Convert.ToDouble (int.Parse (hexB, System.Globalization.NumberStyles.HexNumber));
                    double maxRVB = 255;
                    double ratioR = maxR / maxRVB;
                    double ratioV = maxV / maxRVB;
                    double ratioB = maxB / maxRVB;
                    int colorR = Convert.ToInt32 (maxR - (ratioR * ((int)starsZ [i] * 0.255)));
                    int colorV = Convert.ToInt32 (maxV - (ratioV * ((int)starsZ [i] * 0.255)));
                    int colorB = Convert.ToInt32 (maxB - (ratioB * (int)starsZ [i] * 0.255));
                    //180-240-255
                    ParticlePixel pp = new ParticlePixel (Color.FromArgb (colorR, colorV, colorB), starsScreenX [i], starsScreenY [i]);
                    pp.Render (pixels);
                    lstPixels.Add (pp);
                }
                ScreenManager.MainScreen.Blit (pixels, new Point (0, 0));
            } else {
                ScreenManager.MainScreen.Blit (sfBackgroundImage, new Point (0, 0));
            }

            ScreenManager.MainScreen.Blit (_sfTitle, _ptTitle);
            switch (currentEmulator) {
            case 0:
                sfPlatefromName = new Surface (ConfigurationSettings.AppSettings ["MameLogo"]);
                break;
            case 1:
                sfPlatefromName = new Surface (ConfigurationSettings.AppSettings ["SnesLogo"]);
                break;
            }
            string txtNbRoms = "";
            if (gameList.Count <= 1)
                txtNbRoms = Convert.ToString(gameList.Count) + " rom";
            else
                txtNbRoms = Convert.ToString(gameList.Count) + " roms";
            sfNbRoms = new Surface(font24.Render(txtNbRoms,Color.White));
            ScreenManager.MainScreen.Blit (sfNbRoms, new Point (((ScreenManager.MainScreen.Width - sfNbRoms.Width) / 2), 250));
            //sfPlatefromName = fontXXL.Render (emulators [currentEmulator], Color.White);
            ScreenManager.MainScreen.Blit (sfPlatefromName, new Point (Convert.ToInt32 ((ScreenManager.MainScreen.Width - sfPlatefromName.Width) / 2), 150));

            int currentGame = 0;
            foreach (Surface s in itemList) {
                s.Dispose ();
            }
            itemList.Clear ();

            //items vides début
            int emptyLines = 0;
            if (currentIndex < 10) {
                for (int i=0; i<10-currentIndex; i++) {
                    switch (itemList.Count)
                    {
                    case 0:
                        itemList.Add (font8.Render (" ", Color.White));
                        break;
                    case 1:
                        itemList.Add (font10.Render (" ", Color.White));
                        break;
                    case 2:
                        itemList.Add (font12.Render (" ", Color.White));
                        break;
                    case 3:
                        itemList.Add (font14.Render (" ", Color.White));
                        break;
                    case 4:
                        itemList.Add (font16.Render (" ", Color.White));
                        break;
                    case 5:
                        itemList.Add (font18.Render (" ", Color.White));
                        break;
                    case 6:
                        itemList.Add (font20.Render (" ", Color.White));
                        break;
                    case 7:
                        itemList.Add (font24.Render (" ", Color.White));
                        break;
                    case 8:
                        itemList.Add (font28.Render (" ", Color.White));
                        break;
                    case 9:
                        itemList.Add (font32.Render (" ", Color.White));
                        break;
                    }

                    ScreenManager.MainScreen.Blit (itemList [itemList.Count - 1], new Point (itemX[itemList.Count - 1], itemY[itemList.Count - 1]));
                    emptyLines++;
                }
            }
            foreach (Game g in gameList) {

                //We need to show 21 products
                //Selected product is always in the middle of the list
                // We can have 10 empty items when at the begining or the end of the list
                //So we display 10 items in top of the selected item and 10 at the bottom
                if (currentGame >= currentIndex - 10 && currentGame < (currentIndex + 11)) {
                    if (currentGame == currentIndex) {
                        //Selected Item
                        string hexStarsColors = ConfigurationSettings.AppSettings ["HexaRGBSelectedItemColor"];
                        string hexSelectedItemR = hexStarsColors.Substring (0, 2);
                        string hexSelectedItemG = hexStarsColors.Substring (2, 2);
                        string hexSelectedItemB = hexStarsColors.Substring (4, 2);

                        itemList.Add (font40.Render (g.gameName, Color.FromArgb (int.Parse (hexSelectedItemR, System.Globalization.NumberStyles.HexNumber), int.Parse (hexSelectedItemG, System.Globalization.NumberStyles.HexNumber), int.Parse (hexSelectedItemB, System.Globalization.NumberStyles.HexNumber))));
                        sfGameName = fontXL.Render (g.gameName, Color.White);
                        sfGameGenre = fontNormal.Render (g.genre, Color.White);
                        sfGameDeveloperYear = fontNormal.Render (g.developer + " " + g.year, Color.White);
                        ScreenManager.MainScreen.Blit (sfGameName, new Point (ScreenManager.MainScreen.Width - (sfGameName.Width + 20), 294));
                        ScreenManager.MainScreen.Blit (sfGameGenre, new Point (ScreenManager.MainScreen.Width - (sfGameGenre.Width + 20), 330));
                        ScreenManager.MainScreen.Blit (sfGameDeveloperYear, new Point (ScreenManager.MainScreen.Width - (sfGameDeveloperYear.Width + 20), 360));
                        ScreenManager.MainScreen.Blit (itemList [itemList.Count - 1], new Point (itemX[itemList.Count - 1], itemY[itemList.Count - 1]));

                        //Load image
                        //Check roms present in rom folder and return the list with extra infos
                        DirectoryInfo di;
                        FileInfo[] rgFiles;
                        switch (currentEmulator) {
                        case 0:
                            di = new DirectoryInfo (ConfigurationSettings.AppSettings ["MameCovers"]);

                            try {
                                rgFiles = di.GetFiles (g.filename + ".png");
                                if (rgFiles.Length > 0) {
                                    sfGameImage = new Surface (ConfigurationSettings.AppSettings ["MameCovers"] + "\\" + g.filename + ".png");
                                    ScreenManager.MainScreen.Blit (sfGameImage, new Point (ScreenManager.MainScreen.Width - (sfGameImage.Width + 20), 420));
                                }
                            } catch (Exception ex) {

                            }

                            break;
                        case 1:
                            di = new DirectoryInfo (ConfigurationSettings.AppSettings ["SnesCovers"]);
                            if (!string.IsNullOrEmpty (g.gameName) && !string.IsNullOrEmpty (g.region)) {
                                try {
                                    rgFiles = di.GetFiles (g.gameName + " (" + g.region + ").png");
                                    if (rgFiles.Length > 0) {
                                        sfGameImage = new Surface (ConfigurationSettings.AppSettings ["SnesCovers"] + "\\" + g.gameName + " (" + g.region + ").png");
                                        ScreenManager.MainScreen.Blit (sfGameImage, new Point (ScreenManager.MainScreen.Width - (sfGameImage.Width + 20), 420));
                                    }
                                } catch (Exception ex) {
                                    //file does not exists
                                }

                            }

                            break;
                        }
                    } else {
                        //Other items
                        switch (itemList.Count)
                        {
                        case 0:
                        case 20:
                            itemList.Add (font8.Render (g.gameName, Color.White));
                            break;
                        case 1:
                        case 19:
                            itemList.Add (font10.Render (g.gameName, Color.White));
                            break;
                        case 2:
                        case 18:
                            itemList.Add (font12.Render (g.gameName, Color.White));
                            break;
                        case 3:
                        case 17:
                            itemList.Add (font14.Render (g.gameName, Color.White));
                            break;
                        case 4:
                        case 16:
                            itemList.Add (font16.Render (g.gameName, Color.White));
                            break;
                        case 5:
                        case 15:
                            itemList.Add (font18.Render (g.gameName, Color.White));
                            break;
                        case 6:
                        case 14:
                            itemList.Add (font20.Render (g.gameName, Color.White));
                            break;
                        case 7:
                        case 13:
                            itemList.Add (font24.Render (g.gameName, Color.White));
                            break;
                        case 8:
                        case 12:
                            itemList.Add (font28.Render (g.gameName, Color.White));
                            break;
                        case 9:
                        case 11:
                            itemList.Add (font32.Render (g.gameName, Color.White));
                            break;
                        }
                        ScreenManager.MainScreen.Blit (itemList [itemList.Count - 1], new Point (itemX[itemList.Count - 1], (itemY[itemList.Count - 1])));
                    }
                    //3 cases
                    //currentIndex < 5 must show emtpy items
                    //currentIndex >= 5 && currentIndex <= (gameList.Length - 5)
                    //currentIndex > (gameList.Length - 5) must show emtpy items
                    /*
                if (currentGame >= currentIndex && currentGame < currentIndex + displayedItems) {

                    if (currentGame == currentIndex) {
                        //Selected Item
                        string hexStarsColors = ConfigurationSettings.AppSettings ["HexaRGBSelectedItemColor"];
                        string hexSelectedItemR = hexStarsColors.Substring (0, 2);
                        string hexSelectedItemG = hexStarsColors.Substring (2, 2);
                        string hexSelectedItemB = hexStarsColors.Substring (4, 2);

                        itemList.Add (fontLarge.Render (g.gameName, Color.FromArgb (int.Parse (hexSelectedItemR, System.Globalization.NumberStyles.HexNumber), int.Parse (hexSelectedItemG, System.Globalization.NumberStyles.HexNumber), int.Parse (hexSelectedItemB, System.Globalization.NumberStyles.HexNumber))));
                        sfGameName = fontXL.Render (g.gameName, Color.White);
                        sfGameGenre = fontNormal.Render (g.genre, Color.White);
                        sfGameDeveloperYear = fontNormal.Render (g.developer + " " + g.year, Color.White);
                        ScreenManager.MainScreen.Blit (sfGameName, new Point (ScreenManager.MainScreen.Width - (sfGameName.Width + 20), 294));
                        ScreenManager.MainScreen.Blit (sfGameGenre, new Point (ScreenManager.MainScreen.Width - (sfGameGenre.Width + 20), 330));
                        ScreenManager.MainScreen.Blit (sfGameDeveloperYear, new Point (ScreenManager.MainScreen.Width - (sfGameDeveloperYear.Width + 20), 360));
                        ScreenManager.MainScreen.Blit (itemList [currentGame - currentIndex], new Point (startX, startY + ((currentGame - currentIndex) * lineSpacing) - 2));

                        //Load image
                        //Check roms present in rom folder and return the list with extra infos
                        DirectoryInfo di;
                        FileInfo[] rgFiles;
                        switch (currentEmulator) {
                        case 0:
                            di = new DirectoryInfo (ConfigurationSettings.AppSettings ["MameCovers"]);

                            try {
                                rgFiles = di.GetFiles (g.filename + ".png");
                                if (rgFiles.Length > 0) {
                                    sfGameImage = new Surface (ConfigurationSettings.AppSettings ["MameCovers"] + "\\" + g.filename + ".png");
                                    ScreenManager.MainScreen.Blit (sfGameImage, new Point (ScreenManager.MainScreen.Width - (sfGameImage.Width + 20), 420));
                                }
                            } catch (Exception ex) {

                            }

                            break;
                        case 1:
                            di = new DirectoryInfo (ConfigurationSettings.AppSettings ["SnesCovers"]);
                            if (!string.IsNullOrEmpty (g.gameName) && !string.IsNullOrEmpty (g.region)) {
                                try {
                                    rgFiles = di.GetFiles (g.gameName + " (" + g.region + ").png");
                                    if (rgFiles.Length > 0) {
                                        sfGameImage = new Surface (ConfigurationSettings.AppSettings ["SnesCovers"] + "\\" + g.gameName + " (" + g.region + ").png");
                                        ScreenManager.MainScreen.Blit (sfGameImage, new Point (ScreenManager.MainScreen.Width - (sfGameImage.Width + 20), 420));
                                    }
                                } catch (Exception ex) {
                                    //file does not exists
                                }

                            }

                            break;
                        }
                    } else {
                        //Other items
                        itemList.Add (fontNormal.Render (g.gameName, Color.White));
                        ScreenManager.MainScreen.Blit (itemList [currentGame - currentIndex], new Point (startX, startY + ((currentGame - currentIndex) * lineSpacing)));
                    }
                }*/

                }
                currentGame++;
            }
            /*
            //Add empty items i needed
            if (itemList.Count < 9) {
                for (int i=0; i<9-itemList.Count;i++)
                {
                    itemList.Add (fontNormal.Render ("empty", Color.White));
                    ScreenManager.MainScreen.Blit (itemList [itemList.Count-1], new Point (startX, startY + ((itemList.Count-1) * lineSpacing)));
                }
            }
            */

            if ((SdlDotNet.Core.Timer.TicksElapsed - time) < 40) {
                System.Threading.Thread.Sleep (40 - (SdlDotNet.Core.Timer.TicksElapsed - time));
            }

            int fps = 1000 / (SdlDotNet.Core.Timer.TicksElapsed - time);
            time = SdlDotNet.Core.Timer.TicksElapsed;
            sfFPS = fontNormal.Render (Convert.ToString (fps) + " fps", Color.White);
            ScreenManager.MainScreen.Blit (sfFPS, new Point (ScreenManager.MainScreen.Width - (sfFPS.Width + 20), 20));

            ScreenManager.MainScreen.Blit (sfErrorBackground, new Point (((ScreenManager.MainScreen.Width - sfErrorBackground.Width) / 2), 250));
        }