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; }
private void m_Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { AnimationCollection current = m_Animations[m_CurrentAnimation]; m_Timer.Interval = current.Delay; if (m_Frame >= current.Count && current.AnimateForward) // Going forwards and past last frame { if (current.Loop) { m_Frame = 0; } } else if (m_Frame <= 0 && !current.AnimateForward) // Going backwards and past first frame { if (current.Loop) { m_Frame = current.Count - 1; } } else // Still going { m_Frame = m_Frame + current.FrameIncrement; } }
public base_player() : base() { mTexFrames = new AnimationCollection(); mTexFrames.Add("tex3.bmp", new System.Drawing.Size(64, 64)); //mTexFrames.Add("tex2.bmp", new System.Drawing.Size(64, 64)); mTexture = new AnimatedSprite("player", mTexFrames); }
public e_pillar(Vector2 pos, string tex) : base() { mPosition = pos; mTexFrames = new AnimationCollection(); mTexFrames.Add(tex, new Size(64, 64)); mTexture = new AnimatedSprite("pillar", mTexFrames); }
///// <summary> ///// Creates a new AnimatedSprite from a surface collection and a name ///// </summary> ///// <param name="name">The name of the animation</param> ///// <param name="surfaces">The surface collection containing the frames of the animation.</param> //public AnimatedSprite(string name, SurfaceCollection surfaces) // : this(surfaces, new Vector(0, 0, 0)) //{ // this.CurrentAnimation = name; //} /// <summary> /// Creates a new AnimatedSprite from a surface collection and a name /// </summary> /// <param name="name">The name of the animation</param> /// <param name="surfaces">The surface collection containing the frames of the animation.</param> /// <param name="vector">Vector of sprite</param> public AnimatedSprite(string name, SurfaceCollection surfaces, Vector vector) : base(surfaces, vector) { this.m_CurrentAnimation = name; m_Timer.Elapsed += new System.Timers.ElapsedEventHandler(m_Timer_Elapsed); m_Timer.Interval = m_Animations[m_CurrentAnimation].Delay; //this.CurrentAnimation = name; AnimationCollection animation = new AnimationCollection(); animation.Add(surfaces); m_Animations.Add(name, animation); }
/// <summary> /// Creates AnumatedSprite from Surface Collection /// </summary> /// <param name="surfaces">SurfaceCollection</param> /// <param name="vector">Starting coordinates</param> public AnimatedSprite(SurfaceCollection surfaces, Vector vector) : base(surfaces, vector) { if (surfaces == null) { throw new ArgumentNullException("surfaces"); } m_Timer.Elapsed += new System.Timers.ElapsedEventHandler(m_Timer_Elapsed); AnimationCollection anim = new AnimationCollection(); anim.Add(surfaces); m_Animations.Add("Default", anim); }
/// <summary> /// Create AnimatedSprite from AnimationCollection /// </summary> /// <param name="name">Name of animation</param> /// <param name="animation">animation</param> public AnimatedSprite(string name, AnimationCollection animation) : base(animation, new Vector(0, 0, 0)) { if (animation == null) { throw new ArgumentNullException("animation"); } m_Animations.Add(name, animation); //base.Surface = animation[0]; this.m_CurrentAnimation = name; m_Timer.Elapsed += new System.Timers.ElapsedEventHandler(m_Timer_Elapsed); m_Timer.Interval = m_Animations[m_CurrentAnimation].Delay; //this.CurrentAnimation = name; }
/* 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 }
/// <summary> /// Constructs the internal sprites needed for our demo. /// </summary> public DragMode() { // Create the fragment marbles int rows = 3; int cols = 3; int sx = (SpriteDemosMain.Size.Width - cols * 50) / 2; int sy = (SpriteDemosMain.Size.Height - rows * 50) / 2; SurfaceCollection m1 = LoadMarble("marble1"); SurfaceCollection m2 = LoadMarble("marble2"); AnimationCollection anim1 = new AnimationCollection(); anim1.Add(m1); AnimationCollection anim2 = new AnimationCollection(); anim2.Add(m2); AnimationDictionary frames = new AnimationDictionary(); frames.Add("marble1", anim1); frames.Add("marble2", anim2); DragSprite dragSprite; for (int i = 0; i < cols; i++) { Thread.Sleep(10); for (int j = 0; j < rows; j++) { dragSprite = new DragSprite(frames["marble1"], new Point(sx + i * 50, sy + j * 50) ); dragSprite.Animations.Add("marble1", anim1); dragSprite.Animations.Add("marble2", anim2); dragSprite.Animate = true; if (Randomizer.Next(2) == 1) { dragSprite.AnimateForward = false; } Thread.Sleep(10); Sprites.Add(dragSprite); } } }
/// <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(); }
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); }
/// <summary> /// Create AnimatedSprite from AnimationCollection /// </summary> /// <param name="animation">animation</param> public AnimatedSprite(AnimationCollection animation) : this("Default", animation) { }
public static AnimatedSprite CreateColored(AnimatedSprite os, Color c) { if (os == null) return null; AnimatedSprite nsprite = new AnimatedSprite(); foreach (KeyValuePair<string, AnimationCollection> kv in os.Animations) { string key = kv.Key; AnimationCollection anim = kv.Value; AnimationCollection nAnim = new AnimationCollection(); foreach (Surface s in anim) { Surface ns = CreateColored(s, c); nAnim.Add(ns); } nAnim.Loop = anim.Loop; nAnim.Delay = anim.Delay; nAnim.FrameIncrement = anim.FrameIncrement; nAnim.Alpha = anim.Alpha; nAnim.AlphaBlending = anim.AlphaBlending; nAnim.AnimateForward = anim.AnimateForward; //nAnim.AnimationTime = anim.AnimationTime; nAnim.Transparent = anim.Transparent; nAnim.TransparentColor = anim.TransparentColor; nsprite.Animations.Add(key, nAnim); } nsprite.AllowDrag = os.AllowDrag; nsprite.Alpha = os.Alpha; nsprite.AlphaBlending = os.AlphaBlending; nsprite.Animate = os.Animate; nsprite.AnimateForward = os.AnimateForward; nsprite.CurrentAnimation = os.CurrentAnimation; nsprite.Frame = os.Frame; nsprite.Transparent = os.Transparent; nsprite.TransparentColor = os.TransparentColor; nsprite.Visible = os.Visible; return nsprite; }