コード例 #1
0
ファイル: BoomTexturePacker.cs プロジェクト: WuZongJin/MyGame
        public BoomTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("Images/Players/Allplayer");

            Packer = new TexturePackerAtlas(texture);
            initBoombTexture();
        }
コード例 #2
0
        private static List <Subtexture> LoadTextureList(TexturePackerAtlas atlas, int startIndex, int endIndex)
        {
            var textures = new List <Subtexture>();

            for (int i = startIndex; i < endIndex; i++)
            {
                textures.Add(atlas.subtextures[i]);
            }

            return(textures);
        }
コード例 #3
0
        public static SpriteAnimation LoadMonsterIdle(MonsterIdle idle, TexturePackerAtlas atlas)
        {
            switch (idle)
            {
            case MonsterIdle.Stand:
                return(new SpriteAnimation(LoadTextureList(atlas, 0, 7)));

            default:
                return(null);
            }
        }
コード例 #4
0
        public override void onAddedToEntity()
        {
            //TODO: factory
            //TODO: test with lgbdx
            TexturePackerAtlas atlas = entity.scene.content.Load<TexturePackerAtlas>(@"player/atlas");
            animation = entity.addComponent(new Sprite<Animations>());
            animation.addAnimation(Animations.WalkDown, atlas.getSpriteAnimation("walk-down"));
            animation.addAnimation(Animations.WalkUp, atlas.getSpriteAnimation("walk-up"));
            animation.addAnimation(Animations.WalkLeft, atlas.getSpriteAnimation("walk-left"));
            animation.addAnimation(Animations.WalkRight, atlas.getSpriteAnimation("walk-right"));
            animationKey = Animations.WalkDown;

            mover = entity.addComponent(new Mover());
            xAxisInput = new VirtualIntegerAxis();
            xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadLeftRight());
            xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickX());
            xAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.A, Keys.D));
            yAxisInput = new VirtualIntegerAxis();
            yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadUpDown());
            yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickY());
            yAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.W, Keys.S));
        }
コード例 #5
0
 /// <summary>
 /// 加载图集
 /// </summary>
 public static void LoadAtlas()
 {
     GjsAtlas      = Core.content.Load <TexturePackerAtlas>("mainRole/main_gjs");
     YmrStandAtlas = Core.content.Load <TexturePackerAtlas>("mainMonster/main_ymr");
 }
コード例 #6
0
ファイル: Bottle01.cs プロジェクト: WuZongJin/MyGame
        public override void onAddedToScene()
        {
            base.onAddedToScene();

            var texture       = scene.content.Load <Texture2D>("TileMaps/MapTextures/objects");
            var texturePacker = TexturePackerAtlas.create(texture, 32, 32);

            animationTexture[0] = texturePacker.createRegion("1", 64, 96, 32, 32);
            animationTexture[1] = texturePacker.createRegion("2", 96, 96, 32, 32);
            animationTexture[2] = texturePacker.createRegion("3", 128, 96, 32, 32);
            animationTexture[3] = texturePacker.createRegion("4", 160, 96, 32, 32);

            animation = addComponent(new Sprite <BottleAnimation>(animationTexture[0]));
            animation.setLayerDepth(LayerDepthExt.caluelateLayerDepth(this.position.Y));

            animation.addAnimation(BottleAnimation.Idle, new SpriteAnimation(animationTexture[0]));
            var spriteAnimation = new SpriteAnimation(new List <Subtexture>()
            {
                animationTexture[0],
                animationTexture[1],
                animationTexture[2],
                animationTexture[3],
            });

            spriteAnimation.loop = false;
            animation.addAnimation(BottleAnimation.Broke, spriteAnimation);
            animation.onAnimationCompletedEvent += Animation_onAnimationCompletedEvent;

            animation.currentAnimation = BottleAnimation.Idle;
            animation.play(BottleAnimation.Idle);

            var rigidBody = addComponent <FSRigidBody>()
                            .setBodyType(FarseerPhysics.Dynamics.BodyType.Dynamic);

            var shape = addComponent <SceneObjectTriggerComponent>();

            shape.setRadius(5)
            ;

            shape.setCollisionCategories(CollisionSetting.tiledObjectCategory);
            shape.setCollidesWith(CollisionSetting.allAttackCategory | CollisionSetting.allAttackTypeCategory);

            shape.onAdded = onAddedMethod;

            colliderEntity = scene.createEntity("collision");
            colliderEntity.setPosition(this.position);
            colliderEntity.addComponent <FSRigidBody>()
            .setBodyType(BodyType.Static);

            var colliderShape = colliderEntity.addComponent <FSCollisionCircle>();

            colliderShape.setRadius(4);
            colliderShape.setCollisionCategories(CollisionSetting.wallCategory);

            triggerEvent = () =>
            {
                if (!colliderEntity.isDestroyed)
                {
                    colliderEntity.destroy();
                }
            };
        }
コード例 #7
0
        public yObjectTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("TileMaps/MapTextures/objects");

            Packer = TexturePackerAtlas.create(texture, 16, 16);
        }
コード例 #8
0
        public xObjectTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("Images/ItemsObjects/springObjects");

            Packer = TexturePackerAtlas.create(texture, 16, 16);
        }
コード例 #9
0
ファイル: Bat.cs プロジェクト: WuZongJin/MyGame
        public override void onAddedToScene()
        {
            base.onAddedToScene();
            this.setScale(2f);

            this.actorProperty           = addComponent <ActorPropertyComponent>();
            this.actorProperty.HP        = this.actorProperty.MaxHP = 30;
            this.actorProperty.moveSpeed = 70f;

            var texture       = scene.content.Load <Texture2D>("Images/Enemys/Bat");
            var texturePacker = new TexturePackerAtlas(texture);
            var idleTexture   = texturePacker.createRegion("batidle", 0, 33, 16, 16);
            var flyTextur1    = texturePacker.createRegion("fly01", 0, 9, 16, 16);
            var flyTextur2    = texturePacker.createRegion("fly02", 16, 9, 16, 16);
            var flyTextur3    = texturePacker.createRegion("fly03", 32, 9, 16, 16);
            var flyTextur4    = texturePacker.createRegion("fly04", 48, 9, 16, 16);

            animation = addComponent(new Sprite <BatAnimations>(idleTexture));
            animation.setRenderLayer(GameLayerSetting.tiledActorUpLayer);
            animation.addAnimation(BatAnimations.Idle, new SpriteAnimation(idleTexture));
            animation.addAnimation(BatAnimations.Fly, new SpriteAnimation(new List <Subtexture>()
            {
                flyTextur1, flyTextur2, flyTextur3, flyTextur4
            }));
            animation.currentAnimation = BatAnimations.Idle;


            addComponent <FSRigidBody>()
            .setBodyType(BodyType.Dynamic).
            setLinearDamping(0.8f)
            .setMass(1.5f);

            var enemtCollider = addComponent <FSCollisionCircle>()
                                .setRadius(8);

            enemtCollider.setCollisionCategories(CollisionSetting.enemyCategory);
            enemtCollider.setCollidesWith(
                CollisionSetting.allAttackTypeCategory
                | CollisionSetting.playerAttackCategory
                );

            var damageTriger = addComponent <DamageTrigerComponent>();

            damageTriger.setRadius(10).setIsSensor(true);
            damageTriger.setCollisionCategories(
                CollisionSetting.enemyAttackCategory);
            damageTriger.setCollidesWith(CollisionSetting.playerCategory);
            damageTriger.onAdded += () =>
            {
                damageTriger.GetFixture().onCollision += (fixtureA, fixtureB, contact) =>
                {
                    var component     = fixtureB.userData as Component;
                    var actorProperty = component.entity.getComponent <ActorPropertyComponent>();
                    actorProperty.executeDamage?.Invoke(AttackTypes.Physics, 5);
                    var rigidbody = component.entity.getComponent <FSRigidBody>();
                    var dir       = component.entity.position - this.position;
                    dir.Normalize();
                    rigidbody.body.applyLinearImpulse(dir * rigidbody.body.mass);
                    return(true);
                };
            };


            var viewFieldTrigger = addComponent <EnemyViewComponent>();

            viewFieldTrigger.setRadius(fieldOfView);
            viewFieldTrigger.setIsSensor(true);
            viewFieldTrigger.setCollisionCategories(CollisionSetting.enemyCategory);
            viewFieldTrigger.setCollidesWith(CollisionSetting.playerCategory);

            viewFieldTrigger.onAdded += () =>
            {
                viewFieldTrigger.GetFixture().onCollision += (fixtureA, fixtureB, contact) =>
                {
                    target       = ((Component)(fixtureB.userData)).entity;
                    isFindTarget = true;
                    return(true);
                };
            };



            addComponent <RigidBodyVelocityLimited>();
            addComponent(new BatSampleStateMachine(this));
        }
コード例 #10
0
        public xAnimationsTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("Images/ItemsObjects/animations");

            Packer = TexturePackerAtlas.create(texture, 16, 16);
        }