Ejemplo n.º 1
0
        public void TextureAtlas_RemoveRegions_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            var region0 = atlas.CreateRegion("region0", 10, 20, 30, 40);
            var region1 = atlas.CreateRegion("region1", 50, 60, 35, 45);
            var region2 = atlas.CreateRegion("region2", 32, 33, 34, 35);

            Assert.AreSame(texture, atlas.Texture);
            Assert.AreEqual(3, atlas.RegionCount);
            Assert.AreEqual(atlas.RegionCount, atlas.Regions.Count());
            Assert.AreSame(region1, atlas[1]);

            atlas.RemoveRegion(1);

            Assert.AreEqual(2, atlas.Regions.Count());
            Assert.AreSame(region0, atlas[0]);
            Assert.AreSame(region2, atlas[1]);

            atlas.RemoveRegion("region0");

            Assert.AreEqual(1, atlas.Regions.Count());
            Assert.AreSame(region2, atlas[0]);
        }
        public SpriteSheetAnimator(Sprite targetSprite, TextureAtlas textureAtlas)
        {
            _sprite = targetSprite;
            _textureAtlas = textureAtlas;
            _animations = new Dictionary<string, SpriteSheetAnimation>();

            IsPlaying = true;
            FramesPerSecond = 15;
        }
        public SpriteSheetAnimator(Sprite sprite, TextureAtlas textureAtlas)
        {
            _sprite = sprite;
            _textureAtlas = textureAtlas;
            _animations = new Dictionary<string, SpriteSheetAnimation>();
            _frameIndex = 0;

            IsPlaying = true;
            IsLooping = true;
        }
        public SpriteAnimator(Sprite sprite, TextureAtlas textureAtlas)
        {
            Loop = true;
            Speed = 100;

            _sprite = sprite;
            _textureAtlas = textureAtlas;

            _sprite.TextureRegion = _textureAtlas[_frameIndex];
        }
Ejemplo n.º 5
0
 public SpriteAnimator(Sprite sprite, TextureAtlas textureAtlas, int framesPerSecond = 60)
 {
     IsLooping = true;
     IsPlaying = true;
     FramesPerSecond = framesPerSecond;
     
     _sprite = sprite;
     _textureAtlas = textureAtlas;
     _frameIndex = 0;
     _nextFrameDelay = 0;
     _sprite.TextureRegion = _textureAtlas[_frameIndex];
 }
Ejemplo n.º 6
0
        public void TextureAtlas_GetRegionsByName_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            var region0 = atlas.CreateRegion("region0", 10, 20, 30, 40);
            var region1 = atlas.CreateRegion("region1", 50, 60, 35, 45);

            Assert.AreSame(region0, atlas["region0"]);
            Assert.AreSame(region1, atlas["region1"]);
            Assert.AreSame(region0, atlas.GetRegion("region0"));
            Assert.AreSame(region1, atlas.GetRegion("region1"));
        }
Ejemplo n.º 7
0
        public void TextureAtlas_CreateRegion_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            var region = atlas.CreateRegion("region0", 10, 20, 30, 40);

            Assert.AreSame(texture, region.Texture);
            Assert.AreEqual(10, region.X);
            Assert.AreEqual(20, region.Y);
            Assert.AreEqual(30, region.Width);
            Assert.AreEqual(40, region.Height);
        }
Ejemplo n.º 8
0
        public Zombie(TextureAtlas textureAtlas)
        {
            _sprite = new Sprite(textureAtlas[0])
            {
                OriginNormalized = new Vector2(0.5f, 1.0f)
            };

            _animator = new SpriteSheetAnimator(_sprite, textureAtlas);
            _animator.AddAnimation("appear", framesPerSecond: 8, firstFrameIndex: 0, lastFrameIndex: 10);
            _animator.AddAnimation("idle", framesPerSecond: 8, firstFrameIndex: 36, lastFrameIndex: 41);
            _animator.AddAnimation("walk", framesPerSecond: 8, firstFrameIndex: 19, lastFrameIndex: 28);
            _animator.AddAnimation("attack", framesPerSecond: 8, firstFrameIndex: 29, lastFrameIndex: 35);
            _animator.AddAnimation("die", framesPerSecond: 8, firstFrameIndex: 11, lastFrameIndex: 18);

            _animator.PlayAnimation("appear", ResumeIdle);
        }
Ejemplo n.º 9
0
        public Zombie(TextureAtlas textureAtlas)
        {
            _sprite = new Sprite(textureAtlas[0])
            {
                OriginNormalized = new Vector2(0.5f, 1.0f)
            };

            _animator = new SpriteSheetAnimator(_sprite, textureAtlas);
            _animator.AddAnimation("appear", framesPerSecond: 8, firstFrameIndex: 0, lastFrameIndex: 10);
            _animator.AddAnimation("idle", framesPerSecond: 8, firstFrameIndex: 36, lastFrameIndex: 41);
            _animator.AddAnimation("walk", framesPerSecond: 12, firstFrameIndex: 19, lastFrameIndex: 28);
            _animator.AddAnimation("attack", framesPerSecond: 8, firstFrameIndex: 29, lastFrameIndex: 35);
            _animator.AddAnimation("die", framesPerSecond: 8, firstFrameIndex: 11, lastFrameIndex: 18);

            State = ZombieState.Appearing;
            IsOnGround = false;
        }
Ejemplo n.º 10
0
		private static void LoadContent(ContentManager content)
		{
			AtlasTextures = content.Load<TextureAtlas>(TEXTURE_ASSETNAME);

			TexTileBorder = AtlasTextures["grid"];

			TexCannonBody         = AtlasTextures["simple_circle"];
			TexCannonBodyShadow   = AtlasTextures["cannonbody_shadow"];
			TexCannonBarrel       = AtlasTextures["cannonbarrel"];
			TexCannonBarrelShadow = AtlasTextures["cannonbarrel_shadow"];
			TexCannonCrosshair    = AtlasTextures["cannoncrosshair"];

			TexLevelNodeStructure = AtlasTextures["levelnode_structure"];
			TexLevelNodeSegment   = AtlasTextures["levelnode_segment"];

			AnimCannonCog = Enumerable.Range(0, ANIMATION_CANNONCOG_SIZE).Select(p => AtlasTextures[$"cannoncog_{p:000}"]).ToArray();

			TexBullet         = AtlasTextures["cannonball"];
			TexBulletSplitter = AtlasTextures["cannonball_piece"];

			TexCircle      = AtlasTextures["simple_circle"];
			TexCircleEmpty = AtlasTextures["simple_circle_empty"];
			TexPixel       = AtlasTextures["simple_pixel"];
			TexPixel       = new TextureRegion2D(TexPixel.Texture, TexPixel.X + TexPixel.Width / 2, TexPixel.Y + TexPixel.Height / 2, 1, 1); // Anti-Antialising
			TexParticle    = Enumerable.Range(0, 16).Select(p => AtlasTextures[$"particle_{p:00}"]).ToArray();

			TexHUDButtonBase = AtlasTextures["hud_button_base"];
			TexHUDButtonPause = Enumerable.Range(0, ANIMATION_HUDBUTTONPAUSE_SIZE).Select(p => AtlasTextures[$"hud_pause_{p:00}"]).ToArray();
			TexHUDButtonSpeedHand  = AtlasTextures["hud_time_hand"];
			TexHUDButtonSpeedSet0  = AtlasTextures["hud_time_0"];
			TexHUDButtonSpeedSet1  = AtlasTextures["hud_time_1"];
			TexHUDButtonSpeedSet2  = AtlasTextures["hud_time_2"];
			TexHUDButtonSpeedSet3  = AtlasTextures["hud_time_3"];
			TexHUDButtonSpeedSet4  = AtlasTextures["hud_time_4"];
			TexHUDButtonSpeedClock = AtlasTextures["hud_time_clock"];
			TexHUDButtonPauseMenuMarker           = AtlasTextures["pausemenu_marker"];
			TexHUDButtonPauseMenuMarkerBackground = AtlasTextures["pausemenu_marker_background"];

			TexPanelBlurEdge   = AtlasTextures["panel_blur_edge"];
			TexPanelBlurCorner = AtlasTextures["panel_blur_corner"];
			TexPanelCorner     = AtlasTextures["panel_corner"];

			TexIconBack = AtlasTextures["icon_back"];
			TexIconNext = AtlasTextures["icon_next"];
			TexIconRedo = AtlasTextures["icon_redo"];

			TexDifficulty0 = AtlasTextures["difficulty_0"];
			TexDifficulty1 = AtlasTextures["difficulty_1"];
			TexDifficulty2 = AtlasTextures["difficulty_2"];
			TexDifficulty3 = AtlasTextures["difficulty_3"];

			HUDFontRegular = content.Load<SpriteFont>("fonts/hudFontRegular");
			HUDFontBold = content.Load<SpriteFont>("fonts/hudFontBold");

#if DEBUG
			DebugFont      = content.Load<SpriteFont>("fonts/debugFont");
			DebugFontSmall = content.Load<SpriteFont>("fonts/debugFontSmall");
#endif
			
			StaticTextures.DEFAULT_TEXTURE_SCALE = DEFAULT_TEXTURE_SCALE;

			StaticTextures.SinglePixel     = TexPixel;
			StaticTextures.PanelBlurCorner = TexPanelBlurCorner;
			StaticTextures.PanelBlurEdge   = TexPanelBlurEdge;
			StaticTextures.PanelCorner     = TexPanelCorner;
		}
Ejemplo n.º 11
0
        public void TextureAtlas_GetRegion_InvalidIndexThrowsException_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            atlas.CreateRegion("region0", 10, 20, 30, 40);

            atlas.GetRegion(-1);
        }
Ejemplo n.º 12
0
        public void TextureAtlas_CreateRegionThatAlreadyExistsThrowsException_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            atlas.CreateRegion("region0", 10, 20, 30, 40);
            atlas.CreateRegion("region0", 50, 60, 35, 45);
        }
Ejemplo n.º 13
0
        public void TextureAtlas_EnumerateRegions_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            var regions = new TextureRegion2D[3];
            regions[0] = atlas.CreateRegion("region0", 10, 20, 30, 40);
            regions[1] = atlas.CreateRegion("region1", 50, 60, 35, 45);
            regions[2] = atlas.CreateRegion("region2", 32, 33, 34, 35);
            var index = 0;

            foreach (var region in atlas)
            {
                Assert.AreSame(region, regions[index]);
                index++;
            }
        }
 public SpriteSheetAnimator(TextureAtlas textureAtlas)
     : this(null, textureAtlas)
 {
 }
 public SpriteSheetAnimator(Sprite sprite, TextureAtlas textureAtlas)
     : this(sprite, textureAtlas.Select(t => t))
 {
 }
        public void TextureAtlas_GetRegion_InvalidNameThrowsException_Test()
        {
            var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200);
            var atlas = new TextureAtlas(texture);

            atlas.CreateRegion("region0", 10, 20, 30, 40);
            Assert.Throws<KeyNotFoundException>(() => atlas.GetRegion("region1"));
        }