private void updateDevices() { _deviceInfos.Clear(); _deviceInfos = new List <DeviceInfo>(_audioInput.DeviceInfos); string[] infoStrs = Array.ConvertAll <DeviceInfo, string>( _deviceInfos.ToArray(), (di) => { return(getDeviceDrawString(di)); }); _devSurfaces = new SurfaceCollection(); _devRects = new Rectangle[infoStrs.Length]; ImageUtil.CreateStrMenu(infoStrs, Constants.Color_Foreground, ref _devSurfaces, ref _devRects, _devRect.Width); int ih = 30; if (_devRects.Length > 0) { ih = _devRects[0].Height; } _devDrawLength = (int)Math.Floor(_devRect.Height / (double)ih); if (_devDrawLength > _devRects.Length) { _devDrawLength = _devRects.Length; } _devDrawFirstIdx = -1; _devSelectedIdx = _parent.SelectedDeviceIndex; if (_deviceInfos.Count == 0) { _state = SelectionState.Back; } updateDevicesIndex(); }
/// <summary> /// /// </summary> /// <param name="surfaces"></param> /// <param name="bounds"></param> /// <param name="coordinates"></param> public BoundedSprite(SurfaceCollection surfaces, Rectangle bounds, Vector coordinates) : base(surfaces, coordinates) { if (surfaces == null) { throw new ArgumentNullException("surfaces"); } this.bounds = bounds; int tempHeight; int tempWidth; tempWidth = this.bounds.Size.Width - (int)surfaces.Size.Width; tempHeight = this.bounds.Size.Height - (int)surfaces.Size.Height; this.bounds.Size = new Size(tempWidth, tempHeight); base.Frame = rand.Next(surfaces.Count); if (rand.Next(2) % 2 == 0) { this.AnimateForward = true; } else { this.AnimateForward = false; } this.Animate = true; }
public SceneGameOver() { sceneType = SceneType.GameOver; _menuItems = new MenuItem[] { new MenuItem(Key.R, Properties.Resources.MenuItem_RetryStage), new MenuItem(Key.M, Properties.Resources.MenuItem_MapSelect), new MenuItem(Key.T, Properties.Resources.MenuItem_ReturnTitle) }; _keys = new Key[] { Key.UpArrow, Key.DownArrow, Key.Return, Key.Escape, Key.M, Key.R, Key.T }; _cursor = ResourceManager.GetColoredCursorGraphic(_foreColor); _overImgSurface = ResourceManager.LoadSurface(Constants.Filename_GameoverImage); ImageUtil.SetColor(_overImgSurface, _foreColor); _menuSurfaces = new SurfaceCollection(); _menuRects = new Rectangle[_menuItems.Length]; ImageUtil.CreateStrMenu(_menuItems, _foreColor, ref _menuSurfaces, ref _menuRects, Constants.ScreenWidth); }
public SceneTitle() { sceneType = SceneType.Title; _menuItems = new MenuItem[] { new MenuItem(Key.S, "Start"), new MenuItem(Key.O, "Option"), new MenuItem(Key.Q, "Quit") }; _keys = new Key[] { Key.UpArrow, Key.DownArrow, Key.Return, Key.M, Key.O, Key.Q }; _cursor = ResourceManager.GetColoredCursorGraphic(Constants.Color_Foreground); if (_menuSurfaces == null) { _menuSurfaces = new SurfaceCollection(); _menuRects = new Rectangle[_menuItems.Length]; ImageUtil.CreateStrMenu(_menuItems, Constants.Color_Foreground, ResourceManager.MiddlePFont, ref _menuSurfaces, ref _menuRects, Constants.ScreenWidth); } }
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); }
/// <summary> /// マップ情報読み込み /// </summary> private void updateMapInfos() { _mapInfos.Clear(); _mapInfos = _loader.LoadMapInfos(); string[] infoStrs = Array.ConvertAll <MapInfo, string>(_mapInfos.ToArray(), (mi) => { return(mi.MapName); }); _mapSurfaces = new SurfaceCollection(); _mapRects = new Rectangle[infoStrs.Length]; ImageUtil.CreateStrMenu(infoStrs, Constants.Color_Foreground, ref _mapSurfaces, ref _mapRects, _mapRect.Width); int ih = 30; if (_mapRects.Length > 0) { ih = _mapRects[0].Height; } _mapDrawLength = (int)Math.Floor(_mapRect.Height / (double)ih); if (_mapDrawLength > _mapInfos.Count) { _mapDrawLength = _mapInfos.Count; } _mapDrawFirstIdx = -1; _mapSelectedIdx = 0; if (_mapInfos.Count == 0) { _mapFocus = false; } updateMapIndex(); }
public BlpTexture(string filename, bool loadMipMaps) { using (var stream = File.Open(filename, FileMode.Open)) LoadFromStream(stream, loadMipMaps); mipmapCollection = new SurfaceCollection(this); }
private void release() { if (_prevSurface != null) _prevSurface.Dispose(); if (_errorMessageSurface != null) foreach (Surface s in _errorMessageSurface) s.Dispose(); _prevSurface = null; _errorMessageSurface = null; }
internal Sprite(SurfaceCollection surfaces, Vector vector) { if (surfaces == null) { throw new ArgumentNullException("surfaces"); } this.surf = surfaces[0]; this.vector = vector; }
/// <summary> /// /// </summary> /// <param name="frames"></param> /// <param name="key"></param> /// <param name="coordinates"></param> /// <param name="bounds"></param> public DragSprite(SurfaceCollection frames, Point coordinates) : base(frames, coordinates) { if (frames == null) { throw new ArgumentNullException("frames"); } this.AllowDrag = true; }
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); }
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)); }
/// <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; }
public SceneGameStage(map.Map map) { sceneType = SceneType.GameStage; _map = map; #region メニューアイテム _clearMenuItems = new MenuItem[] { new MenuItem(Key.M, Properties.Resources.MenuItem_MapSelect), new MenuItem(Key.T, Properties.Resources.MenuItem_ReturnTitle) }; #endregion _keys = new Key[] { Key.UpArrow, Key.DownArrow, Key.Return, Key.Escape, Key.R, Key.M, Key.T }; // 画像読み込み _lifeSurfaces = ResourceManager.LoadSurfaces(Constants.Filename_LifeImage, new Size(30, 32)); #region 配置 _viewRect = new Rectangle( Constants.ScreenWidth - Constants.StageViewWidth - Constants.StageMargin, Constants.StageMargin, Constants.StageViewWidth, Constants.StageViewHeight); _keyRect = new Rectangle( Constants.StageMargin, Constants.StageMargin, _viewRect.Left - 1 - Constants.StageMargin, Constants.StageViewHeight); _miniMapRect = new Rectangle( Constants.ScreenWidth - Constants.MiniMapWidth - Constants.StageMargin, _viewRect.Bottom + Constants.StageGap, Constants.MiniMapWidth, Constants.ScreenHeight - Constants.StageMargin - _viewRect.Bottom - Constants.StageGap); _playerInfoRect = new Rectangle( Constants.StageMargin, _viewRect.Bottom + Constants.StageGap, _miniMapRect.Left - Constants.StageMargin - Constants.StageGap, _miniMapRect.Height); #endregion #region PID制御係数決定 _prevYDiff = 0; _yDiff = 0; _coefP = 0.5; _coefI = _coefP * 0.4; _coefD = _coefP * 0.01; _diffT = 1 / (double)SdlDotNet.Core.Events.TargetFps; #endregion }
private void disposeSurfaceCollection(SurfaceCollection sc) { if (sc != null) { foreach (Surface s in sc) { s.Dispose(); } sc = null; } }
/// <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); }
/// <summary> /// Creates a new Vertex structure object /// </summary> public VertexStructure(int verticesCapacity) { m_name = string.Empty; m_description = string.Empty; m_vertices = new List <Vertex>(verticesCapacity); m_surfaces = new List <VertexStructureSurface>(); m_vertexCollection = new VertexCollection(m_vertices); m_surfaceCollection = new SurfaceCollection(m_surfaces); }
/// <summary> /// /// </summary> /// <param name="surfaces"></param> /// <param name="coordinates"></param> public BounceSprite(SurfaceCollection surfaces, Point coordinates) : base(surfaces, coordinates) { //Sprites will be bounded by the screen edges minus //their size so they will not go off the screen this.bounds = new Rectangle(0, 0, 0, 0); //The sprite can be dragged this.Animate = true; this.AllowDrag = true; }
/// <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; }
///// <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> /// 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); }
/// <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); }
/// <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(); }
/// <summary> /// Constructs the internal sprites needed for our demo. /// </summary> public ViewportMode() { // Create the fragment marbles SurfaceCollection td = LoadMarble("marble1"); SurfaceCollection td2 = LoadMarble("marble2"); // Load the floor SurfaceCollection floorTiles = LoadFloor(); // Place the floors int rows = 8; int cols = 15; size = new Size(floorTiles[0].Size.Width * cols, floorTiles[0].Size.Height * rows); rect = new Rectangle(new Point(0, 0), size); for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { // Create the floor tile sprites AnimatedSprite dw = new AnimatedSprite(floorTiles, new Point(i * floorTiles[0].Size.Width, j * floorTiles[0].Size.Height)); Sprites.Add(dw); } } // Load the trigger sprite sprite = new BounceSprite(td2, rect, new Vector(Randomizer.Next(rect.Left, rect.Right - (int)td2.Size.Width), Randomizer.Next(rect.Top, rect.Bottom - (int)td2.Size.Height), 1)); Sprites.Add(sprite); CenterSprite.Add(sprite); // Load the bouncing sprites for (int i = 0; i < 10; i++) { Thread.Sleep(10); BounceSprite bounceSprite = new BounceSprite(td, rect, new Vector(Randomizer.Next(rect.Left, rect.Right - (int)td.Size.Width), Randomizer.Next(rect.Top, rect.Bottom - (int)td.Size.Height), 1)); Sprites.Add(bounceSprite); } }
/// <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); }
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)); } }
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); }
private void release() { if (_prevSurface != null) { _prevSurface.Dispose(); } if (_errorMessageSurface != null) { foreach (Surface s in _errorMessageSurface) { s.Dispose(); } } _prevSurface = null; _errorMessageSurface = null; }
public BlpTexture(Stream stream, bool loadMipMaps) { long position = 0; if (stream.CanSeek) { position = stream.Position; } LoadFromStream(stream, loadMipMaps); if (stream.CanSeek) { stream.Seek(position, SeekOrigin.Begin); } mipmapCollection = new SurfaceCollection(this); }
/// <summary> /// Constructs the internal sprites needed for our demo. /// </summary> public BounceMode() { // Create the fragment marbles Rectangle rect = new Rectangle(new Point(0, 0), SpriteDemosMain.Size); for (int i = 0; i < 10; i++) { Thread.Sleep(10); SurfaceCollection d = LoadRandomMarble(); BounceSprite bounceSprite = new BounceSprite(d, new Rectangle(new Point(0, 0), SpriteDemosMain.Size), new Vector(Randomizer.Next(rect.Left, rect.Right), Randomizer.Next(rect.Top, rect.Bottom), 1)); Sprites.Add(bounceSprite); } }
/// <summary> /// /// </summary> /// <param name="surfaces"></param> /// <param name="coordinates"></param> public BounceSprite(SurfaceCollection surfaces, Point coordinates) : base(surfaces, coordinates) { if (surfaces == null) { throw new ArgumentNullException("surfaces"); } //Sprites will be bounded by the screen edges minus //their size so they will not go off the screen this.bounds = new Rectangle(0, 0, Video.Screen.Rectangle.Width - (int)surfaces.Size.Width, Video.Screen.Rectangle.Height - (int)surfaces.Size.Height); //The sprite can be dragged this.Animate = true; this.AllowDrag = true; }
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); }
/* 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> /// マップ情報読み込み /// </summary> private void updateMapInfos() { _mapInfos.Clear(); _mapInfos = _loader.LoadMapInfos(); string[] infoStrs = Array.ConvertAll<MapInfo, string>(_mapInfos.ToArray(), (mi) => { return mi.MapName; }); _mapSurfaces = new SurfaceCollection(); _mapRects = new Rectangle[infoStrs.Length]; ImageUtil.CreateStrMenu(infoStrs, Constants.Color_Foreground, ref _mapSurfaces, ref _mapRects, _mapRect.Width); int ih = 30; if (_mapRects.Length > 0) ih = _mapRects[0].Height; _mapDrawLength = (int)Math.Floor(_mapRect.Height / (double)ih); if (_mapDrawLength > _mapInfos.Count) _mapDrawLength = _mapInfos.Count; _mapDrawFirstIdx = -1; _mapSelectedIdx = 0; if (_mapInfos.Count == 0) _mapFocus = false; updateMapIndex(); }
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> /// 初期化処理 /// </summary> /// <param name="parent">ゲームクラス</param> public override void Init(PitchPitch parent) { base.Init(parent); parent.Player.Init(parent); // 各種フラグのリセット IsPaused = false; _isCleared = false; _isOver = false; _pauseSelectedIdx = 0; _clearSelectedIdx = 0; #region 色 initColor(_map.MapInfo.ForegroundColor, _map.MapInfo.BackgroundColor, _map.MapInfo.StrongColor); #endregion #region View/Map/Player _mapMargin = (int)(_viewRect.Width * 3 / 4.0) * _map.MapInfo.PlayerVx; Console.WriteLine(_mapMargin); _view.Width = _viewRect.Width; _view.Height = _viewRect.Height; _map.Init(parent, new Size(_view.Width, _view.Height)); _view.X = -_mapMargin; _view.Y = (long)(_map.Height / 2.0 - _view.Height / 2.0); _map.SetView(_view); _parent.Player.X = _playerXRatio * _view.Width - _mapMargin; _parent.Player.Y = _map.Height / 2.0; _parent.Player.Vx = _map.MapInfo.PlayerVx; _prevX = _parent.Player.X; _view.X = -_mapMargin; // BGM if (_map.Bgm != null) { SdlDotNet.Audio.MusicPlayer.Load(_map.Bgm); int ivol = (int)(128 * _map.BgmVolume / 100.0); ivol = ivol < 0 ? 0 : (ivol > 128 ? 128 : ivol); SdlDotNet.Audio.MusicPlayer.Volume = ivol; } #endregion #region メニュー作成 if (_map.HasEnd) { _pauseMenuItems = new MenuItem[] { new MenuItem(Key.Escape, Properties.Resources.MenuItem_ResumeGame), new MenuItem(Key.R, Properties.Resources.MenuItem_RetryStage), new MenuItem(Key.M, Properties.Resources.MenuItem_MapSelect), new MenuItem(Key.T, Properties.Resources.MenuItem_ReturnTitle) }; } else { _pauseMenuItems = new MenuItem[] { new MenuItem(Key.Escape, Properties.Resources.MenuItem_ResumeGame), new MenuItem(Key.M, Properties.Resources.MenuItem_MapSelect), new MenuItem(Key.T, Properties.Resources.MenuItem_ReturnTitle) }; } _pauseMenuSurfaces = new SurfaceCollection(); _pauseMenuRects = new Rectangle[_pauseMenuItems.Length]; ImageUtil.CreateStrMenu(_pauseMenuItems, _backColor, ref _pauseMenuSurfaces, ref _pauseMenuRects); _clearMenuSurfaces = new SurfaceCollection(); _clearMenuRects = new Rectangle[_clearMenuItems.Length]; ImageUtil.CreateStrMenu(_clearMenuItems, _foreColor, ref _clearMenuSurfaces, ref _clearMenuRects); #endregion #region ピッチ設定 if (_map.MapInfo.PitchType == map.PitchType.Fixed) { _isFixedPitchMap = true; _maxFreq = _map.MapInfo.MaxPitch; _minFreq = _map.MapInfo.MinPitch; if (_map.MapInfo.OctaveLevel != 0) { _maxFreq *= Math.Pow(2, _map.MapInfo.OctaveLevel); _minFreq *= Math.Pow(2, _map.MapInfo.OctaveLevel); } } else { _isFixedPitchMap = false; _minFreq = Config.Instance.MinFreq; _maxFreq = Config.Instance.MaxFreq; } _maxFreqLog = Math.Log(_maxFreq); _minFreqLog = Math.Log(_minFreq); #endregion createKeyRects(); _prevProcTime = Environment.TickCount; }
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(); }
/// <summary> /// Creates a new AnimationCollection with a SurfaceCollection /// representing the animation. /// </summary> /// <param name="frames"> /// The collection of /// surfaces in the animation. /// </param> /// <param name="delay"> /// The amount of delay to be /// had between each frame. Defaults to 30. /// </param> public virtual void Add(SurfaceCollection frames, double delay) { this.m_Delay = delay; base.Add(frames); }
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)); }
//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(); }
/// <summary> /// Creates a new AnimationCollection with a SurfaceCollection representing the /// animation. /// </summary> /// <param name="frames"> /// The collection of surfaces in the animation. /// </param> /// <param name="delay"> /// The amount of delay to be had between each frame. /// </param> /// <param name="loop"> /// Whether or not the animation is /// to loop when reached the end. Defaults to true. /// </param> public virtual void Add(SurfaceCollection frames, double delay, bool loop) { this.m_Delay = delay; this.m_Loop = loop; base.Add(frames); }
/// <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); }
/// <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); } }
/// <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="surfaces">The surface collection to choose surfaces from when emitting.</param> public ParticleSurfaceEmitter(ParticleSystem system, SurfaceCollection surfaces) : base(system) { m_Surfaces = surfaces; }
/// <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); }
/// <summary> /// Creates a new particle emitter that emits surface objects. /// </summary> /// <param name="surfaces">The surface collection to choose surfaces from when emitting.</param> public ParticleSurfaceEmitter(SurfaceCollection surfaces) { m_Surfaces = surfaces; }
protected override void draw(SdlDotNet.Graphics.Surface s) { if (_prevSurface == null) { _prevSurface = new Surface(s); _prevSurface.Transparent = true; _prevSurface.AlphaBlending = true; _prevSurface.Alpha = 64; } s.Fill(Color.Black); s.Blit(_prevSurface, Point.Empty); if (_errorMessageSurface == null && _errorMessages != null) { _errorMessageSurface = new SurfaceCollection(); _errorMessageRects = new Rectangle[_errorMessages.Length]; ImageUtil.CreateStrMenu(_errorMessages, Color.White, ref _errorMessageSurface, ref _errorMessageRects, s.Width); } if (_errorMessageSurface != null) { ImageUtil.DrawSurfaces(s, _errorMessageSurface, _errorMessageRects, new Point(0, 100), MenuItemAlign.TopCenter); } }
public SceneMapSelect() { sceneType = scene.SceneType.MapSelect; _loader = new MapLoader(); _loader.OnMapLoaded += (s, e) => { _loadedMap = e.Map; _loadEnd = true; _loading = false; }; _loader.OnMapLoadCanceled += (s, e) => { _loadedException = e.Exception; _loadedMap = null; _loadingMapInfo = null; _loadEnd = true; _loading = false; }; _mapInfos = new List<MapInfo>(); _keys = new Key[] { Key.UpArrow, Key.DownArrow, Key.LeftArrow, Key.RightArrow, Key.Return, Key.Escape, Key.One, Key.Two, Key.R }; _builtinMapInfos = new MapInfo[] { EmptyMap.GetMapInfo(), EmptyFixedMap.GetMapInfo(), RandomMap.GetMapInfo(3), RandomMap.GetMapInfo(5), RandomEndlessMap.GetMapInfo(3) }; _randItems = new string[_builtinMapInfos.Length + 1]; for (int i = 0; i < _builtinMapInfos.Length; i++) { _randItems[i] = _builtinMapInfos[i].MapName; } _randItems[_randItems.Length - 1] = Properties.Resources.MenuItem_ReloadMap; _cursor = ResourceManager.GetColoredCursorGraphic(Constants.Color_Foreground); _strongCursor = ResourceManager.GetColoredCursorGraphic(Constants.Color_Strong); #region レイアウト初期化 Size escSize = ResourceManager.MiddlePFont.SizeText(_escItems[0].ToString()); _escRect = new Rectangle( Constants.ScreenWidth - Constants.RightBottomItemMargin - escSize.Width - Constants.CursorMargin, Constants.ScreenHeight - Constants.RightBottomItemMargin - escSize.Height, escSize.Width + Constants.CursorMargin, escSize.Height); _expRect = new Rectangle( Constants.HeaderX + Constants.UnderHeaderMargin, Constants.HeaderY + ResourceManager.LargePFont.Height + Constants.HeaderBottomMargin, Constants.ScreenWidth - Constants.UnderHeaderMargin * 2, ResourceManager.SmallPFont.Height); int top = _expRect.Bottom + Constants.SubHeaderBottomMargin; int bottom = _escRect.Top - Constants.UnderHeaderMargin; _mapRect = new Rectangle( Constants.HeaderX + Constants.UnderHeaderMargin + Constants.CursorMargin, top, (int)((Constants.ScreenWidth - (Constants.HeaderX + Constants.UnderHeaderMargin * 2) - Constants.MenuColumnGap) / 2.0) - Constants.CursorMargin, bottom - top); _randRect = new Rectangle( _mapRect.Right + Constants.MenuColumnGap + Constants.CursorMargin, _mapRect.Top, _mapRect.Width, _mapRect.Height); #endregion _randSurfaces = new SurfaceCollection(); _randRects = new Rectangle[_randItems.Length]; ImageUtil.CreateStrMenu(_randItems, Constants.Color_Foreground, ref _randSurfaces, ref _randRects, _randRect.Width); _randRects[_randRects.Length - 1].Offset(0, ResourceManager.SmallPFont.Height); _escSurfaces = new SurfaceCollection(); _escRects = new Rectangle[_escItems.Length]; ImageUtil.CreateStrMenu(_escItems, Constants.Color_Strong, ResourceManager.MiddlePFont, ref _escSurfaces, ref _escRects, _escRect.Width, ResourceManager.MiddlePFont.Height); }
/// <summary> /// 読み込んだマップ表示のスクロール処理 /// </summary> private void updateMapIndex() { if (_mapDrawFirstIdx >= 0 && _mapDrawFirstIdx <= _mapSelectedIdx && _mapSelectedIdx < _mapDrawFirstIdx + _mapDrawLength) { // 入ってる return; } else { // 入っていない if (_mapDrawFirstIdx < 0) // 最初 { _mapDrawFirstIdx = 0; } else if (_mapSelectedIdx < _mapDrawFirstIdx) // 前にずらす { _mapDrawFirstIdx = _mapSelectedIdx; } else // 後ろにずらす { _mapDrawFirstIdx = _mapSelectedIdx + 1 - _mapDrawLength; } } string[] infoStrs = Array.ConvertAll<MapInfo, string>( _mapInfos.GetRange(_mapDrawFirstIdx, _mapDrawLength).ToArray(), (mi) => { return mi.MapName; }); if (_mapDrawSurfaces != null) foreach (Surface s in _mapDrawSurfaces) s.Dispose(); _mapDrawSurfaces = new SurfaceCollection(); _mapDrawRects = new Rectangle[infoStrs.Length]; ImageUtil.CreateStrMenu(infoStrs, Constants.Color_Foreground, ref _mapDrawSurfaces, ref _mapDrawRects, _mapRect.Width); }