示例#1
0
        public Cube(Card[] cards, PhysicsBody physicsBody=null)
        {
            if (!initialized) {
                Initialize();
            }
            _physicsBody = physicsBody;

            this.TextureInfo = new TextureInfo();
            this.TextureInfo.Texture = new Texture2D(256, 256,false,PixelFormat.Rgba);
            //			this.TextureInfo.Texture = new Texture2D(167, 191,false,PixelFormat.Rgba);

            setColorData (cards[0].Color);
            if ( cards[0].cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                addToTexture (_imgTop, new Vector2i(45,0), colorData );
            } else if ( cards[0].cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                addToTexture (_imgTopStripe, new Vector2i(45,0), colorData );
            } else {
                addToTexture (_imgTopDot, new Vector2i(45,0), colorData );
            }
            setColorData (cards[1].Color);
            if ( cards[0].cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                addToTexture (_imgLeft, new Vector2i(0,-78), colorData );
            } else if ( cards[0].cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                addToTexture (_imgLeftStripe, new Vector2i(0,-78), colorData );
            } else {
                addToTexture (_imgLeftDot, new Vector2i(0,-78), colorData );
            }
            //			addToTexture (_imgLeft, new Vector2i(0,-78), colorData );
            setColorData (cards[2].Color);
            if ( cards[0].cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                addToTexture (_imgRight, new Vector2i(92,-78), colorData);
            } else if ( cards[0].cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                addToTexture (_imgRightStripe, new Vector2i(92,-78), colorData);
            } else {
                addToTexture (_imgRightDot, new Vector2i(92,-78), colorData);
            }
            //			addToTexture (_imgRight, new Vector2i(92,-78), colorData);

            this.Scale = this.CalcSizeInPixels()/4f;
            this.Pivot = new Sce.PlayStation.Core.Vector2(0.5f,0.5f);

            System.Random rand = new System.Random();
            this.Position = new Sce.PlayStation.Core.Vector2(0,0);
            float angle = (float)rand.Next(0,360);

            if((angle%90) <=25) angle +=25.0f;
            this._physicsBody.Velocity = new Vector2(0.0f,Card.BALL_VELOCITY).Rotate(PhysicsUtility.GetRadian(angle));;

            Scheduler.Instance.ScheduleUpdateForTarget(this,0,false);
        }
示例#2
0
        public static bool analyze(Card[] cards)
        {
            bool match = true;

            //			int[] data = new int[3];

            match = match && 0 != ( cards[0].cardData.color & cards[1].cardData.color & cards[2].cardData.color );
            if (!match) {
                // NOT ALL SAME
                match = (int)CardData.COLOR.BLUE + (int)CardData.COLOR.RED + (int)CardData.COLOR.WHITE == ( cards[0].cardData.color | cards[1].cardData.color | cards[2].cardData.color );
                if (!match) {
                    // NOT ALL SAME OR ALL DIFFERENT -- NOT A VALID SET
            //					clearGroup ();
                    return match;
                }
            }
            match = match && 0 != ( cards[0].cardData.pattern & cards[1].cardData.pattern & cards[2].cardData.pattern );
            if (!match) {
                // NOT ALL SAME
                match = (int)CardData.PATTERN.DOT + (int)CardData.PATTERN.SOLID + (int)CardData.PATTERN.STRIPE == ( cards[0].cardData.pattern | cards[1].cardData.pattern | cards[2].cardData.pattern );
                if (!match) {
                    // NOT ALL SAME OR ALL DIFFERENT -- NOT A VALID SET
            //					clearGroup ();
                    return match;
                }
            }
            match = match && 0 != ( cards[0].cardData.sound & cards[1].cardData.sound & cards[2].cardData.sound );
            if (!match) {
                // NOT ALL SAME
                match = (int)CardData.SOUND.A + (int)CardData.SOUND.B + (int)CardData.SOUND.C == ( cards[0].cardData.sound | cards[1].cardData.sound | cards[2].cardData.sound );
                if (!match) {
                    // NOT ALL SAME OR ALL DIFFERENT -- NOT A VALID SET
            //					clearGroup ();
                    return match;
                }
            }
            //			if( cards[0].Color == cards[1].Color && cards[0].Color == cards[2].Color ) {
            ////				return match;
            //			} else {
            //				match = ( cards[0].Color != cards[1].Color &&
            //				          cards[0].Color != cards[2].Color &&
            //				          cards[1].Color != cards[2].Color );
            ////				return match;
            //			}
            //			if (match) {
            //				System.Console.WriteLine("SET!");
            //				Cube cube = new Cube(cards, GameScene._physics.addCardPhysics(cards[0].Position));
            //				Director.Instance.CurrentScene.AddChild(cube);
            //				foreach ( Card c in cards ) {
            //					Director.Instance.CurrentScene.RemoveChild(c, true);
            //					GameScene._physics.removePhysicsBody(c.physicsBody);
            //				}
            //			}
            //			clearGroup();
            return match;
        }
示例#3
0
 //this function takes the card that is selected,
 //and if there's a match, gets the other 2 corresponding faces
 //and makes the cube. -- I think.
 private void addCard(Card card)
 {
     for (int i=0; i<3; i++) {
         if ( cards[i] == null ) {
             cards[i] = card;
             switch(i) {
                 case 0:
                     if ( card.cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                         card.TileIndex2D = _ss.Get("topSide").TileIndex2D;
                     } else if ( card.cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                         card.TileIndex2D = _ss.Get("stripeTop").TileIndex2D;
                     } else {
                         card.TileIndex2D = _ss.Get("dotTop").TileIndex2D;
                     }
     //							card.TileIndex2D = _ss.Get("topSide").TileIndex2D;
                     _population++;
                     break;
                 case 1:
                     if ( card.cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                         card.TileIndex2D = _ss.Get("leftSide").TileIndex2D;
                     } else if ( card.cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                         card.TileIndex2D = _ss.Get("stripeLeft").TileIndex2D;
                     } else {
                         card.TileIndex2D = _ss.Get("dotLeft").TileIndex2D;
                     }
     //							card.TileIndex2D = _ss.Get ("leftSide").TileIndex2D;
                     _population++;
                     break;
                 case 2:
                     if ( card.cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                         card.TileIndex2D = _ss.Get("rightSide").TileIndex2D;
                     } else if ( card.cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                         card.TileIndex2D = _ss.Get("stripeRight").TileIndex2D;
                     } else {
                         card.TileIndex2D = _ss.Get("dotRight").TileIndex2D;
                     }
     //							card.TileIndex2D = _ss.Get ("rightSide").TileIndex2D;
                     _population++;
                     break;
                 default:
                     break;
             }
             if (i==2) {
                 complete = true;
             }
             card.groupID = cards[0].groupID;
             return;
         }
     }
 }
示例#4
0
 public void updateCard(Card card)
 {
     if ( card == cards[1] ) {
     //				card.physicsBody.Position = new Vector2(cards[0].Position.X-12f,cards[0].Position.Y-18f) / GamePhysics.PtoM;
     //				card.physicsBody.Position = cards[0].physicsBody.Position;
     } else {
     //				card.physicsBody.Position = new Vector2(cards[0].Position.X+10f,cards[0].Position.Y-18f) / GamePhysics.PtoM;
     //				card.physicsBody.Position = cards[0].physicsBody.Position;
     }
 }
示例#5
0
 public void tryAddingCard(Card card)
 {
     // Filter out current group members
     if (Array.IndexOf(cards,card) != -1) {
         return;
     }
     if ( card.groupID != -1) {
         Group g = GameScene.groups[card.groupID];
         if (g != this && Array.IndexOf(g.cards,card) != -1) {
             if (g.population >= 2 ) {
                 // Filter out 2-groups merging with 2-groups
                 if (this.population >= 2) {
                     return;
                 // Add single entity to existing group of 2
                 } else {
                     card = cards[0];
                     clearGroup();
                     g.tryAddingCard(card);
                     return;
                 }
             }
         }
     }
     addCard(card);
 }
示例#6
0
 public void removeCard(Card card)
 {
     for (int i=0; i<3; i++) {
         if ( cards[i] == card ) {
             card.groupID = -1;
             if ( card.cardData.pattern == (int)CardData.PATTERN.SOLID ) {
                 card.TileIndex2D = _ss.Get("topSide").TileIndex2D;
             } else if ( card.cardData.pattern == (int)CardData.PATTERN.STRIPE ) {
                 card.TileIndex2D = _ss.Get("stripeTop").TileIndex2D;
             } else {
                 card.TileIndex2D = _ss.Get("dotTop").TileIndex2D;
             }
             card.TileIndex2D = _ss.Get ("topSide").TileIndex2D;
             cards[i] = null;
             _population--;
         }
     }
 }