Ejemplo n.º 1
0
 /*
  * Sets up the start scene, which contains one "start" button
  */
 public override void DidMoveToView(SKView view)
 {
     //set the button size and position
     start.ScaleTo(new CGSize(width: 500, height: 400));
     start.Position = new CGPoint(Frame.Width / 2, Frame.Height / 2.5);
     AddChild(start); //add the node to the scene
 }
Ejemplo n.º 2
0
        public override void DidMoveToView(SKView view)
        {
            //Load in the "table top"
            SKSpriteNode background = SKSpriteNode.FromImageNamed(NSBundle.MainBundle.PathForResource("bg_1", "jpg"));

            background.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY());
            background.ScaleTo(Frame.Size);
            background.ZPosition = -1000;
            AddChild(background);



            DealCards();
        }
Ejemplo n.º 3
0
        public override void DidMoveToView(SKView view)
        {
            // Setup Scene with SKNodes and call the sparks generator
            Proto1Dim1 = 0;
            Proto1Dim2 = 0;
            Proto1Dim3 = 0;

            switchInfo = false;
            infoTouch  = false;

            // Set inital bgcolor
            BackgroundColor = UIColor.FromRGBA(100, 200, 150, 120);

            // Background Sprite
            backgroundSprite = new SKSpriteNode("spark");
            backgroundSprite.ScaleTo(Frame.Size);
            backgroundSprite.Position  = new CGPoint(Frame.Width / 2, Frame.Height / 2);
            backgroundSprite.ZPosition = 0;
            backgroundSprite.Alpha     = 0.1f;
            AddChild(backgroundSprite);

            // Add Gravity Field
            fieldNode          = SKFieldNode.CreateSpringField();
            fieldNode.Enabled  = false;
            fieldNode.Position = new CGPoint(Frame.Size.Width / 2, Frame.Size.Height / 2);
            fieldNode.Strength = 0.5f;
            fieldNode.Region   = new SKRegion(Frame.Size);
            AddChild(fieldNode);

            // Change color, child not added only in test env
            mySave = new SKLabelNode("AppleSDGothicNeo-UltraLight")
            {
                Text     = "next >",
                FontSize = 18,
                Position = new CGPoint(Frame.Width - 65, (Frame.Height - 53))
            };
            mySave.Name      = "next";
            mySave.FontColor = UIColor.FromHSB(0, 0, 3f);
            mySave.Alpha     = 0.9f;
            mySave.ZPosition = 10;
            // AddChild(mySave);

            // Invisible sprite node to change to Info Mode, on the right top side infront of the info sprite
            navSprite           = new SKSpriteNode();
            navSprite.Name      = "navSprite";
            navSprite.Alpha     = 0.0000001f;
            navSprite.ZPosition = 10;
            navSprite.Color     = UIColor.FromHSB(0, 1, 0.0f);
            navSprite.Size      = new CGSize(100, 70);
            navSprite.Position  = new CGPoint((View.Frame.Width - (50)), (View.Frame.Height - (35)));
            AddChild(navSprite);

            // Container field to fill different background (Info Mode)
            container           = new SKSpriteNode("background_newcolor");
            container.Size      = new CGSize(Frame.Width, Frame.Height);
            container.Position  = new CGPoint(Frame.Width / 2, Frame.Height / 2);
            container.ZPosition = 0;
            container.Alpha     = 0f;
            AddChild(container);

            // Sprite Node with the info icon
            infoSprite           = new SKSpriteNode("info");
            infoSprite.Name      = "navSprite";
            infoSprite.Position  = new CGPoint(Frame.Width - 40, Frame.Height - 40);
            infoSprite.ZPosition = 10;
            infoSprite.XScale    = 0.6f;
            infoSprite.YScale    = 0.6f;
            infoSprite.Alpha     = 0.8f;
            infoSprite.Name      = "info";
            AddChild(infoSprite);

            // Start with the info text
            SetInfoText();

            // Generate Sparks
            GenerateSparks();
        }
Ejemplo n.º 4
0
        /*
         * When the finger is pressed down
         */
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            SKNode sprite; //used for detecting touched object

            base.TouchesEnded(touches, evt);

            // Called when a touch begins
            foreach (var touch in touches)
            {
                var location = ((UITouch)touch).LocationInNode(this);

                // logic for start button when it is touched
                if ((sprite = GetNodeAtPoint(location)).Equals(start))
                {
                    removelist[0] = start;
                    RemoveChildren(removelist); //remove the start button and set up the instruction

                    instructions.ScaleTo(new CGSize(width: 375, height: 600));
                    instructions.Position = new CGPoint(Frame.Width / 2, Frame.Height / 2);

                    AddChild(instructions); //set up the instruction scene
                }
                // logic for instruction when it is touched
                else if ((sprite = GetNodeAtPoint(location)).Equals(instructions))
                {
                    removelist[0] = instructions;
                    RemoveChildren(removelist); //remove the instruction and set up the experiment

                    //set up the card decks
                    card1.ScaleTo(new CGSize(width: 150, height: 150));
                    card1.Position = new CGPoint(Frame.Width / 2.3, Frame.Height / 1.3);
                    AddChild(card1);

                    card2.ScaleTo(new CGSize(width: 150, height: 150));
                    card2.Position = new CGPoint(Frame.Width / 1.7, Frame.Height / 1.3);
                    AddChild(card2);

                    card3.ScaleTo(new CGSize(width: 150, height: 150));
                    card3.Position = new CGPoint(Frame.Width / 2.3, Frame.Height / 2.2);
                    AddChild(card3);

                    card4.ScaleTo(new CGSize(width: 150, height: 150));
                    card4.Position = new CGPoint(Frame.Width / 1.7, Frame.Height / 2.2);
                    AddChild(card4);

                    dragcardhere.ScaleTo(new CGSize(width: 150, height: 150));
                    dragcardhere.Position = new CGPoint(Frame.Width / 1.97, Frame.Height / 5.1);
                    AddChild(dragcardhere);

                    moneytitle = new SKLabelNode("Arial")
                    {
                        Text     = "Total money: ",
                        FontSize = 18,
                        Position = new CGPoint(Frame.Width / 2.7, Frame.Height / 5.1)
                    };

                    cardtitle = new SKLabelNode("Arial")
                    {
                        Text     = "Last card value: ",
                        FontSize = 18,
                        Position = new CGPoint(Frame.Width / 1.55, Frame.Height / 5.1)
                    };

                    moneylabel = new SKLabelNode("Arial")
                    {
                        Text     = totalMoney.ToString(),
                        FontSize = 18,
                        Position = new CGPoint(Frame.Width / 2.7, Frame.Height / 6)
                    };

                    cardlabel = new SKLabelNode("Arial")
                    {
                        Text     = "",
                        FontSize = 18,
                        Position = new CGPoint(Frame.Width / 1.55, Frame.Height / 6)
                    };

                    AddChild(moneytitle);
                    AddChild(cardtitle);
                    AddChild(moneylabel);
                    AddChild(cardlabel);
                }
                else if ((sprite = GetNodeAtPoint(location)).Equals(gameOver))
                {
                    counter1      = 0;
                    counter2      = 0;
                    counter3      = 0;
                    counter4      = 0;
                    turn          = 0;
                    totalMoney    = 2000;
                    removelist[0] = gameOver;
                    RemoveChildren(removelist);
                    cardlabel.Text = "";
                    start.ScaleTo(new CGSize(width: 500, height: 400));
                    start.Position = new CGPoint(Frame.Width / 2, Frame.Height / 2.5);
                    AddChild(start);
                }
                else // logic for card decks when they are touched
                {
                    // card deck 1 (blue)
                    if ((sprite = GetNodeAtPoint(location)).Equals(card1) || sprite.Equals(card1move))
                    {
                        removelist[0] = card1move;
                        RemoveChildren(removelist);
                        move = 1; //toggle the flag to 1 for TouhesMoved and Ended
                        if (counter1 == 39)
                        {
                            removelist[0] = card1;
                            RemoveChildren(removelist);
                            rcard1 = true;
                        }
                        card1move.ScaleTo(new CGSize(width: 150, height: 150));
                        card1move.Position = new CGPoint(Frame.Width / 2.3, Frame.Height / 1.3);
                        AddChild(card1move); //add the moving card 1
                        move1 = true;
                    }
                    // card deck 2 (green)
                    else if ((sprite = GetNodeAtPoint(location)).Equals(card2) || sprite.Equals(card2move))
                    {
                        removelist[0] = card2move;
                        RemoveChildren(removelist);
                        move = 2;
                        if (counter2 == 39)
                        {
                            removelist[0] = card2;
                            RemoveChildren(removelist);
                            rcard2 = true;
                        }
                        card2move.ScaleTo(new CGSize(width: 150, height: 150));
                        card2move.Position = new CGPoint(Frame.Width / 1.7, Frame.Height / 1.3);
                        AddChild(card2move);
                        move2 = true;
                    }
                    // card deck 3 (blue)
                    else if ((sprite = GetNodeAtPoint(location)).Equals(card3) || sprite.Equals(card3move))
                    {
                        removelist[0] = card3move;
                        RemoveChildren(removelist);
                        move = 3;
                        if (counter3 == 39)
                        {
                            removelist[0] = card3;
                            RemoveChildren(removelist);
                            rcard3 = true;
                        }
                        card3move.ScaleTo(new CGSize(width: 150, height: 150));
                        card3move.Position = new CGPoint(Frame.Width / 2.3, Frame.Height / 2.2);
                        AddChild(card3move);
                        move3 = true;
                    }
                    // card deck 4 (purple)
                    else if ((sprite = GetNodeAtPoint(location)).Equals(card4) || sprite.Equals(card4move))
                    {
                        removelist[0] = card4move;
                        RemoveChildren(removelist);
                        move = 4;
                        if (counter4 == 39)
                        {
                            removelist[0] = card4;
                            RemoveChildren(removelist);
                            rcard4 = true;
                        }
                        card4move.ScaleTo(new CGSize(width: 150, height: 150));
                        card4move.Position = new CGPoint(Frame.Width / 1.7, Frame.Height / 2.2);
                        AddChild(card4move);
                        move4 = true;
                    }
                    else
                    {
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /*
         * When the finger is released
         */
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            var moveDest = new CGPoint(); //the destination of the movement

            foreach (var touch in touches)
            {
                // logic for different moving card based on the move flag
                switch (move)
                {
                case 1:

                    CGPoint card1Pos = card1move.Position;
                    dragCardHerePos = dragcardhere.Position;
                    if (card1Pos.X < dragCardHerePos.X + 75.0 && card1Pos.X > dragCardHerePos.X - 75.0 &&
                        card1Pos.Y < dragCardHerePos.Y + 75.0 && card1Pos.Y > dragCardHerePos.Y - 75.0)
                    {
                        totalMoney     += -arr1[counter1] + 100;
                        cardlabel.Text  = (-arr1[counter1] + 100).ToString();
                        moneylabel.Text = totalMoney.ToString();
                        counter1++;
                        turn++;
                        removelist[0] = card1move;
                        RemoveChildren(removelist);
                    }
                    else
                    {
                        moveDest = new CGPoint(Frame.Width / 2.3, Frame.Height / 1.3);


                        card1move.RunAction(SKAction.MoveTo(moveDest, 0.2));

                        removelist[0] = card1move;
                    }
                    break;

                case 2:
                    CGPoint card2Pos = card2move.Position;
                    dragCardHerePos = dragcardhere.Position;
                    if (card2Pos.X < dragCardHerePos.X + 75.0 && card2Pos.X > dragCardHerePos.X - 75.0 &&
                        card2Pos.Y < dragCardHerePos.Y + 75.0 && card2Pos.Y > dragCardHerePos.Y - 75.0)
                    {
                        totalMoney     += -arr2[counter2] + 100;
                        cardlabel.Text  = (-arr2[counter2] + 100).ToString();
                        moneylabel.Text = totalMoney.ToString();
                        counter2++;
                        turn++;
                        removelist[0] = card2move;
                        RemoveChildren(removelist);
                    }
                    else
                    {
                        moveDest = new CGPoint(Frame.Width / 1.7, Frame.Height / 1.3);

                        card2move.RunAction(SKAction.MoveTo(moveDest, 0.2));

                        removelist[0] = card2move;
                    }
                    break;

                case 3:
                    CGPoint card3Pos = card3move.Position;
                    dragCardHerePos = dragcardhere.Position;
                    if (card3Pos.X < dragCardHerePos.X + 75.0 && card3Pos.X > dragCardHerePos.X - 75.0 &&
                        card3Pos.Y < dragCardHerePos.Y + 75.0 && card3Pos.Y > dragCardHerePos.Y - 75.0)
                    {
                        totalMoney     += -arr3[counter3] + 50;
                        cardlabel.Text  = (-arr3[counter3] + 50).ToString();
                        moneylabel.Text = totalMoney.ToString();
                        counter3++;

                        turn++;
                        removelist[0] = card3move;
                        RemoveChildren(removelist);
                    }
                    else
                    {
                        moveDest = new CGPoint(Frame.Width / 2.3, Frame.Height / 2.2);


                        card3move.RunAction(SKAction.MoveTo(moveDest, 0.2));

                        removelist[0] = card3move;
                    }
                    break;

                case 4:
                    CGPoint card4Pos = card4move.Position;
                    dragCardHerePos = dragcardhere.Position;
                    if (card4Pos.X < dragCardHerePos.X + 75.0 && card4Pos.X > dragCardHerePos.X - 75.0 &&
                        card4Pos.Y < dragCardHerePos.Y + 75.0 && card4Pos.Y > dragCardHerePos.Y - 75.0)
                    {
                        totalMoney     += -arr4[counter4] + 50;
                        cardlabel.Text  = (-arr4[counter4] + 50).ToString();
                        moneylabel.Text = totalMoney.ToString();
                        counter4++;
                        turn++;
                        removelist[0] = card4move;
                        RemoveChildren(removelist);
                    }
                    else
                    {
                        moveDest = new CGPoint(Frame.Width / 1.7, Frame.Height / 2.2);
                        card4move.RunAction(SKAction.MoveTo(moveDest, 0.2));

                        removelist[0] = card4move;
                    }
                    break;
                }
                if (turn == 4)
                {
                    if (move1)
                    {
                        removelist[0] = card1move;
                        RemoveChildren(removelist);
                    }
                    if (move2)
                    {
                        removelist[0] = card2move;
                        RemoveChildren(removelist);
                    }
                    if (move3)
                    {
                        removelist[0] = card3move;
                        RemoveChildren(removelist);
                    }
                    if (move4)
                    {
                        removelist[0] = card4move;
                        RemoveChildren(removelist);
                    }
                    if (!rcard1)
                    {
                        removelist[0] = card1;
                        RemoveChildren(removelist);
                    }
                    if (!rcard2)
                    {
                        removelist[0] = card2;
                        RemoveChildren(removelist);
                    }
                    if (!rcard3)
                    {
                        removelist[0] = card3;
                        RemoveChildren(removelist);
                    }
                    if (!rcard4)
                    {
                        removelist[0] = card4;
                        RemoveChildren(removelist);
                    }
                    removelist[0] = dragcardhere;
                    RemoveChildren(removelist);

                    removelabellist[0] = moneylabel;
                    RemoveChildren(removelabellist);
                    removelabellist[0] = moneytitle;
                    RemoveChildren(removelabellist);
                    removelabellist[0] = cardtitle;
                    RemoveChildren(removelabellist);
                    removelabellist[0] = cardlabel;
                    RemoveChildren(removelabellist);
                    gameOver.ScaleTo(new CGSize(width: 375, height: 650));
                    gameOver.Position = new CGPoint(Frame.Width / 2, Frame.Height / 2);
                    AddChild(gameOver);
                }
            }

            //if(move!=0){
            //    RemoveChildren(removelist);
            //}

            move = 0; //reset the move to 0 before the next time finger is pressed
        }