Example #1
0
        public SpriteSheet(string spriteSheetFilename, Color transparentColor, Size frameSize, int rotationPerFrameDeg, int firstFrameShipDirectionDeg, int rotationAnimationDelay, int cannonBarrelLength, int forwardThrusterEngineLength, int reverseThrusterEngineLength)
        {
            this.bitmap = new Bitmap(spriteSheetFilename);
            this.transparentColor = transparentColor;
            this.frameSize = frameSize;
            this.rotationPerFrameDeg = rotationPerFrameDeg;
            this.firstFrameShipDirectionDeg = firstFrameShipDirectionDeg;
            this.cannonBarrelLength = cannonBarrelLength;
            this.reverseThrusterEngineLength = reverseThrusterEngineLength;
            this.forwardThrusterEngineLength = forwardThrusterEngineLength;

            SurfaceCollection spriteSheet_SurfaceCollection = new SurfaceCollection();
            Surface spriteSheet_Surface = new Surface(this.bitmap).Convert(Video.Screen, true, false);

            spriteSheet_SurfaceCollection.Add(spriteSheet_Surface, this.frameSize);

            AnimationCollection animationCollection = new AnimationCollection();
            animationCollection.Add(spriteSheet_SurfaceCollection);
            animationCollection.Delay = rotationAnimationDelay;

            AnimatedSprite animatedSprite = new AnimatedSprite(animationCollection);

            animatedSprite.TransparentColor = this.transparentColor;
            animatedSprite.Transparent = true;

            this.animatedSprite = animatedSprite;
        }
        public static SurfaceCollection LoadSurfaces(string resourceName, Size tileSize)
        {
            SurfaceCollection ret = new SurfaceCollection();

            ret.AlphaBlending = true;

            using (Surface s = LoadSurface(resourceName))
            {
                for (int i = 0; i < s.Width; i += tileSize.Width)
                {
                    for (int j = 0; j < s.Height; j += tileSize.Height)
                    {
                        Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
                        ss.Transparent   = true;
                        ss.AlphaBlending = true;
                        Color[,] tmp     = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
                        ss.SetPixels(Point.Empty, tmp);
                        tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
                        ss.Update();
                        ret.Add(ss);
                    }
                }
            }
            return(ret);
        }
Example #3
0
        protected virtual void loadImages()
        {
            int[] tmp = { 0, 1, 2 };
            _playerSurfaces = ResourceManager.LoadSurfaces(
                Array.ConvertAll <int, string>(tmp, (i) => { return(string.Format(Constants.Filename_PlayerImage, i)); }));
            _playerSurfaces.Add(_playerSurfaces[1]);

            _explosionSurfaces = ResourceManager.LoadSurfaces(Constants.Filename_ExplosionImage, new Size(24, 24));
        }
Example #4
0
		public void TestImageLoad()
		{
			// Load the image
			SurfaceCollection id = new SurfaceCollection();
            id.Add(new Surface("../../../examples/SpriteGuiDemos/Data/marble1.png"));
			// Make sure the height and width match
			Assert.AreEqual(384, id.Size.Width);
			Assert.AreEqual(384, id.Size.Height);
		}
Example #5
0
 /// <summary>
 /// Loads a floor title into memory.
 /// </summary>
 protected static SurfaceCollection LoadFloor()
 {
     if (File.Exists(Path.Combine(dataDirectory, "floor-00.png")))
     {
         filePath = "";
     }
     SurfaceCollection id = new SurfaceCollection();
     id.Add(Path.Combine(filePath, Path.Combine(dataDirectory, "floor")), ".png");
     return id;
 }
Example #6
0
        public void TestImageLoad()
        {
            // Load the image
            SurfaceCollection id = new SurfaceCollection();

            id.Add(new Surface("../../../examples/SpriteGuiDemos/Data/marble1.png"));
            // Make sure the height and width match
            Assert.AreEqual(384, id.Size.Width);
            Assert.AreEqual(384, id.Size.Height);
        }
Example #7
0
        /// <summary>
        /// Loads a floor title into memory.
        /// </summary>
        protected static SurfaceCollection LoadFloor()
        {
            if (File.Exists(Path.Combine(dataDirectory, "floor-00.png")))
            {
                filePath = "";
            }
            SurfaceCollection id = new SurfaceCollection();

            id.Add(Path.Combine(filePath, Path.Combine(dataDirectory, "floor")), ".png");
            return(id);
        }
Example #8
0
        /// <summary>
        /// Loads the marble series into memory and returns the
        /// collection.
        /// </summary>
        protected static SurfaceCollection LoadMarble(string name)
        {
            if (File.Exists(Path.Combine(dataDirectory, name + ".png")))
            {
                filePath = "";
            }

            SurfaceCollection icd = new SurfaceCollection();
            icd.Add(Path.Combine(filePath, Path.Combine(dataDirectory, name + ".png")), new Size(50, 50));
            return icd;
        }
Example #9
0
        /// <summary>
        /// Loads the marble series into memory and returns the
        /// collection.
        /// </summary>
        protected static SurfaceCollection LoadMarble(string name)
        {
            if (File.Exists(Path.Combine(dataDirectory, name + ".png")))
            {
                filePath = "";
            }

            SurfaceCollection icd = new SurfaceCollection();

            icd.Add(Path.Combine(filePath, Path.Combine(dataDirectory, name + ".png")), new Size(50, 50));
            return(icd);
        }
Example #10
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();
        }
Example #11
0
        /// <summary>
        /// Loads a marble from a single image and tiles it.
        /// </summary>
        protected static SurfaceCollection LoadTiledMarble(string name)
        {
            if (File.Exists(Path.Combine(dataDirectory, name + ".png")))
            {
                filePath = "";
            }
            // Load the marble
            SurfaceCollection td = new SurfaceCollection();

            td.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, name + ".png"))), new Size(50, 50));
            return(td);
        }
Example #12
0
        protected void initColor(Color fore, Color back, Color strong)
        {
            _foreColor   = fore;
            _backColor   = back;
            _strongColor = strong;

            _map.ForeColor   = _foreColor;
            _map.BackColor   = _backColor;
            _map.StrongColor = _strongColor;

            _parent.Player.ForeColor      = _foreColor;
            _parent.Player.ExplosionColor = _backColor;

            _foreCursor = ResourceManager.GetColoredCursorGraphic(_foreColor);
            _backCursor = ResourceManager.GetColoredCursorGraphic(_backColor);

            if (_keyboardSurface != null)
            {
                _keyboardSurface.Dispose(); _keyboardSurface = null;
            }
            if (_mapSurface != null)
            {
                _mapSurface.Dispose(); _mapSurface = null;
            }
            if (_pauseSurface != null)
            {
                _pauseSurface.Dispose(); _pauseSurface = null;
            }
            if (_clearSurface != null)
            {
                _clearSurface.Dispose(); _clearSurface = null;
            }
            if (_playerInfoSurface != null)
            {
                _playerInfoSurface.Dispose(); _playerInfoSurface = null;
            }

            if (_coloredLifeSurfaces != null)
            {
                foreach (Surface s in _coloredLifeSurfaces)
                {
                    s.Dispose();
                }
                _coloredLifeSurfaces = null;
            }
            _coloredLifeSurfaces = new SurfaceCollection();
            foreach (Surface s in _lifeSurfaces)
            {
                _coloredLifeSurfaces.Add(ImageUtil.CreateColored(s, _backColor, _strongColor));
            }
        }
Example #13
0
        public static SurfaceCollection CreateColored(SurfaceCollection os, Color c)
        {
            if (os == null)
            {
                return(null);
            }
            SurfaceCollection col = new SurfaceCollection();

            foreach (Surface s in os)
            {
                Surface ns = CreateColored(s, c);
                col.Add(ns);
            }
            return(col);
        }
Example #14
0
        public static void CreateStrMenu(string[] items, Color c, SdlDotNet.Graphics.Font font, ref SurfaceCollection surfaces, ref Rectangle[] rects, int width = 300, int height = 30)
        {
            int y = 0; int idx = 0;

            if (height < 0)
            {
                height = (int)(font.Height * Constants.MenuLineHeight);
            }
            foreach (string mi in items)
            {
                Surface s = font.Render(mi, c, true);
                surfaces.Add(s);
                Rectangle r = new Rectangle(0, y, width, height);
                y            = r.Bottom;
                rects[idx++] = r;
            }
        }
        public static SurfaceCollection LoadSurfaces(string[] resourceNames)
        {
            SurfaceCollection ret = new SurfaceCollection();

            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            foreach (string resourceName in resourceNames)
            {
                using (Bitmap bmp = new Bitmap(asm.GetManifestResourceStream(getImgResourceFullName(resourceName))))
                {
                    Surface s = new Surface(bmp);
                    s.AlphaBlending = true;
                    s.Update();
                    ret.Add(s);
                }
            }
            ret.AlphaBlending = true;
            return(ret);
        }
Example #16
0
        /*
        public void displaySprite(Surface image, Point point) {

            
        
        } */

        public void loadPlayerSprite()
        {

            

            // SORCEROR ----------------------------------------------

            // Load the tileset image
            Surface image = new Surface(Path.Combine("tiles", Path.Combine("persons","sorceror.png")));
            image.TransparentColor = Color.Magenta;
            image.Transparent = true;

            // Create the animation frames
            SurfaceCollection sorceror_walk_down  = new SurfaceCollection();
            SurfaceCollection sorceror_walk_left  = new SurfaceCollection();
            SurfaceCollection sorceror_walk_up    = new SurfaceCollection();
            SurfaceCollection sorceror_walk_right = new SurfaceCollection();

            sorceror_walk_down.Add(image, sprite_size, 0);
            sorceror_walk_left.Add(image, sprite_size, 1);
            sorceror_walk_up.Add(image, sprite_size, 2);
            sorceror_walk_right.Add(image, sprite_size, 3);

            // Add the animations to the hero
            AnimationCollection animSorceror_walk_down  = new AnimationCollection();
            AnimationCollection animSorceror_walk_left  = new AnimationCollection();
            AnimationCollection animSorceror_walk_up    = new AnimationCollection();
            AnimationCollection animSorceror_walk_right = new AnimationCollection();

            animSorceror_walk_down.Add(sorceror_walk_down, 35);
            animSorceror_walk_left.Add(sorceror_walk_left, 35);
            animSorceror_walk_up.Add(sorceror_walk_up, 35);
            animSorceror_walk_right.Add(sorceror_walk_right, 35);

            sorceror.Animations.Add("WalkDown", animSorceror_walk_down);
            sorceror.Animations.Add("WalkLeft", animSorceror_walk_left);
            sorceror.Animations.Add("WalkUp",   animSorceror_walk_up);
            sorceror.Animations.Add("WalkRight",animSorceror_walk_right);
            // Change the transparent color of the sprite
            
            
        }
Example #17
0
        //Main program loop
        private void Go()
        {
            //Set up screen
            if (File.Exists(Path.Combine(dataDirectory, "background.png")))
            {
                filePath = "";
            }
            background = new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "background.png")));
            Video.WindowIcon();
            Video.WindowCaption = "SDL.NET - Bounce Sprites";
            screen = Video.SetVideoMode(width, height);
            screen.Blit(background);
            screen.Update();

            //This loads the various images (provided by Moonfire)
            // into a SurfaceCollection for animation
            SurfaceCollection marbleSurfaces = new SurfaceCollection();

            marbleSurfaces.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png"))), new Size(50, 50));

            for (int i = 0; i < this.maxBalls; i++)
            {
                //Create a new Sprite at a random location on the screen
                master.Add(new BounceSprite(marbleSurfaces,
                                            new Point(rand.Next(screen.Rectangle.Left, screen.Rectangle.Right),
                                                      rand.Next(screen.Rectangle.Top, screen.Rectangle.Bottom))));
            }

            //The collection will respond to mouse button clicks, mouse movement and the ticker.
            master.EnableMouseButtonEvent();
            master.EnableMouseMotionEvent();
            master.EnableTickEvent();

            //These bind the events to the above methods.
            Events.KeyboardDown +=
                new EventHandler <KeyboardEventArgs>(this.KeyboardDown);
            Events.Tick += new EventHandler <TickEventArgs>(this.Tick);
            Events.Quit += new EventHandler <QuitEventArgs>(this.Quit);

            //Start the event ticker
            Events.Run();
        }
Example #18
0
 private void updateExpColor()
 {
     if (_explosionSurfaces != null)
     {
         if (_explosionColoredSurfaces != null)
         {
             foreach (Surface s in _explosionColoredSurfaces)
             {
                 s.Dispose();
             }
         }
         _explosionColoredSurfaces = new SurfaceCollection();
         foreach (Surface s in _explosionSurfaces)
         {
             _explosionColoredSurfaces.Add(ImageUtil.CreateColored(s,
                                                                   _foreColor, _explosionColor));
         }
     }
     initExplosion();
 }
        public static SurfaceCollection LoadSurfacesFromFile(string filePath, Size tileSize)
        {
            SurfaceCollection ret = new SurfaceCollection();

            ret.AlphaBlending = true;
            if (!File.Exists(filePath))
            {
                return(ret);
            }

            using (Bitmap bmp = (Bitmap)Bitmap.FromFile(filePath))
            {
                using (Surface s = new Surface(bmp))
                {
                    s.Lock();
                    for (int i = 0; i < s.Width; i += tileSize.Width)
                    {
                        for (int j = 0; j < s.Height; j += tileSize.Height)
                        {
                            Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
                            ss.Transparent   = true;
                            ss.AlphaBlending = true;

                            Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
                            ss.Lock();
                            ss.SetPixels(Point.Empty, tmp);
                            tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
                            ss.Unlock();
                            ss.Update();
                            ret.Add(ss);
                        }
                    }
                    s.Unlock();
                }
            }

            return(ret);
        }
Example #20
0
        //Main program loop
        private void Go()
        {
            //Set up screen
            if (File.Exists(Path.Combine(dataDirectory, "background.png")))
            {
                filePath = "";
            }
            background = new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "background.png")));
            Video.WindowIcon();
            Video.WindowCaption = "SDL.NET - Bounce Sprites";
            screen = Video.SetVideoMode(width, height);
            screen.Blit(background);
            screen.Update();

            //This loads the various images (provided by Moonfire) 
            // into a SurfaceCollection for animation
            SurfaceCollection marbleSurfaces = new SurfaceCollection();
            marbleSurfaces.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png"))), new Size(50, 50));

            for (int i = 0; i < this.maxBalls; i++)
            {
                //Create a new Sprite at a random location on the screen
                master.Add(new BounceSprite(marbleSurfaces,
                    new Point(rand.Next(screen.Rectangle.Left, screen.Rectangle.Right),
                    rand.Next(screen.Rectangle.Top, screen.Rectangle.Bottom))));
            }

            //The collection will respond to mouse button clicks, mouse movement and the ticker.
            master.EnableMouseButtonEvent();
            master.EnableMouseMotionEvent();
            master.EnableTickEvent();

            //These bind the events to the above methods.
            Events.KeyboardDown +=
                new EventHandler<KeyboardEventArgs>(this.KeyboardDown);
            Events.Tick += new EventHandler<TickEventArgs>(this.Tick);
            Events.Quit += new EventHandler<QuitEventArgs>(this.Quit);

            //Start the event ticker
            Events.Run();
        }
Example #21
0
 public static SurfaceCollection CreateColored(SurfaceCollection os, Color c)
 {
     if (os == null) return null;
     SurfaceCollection col = new SurfaceCollection();
     foreach (Surface s in os)
     {
         Surface ns = CreateColored(s, c);
         col.Add(ns);
     }
     return col;
 }
Example #22
0
        public static SurfaceCollection LoadSurfaces(string resourceName, Size tileSize)
        {
            SurfaceCollection ret = new SurfaceCollection();
            ret.AlphaBlending = true;

            using (Surface s = LoadSurface(resourceName))
            {
                for (int i = 0; i < s.Width; i += tileSize.Width)
                {
                    for (int j = 0; j < s.Height; j += tileSize.Height)
                    {
                        Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
                        ss.Transparent = true;
                        ss.AlphaBlending = true;
                        Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
                        ss.SetPixels(Point.Empty, tmp);
                        tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
                        ss.Update();
                        ret.Add(ss);
                    }
                }
            }
            return ret;
        }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        public CDPlayerApp()
        {
            stringManager =
                new ResourceManager("SdlDotNetExamples.CDPlayer.Properties.Resources", Assembly.GetExecutingAssembly());
            InitializeComponent();
            this.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Title", CultureInfo.CurrentUICulture);
            this.label1.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "SelectDrive", CultureInfo.CurrentUICulture);
            this.buttonPlay.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Play", CultureInfo.CurrentUICulture);
            this.buttonPause.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Pause", CultureInfo.CurrentUICulture);
            this.buttonStop.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Stop", CultureInfo.CurrentUICulture);
            this.buttonEject.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Eject", CultureInfo.CurrentUICulture);
            this.labelStatus.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Track", CultureInfo.CurrentUICulture);
            this.buttonPrevious.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Previous", CultureInfo.CurrentUICulture);
            this.buttonNext.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Next", CultureInfo.CurrentUICulture);
            this.KeyPreview = true;
            surf            =
                new Surface(
                    this.surfaceControl.Width,
                    this.surfaceControl.Height);
            if (File.Exists(Path.Combine(dataDirectory, "marble1.png")))
            {
                filePath = "";
            }
            SurfaceCollection marbleSurfaces = new SurfaceCollection();

            marbleSurfaces.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png"))), new Size(50, 50));

            for (int i = 0; i < 1; i++)
            {
                //Create a new Sprite at a random location on the screen
                BounceSprite bounceSprite =
                    new BounceSprite(marbleSurfaces,
                                     new Point(rand.Next(0, 350),
                                               rand.Next(0, 200)));
                bounceSprite.Bounds = new Rectangle(new Point(0, 0), this.surfaceControl.Size);

                // Randomize rotation direction
                bounceSprite.AnimateForward = rand.Next(2) == 1 ? true : false;

                //Add the sprite to the SpriteCollection
                master.Add(bounceSprite);
            }

            //The collection will respond to mouse button clicks, mouse movement and the ticker.
            master.EnableMouseButtonEvent();
            master.EnableMouseMotionEvent();
            master.EnableVideoResizeEvent();
            master.EnableKeyboardEvent();
            master.EnableTickEvent();

            SdlDotNet.Core.Events.Fps   = 30;
            SdlDotNet.Core.Events.Tick += new EventHandler <TickEventArgs>(this.Tick);
            SdlDotNet.Core.Events.Quit += new EventHandler <QuitEventArgs>(this.Quit);

            try
            {
                int num = CDRom.NumberOfDrives;
                _drive = CDRom.OpenDrive(0);
                for (int i = 0; i < num; i++)
                {
                    comboBoxDrive.Items.Add(CDRom.DriveName(i));
                }

                if (comboBoxDrive.Items.Count > 0)
                {
                    comboBoxDrive.SelectedIndex = 0;
                }
            }
            catch (SdlException ex)
            {
                Console.WriteLine(ex);
            }
        }
Example #24
0
        /// <summary>
        /// 
        /// </summary>
        public CDPlayerApp()
        {
            stringManager =
                new ResourceManager("SdlDotNetExamples.CDPlayer.Properties.Resources", Assembly.GetExecutingAssembly());
            InitializeComponent();
            this.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Title", CultureInfo.CurrentUICulture);
            this.label1.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                       "SelectDrive", CultureInfo.CurrentUICulture);
            this.buttonPlay.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Play", CultureInfo.CurrentUICulture);
            this.buttonPause.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Pause", CultureInfo.CurrentUICulture);
            this.buttonStop.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Stop", CultureInfo.CurrentUICulture);
            this.buttonEject.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Eject", CultureInfo.CurrentUICulture);
            this.labelStatus.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Track", CultureInfo.CurrentUICulture);
            this.buttonPrevious.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Previous", CultureInfo.CurrentUICulture);
            this.buttonNext.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                        "Next", CultureInfo.CurrentUICulture);
            this.KeyPreview = true;
            surf =
                new Surface(
                this.surfaceControl.Width,
                this.surfaceControl.Height);
            if (File.Exists(Path.Combine(dataDirectory, "marble1.png")))
            {
                filePath = "";
            }
            SurfaceCollection marbleSurfaces = new SurfaceCollection();
            marbleSurfaces.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png"))), new Size(50, 50));

            for (int i = 0; i < 1; i++)
            {
                //Create a new Sprite at a random location on the screen
                BounceSprite bounceSprite =
                    new BounceSprite(marbleSurfaces,
                    new Point(rand.Next(0, 350),
                    rand.Next(0, 200)));
                bounceSprite.Bounds = new Rectangle(new Point(0, 0), this.surfaceControl.Size);

                // Randomize rotation direction
                bounceSprite.AnimateForward = rand.Next(2) == 1 ? true : false;

                //Add the sprite to the SpriteCollection
                master.Add(bounceSprite);
            }

            //The collection will respond to mouse button clicks, mouse movement and the ticker.
            master.EnableMouseButtonEvent();
            master.EnableMouseMotionEvent();
            master.EnableVideoResizeEvent();
            master.EnableKeyboardEvent();
            master.EnableTickEvent();

            SdlDotNet.Core.Events.Fps = 30;
            SdlDotNet.Core.Events.Tick += new EventHandler<TickEventArgs>(this.Tick);
            SdlDotNet.Core.Events.Quit += new EventHandler<QuitEventArgs>(this.Quit);

            try
            {
                int num = CDRom.NumberOfDrives;
                _drive = CDRom.OpenDrive(0);
                for (int i = 0; i < num; i++)
                {
                    comboBoxDrive.Items.Add(CDRom.DriveName(i));
                }

                if (comboBoxDrive.Items.Count > 0)
                {
                    comboBoxDrive.SelectedIndex = 0;
                }
            }
            catch (SdlException ex)
            {
                Console.WriteLine(ex);
            }
        }
Example #25
0
 /// <summary>
 /// Loads a marble from a single image and tiles it.
 /// </summary>
 protected static SurfaceCollection LoadTiledMarble(string name)
 {
     if (File.Exists(Path.Combine(dataDirectory, name + ".png")))
     {
         filePath = "";
     }
     // Load the marble
     SurfaceCollection td = new SurfaceCollection();
     td.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, name + ".png"))), new Size(50, 50));
     return td;
 }
Example #26
0
 public static void CreateStrMenu(string[] items, Color c, SdlDotNet.Graphics.Font font, ref SurfaceCollection surfaces, ref Rectangle[] rects, int width = 300, int height = 30)
 {
     int y = 0; int idx = 0;
     if (height < 0) height = (int)(font.Height * Constants.MenuLineHeight);
     foreach (string mi in items)
     {
         Surface s = font.Render(mi, c, true);
         surfaces.Add(s);
         Rectangle r = new Rectangle(0, y, width, height);
         y = r.Bottom;
         rects[idx++] = r;
     }
 }
 /// <summary>
 /// Creates a new particle emitter that emits surface objects.
 /// </summary>
 /// <param name="system">The particle system to add this particle emitter.</param>
 /// <param name="surface">The surface to emit.</param>
 public ParticleSurfaceEmitter(ParticleSystem system, Surface surface)
     : base(system)
 {
     m_Surfaces = new SurfaceCollection();
     m_Surfaces.Add(surface);
 }
Example #28
0
 /// <summary>
 /// Loads all tilesets used by this map into memory and assigns
 /// the correct tile ids to the tiles in them.
 /// </summary>
 public void LoadTilesets()
 {
     // TODO: It'd probably be a good idea to cache the
     // tilesets globally.
     tilesets = new SurfaceCollection[tilesetNames.Count];
     totalTiles = 0;
     for (int i = 0; i < tilesets.Length; i++) {
         var coll = new SurfaceCollection();
         coll.Add(Path.Combine("tiles", tilesetNames[i]),
                  new Size(32, 32));
         tilesets[i] = coll;
         totalTiles += coll.Count;
     }
 }
 /// <summary>
 /// Creates a new particle emitter that emits surface objects.
 /// </summary>
 /// <param name="surface">The surface to emit.</param>
 public ParticleSurfaceEmitter(Surface surface)
 {
     m_Surfaces = new SurfaceCollection();
     m_Surfaces.Add(surface);
 }
Example #30
0
 public static SurfaceCollection LoadSurfaces(string[] resourceNames)
 {
     SurfaceCollection ret = new SurfaceCollection();
     System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
     foreach (string resourceName in resourceNames)
     {
         using (Bitmap bmp = new Bitmap(asm.GetManifestResourceStream(getImgResourceFullName(resourceName))))
         {
             Surface s = new Surface(bmp);
             s.AlphaBlending = true;
             s.Update();
             ret.Add(s);
         }
     }
     ret.AlphaBlending = true;
     return ret;
 }
Example #31
0
 /// <summary>
 /// Creates a new particle emitter that emits surface objects.
 /// </summary>
 /// <param name="system">The particle system to add this particle emitter.</param>
 /// <param name="surface">The surface to emit.</param>
 public ParticleSurfaceEmitter(ParticleSystem system, Surface surface)
     : base(system)
 {
     m_Surfaces = new SurfaceCollection();
     m_Surfaces.Add(surface);
 }
Example #32
0
 /// <summary>
 /// Creates a new particle emitter that emits surface objects.
 /// </summary>
 /// <param name="surface">The surface to emit.</param>
 public ParticleSurfaceEmitter(Surface surface)
 {
     m_Surfaces = new SurfaceCollection();
     m_Surfaces.Add(surface);
 }
Example #33
0
        protected void initColor(Color fore, Color back, Color strong)
        {
            _foreColor = fore;
            _backColor = back;
            _strongColor = strong;

            _map.ForeColor = _foreColor;
            _map.BackColor = _backColor;
            _map.StrongColor = _strongColor;

            _parent.Player.ForeColor = _foreColor;
            _parent.Player.ExplosionColor = _backColor;

            _foreCursor = ResourceManager.GetColoredCursorGraphic(_foreColor);
            _backCursor = ResourceManager.GetColoredCursorGraphic(_backColor);

            if (_keyboardSurface != null) { _keyboardSurface.Dispose(); _keyboardSurface = null; }
            if (_mapSurface != null) { _mapSurface.Dispose(); _mapSurface = null; }
            if (_pauseSurface != null) { _pauseSurface.Dispose(); _pauseSurface = null; }
            if (_clearSurface != null) { _clearSurface.Dispose(); _clearSurface = null; }
            if (_playerInfoSurface != null) { _playerInfoSurface.Dispose(); _playerInfoSurface = null; }

            if (_coloredLifeSurfaces != null)
            {
                foreach (Surface s in _coloredLifeSurfaces) s.Dispose();
                _coloredLifeSurfaces = null;
            }
            _coloredLifeSurfaces = new SurfaceCollection();
            foreach (Surface s in _lifeSurfaces)
            {
                _coloredLifeSurfaces.Add(ImageUtil.CreateColored(s, _backColor, _strongColor));
            }
        }
Example #34
0
        public HeroExample()
        {
            // Start up the window
            Video.WindowIcon();
            Video.WindowCaption = "SDL.NET - Hero Example";
            Video.SetVideoMode(400, 300);

            string filePath      = Path.Combine("..", "..");
            string fileDirectory = "Data";
            string fileName      = "hero.png";

            if (File.Exists(fileName))
            {
                filePath      = "";
                fileDirectory = "";
            }
            else if (File.Exists(Path.Combine(fileDirectory, fileName)))
            {
                filePath = "";
            }

            string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName);

            // Load the image
            Surface image = new Surface(file);

            // Create the animation frames
            SurfaceCollection walkUp = new SurfaceCollection();

            walkUp.Add(image, new Size(24, 32), 0);
            SurfaceCollection walkRight = new SurfaceCollection();

            walkRight.Add(image, new Size(24, 32), 1);
            SurfaceCollection walkDown = new SurfaceCollection();

            walkDown.Add(image, new Size(24, 32), 2);
            SurfaceCollection walkLeft = new SurfaceCollection();

            walkLeft.Add(image, new Size(24, 32), 3);

            // Add the animations to the hero
            AnimationCollection animWalkUp = new AnimationCollection();

            animWalkUp.Add(walkUp, 35);
            hero.Animations.Add("WalkUp", animWalkUp);
            AnimationCollection animWalkRight = new AnimationCollection();

            animWalkRight.Add(walkRight, 35);
            hero.Animations.Add("WalkRight", animWalkRight);
            AnimationCollection animWalkDown = new AnimationCollection();

            animWalkDown.Add(walkDown, 35);
            hero.Animations.Add("WalkDown", animWalkDown);
            AnimationCollection animWalkLeft = new AnimationCollection();

            animWalkLeft.Add(walkLeft, 35);
            hero.Animations.Add("WalkLeft", animWalkLeft);

            // Change the transparent color of the sprite
            hero.TransparentColor = Color.Magenta;
            hero.Transparent      = true;

            // Setup the startup animation and make him not walk
            hero.CurrentAnimation = "WalkDown";
            hero.Animate          = false;
            // Put him in the center of the screen
            hero.Center = new Point(
                Video.Screen.Width / 2,
                Video.Screen.Height / 2);
        }
Example #35
0
        public HeroExample()
        {
            // Start up the window
            Video.WindowIcon();
            Video.WindowCaption = "SDL.NET - Hero Example";
            Video.SetVideoMode(400, 300);

            string filePath = Path.Combine("..", "..");
            string fileDirectory = "Data";
            string fileName = "hero.png";
            if (File.Exists(fileName))
            {
                filePath = "";
                fileDirectory = "";
            }
            else if (File.Exists(Path.Combine(fileDirectory, fileName)))
            {
                filePath = "";
            }

            string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName);

            // Load the image
            Surface image = new Surface(file);

            // Create the animation frames
            SurfaceCollection walkUp = new SurfaceCollection();
            walkUp.Add(image, new Size(24, 32), 0);
            SurfaceCollection walkRight = new SurfaceCollection();
            walkRight.Add(image, new Size(24, 32), 1);
            SurfaceCollection walkDown = new SurfaceCollection();
            walkDown.Add(image, new Size(24, 32), 2);
            SurfaceCollection walkLeft = new SurfaceCollection();
            walkLeft.Add(image, new Size(24, 32), 3);

            // Add the animations to the hero
            AnimationCollection animWalkUp = new AnimationCollection();
            animWalkUp.Add(walkUp, 35);
            hero.Animations.Add("WalkUp", animWalkUp);
            AnimationCollection animWalkRight = new AnimationCollection();
            animWalkRight.Add(walkRight, 35);
            hero.Animations.Add("WalkRight", animWalkRight);
            AnimationCollection animWalkDown = new AnimationCollection();
            animWalkDown.Add(walkDown, 35);
            hero.Animations.Add("WalkDown", animWalkDown);
            AnimationCollection animWalkLeft = new AnimationCollection();
            animWalkLeft.Add(walkLeft, 35);
            hero.Animations.Add("WalkLeft", animWalkLeft);

            // Change the transparent color of the sprite
            hero.TransparentColor = Color.Magenta;
            hero.Transparent = true;

            // Setup the startup animation and make him not walk
            hero.CurrentAnimation = "WalkDown";
            hero.Animate = false;
            // Put him in the center of the screen
            hero.Center = new Point(
                Video.Screen.Width / 2,
                Video.Screen.Height / 2);
        }
Example #36
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();
        }
Example #37
0
 private void updateExpColor()
 {
     if (_explosionSurfaces != null)
     {
         if (_explosionColoredSurfaces != null)
         {
             foreach (Surface s in _explosionColoredSurfaces)
             {
                 s.Dispose();
             }
         }
         _explosionColoredSurfaces = new SurfaceCollection();
         foreach (Surface s in _explosionSurfaces)
         {
             _explosionColoredSurfaces.Add(ImageUtil.CreateColored(s,
                 _foreColor, _explosionColor));
         }
     }
     initExplosion();
 }
Example #38
0
        protected virtual void loadImages()
        {
            int[] tmp = { 0, 1, 2 };
            _playerSurfaces = ResourceManager.LoadSurfaces(
                Array.ConvertAll<int, string>(tmp, (i) => { return string.Format(Constants.Filename_PlayerImage, i); }));
            _playerSurfaces.Add(_playerSurfaces[1]);

            _explosionSurfaces = ResourceManager.LoadSurfaces(Constants.Filename_ExplosionImage, new Size(24, 24));
        }
Example #39
0
        public static SurfaceCollection LoadSurfacesFromFile(string filePath, Size tileSize)
        {
            SurfaceCollection ret = new SurfaceCollection();
            ret.AlphaBlending = true;
            if (!File.Exists(filePath)) return ret;

            using (Bitmap bmp = (Bitmap)Bitmap.FromFile(filePath))
            {
                using (Surface s = new Surface(bmp))
                {
                    s.Lock();
                    for (int i = 0; i < s.Width; i += tileSize.Width)
                    {
                        for (int j = 0; j < s.Height; j += tileSize.Height)
                        {
                            Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
                            ss.Transparent = true;
                            ss.AlphaBlending = true;

                            Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
                            ss.Lock();
                            ss.SetPixels(Point.Empty, tmp);
                            tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
                            ss.Unlock();
                            ss.Update();
                            ret.Add(ss);
                        }
                    }
                    s.Unlock();
                }
            }

            return ret;
        }