예제 #1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var zombieAnimations = Content.Load <SpriteSheetAnimationFactory>("Animations/zombie-animations");

            _zombie = new Zombie(zombieAnimations)
            {
                Position = new Vector2(100, 100)
            };

            var fireballTexture = Content.Load <Texture2D>("Animations/fireball");
            var fireballAtlas   = TextureAtlas.Create("Animations/fireball-atlas", fireballTexture, 130, 50);

            _animation = new SpriteSheetAnimation("fireballAnimation", fireballAtlas.Regions.ToArray())
            {
                FrameDuration = 0.2f
            };
            _fireballSprite = new Sprite(_animation.CurrentFrame);// { Position = new Vector2(-150, 100) };

            var motwTexture          = Content.Load <Texture2D>("Animations/motw");
            var motwAtlas            = TextureAtlas.Create("Animations/fireball-atlas", motwTexture, 52, 72);
            var motwAnimationFactory = new SpriteSheetAnimationFactory(motwAtlas);

            motwAnimationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 }));
            motwAnimationFactory.Add("walkSouth", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }, isLooping: false));
            motwAnimationFactory.Add("walkWest", new SpriteSheetAnimationData(new[] { 12, 13, 14, 13 }, isLooping: false));
            motwAnimationFactory.Add("walkEast", new SpriteSheetAnimationData(new[] { 24, 25, 26, 25 }, isLooping: false));
            motwAnimationFactory.Add("walkNorth", new SpriteSheetAnimationData(new[] { 36, 37, 38, 37 }, isLooping: false));
            _motwSprite = new AnimatedSprite(motwAnimationFactory);// { Position = new Vector2(20, 20) };
            _motwSprite.Play("walkSouth").IsLooping = true;
        }
 public AnimatedObject(Texture2D spritesheet, Dictionary <string, Rectangle> map, Vector2 scale)
 {
     spriteAtlas      = new TextureAtlas("animations", spritesheet, map);
     animationFactory = new SpriteSheetAnimationFactory(spriteAtlas);
     animatedSprite   = new AnimatedSprite(animationFactory);
     Scale            = scale;
 }
예제 #3
0
        public Animation(Texture2D texture, SpriteSheetData spriteSheetData, int direction = 0, bool isPlayer = false)
        {
            var spriteWidth   = spriteSheetData.Width;
            var spriteHeight  = spriteSheetData.Height;
            var objectTexture = texture;
            var objectAtlas   = TextureAtlas.Create("objectAtlas", objectTexture, spriteWidth, spriteHeight);

            var animationFactory = new SpriteSheetAnimationFactory(objectAtlas);

            for (int i = 0; i < spriteSheetData.AnimationName.Count; i++)
            {
                animationFactory.Add(spriteSheetData.AnimationName[i], new SpriteSheetAnimationData(spriteSheetData.FrameArray[i], spriteSheetData.FrameDuration[i], spriteSheetData.IsLooping[i]));
            }

            if (isPlayer)
            {
                objectAnimated = new AnimatedSprite(animationFactory, HUD.PlayerCurrentState.ToString());
            }
            else
            {
                objectAnimated = new AnimatedSprite(animationFactory, "Idle");
            }

            objectSprite        = objectAnimated;
            objectSprite.Origin = Vector2.Zero;

            if (direction == (int)Direction.Right)
            {
                objectAnimated.Effect = SpriteEffects.None;
            }
            else
            {
                objectAnimated.Effect = SpriteEffects.FlipHorizontally;
            }
        }
예제 #4
0
        private SpriteSheetAnimationFactory CreateAnimationFactory(ContentManager contentManager, CharacterSide side)
        {
            var sideString = side.ToString().ToLower();
            var texture    = contentManager.Load <Texture2D>($"sprites/{sideString}/sprites");
            var map        = contentManager.Load <Dictionary <string, Rectangle> >($"sprites/{sideString}/spritesMap");
            var atlas      = new TextureAtlas("character", texture, map);
            var factory    = new SpriteSheetAnimationFactory(atlas);

            var start = -1;

            factory.Add(GetSpriteTag(CharacterColour.Blue, CharacterFacing.East), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Blue, CharacterFacing.North), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Blue, CharacterFacing.South), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Blue, CharacterFacing.West), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Green, CharacterFacing.East), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Green, CharacterFacing.North), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Green, CharacterFacing.South), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Green, CharacterFacing.West), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.None, CharacterFacing.East), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.None, CharacterFacing.North), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.None, CharacterFacing.South), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.None, CharacterFacing.West), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Red, CharacterFacing.East), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Red, CharacterFacing.North), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Red, CharacterFacing.South), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.Red, CharacterFacing.West), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.White, CharacterFacing.East), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.White, CharacterFacing.North), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.White, CharacterFacing.South), new SpriteSheetAnimationData(Next6(ref start)));
            factory.Add(GetSpriteTag(CharacterColour.White, CharacterFacing.West), new SpriteSheetAnimationData(Next6(ref start)));

            return(factory);
        }
예제 #5
0
        public override void Load(ContentManager content)
        {
            // initiliaze sprite
            spriteWidth   = 48;
            spriteHeight  = 32;
            objectTexture = content.Load <Texture2D>("Sprites/player");
            objectAtlas   = TextureAtlas.Create("objectAtlas", objectTexture, spriteWidth, spriteHeight);

            //create animations from sprite sheet
            animationFactory = new SpriteSheetAnimationFactory(objectAtlas);
            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 }));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 1, 2, 3, 4 }, frameDuration: 0.1f, isLooping: true));
            animationFactory.Add("jump", new SpriteSheetAnimationData(new[] { 3 }));
            animationFactory.Add("attack", new SpriteSheetAnimationData(new[] { 6, 7, 8, 9 }, frameDuration: 0.1f, isLooping: true));
            animationFactory.Add("attackDown", new SpriteSheetAnimationData(new[] { 6, 7, 8, 9 }, frameDuration: 0.1f, isLooping: true));
            animationFactory.Add("hurt", new SpriteSheetAnimationData(new[] { 3 }));
            animationFactory.Add("duck", new SpriteSheetAnimationData(new[] { 10 }, frameDuration: 0.1f, isLooping: true));

            objectAnimated = new AnimatedSprite(animationFactory, "idle");
            objectSprite   = objectAnimated;

            objectSprite.Depth = 0.1f;

            // load sound effects
            jumpSFX   = content.Load <SoundEffect>("Audio/Sound Effects/Jump");
            attackSFX = content.Load <SoundEffect>("Audio/Sound Effects/playerAttack");
            hurtSFX   = content.Load <SoundEffect>("Audio/Sound Effects/playerHurt");
            deadSFX   = content.Load <SoundEffect>("Audio/Sound Effects/playerDeath");

            base.Load(content);
            boundingBoxWidth  = 14;
            boundingBoxHeight = 24;
            boundingBoxOffset = new Vector2(17, 7);
        }
예제 #6
0
        public override void Load(ContentManager content)
        {
            #region  INITIALIZE TEXTURE ATLAS AND ANIMATION

            var spriteWidth   = 16;
            var spriteHeight  = 16;
            var objectTexture = content.Load <Texture2D>("Sprites/Player/s_player_overworld_atlas");
            var objectAtlas   = TextureAtlas.Create("objectAtlas", objectTexture, spriteWidth, spriteHeight);

            var animationFactory = new SpriteSheetAnimationFactory(objectAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 }));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 0, 1 }, frameDuration: 0.2f, isLooping: true));

            #endregion


            objectAnimated = new AnimatedSprite(animationFactory, "idle");
            objectSprite   = objectAnimated;

            base.Load(content);

            objectSprite.Origin = Vector2.Zero + origin;
            //set custom hitbox
            boundingBoxTopLeft     = Vector2.Zero;
            boundingBoxBottomRight = new Vector2(16, 16);
        }
예제 #7
0
        public Zombie(SpriteSheetAnimationFactory animations)
        {
            _sprite = new AnimatedSprite(animations);

            State      = ZombieState.Appearing;
            IsOnGround = false;
        }
예제 #8
0
        public static Entity Create(Engine engine, Texture2D texture, Vector2 position)
        {
            Entity entity = engine.CreateEntity();

            entity.AddComponent(new TransformComponent(position));
            entity.AddComponent(new SpriteComponent(texture, Constants.ObjectBounds.EXPLOSION_BOUNDS));
            entity.AddComponent(new ExplosionComponent());

            Dictionary <string, Rectangle> explMap = new Dictionary <string, Rectangle>();

            explMap.Add("Explosion1", new Rectangle(0, 0, 32, 32));
            explMap.Add("Explosion2", new Rectangle(32, 0, 32, 32));
            explMap.Add("Explosion3", new Rectangle(64, 0, 32, 32));
            explMap.Add("Explosion4", new Rectangle(96, 0, 32, 32));
            explMap.Add("Explosion5", new Rectangle(128, 0, 32, 32));
            explMap.Add("Explosion6", new Rectangle(160, 0, 32, 32));
            explMap.Add("Explosion7", new Rectangle(192, 0, 32, 32));
            TextureAtlas explAtlas = new TextureAtlas("explosion", texture, explMap);
            SpriteSheetAnimationFactory explAnimationFactory = new SpriteSheetAnimationFactory(explAtlas);

            explAnimationFactory.Add("default", new SpriteSheetAnimationData(new[] { 0, 1, 2, 3, 4, 5, 6 }, isLooping: false, frameDuration: 0.1f));
            AnimatedSprite explAnim = new AnimatedSprite(explAnimationFactory);

            entity.AddComponent(new Components.AnimationComponent(explAnimationFactory, new AnimatedSprite[] { explAnim }));
            entity.GetComponent <Components.AnimationComponent>().ActiveAnimationIndex = 0;
            explAnim.Play("default", () =>
            {
                entity.GetComponent <Components.AnimationComponent>().ActiveAnimationIndex = -1;
            });

            return(entity);
        }
예제 #9
0
        //protected override void Initialize()
        //{
        //    base.Initialize();

        //    _graphicsDeviceManager.IsFullScreen = true;
        //    _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
        //    _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
        //    _graphicsDeviceManager.ApplyChanges();
        //}

        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _font            = Content.Load <BitmapFont>("Fonts/montserrat-32");

            _camera = new OrthographicCamera(_viewportAdapter);
            _explosionAnimations = Content.Load <SpriteSheetAnimationFactory>("explosion-animations");

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _backgroundTexture = Content.Load <Texture2D>("black");

            var bulletTexture = Content.Load <Texture2D>("laserBlue03");
            var bulletRegion  = new TextureRegion2D(bulletTexture);

            _bulletFactory = new BulletFactory(_entityManager, bulletRegion);

            SpawnPlayer(_bulletFactory);

            _meteorFactory = new MeteorFactory(_entityManager, Content);

            for (var i = 0; i < 13; i++)
            {
                _meteorFactory.SpawnNewMeteor(_player.Position);
            }
        }
예제 #10
0
        public Entity CreatePlayer(Vector2 position)
        {
            var dudeTexture = _contentManager.Load <Texture2D>("Graphics/hero");
            var dudeAtlas   = TextureAtlas.Create("dudeAtlas", dudeTexture, 16, 16);
            var entity      = _world.CreateEntity();

            var animationFactory = new SpriteSheetAnimationFactory(dudeAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 6, 7, 8, 9, 10, 11 }, frameDuration: 0.1f));
            animationFactory.Add("combat", new SpriteSheetAnimationData(new[] { 25 }, frameDuration: 0.1f, isLooping: false));
            animationFactory.Add("guard", new SpriteSheetAnimationData(new[] { 24 }, frameDuration: 0.3f, isLooping: false));

            entity.Attach(new AnimatedSprite(animationFactory, "idle"));
            entity.Attach(new Transform2(position, 0, Vector2.One * 4));
            entity.Attach(new Body {
                Position = position, Size = new Vector2(40, 96), BodyType = BodyType.Dynamic
            });
            entity.Attach(new Focusable {
                IsFocused = true
            });
            entity.Attach(new Health()
            {
                LifePoints = 3
            });
            entity.Attach(new Player());

            return(entity);
        }
예제 #11
0
파일: Game1.cs 프로젝트: kirbunkle/potion
        public static AnimatedSprite CreateAnimatedSprite(SpriteSheetAnimationFactory factory, string name)
        {
            AnimatedSprite a = new AnimatedSprite(factory, name);

            a.Origin = new Vector2(0, 0);
            return(a);
        }
예제 #12
0
        public Entity CreateNecromancer(Vector2 position)
        {
            var necroTexture = _contentManager.Load <Texture2D>("Graphics/YeOldyNecroGuy");
            var necroAtlas   = TextureAtlas.Create("necroAtlas", necroTexture, 28, 28);
            var entity       = _world.CreateEntity();

            var animationFactory = new SpriteSheetAnimationFactory(necroAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 6, 7, 8, 9, 10, 11 }, frameDuration: 0.1f));
            animationFactory.Add("combat", new SpriteSheetAnimationData(new[] { 25 }, frameDuration: 0.1f, isLooping: false));
            entity.Attach(new AnimatedSprite(animationFactory, "idle"));
            entity.Attach(new Transform2(position, 0, Vector2.One * 4));
            entity.Attach(new Body {
                Position = position, Size = new Vector2(40, 96), BodyType = BodyType.Static
            });
            entity.Attach(new Health()
            {
                LifePoints = 3
            });
            entity.Attach(new Enemy()
            {
                Facing = Facing.Left
            });

            return(entity);
        }
예제 #13
0
        public static Entity Create(Engine engine, Texture2D texture, Vector2 position)
        {
            Entity entity = engine.CreateEntity();

            entity.AddComponent(new TransformComponent(position));
            entity.AddComponent(new SpriteComponent(texture, Constants.ObjectBounds.KAMIKAZE_SHIP_BOUNDS));
            entity.AddComponent(new RotationComponent(Constants.GamePlay.KAMIKAZE_ROTATION_SPEED));
            entity.AddComponent(new MovementComponent());
            entity.GetComponent <MovementComponent>().speed = Constants.GamePlay.KAMIKAZE_ENEMY_SPEED;
            entity.AddComponent(new EnemyComponent());
            entity.AddComponent(new CollisionComponent(new BoundingRect(0, 0, 21.875f, 21.875f)));
            entity.AddComponent(new KamikazeComponent());

            Dictionary <string, Rectangle> animMap = new Dictionary <string, Rectangle>();

            animMap.Add("2", new Rectangle(0, 0, 32, 32));
            animMap.Add("1", new Rectangle(32, 0, 32, 32));
            TextureAtlas animAtlas = new TextureAtlas("explosion", texture, animMap);
            SpriteSheetAnimationFactory animAnimationFactory = new SpriteSheetAnimationFactory(animAtlas);

            animAnimationFactory.Add("default", new SpriteSheetAnimationData(new[] { 0, 1 }, isLooping: true, frameDuration: 0.4f));
            AnimatedSprite anim = new AnimatedSprite(animAnimationFactory);

            entity.AddComponent(new Components.AnimationComponent(animAnimationFactory, new AnimatedSprite[] { anim }));
            entity.GetComponent <Components.AnimationComponent>().ActiveAnimationIndex = 0;
            anim.Play("default");

            return(entity);
        }
예제 #14
0
        public override void Load(ContentManager content)
        {
            // initiliaze sprite
            spriteWidth   = 20;
            spriteHeight  = 20;
            objectTexture = content.Load <Texture2D>("Sprites/playerOverworld");
            objectAtlas   = TextureAtlas.Create("objectAtlas", objectTexture, spriteWidth, spriteHeight);

            //create animations from sprite sheet
            animationFactory = new SpriteSheetAnimationFactory(objectAtlas);
            animationFactory.Add("down", new SpriteSheetAnimationData(new[] { 0 }));
            animationFactory.Add("downwalk", new SpriteSheetAnimationData(new[] { 1, 2 }, frameDuration: 0.2f, isLooping: true));

            animationFactory.Add("up", new SpriteSheetAnimationData(new[] { 3 }));
            animationFactory.Add("upwalk", new SpriteSheetAnimationData(new[] { 4, 5 }, frameDuration: 0.2f, isLooping: true));

            animationFactory.Add("right", new SpriteSheetAnimationData(new[] { 6 }));
            animationFactory.Add("rightwalk", new SpriteSheetAnimationData(new[] { 7, 8 }, frameDuration: 0.2f, isLooping: true));

            animationFactory.Add("left", new SpriteSheetAnimationData(new[] { 9 }));
            animationFactory.Add("leftwalk", new SpriteSheetAnimationData(new[] { 10, 11 }, frameDuration: 0.2f, isLooping: true));

            objectAnimated = new AnimatedSprite(animationFactory, "down");
            objectSprite   = objectAnimated;

            objectSprite.Depth = 0.1f;

            base.Load(content);
            boundingBoxWidth  = 16;
            boundingBoxHeight = 16;
            boundingBoxOffset = new Vector2(2, 4);
        }
예제 #15
0
        public Character(List <string> data, int x, int y, Location loc) : base(loc)
        {
            drawToolInteractBox      = true;
            interactBoxTexture       = Game1.content.Load <Texture2D>("spriteSheets/simplebox");
            interactToolBoxRectangle = FindInteractToolBoxRectangle();
            interactBoxRectangle     = FindInteractBoxRectangle();

            velocityX = 0;
            velocityY = 0;

            curSprite = "";
            speed     = 0.15f;

            events = new List <Event>();

            spriteFactory = Game1.CreateAnimationFactory(data[2], data[3]);
            float frameDuration = float.Parse(data[4]);

            for (int i = 5; i < data.Count; i++)
            {
                var   indexes         = data[i].Split(',');
                int[] animationFrames = new int[indexes.Count() - 1];
                for (int j = 0; j < indexes.Count() - 1; j++)
                {
                    animationFrames[j] = Int32.Parse(indexes[j + 1]);
                }
                spriteFactory.Add(indexes[0], new SpriteSheetAnimationData(animationFrames, frameDuration, (animationFrames.Count() > 1)));
            }
            curSprite       = "down_idle";
            facingDirection = Direction.Down;
            sprite          = Game1.CreateAnimatedSprite(spriteFactory, curSprite);
            collisionBox    = MakeCollisionBoundingBox();
            posX            = x;
            posY            = y;
        }
예제 #16
0
 public Explosion(SpriteSheetAnimationFactory animations, Vector2 position, float radius)
 {
     _sprite = new AnimatedSprite(animations);
     _sprite.Play("explode", Destroy);
     _transform = new Transform2 {
         Position = position, Scale = Vector2.One * radius * 0.2f
     };
 }
예제 #17
0
        public AnimatedSprite(SpriteSheetAnimationFactory animationFactory, string playAnimation = null)
            : base(animationFactory.Frames[0])
        {
            _animationFactory = animationFactory;

            if (playAnimation != null)
            {
                Play(playAnimation);
            }
        }
예제 #18
0
        private SpriteSheetAnimationFactory LoadAnimationFactory(TextureAtlas atlas, Animation[] animations)
        {
            var animationFactory = new SpriteSheetAnimationFactory(atlas);

            foreach (var animation in animations)
            {
                animationFactory.Add(animation.Name, new SpriteSheetAnimationData(animation.FrameIndices,
                                                                                  animation.FrameDuration, animation.IsLooping));
            }

            return(animationFactory);
        }
예제 #19
0
        private void loadSpriteSheet(ContentManager content)
        {
            Texture2D enemyTexture = content.Load <Texture2D>("Assets/SpriteSheets/Zombie");
            Dictionary <string, Rectangle> characterMap = content.Load <Dictionary <string, Rectangle> >("Assets/SpriteSheets/ZombieMap");
            TextureAtlas zombieAtlas = new TextureAtlas("zombie", enemyTexture, characterMap);
            SpriteSheetAnimationFactory zombieAnimationFactory = new SpriteSheetAnimationFactory(zombieAtlas);

            zombieAnimationFactory.Add("walking", new SpriteSheetAnimationData(new[] { 0, 1, 2, 3 }, isLooping: true, frameDuration: 0.2f));

            this.zombieAnimationFactory = zombieAnimationFactory;

            //AnimatedSprite characterSpriteAnimation = new AnimatedSprite(zombieAnimationFactory, "walking");
            //anim = characterSpriteAnimation;
        }
예제 #20
0
        public override void OnAddedToScene()
        {
            var goblinAnimations   = Scene.Content.Load <Animation[]>(ContentPaths.AnimatedSprites.GoblinAnimations);
            var skeletonAnimations = Scene.Content.Load <Animation[]>(ContentPaths.AnimatedSprites.SkeletonAnimations);
            var wyvernAnimations   = Scene.Content.Load <Animation[]>(ContentPaths.AnimatedSprites.WyvernAnimations);

            var goblinAtlas   = Scene.Content.Load <TextureAtlas>(ContentPaths.AnimatedSprites.GoblinAtlas);
            var skeletonAtlas = Scene.Content.Load <TextureAtlas>(ContentPaths.AnimatedSprites.SkeletonAtlas);
            var wyvernAtlas   = Scene.Content.Load <TextureAtlas>(ContentPaths.AnimatedSprites.WyvernAtlas);

            goblinAnimationFactory   = LoadAnimationFactory(goblinAtlas, goblinAnimations);
            skeletonAnimationFactory = LoadAnimationFactory(skeletonAtlas, skeletonAnimations);
            wyvernAnimationFactory   = LoadAnimationFactory(wyvernAtlas, wyvernAnimations);
        }
예제 #21
0
        public Shuriken(Entities entities, GameObject owner, ContentManager content)
        {
            _entities = entities;
            _owner    = owner;
            _texture  = content.Load <Texture2D>("Textures/s_star");

            // create animation sprite
            var spriteWidth  = 9;
            var spriteHeight = 9;
            var objectAtlas  = TextureAtlas.Create("objectAtlas", _texture, spriteWidth, spriteHeight);

            _animationFactory = new SpriteSheetAnimationFactory(objectAtlas);

            _animationFactory.Add("Init", new SpriteSheetAnimationData(new[] { 0, 1 }, 0.05f, true));
        }
예제 #22
0
        public FlameStrike(Entities entities, GameObject owner, ContentManager content)
        {
            _entities = entities;
            _owner    = owner;
            _texture  = content.Load <Texture2D>("Textures/s_flame_strike");

            // create animation sprite
            var spriteWidth  = 32;
            var spriteHeight = 32;
            var objectAtlas  = TextureAtlas.Create("objectAtlas", _texture, spriteWidth, spriteHeight);

            _animationFactory = new SpriteSheetAnimationFactory(objectAtlas);

            _animationFactory.Add("Init", new SpriteSheetAnimationData(new[] { 0, 1, 2, 3, 4 }, 0.2f, true, false, true));
        }
예제 #23
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var characterTexture          = Content.Load <Texture2D>("furret");
            var characterMap              = Content.Load <Dictionary <string, Rectangle> >("furretMap");
            var characterAtlas            = new TextureAtlas("furret", characterTexture, characterMap);
            var characterAnimationFactory = new SpriteSheetAnimationFactory(characterAtlas);

            characterAnimationFactory.Add("idle", new SpriteSheetAnimationData(Enumerable.Range(0, 29).ToArray(), isLooping: true));

            _characterSpriteAnimation = new AnimatedSprite(characterAnimationFactory, "idle");

            // TODO: use this.Content to load your game content here
        }
예제 #24
0
        public Storm(SpriteSheetAnimationFactory lightningAnimation)
        {
            mGenerator = new Random();
            mAnim      = lightningAnimation;

            mStormClouds = new List <Cloud>();

            mStormRegion = new Rectangle(mGenerator.Next(0, Game1.mMapScreen.mMapCamera.mMapHeight),
                                         mGenerator.Next(0, Game1.mMapScreen.mMapCamera.mMapWidth), mGenerator.Next(300, 1000), mGenerator.Next(200, 700));

            mNewLightning = mGenerator.Next(10, 100);
            Spawn();
            mLightningactivated = false;
            mTimeToLive         = mGenerator.Next(0, 200);
        }
예제 #25
0
        public void LoadContent()
        {
            var aliens     = _game.Content.Load <Texture2D>("aliens");
            var alienAtlas = TextureAtlas.Create("aliens",
                                                 aliens,
                                                 16,
                                                 10);

            _animationFactory = new SpriteSheetAnimationFactory(alienAtlas);
            _animationFactory.Add("alien0", new SpriteSheetAnimationData(new[] { 0, 1 }, 0.5f));
            _animationFactory.Add("alien1", new SpriteSheetAnimationData(new[] { 2, 3 }, 0.5f));
            _animationFactory.Add("alien2", new SpriteSheetAnimationData(new[] { 4, 5 }, 0.5f));

            _ship   = _game.Content.Load <Texture2D>("ship");
            _bullet = _game.Content.Load <Texture2D>("bullet");
        }
예제 #26
0
        public void SpawnExplosion(Vector2 position, Vector2 velocity)
        {
            var frames           = new[] { 256, 257, 258, 259, 260, 261, 262, 263, 264 };
            var animationFactory = new SpriteSheetAnimationFactory(frames.Select(f => _tileset.GetTile(f)));

            animationFactory.Add("explode", new SpriteSheetAnimationData(new [] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, isLooping: false, frameDuration: 1f / 32f));
            var entity         = World.CreateEntity();
            var animatedSprite = new AnimatedSprite(animationFactory);

            entity.Attach(animatedSprite);
            entity.Attach(new Transform2(position));
            entity.Attach(new Body {
                Velocity = velocity
            });
            animatedSprite.Play("explode", () => entity.Destroy());
        }
예제 #27
0
        public Entity CreatePlayer(Vector2 position)
        {
            var entity           = _entityComponentSystem.CreateEntity(Entities.Player, position);
            var textureRegion    = _characterTextureAtlas[0];
            var animationFactory = new SpriteSheetAnimationFactory(_characterTextureAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 12, 13 }, 1.0f));
            animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 0, 1, 2, 3 }));
            animationFactory.Add("jump", new SpriteSheetAnimationData(new[] { 8, 9 }, isLooping: false));

            entity.AttachComponent(new TransformableComponent <Sprite>(new AnimatedSprite(animationFactory)));
            entity.AttachComponent(new BasicCollisionBody(textureRegion.Size, Vector2.One * 0.5f));
            entity.AttachComponent(new PlayerCollisionHandler());
            entity.AttachComponent(new CharacterState());
            entity.Tag = Entities.Player;

            return(entity);
        }
예제 #28
0
        public override void Load(ContentManager content)
        {
            objectTexture = content.Load <Texture2D>("Maps/MapObjects/" + platformSize);
            spriteWidth   = objectTexture.Width;
            spriteHeight  = objectTexture.Height;

            objectAtlas      = TextureAtlas.Create("objectAtlas", objectTexture, spriteWidth, spriteHeight);
            animationFactory = new SpriteSheetAnimationFactory(objectAtlas);

            animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 }));
            objectAnimated     = new AnimatedSprite(animationFactory, "idle");
            objectSprite       = objectAnimated;
            objectSprite.Depth = 0.5f;
            base.Load(content);

            boundingBoxWidth  = objectTexture.Width;
            boundingBoxHeight = objectTexture.Height;
        }
예제 #29
0
        public Character(string name, Map map, Vector2 position) : base(map, position)
        {
            this.RenderBounds    = new RectangleF(-0.5F, -1.5F, 1, 2);
            this.CollisionBounds = new RectangleF(-0.4F, 0, 0.8F, 0.35F);

            this.AnimationFactory = new SpriteSheetAnimationFactory(new TextureAtlas(
                                                                        name,
                                                                        GameImpl.LoadContent <Texture2D>("Characters/" + name),
                                                                        GameImpl.LoadContent <Dictionary <string, Rectangle> >("Characters/Animation")));
            this.AnimationFactory.Add("StandingDown", new SpriteSheetAnimationData(new[] { 0 }));
            this.AnimationFactory.Add("Down", new SpriteSheetAnimationData(new[] { 1, 2, 3 }, isPingPong: true));
            this.AnimationFactory.Add("StandingUp", new SpriteSheetAnimationData(new[] { 4 }));
            this.AnimationFactory.Add("Up", new SpriteSheetAnimationData(new[] { 5, 6, 7 }, isPingPong: true));
            this.AnimationFactory.Add("StandingLeft", new SpriteSheetAnimationData(new[] { 8 }));
            this.AnimationFactory.Add("Left", new SpriteSheetAnimationData(new[] { 9, 10, 11 }, isPingPong: true));
            this.AnimationFactory.Add("StandingRight", new SpriteSheetAnimationData(new[] { 12 }));
            this.AnimationFactory.Add("Right", new SpriteSheetAnimationData(new[] { 13, 14, 15 }, isPingPong: true));
            this.CurrentAnimation = this.AnimationFactory.Create("StandingDown");
        }
예제 #30
0
        public EfxGenerator(Texture2D texture)
        {
            var spriteWidth  = 32;
            var spriteHeight = 32;

            ObjectTexture = texture;
            var objectAtlas = TextureAtlas.Create("objectAtlas", ObjectTexture, spriteWidth, spriteHeight);

            var animationFactory = new SpriteSheetAnimationFactory(objectAtlas);

            animationFactory.Add("Init", new SpriteSheetAnimationData(new[] { 0 }, 0.1f, false));
            animationFactory.Add("Death", new SpriteSheetAnimationData(new[] { 1, 2, 3, 4 }, 0.05f, false));
            animationFactory.Add("Smoke", new SpriteSheetAnimationData(new[] { 5, 6, 7, 8, 9, 10 }, 0.12f, false));


            ObjectAnimated      = new AnimatedSprite(animationFactory, "Init");
            ObjectSprite        = ObjectAnimated;
            ObjectSprite.Origin = Vector2.Zero;
        }