Ejemplo n.º 1
0
        void StartGame()
        {
            Console.WriteLine("Start game");

            gameLogo.RunAction(SKAction.MoveTo(
                                   new CGPoint(
                                       x: Frame.GetMidX() - 50,
                                       y: Frame.GetMidY() + 600),
                                   0.5),
                               () => gameLogo.Hidden = true);

            bestScore.RunAction(SKAction.MoveTo(
                                    new CGPoint(
                                        x: Frame.GetMidX(),
                                        y: Frame.GetMidY() + (Frame.Size.Height / -2f) + 20),
                                    0.4));

            playButton.RunAction(SKAction.ScaleTo(0, 0.3),
                                 () => playButton.Hidden = true);

            gameBG.SetScale(0);
            currentScore.SetScale(0);
            gameBG.Hidden       = false;
            currentScore.Hidden = false;
            gameBG.RunAction(SKAction.ScaleTo(1, 0.4));
            currentScore.RunAction(SKAction.ScaleTo(1, 0.4));

            game.InitGame();
        }
Ejemplo n.º 2
0
        public void Finish()
        {
            currentScore.RunAction(SKAction.ScaleTo(0, 0.4), () =>
            {
                currentScore.Hidden = true;
            });

            gameBG.RunAction(SKAction.ScaleTo(0, 0.4), () =>
            {
                gameBG.Hidden   = true;
                gameLogo.Hidden = false;

                gameLogo.RunAction(SKAction.MoveTo(
                                       new CGPoint(
                                           x: Frame.GetMidX(),
                                           y: Frame.GetMidY() + (Frame.Size.Height / 2f) - 200),
                                       0.5), () =>
                {
                    playButton.Hidden = false;
                    playButton.RunAction(SKAction.ScaleTo(1, 0.3));

                    bestScore.RunAction(SKAction.MoveTo(
                                            new CGPoint(
                                                x: gameLogo.Position.X,
                                                y: gameLogo.Position.Y - 50),
                                            0.3));
                });
            });
        }
        private void HandlePanFrom(UIPanGestureRecognizer recognizer)
        {
            if (recognizer.State == UIGestureRecognizerState.Began)
            {
                PointF touchLocation = recognizer.LocationInView(recognizer.View);
                touchLocation = this.ConvertPointFromView(touchLocation);
                this.SelectNodeForTouch(touchLocation);
            }
            else if (recognizer.State == UIGestureRecognizerState.Changed)
            {
                PointF translation = recognizer.TranslationInView(recognizer.View);
                translation = new PointF(translation.X, -translation.Y);
                this.PanForTranslation(translation);
                recognizer.SetTranslation(new PointF(0, 0), recognizer.View);
            }
            else if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                float scrollDuration = 0.2f;

                if (this.SelectedNode.Name != ANIMAL_NODE_NAME)
                {
                    PointF velocity = recognizer.VelocityInView(recognizer.View);
                    PointF p        = mult(velocity, scrollDuration);

                    PointF position = this.SelectedNode.Position;
                    PointF newPos   = new PointF(position.X + p.X, position.Y + p.Y);
                    newPos = this.BoundLayerPosition(newPos);
                    this.SelectedNode.RemoveAllActions();

                    SKAction moveTo = SKAction.MoveTo(newPos, scrollDuration);
                    moveTo.TimingMode = SKActionTimingMode.EaseOut;
                    this.SelectedNode.RunAction(moveTo);
                }
            }
        }
Ejemplo n.º 4
0
        protected override void Move()
        {
            double centerX = Controller.Scene.Size.Width / 2;
            double centerY = Controller.Scene.Size.Height / 2;

            var action1 = SKAction.MoveTo(new CGPoint(centerX, centerY), 3);

            Node.RunAction(action1);
        }
Ejemplo n.º 5
0
        public virtual void Draw(GameScene scene)
        {
            if (SkNode == null)
            {
                SkNode = new SKSpriteNode(SKTexture.FromImageNamed("Ball"), UIColor.Clear, new CGSize(5, 5));
                scene.AddChild(SkNode);
            }

            SkNode.RunAction(SKAction.MoveTo(new CGPoint(X - (Z / Math.Sqrt(2.0)), Y - (Z / Math.Sqrt(2.0))), 0.5));
        }
Ejemplo n.º 6
0
        // Move when key is down, and previous movement finished
        public override void KeyDown(NSEvent theEvent)
        {
            // Called when a key is pressed
            base.KeyDown(theEvent);

            if (GetFlag(player1) || GetNear(player1))
            {
                var change = new CGPoint();

                bool collide = move.move(ref player1, ref sprites, theEvent, ref change, Height, Width);
                //fetch.Form1_KeyPress()

                sprites[player1.xPos, player1.yPos, player1.zPos] = player1;
                // Debug
                Debug.WriteLine("Player1 x: {0}, y: {1}", player1.xPos, player1.yPos);
                for (int i = 9; i >= 0; i--)
                {
                    Debug.Write("|");
                    for (int j = 0; j <= 9; j++)
                    {
                        if (sprites[j, i, player1.zPos] == null)
                        {
                            Debug.Write("0|");
                        }

                        else if (sprites[j, i, player1.zPos] == player1)
                        {
                            Debug.Write("p|");
                        }

                        else if (sprites[j, i, player1.zPos].Type == "block")
                        {
                            Debug.Write("b|");
                        }
                    }
                    Debug.WriteLine("");
                }


                if (GetFlag(player1))
                {
                    action = SKAction.MoveTo(new CGPoint(player1.spriteNode.Position.X + change.X, player1.spriteNode.Position.Y + change.Y), 0.5 / (player1.Speed));
                    player1.destination = new CGPoint(player1.spriteNode.Position.X + change.X, player1.spriteNode.Position.Y + change.Y);
                    player1.spriteNode.RunAction(action);
                }
                else
                {
                    Nextmove            = true;
                    player1.destination = new CGPoint(player1.destination.X + change.X, player1.destination.Y + change.Y);
                    action = SKAction.MoveTo(player1.destination, 0.5 / (player1.Speed));
                }
            }
            //AddChild(sprite);
        }
Ejemplo n.º 7
0
        public void FollowPath(GKGraphNode[] path, Action <bool> completion)
        {
            if (path == null)
            {
                completion(false);
                return;
            }

            CharacterSpriteComponent comp = Entity.GetComponent <CharacterSpriteComponent> ();

            if (comp == null)
            {
                completion(false);
                return;
            }

            var dropFirst             = path.Skip(1);
            Queue <SKAction> sequence = new Queue <SKAction> ();
            var sprite = comp.Sprite;

            sprite.RemoveActionForKey(WalkingKey);

            foreach (MapGraphNode node in dropFirst)
            {
                Entity centity              = (Entity)Entity;
                CoreGraphics.CGPoint point  = GameViewController.CurrentScene.CurrentMap.PositionToPoint(node.NodePosition, true);
                List <SKAction>      subseq = new List <SKAction> ();

                subseq.Add(SKAction.Run(() => {
                    comp.Direction = centity.Model.StartPosition.DirectionToPosition(node.NodePosition);
                    centity.Model.StartPosition = node.NodePosition;
                    sprite.ZPosition            = GameViewController.CurrentScene.CurrentMap.ZLevelForPosition(node.NodePosition);
                    comp.Walking = true;
                }));

                subseq.Add(SKAction.MoveTo(point, 0.8));

                sequence.Enqueue(SKAction.Sequence(subseq.ToArray()));
            }

            sequence.Enqueue(SKAction.Run(() => comp.Walking = false));
            if (completion != null)
            {
                sequence.Enqueue(SKAction.Run(() => completion(true)));
            }

            currentWalk = sequence;
            if (!comp.Walking)
            {
                RunNextStep(sprite);
            }
        }
Ejemplo n.º 8
0
        public async void loadStarter()
        {
            var scoreLoad = new SKLabelNode()
            {
                Text      = "" + (GameObj.ToBeatScore + 1) + " To Win",              //.ToString ();
                Position  = new CGPoint(Size.Width / 2, (Size.Height / 2) - 200),
                FontSize  = 66,
                FontColor = UIColor.White,
                FontName  = "GillSans-Bold",
            };

            scoreLoad.SetScale(0.1f);

            var moveUpAction  = SKAction.MoveTo((new CGPoint(Size.Width / 2, Size.Height / 2)), 1.0);
            var scaleUpAction = SKAction.ScaleBy(9f, 1.0);

            AddChild(scoreLoad);

            scoreLoad.RunAction(moveUpAction);
            scoreLoad.RunAction(scaleUpAction);

            await System.Threading.Tasks.Task.Delay(2000);

            scoreLoad.RemoveFromParent();

            for (int i = 0; i < 3; i++)
            {
                var startGameNode = new SKLabelNode()
                {
                    Text      = "" + (3 - i),
                    Position  = new CGPoint(Size.Width / 2, (Size.Height / 2) - 200),
                    FontSize  = 80,
                    FontColor = UIColor.Red,
                    FontName  = "GillSans-Bold",
                };
                startGameNode.SetScale(0.1f);

                var moveUpAction1  = SKAction.MoveTo((new CGPoint(Size.Width / 2, Size.Height / 2)), 1.0);
                var scaleUpAction1 = SKAction.ScaleBy(9f, 1.0);
                AddChild(startGameNode);

                startGameNode.RunAction(moveUpAction1);
                startGameNode.RunAction(scaleUpAction1);

                await System.Threading.Tasks.Task.Delay(2000);

                startGameNode.RemoveFromParent();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Анимация падения камешков на пустые места
        /// </summary>
        /// <param name="gemLists">Списки камешков перемещенных в модели, столбцами</param>
        public void AnimateFallingGemsIn(List <GemList> gemLists)
        {
            foreach (GemList gems in gemLists)
            {
                foreach (Gem gem in gems)
                {
                    CGPoint      newPosition = GetPositionFromRowAndColumn(gem.Row, gem.Column);
                    SKSpriteNode sprite      = gem.Sprite;

                    SKAction action = SKAction.MoveTo(newPosition, Properties.FallAnimationDuration / 1000f);
                    action.TimingMode = SKActionTimingMode.EaseOut;

                    sprite.RunAction(action);
                }
            }
        }
Ejemplo n.º 10
0
        public void Draw(SKScene scene, double sec)
        {
            if (_skNode == null)
            {
                _skNode = new SKSpriteNode(SKTexture.FromImageNamed("Ball"), UIColor.Clear, new CGSize(5, 5));
                scene.AddChild(_skNode);
            }

            _skNode.RunAction(SKAction.MoveTo(new CGPoint(
                                                  OffsetFromZero[0] - (OffsetFromZero[2] / Math.Sqrt(2.0)),
                                                  OffsetFromZero[1] - (OffsetFromZero[2] / Math.Sqrt(2.0))), sec));

            foreach (var child in Children)
            {
                child.Draw(scene, sec);
            }
        }
Ejemplo n.º 11
0
        private SKAction GenerateMovingAction()
        {
            double xMinLimit = Node.Size.Width / 2;
            double xMaxLimit = Controller.Scene.Size.Width - xMinLimit;

            double yMinLimit = Node.Size.Height / 2;
            double yMaxLimit = Controller.Scene.Size.Height - yMinLimit;

            double randX = GMath.GenerateRandomInRange(xMinLimit, xMaxLimit);
            double randY = GMath.GenerateRandomInRange(yMinLimit, yMaxLimit);

            double randTime = GMath.GenerateRandomInRange(2, 5);

            var movePoint = new CGPoint(randX, randY);

            return(SKAction.MoveTo(movePoint, randTime));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Анимация разрушителей. создает спрайт, на месте бонуса, которому придает анимацию
        /// перемещения к центру (зависит от активированного бонуса - вертикально
        /// или горизонтально), с одновременным растягиванием, иммитируя лазерныйй луч
        /// затем удаляет спрайт со сцены
        /// </summary>
        /// <param name="destroyer">Активированный онус.</param>
        public void AnimateLineDestroyer(Gem destroyer)
        {
            SKSpriteNode sprite;
            CGPoint      centerPoint;
            SKAction     resizeSprite;

            // инициализация спрайта, подготовка координат для анимации, размеров
            if (destroyer.IsHorizontal)
            {
                float newWidth = gemCellWidth * Level.ColumnsNumber;

                sprite = SKSpriteNode.FromImageNamed("destroyer_ray_horisontal");

                centerPoint = new CGPoint(gemCellWidth * Level.ColumnsNumber / 2, destroyer.Sprite.Position.Y);

                resizeSprite = SKAction.ResizeToWidth(newWidth, Properties.LineDestructionDuration / 1000f);
            }
            else
            {
                float newHeight = gemCellHeight * Level.RowsNumber;

                sprite = SKSpriteNode.FromImageNamed("destroyer_ray_vertical");

                centerPoint = new CGPoint(destroyer.Sprite.Position.X, gemCellHeight * Level.RowsNumber / 2);

                resizeSprite = SKAction.ResizeToHeight(newHeight, Properties.LineDestructionDuration / 1000f);
            }

            SKAction moveToCenter = SKAction.MoveTo(centerPoint, Properties.LineDestructionDuration / 1000f);

            CGPoint initialPosition = GetPositionFromRowAndColumn(destroyer.Row, destroyer.Column);
            CGSize  initialSize     = new CGSize(gemCellWidth, gemCellHeight);

            sprite.Size      = initialSize;
            sprite.Position  = initialPosition;
            sprite.ZPosition = 110;

            gemLayer.AddChild(sprite);

            sprite.RunAction(moveToCenter);
            sprite.RunAction(SKAction.Sequence(resizeSprite, SKAction.RemoveFromParent()));
        }
Ejemplo n.º 13
0
        // Set Animation of current parent node
        public void MoveAnimation(int disturbFactor, int newX, int newX1, int newX2, int newX3, int newX4, int newY, int newY1, int newY2, int newY3, int newY4, double pointSpeed1, double pointSpeed2, double pointSpeed3, double pointSpeed4, double pointSpeed5, bool vibrate)
        {
            // Remove All Actions from that node
            RemoveAllActions();

            // Set actions similar to related spark node's actions but add the disturb factor to the movement
            SKAction action1  = SKAction.MoveTo(new CGPoint(newX + disturbFactor, newY + disturbFactor), pointSpeed1);
            SKAction action2  = SKAction.MoveTo(new CGPoint(newX1 - disturbFactor, newY1 + disturbFactor), pointSpeed2);
            SKAction action3  = SKAction.MoveTo(new CGPoint(newX2 + disturbFactor, newY2 - disturbFactor), pointSpeed3);
            SKAction action4  = SKAction.MoveTo(new CGPoint(newX3 + disturbFactor, newY3 + disturbFactor), pointSpeed4);
            SKAction action5  = SKAction.MoveTo(new CGPoint(newX4, newY4), pointSpeed5);
            var      sequence = SKAction.Sequence(action1, action2, action3, action4, action5);

            // Repeat following the five routes
            RunAction(SKAction.RepeatActionForever(sequence));

            // Change texture
            ChangeTexture(vibrate, pointSpeed1);

            // Add Heartbeat
            AddHeartbeat(pointSpeed1);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Анимация перемещения камешков
        /// </summary>
        /// <param name="swap">Объект с камешками на обмен</param>
        /// <param name="swapIsValid">Индикатор того, что своп возможен</param>
        public void Animate(Swap swap, bool swapIsValid)
        {
            SKSpriteNode spriteA = swap.GemA.Sprite;
            SKSpriteNode spriteB = swap.GemB.Sprite;

            // Спрайт А "приподнимаем", чтобы создать впечатление, что он пролетает над камешком В
            spriteA.ZPosition = 100;
            spriteB.ZPosition = 90;

            // Анимация камешка А
            SKAction moveA = SKAction.MoveTo(spriteB.Position, Properties.SwapAnimationDuration / 1000f);

            moveA.TimingMode = SKActionTimingMode.EaseOut;

            //Анимация камешка B
            SKAction moveB = SKAction.MoveTo(spriteA.Position, Properties.SwapAnimationDuration / 1000f);

            moveB.TimingMode = SKActionTimingMode.EaseOut;

            if (swapIsValid)
            {
                spriteA.RunAction(moveA);
                spriteB.RunAction(moveB);

                // Проигрываем звук обмена
                RunAction(swapSound);
            }
            else
            {
                spriteA.RunAction(SKAction.Sequence(moveA, moveB));
                spriteB.RunAction(SKAction.Sequence(moveB, moveA));

                // Проигрываем звук ошибки
                RunAction(errorSound);
            }
        }
Ejemplo n.º 15
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
        }
Ejemplo n.º 16
0
        // Set Animation of current node
        public void MoveAnimation(double speed, bool randomMove, bool disturb, int disturbFactor, bool vibrate)
        {
            double pointSpeed1;
            double pointSpeed2;
            double pointSpeed3;
            double pointSpeed4;
            double pointSpeed5;

            SKAction action1;
            SKAction action2;
            SKAction action3;
            SKAction action4;
            SKAction action5;

            // Remove all actions from that node
            RemoveAllActions();

            // Move of the node only 50px away from current center, direction is random
            int newX = rnd.Next((int)CenterOfNode.X - 50, (int)CenterOfNode.X + 50);
            int newY = rnd.Next((int)CenterOfNode.Y - 50, (int)CenterOfNode.Y + 50);

            int newX1 = rnd.Next((int)CenterOfNode.X - 50, (int)CenterOfNode.X + 50);
            int newY1 = rnd.Next((int)CenterOfNode.Y - 50, (int)CenterOfNode.Y + 50);

            int newX2 = rnd.Next((int)CenterOfNode.X - 50, (int)CenterOfNode.X + 50);
            int newY2 = rnd.Next((int)CenterOfNode.Y - 50, (int)CenterOfNode.Y + 50);

            int newX3 = rnd.Next((int)CenterOfNode.X - 50, (int)CenterOfNode.X + 50);
            int newY3 = rnd.Next((int)CenterOfNode.Y - 50, (int)CenterOfNode.Y + 50);

            int newX4 = rnd.Next((int)CenterOfNode.X - 50, (int)CenterOfNode.X + 50);
            int newY4 = rnd.Next((int)CenterOfNode.Y - 50, (int)CenterOfNode.Y + 50);

            // Set min and max speed for all 5 points
            double minSpeed = speed;
            double maxSpeed = speed + 0.5;

            // If random move then point speed is random, other wise speed is constand for all
            if (randomMove == true)
            {
                pointSpeed1 = rnd.NextDouble() * (maxSpeed - minSpeed) + minSpeed;
                pointSpeed2 = rnd.NextDouble() * (maxSpeed - minSpeed) + minSpeed;
                pointSpeed3 = rnd.NextDouble() * (maxSpeed - minSpeed) + minSpeed;
                pointSpeed4 = rnd.NextDouble() * (maxSpeed - minSpeed) + minSpeed;
                pointSpeed5 = rnd.NextDouble() * (maxSpeed - minSpeed) + minSpeed;
            }
            else
            {
                pointSpeed1 = maxSpeed;
                pointSpeed2 = maxSpeed;
                pointSpeed3 = maxSpeed;
                pointSpeed4 = maxSpeed;
                pointSpeed5 = maxSpeed;
            }

            action1 = SKAction.MoveTo(new CGPoint(newX, newY), pointSpeed1);
            action2 = SKAction.MoveTo(new CGPoint(newX1, newY1), pointSpeed2);
            action3 = SKAction.MoveTo(new CGPoint(newX2, newY2), pointSpeed3);
            action4 = SKAction.MoveTo(new CGPoint(newX3, newY3), pointSpeed4);
            action5 = SKAction.MoveTo(new CGPoint(newX4, newY4), pointSpeed5);
            var sequence = SKAction.Sequence(action1, action2, action3, action4, action5);

            // Repeat following the five routes
            RunAction(SKAction.RepeatActionForever(sequence));

            // If disturb is true update parent node's move animation with all parms, if false forward simply the SKActions
            if (disturb)
            {
                if (ParentNode != null)
                {
                    // Set parent nodes center
                    ParentNode.CenterOfNode = CenterOfNode;

                    // Update parent node's animation (with all parms)
                    ParentNode.MoveAnimation(disturbFactor, newX, newX1, newX2, newX3, newX4, newY, newY1, newY2, newY3, newY4, pointSpeed1, pointSpeed2, pointSpeed3, pointSpeed4, pointSpeed5, vibrate);
                }
            }
            else
            {
                if (ParentNode != null)
                {
                    // Set parent nodes center
                    ParentNode.CenterOfNode = CenterOfNode;

                    // Update parent node's animation (with SKActions)
                    ParentNode.MoveAnimation(sequence, pointSpeed1);
                }
            }
        }
Ejemplo n.º 17
0
        public PostGameMenu(CGSize frameSize, IGameUIState gameStateDelegate)
        {
            GameStateDelegate = gameStateDelegate;
            nfloat menuHeight = frameSize.Height * 0.8f;
            var    background = new SKSpriteNode(AppKit.NSColor.Black, new CGSize(frameSize.Width * 0.8f, menuHeight));

            background.ZPosition = -1;
            background.Alpha     = 0.5f;
            background.Position  = new CGPoint(0, -0.2f * menuHeight);

            myLabel          = InGameScene.LabelWithText("Final Score", 65);
            myLabel.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY());

            Position = new CGPoint(frameSize.Width * 0.5f, frameSize.Height * 0.5f);
            UserInteractionEnabled         = true;
            myLabel.UserInteractionEnabled = true;
            AddChild(myLabel);
            InGameScene.DropShadowOnLabel(myLabel);

            var bananaLocation      = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.4f);
            var coinLocation        = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.6f);
            var totalLocation       = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.8f);
            var bananaScoreLocation = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.4f);
            var coinScoreLocation   = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.6f);
            var totalScoreLocation  = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.8f);

            bananaText          = (SKLabelNode)myLabel.Copy();
            bananaText.Text     = "Bananas";
            bananaText.FontSize = 0.1f * menuHeight;
            bananaText.SetScale(0.8f);
            bananaLocation.X   += bananaText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            bananaText.Position = new CGPoint(bananaLocation.X, -2000);
            AddChild(bananaText);
            InGameScene.DropShadowOnLabel(bananaText);

            bananaScore            = (SKLabelNode)bananaText.Copy();
            bananaScore.Text       = "000";
            bananaScoreLocation.X -= bananaScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            bananaScore.Position   = new CGPoint(bananaScoreLocation.X, -2000);
            AddChild(bananaScore);

            coinText          = (SKLabelNode)bananaText.Copy();
            coinText.Text     = "Large Bananas";
            coinLocation.X   += coinText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            coinText.Position = new CGPoint(coinLocation.X, -2000f);
            AddChild(coinText);
            InGameScene.DropShadowOnLabel(coinText);

            coinScore            = (SKLabelNode)coinText.Copy();
            coinScore.Text       = "000";
            coinScoreLocation.X -= coinScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            coinScore.Position   = new CGPoint(coinScoreLocation.X, -2000f);
            AddChild(coinScore);

            totalText          = (SKLabelNode)bananaText.Copy();
            totalText.Text     = "Total";
            totalLocation.X   += totalText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            totalText.Position = new CGPoint(totalLocation.X, -2000f);
            AddChild(totalText);
            InGameScene.DropShadowOnLabel(totalText);

            totalScore            = (SKLabelNode)totalText.Copy();
            totalScore.Text       = "000";
            totalScoreLocation.X -= totalScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            totalScore.Position   = new CGPoint(totalScoreLocation.X, -2000f);
            AddChild(totalScore);

            SKAction flyup = SKAction.MoveTo(new CGPoint(frameSize.Width * 0.5f, frameSize.Height - 100), 0.25);

            flyup.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupBananas = SKAction.MoveTo(bananaLocation, 0.25);

            flyupBananas.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupBananasScore = SKAction.MoveTo(bananaScoreLocation, 0.25f);

            flyupBananasScore.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupCoins = SKAction.MoveTo(coinLocation, 0.25);

            flyupCoins.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupCoinsScore = SKAction.MoveTo(coinScoreLocation, 0.25);

            flyupCoinsScore.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupTotal = SKAction.MoveTo(totalLocation, 0.25);

            flyupTotal.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupTotalScore = SKAction.MoveTo(totalScoreLocation, 0.25);

            flyupTotalScore.TimingMode = SKActionTimingMode.EaseInEaseOut;

            int bananasCollected = gameStateDelegate.BananasCollected;
            int coinsCollected   = gameStateDelegate.CoinsCollected;
            int totalCollected   = bananasCollected + (coinsCollected * 100);

            SKAction countUpBananas = SKAction.CustomActionWithDuration(bananasCollected / 100f, ((node, elapsedTime) => {
                if (bananasCollected > 0)
                {
                    SKLabelNode label = (SKLabelNode)node;
                    nint total = (nint)(elapsedTime / (bananasCollected / 100.0f) * bananasCollected);
                    label.Text = total.ToString();

                    if (total % 10 == 0)
                    {
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    }
                }
            }));

            SKAction countUpCoins = SKAction.CustomActionWithDuration(coinsCollected / 100f, ((node, elapsedTime) => {
                if (coinsCollected > 0)
                {
                    SKLabelNode label = (SKLabelNode)node;
                    nint total = (nint)((elapsedTime / (coinsCollected / 100.0f)) * coinsCollected);
                    label.Text = total.ToString();

                    if (total % 10 == 0)
                    {
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    }
                }
            }));

            SKAction countUpTotal = SKAction.CustomActionWithDuration(totalCollected / 500.0f, ((node, elapsedTime) => {
                if (totalCollected > 0)
                {
                    SKLabelNode label = (SKLabelNode)node;
                    nint total = (nint)((elapsedTime / (totalCollected / 500.0f)) * totalCollected);
                    label.Text = total.ToString();

                    if (total % 25 == 0)
                    {
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    }
                }
            }));

            RunAction(flyup, () => {
                bananaText.RunAction(flyupBananas);
                bananaScore.RunAction(flyupBananasScore, () => {
                    bananaScore.RunAction(countUpBananas, () => {
                        bananaScore.Text = bananasCollected.ToString();
                        coinText.RunAction(flyupCoins);
                        coinScore.RunAction(flyupCoinsScore, () => {
                            coinScore.RunAction(countUpCoins, () => {
                                coinScore.Text = coinsCollected.ToString();
                                totalText.RunAction(flyupTotal);
                                totalScore.RunAction(flyupTotalScore, () => {
                                    totalScore.RunAction(countUpTotal, () => {
                                        totalScore.Text = totalCollected.ToString();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        }
Ejemplo n.º 18
0
        public async void AnalyzeTouch()
        {
            var touchDiff  = LastTouch.Y - FirstTouch.Y;
            var touchDiffX = LastTouch.X - FirstTouch.X;

            if (touchDiff > 66)
            {
                var sprite = new SKSpriteNode("dart_blue")
                {
                    Position = new CGPoint(
                        FirstTouch.X, -5f)
                };


                //dart_blue
//				var sprite1 = new SKSpriteNode ("knife1") {
//					Position = new CGPoint(
//						FirstTouch.X,-5f )
//				};



                sprite.SetScale(1.5f);
                AddChild(sprite);

                var finaldest = new CGPoint();
                var action    = SKAction.MoveTo(finaldest, 0.3);

                if (touchDiff < 150)
                {
                    finaldest = new CGPoint(LastTouch.X + (touchDiffX * 0.5f), LastTouch.Y + (touchDiff * 0.3f));
                    action    = SKAction.MoveTo(finaldest, 0.3);                //FollowPath (np, 3.0);
                }
                else
                {
                    finaldest = new CGPoint(LastTouch.X + (touchDiffX * 0.5f),
                                            LastTouch.Y + (touchDiff * 0.6f));

                    action = SKAction.MoveTo(finaldest, 0.2);
                }

                nfloat rotatingAngle = touchDiffX / 333;

                Console.WriteLine("touchDiff:::" + touchDiffX);
                Console.WriteLine("toRadians:::" + rotatingAngle);

                //to radians
                var RotAction = SKAction.RotateToAngle(-rotatingAngle, 0);

                //to small size
                var scaleAction = SKAction.ScaleTo(0.8f, 0.1555);

                sprite.RunAction(action);
                sprite.RunAction(RotAction);
                sprite.RunAction(scaleAction);

                SpriteCount++;

                //COLLISION
                if (PhotoNode.ContainsPoint(finaldest))
                {
                    CurrentScore++;
                    System.Diagnostics.Debug.WriteLine("POINTS:    " + CurrentScore);
                    System.Diagnostics.Debug.WriteLine("collideddddddd::::::::::::::::::::::");

                    await System.Threading.Tasks.Task.Delay(200);

                    await System.Threading.Tasks.Task.Delay(200);

                    var displayScoreNode = new SKLabelNode();

                    displayScoreNode.Text      = "" + CurrentScore;                    //.ToString ();
                    displayScoreNode.Position  = new CGPoint(Size.Width / 2, (Size.Height / 2) - 200);
                    displayScoreNode.FontSize  = 80;
                    displayScoreNode.FontColor = UIColor.Red;
                    displayScoreNode.FontName  = "GillSans-Bold";
                    displayScoreNode.SetScale(0.1f);

                    var moveUpAction  = SKAction.MoveTo((new CGPoint(Size.Width / 2, Size.Height / 2)), 0.5);
                    var scaleUpAction = SKAction.ScaleBy(9f, 0.5);
                    AddChild(displayScoreNode);

                    displayScoreNode.RunAction(moveUpAction);
                    displayScoreNode.RunAction(scaleUpAction);

                    await System.Threading.Tasks.Task.Delay(1000);

                    displayScoreNode.RemoveFromParent();
                }
                else
                {
                    await System.Threading.Tasks.Task.Delay(300);

                    SystemSound.Vibrate.PlaySystemSound();                     //.PlayAlertSound();
                    SystemSound.Vibrate.Close();
                }

                //REMOVE SLOW DART
                if (touchDiff < 100)
                {
                    await System.Threading.Tasks.Task.Delay(200);

                    sprite.RemoveFromParent();
                    SpriteCount--;
                }

                if (touchDiff > 120 && (!PhotoFrameNode.ContainsPoint(finaldest)))
                {
                    await System.Threading.Tasks.Task.Delay(300);

                    SystemSound.Vibrate.PlaySystemSound();                     //.PlayAlertSound();
                    SystemSound.Vibrate.Close();
                    await System.Threading.Tasks.Task.Delay(200);
                }
            }
        }