Esempio n. 1
0
    void TestFlyWeight()
    {
        FlyweightFactory factory = new FlyweightFactory();

        FlyWeight flyWeightX = factory.GetFlyweight("酷炫效果");

        flyWeightX.Operation();

        FlyWeight flyWeightY = factory.GetFlyweight("旋转效果");

        flyWeightY.Operation();

        FlyWeight flyWeightZ = factory.GetFlyweight("光影效果");

        flyWeightZ.Operation();

        FlyWeight flyWeightUnshared = new UnsharedConcreteFlyWeight("火焰效果");

        flyWeightUnshared.Operation();

        FlyWeight flyWeightM = factory.GetFlyweight("光影效果");

        flyWeightM.Operation();

        FlyWeight flyWeightN = factory.GetFlyweight("光影效果");

        flyWeightN.Operation();

        Debug.Log("Total number of fly weight : " + factory.GetFlyWeightCount());
    }
        private void SetFlyValue(string key, object value)
        {
            if (!CanGetQualifier(_lastOperator, value))
            {
                IsComplex = true;
                return;
            }

            if (FlyWeight.Contains(key))
            {
                var existing = FlyWeight[key] as Expando;
                if (existing != null)
                {
                    var newq = GetQualifier(_lastOperator, value) as Expando;
                    if (newq != null)
                    {
                        existing.Merge(newq);
                        return;
                    }
                }

                IsComplex = true;
                return;
            }

            FlyWeight[key] = GetQualifier(_lastOperator, value);
        }
Esempio n. 3
0
        public Explosion() : base("Explosion")
        {
            this.Layer = (uint)CollisionLayer.Explosion;

            anim = new AnimationRenderer(FlyWeight.Get("Explosion"), 100, 100, 9, new int[]
            {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
                31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
                41, 42, 43, 44, 45, 56, 57, 58, 59, 50,
                51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
                61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
                71, 72, 73, 74, 75
            }, 0.018f, true, false);

            BoxCollider = new BoxCollider2D(new Vector2(1f, 1f));
            BoxCollider.CollisionMode = CollisionMode.Trigger;
            BoxCollider.TriggerEnter += OnTriggerEnter;
            AddComponent(BoxCollider);

            AddComponent(new BoxCollider2DRenderer(new Vector4(1f, -1f, -1f, 0f)));

            AddComponent(anim);
        }
Esempio n. 4
0
 private static void SetupTextures()
 {
     FlyWeight.Add("Font01", "Assets/Font.dat");
     FlyWeight.Add("Box2D", "Assets/Box2D.dat");
     FlyWeight.Add("Wall", "Assets/Wall_01.dat");
     FlyWeight.Add("Obstacle", "Assets/Obstacle_01.dat");
     FlyWeight.Add("BomberMan", "Assets/Bombertab1.dat");
     FlyWeight.Add("Bomb", "Assets/Bomb.dat");
     FlyWeight.Add("Explosion", "Assets/Explosion.dat");
     FlyWeight.Add("AI", "Assets/ballon.dat");
     FlyWeight.Add("Bomb_PW", "Assets/BombsPw.dat");
     FlyWeight.Add("Bombpass_PW", "Assets/BombpassPw.dat");
     FlyWeight.Add("Flamepass_PW", "Assets/FlamepassPw.dat");
     FlyWeight.Add("Mystery_PW", "Assets/MysteryPw.dat");
     FlyWeight.Add("Detonator_PW", "Assets/DetonatorPw.dat");
     FlyWeight.Add("Wallpass_PW", "Assets/WallpassPw.dat");
     FlyWeight.Add("Speed_PW", "Assets/SpeedPw.dat");
     FlyWeight.Add("Flame_PW", "Assets/FlamesPw.dat");
     FlyWeight.Add("MainScreen", "Assets/mainscreen.dat");
     FlyWeight.Add("Lose", "Assets/Lose.dat");
     FlyWeight.Add("Balloom", "Assets/Balloom.dat");
     FlyWeight.Add("Oneal", "Assets/Oneal.dat");
     FlyWeight.Add("Doll", "Assets/Doll.dat");
     FlyWeight.Add("Kondoria", "Assets/Kondoria.dat");
     FlyWeight.Add("Minvo", "Assets/Minvo.dat");
     FlyWeight.Add("Pass", "Assets/Pass.dat");
     FlyWeight.Add("Ovapi", "Assets/Ovapi.dat");
 }
Esempio n. 5
0
        public Ghost(int life, GameObject target, float range = 120)
        {
            //Animation render
            renderer = AddComponent(new AnimationRenderer(FlyWeight.Get("Ghost"), 32, 32, 4, new[] { 0, 1, 2, 3 }, 0.1f, false, true));
            renderer.RenderOffset = (int)RenderLayer.Player;
            AddComponent(new SwitchAnimation(target, range, true));
            renderer.Sprite.pivot = new Vector2(renderer.Sprite.Width / 2, renderer.Sprite.Height / 2);

            //Collider
            box = new BoxCollider2D(Vector2.One);

            AddComponent(box);

            //Behaviours
            AddComponent(new Rotator(target, range));
            AddComponent(new Blower(target.GetComponent <Blowable>(), range, 3));

            //Input
            input       = AddComponent(new InputMove());
            input.Speed = 90.0f;

            //Rollback
            rollBack     = AddComponent(new RollBack());
            rollBack.box = this.box;

            //Lifes
            // lifes = AddComponent(new Lifes(life, target, this));
        }
Esempio n. 6
0
        public MenuBackground(string nameTexture) : base("Menu Background")
        {
            image = new SpriteRenderer(FlyWeight.Get(nameTexture));
            image.RenderOffset = (int)RenderLayer.Gui_01;
            AddComponent(image);
            this.Transform.Scale = new Vector2(Graphics.Instance.Window.OrthoWidth, Graphics.Instance.Window.OrthoHeight);

            AddComponent(new SetPosition());
        }
Esempio n. 7
0
    public UnsharedConcreteFlyWeight GetUnsharedFlyWeight(string key, string SharedContent, string UnSharedContent)
    {
        FlyWeight SharedFlyWeight = GetFlyWeight(key, SharedContent);

        UnsharedConcreteFlyWeight theFlyWeight = new UnsharedConcreteFlyWeight(UnSharedContent);

        theFlyWeight.SetFlyWeight(SharedFlyWeight);

        return(theFlyWeight);
    }
Esempio n. 8
0
        public Bomberman() : base("BomberMan")
        {
            // LayerMask
            this.Layer = (uint)CollisionLayer.BomberMan;

            #region Animations
            playerAnimations.Add(AnimationType.WALK_RIGHT, new AnimationRenderer(FlyWeight.Get("BomberMan"), 68, 88, 7, new int[] { 35, 35, 36, 36, 37, 37, 37 }, 0.04f, false, true));
            playerAnimations.Add(AnimationType.WALK_LEFT, new AnimationRenderer(FlyWeight.Get("BomberMan"), 69, 88, 7, new int[] { 44, 44, 43, 43, 42, 42, 42 }, 0.04f, false, true));
            playerAnimations.Add(AnimationType.WALK_DOWN, new AnimationRenderer(FlyWeight.Get("BomberMan"), 64, 87, 7, new int[] { 0, 0, 1, 1, 2, 2, 2 }, 0.04f, false, true));
            playerAnimations.Add(AnimationType.WALK_UP, new AnimationRenderer(FlyWeight.Get("BomberMan"), 64, 87, 7, new int[] { 7, 7, 8, 8, 9, 9, 9 }, 0.04f, false, true));
            playerAnimations.Add(AnimationType.IDLE, new AnimationRenderer(FlyWeight.Get("BomberMan"), 62, 87, 7, new int[] { 0 }, 0.04f, true, false));

            playerAnimations.ToList().ForEach(item => AddComponent(item.Value));
            playerAnimations.ToList().ForEach(item => item.Value.RenderOffset = (int)RenderLayer.Player);
            #endregion


            //Bomb fsm
            drop = new StateDrop(this);
            drop.OnStateEnter();
            AddComponent(new FSMUpdater(drop));

            #region Components

            AddComponent(new CharacterController());
            AddComponent(new UpdateAnimation(this));

            //Collider
            collider2D = new BoxCollider2D(new Vector2(1f, 1f));
            collider2D.CollisionMode  = CollisionMode.Collision;
            collider2D.CollisionStay += OnCollisionStay;
            collider2D.TriggerEnter  += OnTriggerEnter;
            AddComponent(collider2D);

            AddComponent(new BoxCollider2DRenderer(new Vector4(1f, 0f, 0f, 0f)));
            Rigidbody2D rigidBody = new Rigidbody2D();
            rigidBody.IsGravityAffected = false;
            AddComponent(rigidBody);

            AddComponent(new CameraFollow());

            manager = new InvulnerabilityManager(this);
            AddComponent(manager);
            #endregion
        }
Esempio n. 9
0
 private void InitTextures()
 {
     FlyWeight.Add("GUI", "Assets/gui.dat");
     FlyWeight.Add("Start", "Assets/start.dat");
     FlyWeight.Add("Wall", "Assets/brick.dat");
     FlyWeight.Add("Flames0", "Assets/Flame00.dat");
     FlyWeight.Add("Flames1", "Assets/Flame01.dat");
     FlyWeight.Add("Flames2", "Assets/Flame02.dat");
     FlyWeight.Add("Ghost", "Assets/Ghost.dat");
     FlyWeight.Add("GhostBlow", "Assets/GhostBlow.dat");
     FlyWeight.Add("GhostLose", "Assets/GhostLose.dat");
     FlyWeight.Add("GhostWin", "Assets/GhostWin.dat");
     FlyWeight.Add("Bubble", "Assets/bubble2.dat");
     FlyWeight.Add("Font", "Assets/Font.dat");
     FlyWeight.Add("Explosion", "Assets/explosion.dat");
     FlyWeight.Add("Candle", "Assets/candle_only_light.dat");
     FlyWeight.Add("Background", "Assets/bg.dat");
 }
Esempio n. 10
0
        public Mystery() : base()
        {
            #region LayerMask
            this.Layer = (uint)CollisionLayer.Powerup;
            #endregion
            //ChangeTexture
            SpriteRenderer renderer = new SpriteRenderer(FlyWeight.Get("Mystery_PW"));
            renderer.RenderOffset = (int)RenderLayer.Powerup;
            AddComponent(renderer);

            BoxCollider2D collider2D = new BoxCollider2D(new Vector2(1, 1));
            collider2D.CollisionMode = CollisionMode.Trigger;
            collider2D.TriggerEnter += OnTriggerEnter;
            AddComponent(collider2D);

            rigidBody = new Rigidbody2D();
            rigidBody.IsGravityAffected = false;
            AddComponent(rigidBody);
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            int extrinsicstate = 22;

            FlyWeightFactory flyWeightFactory = new FlyWeightFactory();

            FlyWeight flyWeightX = flyWeightFactory.GetFlyWeight("X");

            flyWeightX.Operation(--extrinsicstate);

            FlyWeight flyWeightY = flyWeightFactory.GetFlyWeight("Y");

            flyWeightY.Operation(--extrinsicstate);

            FlyWeight flyWeightZ = flyWeightFactory.GetFlyWeight("Z");

            flyWeightZ.Operation(--extrinsicstate);

            FlyWeight uf = new UnsharedConcreteFlyWeight();

            uf.Operation(--extrinsicstate);
        }
Esempio n. 12
0
        public Bomb() : base("Bomb")
        {
            this.Layer = (uint)CollisionLayer.Bombs;

            collider = new BoxCollider2D(Vector2.One);
            //collider.CollisionMode = CollisionMode.Collision;
            //collider.CollisionEnter += OnCollisionEnter;
            collider.CollisionMode = CollisionMode.Trigger;
            collider.TriggerExit  += OnTriggerExit;
            colliders = new List <BoxCollider2D>();
            AddComponent(collider);
            AddComponent(new BoxCollider2DRenderer(Vector4.Zero));



            locations = new List <Vector2>();
            renderer  = new AnimationRenderer(FlyWeight.Get("Bomb"), 50, 50, 3, new int[] { 0, 1, 2, 1 }, 0.2f, true, false);
            AddComponent(renderer);

            #region FSM
            wait    = new StateWait(this);
            explode = new StateExplode(this);

            explode.Next = wait;
            wait.Next    = explode;

            wait.OnStateEnter();
            AddComponent(new FSMUpdater(wait));

            #endregion

            for (int i = 0; i < bigExplosion; i++)
            {
                Explosion toAdd = Pool <Explosion> .GetInstance(x => x.Active = false);

                explosionList.Add(toAdd);
            }
            // ChooseBomb();
        }
Esempio n. 13
0
        public Bubble(string fileNameBubble, string fileNameExplosion) : base("Bubble") // base( ( int )RenderLayer.Pawn, "Bubble" )
        {
            Exploded = false;

            #region Renderer

            bubbleRenderer = new Dictionary <AnimType, AnimationRenderer>();
            bubbleRenderer.Add(AnimType.Normal, AddComponent(new AnimationRenderer(FlyWeight.Get("Bubble"), 32, 32, 3, new[] { 0, 1, 2, 1 }, frameLenght, false, true)));
            bubbleRenderer.Add(AnimType.Exploding, AddComponent(new AnimationRenderer(FlyWeight.Get("Explosion"), 32, 32, 3, frames, frameLenght, true, false)));
            bubbleRenderer[AnimType.Normal].RenderOffset    = (int)RenderLayer.Weapon;
            bubbleRenderer[AnimType.Exploding].RenderOffset = (int)RenderLayer.Weapon;
            #endregion

            Rigidbody2D r = this.AddComponent(new Rigidbody2D());
            r.LinearFriction = 3f;
            this.AddComponent(new Blowable());

            collider = new BoxCollider2D(new Vector2(1f, 1f));
            collider.TriggerEnter += OnTriggerEnter;
            AddComponent(collider);

            #region Explosion
            //target.updateTime += Graphics.Instance.Window.deltaTime;
            //target.SetAnimation(AnimType.Normal, true, false);
            //CameraManager.Instance.Shake(1.9f, 0.2f);

            //if (target.updateTime <= target.time)
            //return this;

            //target.min += Graphics.Instance.Window.deltaTime;
            //target.SetAnimation(AnimType.Exploding, false, true);

            //if (!(target.min >= max))
            //return this;
            #endregion
        }
Esempio n. 14
0
        public Tile(Vector2 position, string textureName, bool solidBlock)
        {
            if (solidBlock)
            {
                this.Layer = (uint)CollisionLayer.SolidWall;
            }
            else
            {
                this.Layer = (uint)CollisionLayer.Wall;
            }

            this.Transform.Position = position;
            SpriteRenderer Renderer = new SpriteRenderer(FlyWeight.Get(textureName));

            Renderer.RenderOffset = (int)RenderLayer.Tile;
            AddComponent(Renderer);

            BoxCollider2D collider = new BoxCollider2D(new Vector2(1, 1));

            collider.TriggerEnter += OnTriggerEnter;
            AddComponent(collider);

            //AddComponent(new BoxCollider2DRenderer(new Vector4(-1f, 1f, -1f, 0f)));
        }
Esempio n. 15
0
 public Minvo() : base("Minvo", FlyWeight.Get("Minvo"), 50, 50, 4, new int[] { 0, 1, 2, 3 }, 0.2f, true, false)
 {
 }
Esempio n. 16
0
 public BoxCollider2DRenderer(Vector4 color) : base(FlyWeight.Get("Box2D"))
 {
     this.color = color;
 }
Esempio n. 17
0
 public Wall()
 {
     renderer = new SpriteRenderer(FlyWeight.Get("Wall"));
     collider = new BoxCollider2D(Vector2.One);
 }
Esempio n. 18
0
 public Candle()
 {
     renderer = AddComponent(new AnimationRenderer(FlyWeight.Get("Candle"), 32, 32, 3, new[] { 1, 0, 1, 2, 0 }, 0.5f, false, true));
     renderer.Sprite.pivot = new Vector2(renderer.Sprite.Width / 2, renderer.Sprite.Height / 2);
 }
Esempio n. 19
0
 public Pass() : base("Pass", FlyWeight.Get("Pass"), 50, 50, 4, new int[] { 0, 1, 2, 3 }, 0.2f, true, false)
 {
 }
Esempio n. 20
0
 public UI(string fileName)
 {
     renderer = AddComponent(new SpriteRenderer(FlyWeight.Get(fileName)));
     renderer.RenderOffset = (int)RenderLayer.Gui_00;
 }
Esempio n. 21
0
 public Ovapi() : base("Ovapi", FlyWeight.Get("Ovapi"), 50, 50, 4, new int[] { 0, 1, 2, 3 }, 0.2f, true, false)
 {
 }
Esempio n. 22
0
 public void SetFlyWeight(FlyWeight theFlyWeight)
 {
     m_FlyWeight = theFlyWeight;
 }
Esempio n. 23
0
 public Oneal() : base("Oneal", FlyWeight.Get("Oneal"), 50, 50, 4, new int[] { 0, 1, 2, 3 }, 0.2f, true, false)
 {
 }
Esempio n. 24
0
 public Balloom() : base("Balloom", FlyWeight.Get("Balloom"), 50, 50, 11, new int[] { 0, 1, 2, 3, 4, 5 }, 0.2f, true, false)
 {
 }
Esempio n. 25
0
 public Pontan() : base("Pontan", FlyWeight.Get("Pontan"), 50, 50, 6, new int[] { 0, 1, 2, 3 }, 0.2f, true, false)
 {
 }
Esempio n. 26
0
 public Kondoria() : base("Kondoria", FlyWeight.Get("Kondoria"), (int)18.5f, 17, 4, new int[] { 0, 1, 2, 3 }, 0.2f, true, false)
 {
 }