Exemplo n.º 1
0
        /// <summary>
        /// Анимация счета за уничтожение цепочки
        /// </summary>
        /// <param name="chain">Уничтожаемая цепочка.</param>
        private void AnimateScore(GemList chain)
        {
            SKSpriteNode firstGem = chain.GetFirstGem().Sprite;
            SKSpriteNode lastGem  = chain.GetLastGem().Sprite;

            CGPoint centerPoint = new CGPoint(
                (firstGem.Position.X + lastGem.Position.X) / 2,
                (firstGem.Position.Y + lastGem.Position.Y) / 2 - 8);

            SKLabelNode scoreLabel = new SKLabelNode("GillSans-BoldItalic")
            {
                FontSize  = 16,
                Text      = chain.GetScore() + "",
                Position  = centerPoint,
                ZPosition = 300
            };

            gemLayer.AddChild(scoreLabel);

            SKAction moveAction = SKAction.MoveBy(0, 3, 0.7);

            //.Move(by: CGVector(dx: 0, dy: 3), duration: 0.7)
            moveAction.TimingMode = SKActionTimingMode.EaseOut;
            scoreLabel.RunAction(SKAction.Sequence(moveAction, SKAction.RemoveFromParent()));
        }
Exemplo n.º 2
0
        public void SetStartupPosition(nfloat width, nfloat height)
        {
            Sprite.Position = new CGPoint(width / 2.5, height / 2);
            var action = SKAction.MoveBy(0, GRAVITY, 1);

            Sprite.RunAction(SKAction.RepeatActionForever(action));
        }
        public void FireProjectile()
        {
            var projectile = (SKSpriteNode)Projectile.Copy();

            projectile.Position  = Position;
            projectile.ZRotation = ZRotation;

            var emitter = (SKEmitterNode)ProjectileEmitter.Copy();

            emitter.TargetNode = CharacterScene.GetChildNode("world");
            projectile.AddChild(emitter);

            CharacterScene.AddNode(projectile, WorldLayer.Character);

            var rot = ZRotation;

            float x = -(float)Math.Sin(rot) * HeroProjectileSpeed * HeroProjectileLifetime;
            float y = (float)Math.Cos(rot) * HeroProjectileSpeed * HeroProjectileLifetime;

            projectile.RunAction(SKAction.MoveBy(x, y, HeroProjectileLifetime));

            projectile.RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(HeroProjectileFadeOutTime),
                SKAction.FadeOutWithDuration(HeroProjectileLifetime - HeroProjectileFadeOutTime),
                SKAction.RemoveFromParent()
            }));
            projectile.RunAction(ProjectileSoundAction);

            var userData = new UserData {
                Player = Player
            };


            projectile.UserData = (NSMutableDictionary)userData.Dictionary;
        }
Exemplo n.º 4
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // Called when a touch begins

            // control player motion
            var moveRight = SKAction.RepeatActionForever(SKAction.MoveBy(75.0f, 0, 2.0f));
            var moveLeft  = SKAction.RepeatActionForever(SKAction.MoveBy(-75.0f, 0, 2.0f));

            base.TouchesBegan(touches, evt);
            var touch = (UITouch)touches.AnyObject;

            playerMove(touch);

            // detects left and right screen taps, moves player accordingly
            void playerMove(UITouch location)
            {
                if (touch.LocationInNode(this).X > (Frame.Width / 2))
                {
                    playerObject.RunAction(moveRight);
                }
                if (touch.LocationInNode(this).X < (Frame.Width / 2))
                {
                    playerObject.RunAction(moveLeft);
                }
                Console.WriteLine(touch.LocationInNode(this));
            }
        }
Exemplo n.º 5
0
        protected override void Move()
        {
            var action1     = SKAction.MoveBy(-50, 75, 0.5);
            var action2     = SKAction.MoveBy(-50, -75, 0.5);
            var seq         = SKAction.Sequence(action1, action2);
            var finalAction = SKAction.RepeatActionForever(seq);

            Node.RunAction(finalAction);
        }
Exemplo n.º 6
0
        public void MoveEast()
        {
            if (!(this.hSpeed == MAXhSPEED))
            {
                this.hSpeed += 3;
            }
            this.x_world += 3;
            this.heading  = (int)Math.Atan2(vSpeed, hSpeed);
            var action1 = SKAction.MoveBy(this.hSpeed, 0, 1.0);

            this.enemySprite.RunAction(action1);
        }
Exemplo n.º 7
0
        public void MoveWest()
        {
            if (!(this.hSpeed == MAXhSPEED))
            {
                this.hSpeed -= 3;
            }
            this.x_world -= 3;
            this.heading += 5;
            var action1 = SKAction.MoveBy(this.hSpeed, 0, 1.0);

            this.enemySprite.RunAction(action1);
        }
        public void MoveRight()
        {
            if (!(this.hSpeed == MAXhSPEED))
            {
                this.hSpeed += 3;
            }
            this.x_world += 3;
            this.Pitch   -= 5;
            var action1 = SKAction.MoveBy(this.hSpeed, 0, 1.0);

            this.PlayerSpriteObject.RunAction(action1);
        }
Exemplo n.º 9
0
        public void MoveNorth()
        {
            if (!(this.vSpeed == MAXvSPEED))
            {
                this.vSpeed += 3;
            }

            var action1 = SKAction.MoveBy(0, this.vSpeed, 1.0);

            this.enemySprite.RunAction(action1);

            return;
        }
Exemplo n.º 10
0
        protected virtual SKAction CreateShootAction()
        {
            Mat3 rotationMatrix = new Mat3();
              rotationMatrix.SetRotation(-owner.CurrentRotation);

              Mat3 translationMatrix = new Mat3();
              translationMatrix.SetTranslation(owner.Node.Scene.Size.Width, 0);

              Mat3 transformation = rotationMatrix * translationMatrix;

              return SKAction.MoveBy(
            (nfloat)transformation[6], (nfloat)transformation[7], 1);
        }
Exemplo n.º 11
0
        public void MoveSouth()
        {
            if (!(this.hSpeed == MAXvSPEED))
            {
                this.vSpeed -= 3;
            }

            this.y_world -= 3;
            var action1 = SKAction.MoveBy(0, this.vSpeed, 1.0);

            this.enemySprite.RunAction(action1);

            return;
        }
        public void MoveUp()
        {
            if (!(this.vSpeed == MAXvSPEED))
            {
                this.vSpeed += 3;
            }
            this.altitude += 3;
            this.y_world  += 3;
            var action1 = SKAction.MoveBy(0, this.vSpeed, 1.0);

            this.PlayerSpriteObject.RunAction(action1);

            return;
        }
Exemplo n.º 13
0
        public override void MouseDown(NSEvent theEvent)
        {
            // Called when a mouse click occurs

            var          location = theEvent.LocationInNode(this);
            SKSpriteNode sprite   = SKSpriteNode.FromImageNamed("person");

            //var sprite = SKSpriteNode.FromImageNamed(NSBundle.MainBundle.PathForResource("Spaceship", "png"));

            sprite.Position = location;
            sprite.SetScale(10);

            var action = SKAction.MoveBy(2, 2, 0.1);

            sprite.RunAction(SKAction.RepeatActionForever(action));
            //sprite.RunAction(SKAction.RepeatActionForever(action));
            AddChild(sprite);
        }
Exemplo n.º 14
0
 public Pipe(CGPoint position, bool isRotated = false)
 {
     Sprite = new SKSpriteNode("Pipe")
     {
         Position = position,
         XScale   = 0.5f,
         YScale   = 1.5f
     };
     Sprite.PhysicsBody = SKPhysicsBody.Create(Sprite.Texture, Sprite.Size);
     Sprite.PhysicsBody.AffectedByGravity             = false;
     Sprite.PhysicsBody.CategoryBitMask               = (uint)PhysicsCategoryEnum.Pipe;
     Sprite.PhysicsBody.UsesPreciseCollisionDetection = true;
     Sprite.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(-100, 0, 1)));
     if (isRotated)
     {
         Sprite.RunAction(SKAction.RotateByAngle(NMath.PI, 0));
     }
 }
Exemplo n.º 15
0
        protected override SKAction CreateShootAction()
        {
            Mat3 rotationMatrix = new Mat3();

            rotationMatrix.SetRotation(-owner.CurrentRotation);

            Mat3 translationMatrix = new Mat3();

            translationMatrix.SetTranslation(owner.Node.Scene.Size.Width, 0);

            Mat3 transformation = rotationMatrix * translationMatrix;

            var moveAction = SKAction.MoveBy(
                -(nfloat)transformation[6], -(nfloat)transformation[7], 2.5);

            var doneAction = SKAction.RemoveFromParent();

            return(SKAction.Sequence(moveAction, doneAction));
        }
Exemplo n.º 16
0
        private SKAction CreatePlayerMoveAction()
        {
            var endPoint = new CGPoint(0, 0);

            foreach (ushort keyCode in pressedKeys)
            {
                switch (keyCode)
                {
                case (ushort)GameKeyCodes.W:
                    if (Player.Node.Position.Y + 1 <
                        Scene.Size.Height - Player.Node.Size.Height / 2)
                    {
                        endPoint.Y += 1;
                    }
                    break;

                case (ushort)GameKeyCodes.A:
                    if (Player.Node.Position.X - 1 > Player.Node.Size.Width / 2)
                    {
                        endPoint.X -= 1;
                    }
                    break;

                case (ushort)GameKeyCodes.S:
                    if (Player.Node.Position.Y - 1 > Player.Node.Size.Height / 2)
                    {
                        endPoint.Y -= 1;
                    }
                    break;

                case (ushort)GameKeyCodes.D:
                    if (Player.Node.Position.X + 1 <
                        Scene.Size.Width - Player.Node.Size.Width / 2)
                    {
                        endPoint.X += 1;
                    }
                    break;
                }
            }

            return(SKAction.MoveBy(endPoint.X * 5, endPoint.Y * 5, 0.1));
        }
Exemplo n.º 17
0
        public void MoveRight()
        {
            // Flip texture right
            if (XScale < 0)
            {
                XScale *= -1;
            }

            // Change walking texture
            if (Texture == _heroStand)
            {
                ApplyTexture(_heroMoving);
            }
            else if (Texture == _heroMoving)
            {
                ApplyTexture(_heroStand);
            }

            RunAction(SKAction.MoveBy(5, 0, 0));
        }
Exemplo n.º 18
0
        public override void KeyUp(NSEvent theEvent)
        {
            // Called when a key is

            var location = theEvent.LocationInNode(this);

            //SKSpriteNode sprite = SKSpriteNode.FromImageNamed("p1front");
            var sprite = SKSpriteNode.FromImageNamed(NSBundle.MainBundle.PathForResource("p1front", "png"));

            sprite.Position = location;
            sprite.SetScale(1f);

            var action = SKAction.MoveBy(2, 2, 0.1);

            //SKAction OutofBounds = SKAction.RemoveFromParent();

            //sprite.
            sprite.RunAction(SKAction.RepeatActionForever(action));

            AddChild(sprite);
        }
Exemplo n.º 19
0
        public Player(nfloat width, nfloat height)
        {
            Sprite = new SKSpriteNode("Bird")
            {
                XScale   = 0.1f,
                YScale   = 0.1f,
                Position = new CGPoint(width / 2.5, height / 2)
            };

            var action = SKAction.MoveBy(0, GRAVITY, 1);

            Sprite.RunAction(SKAction.RepeatActionForever(action));

            Sprite.PhysicsBody = SKPhysicsBody.Create(Sprite.Texture, Sprite.Size);
            Sprite.PhysicsBody.AffectedByGravity             = false;
            Sprite.PhysicsBody.UsesPreciseCollisionDetection = true;
            Sprite.PhysicsBody.CategoryBitMask    = (uint)PhysicsCategoryEnum.Player;
            Sprite.PhysicsBody.CollisionBitMask   = (uint)(PhysicsCategoryEnum.Player | PhysicsCategoryEnum.Pipe);
            Sprite.PhysicsBody.ContactTestBitMask = (uint)(PhysicsCategoryEnum.Player | PhysicsCategoryEnum.Pipe);;
            Sprite.PhysicsBody.Mass = 0.1f;
        }
        public void Move(MoveDirection direction, double timeInterval)
        {
            var rot = ZRotation;

            SKAction action = null;
            float    x, y;

            // Build up the movement action.
            switch (direction)
            {
            case MoveDirection.Forward:
                x      = -(float)(Math.Sin(rot) * MovementSpeed * timeInterval);
                y      = (float)(Math.Cos(rot) * MovementSpeed * timeInterval);
                action = SKAction.MoveBy(x, y, timeInterval);
                break;

            case MoveDirection.Back:
                x      = (float)(Math.Sin(rot) * MovementSpeed * timeInterval);
                y      = -(float)(Math.Cos(rot) * MovementSpeed * timeInterval);
                action = SKAction.MoveBy(x, y, timeInterval);
                break;

            case MoveDirection.Left:
                action = SKAction.RotateByAngle(RotationSpeed, timeInterval);
                break;

            case MoveDirection.Right:
                action = SKAction.RotateByAngle(-RotationSpeed, timeInterval);
                break;
            }

            // Play the resulting action.
            if (action != null)
            {
                RequestedAnimation = AnimationState.Walk;
                RunAction(action);
            }
        }
Exemplo n.º 21
0
        protected Bonus(string spriteImgName, GameController controller)
            : base(spriteImgName)
        {
            this.controller   = controller;
            _node.PhysicsBody = SKPhysicsBody.CreateRectangularBody(_node.Size);
            _node.PhysicsBody.CategoryBitMask    = (uint)GameObjects.bonus;
            _node.PhysicsBody.ContactTestBitMask = (uint)GameObjects.playerBullet;
            _node.PhysicsBody.CollisionBitMask   = (uint)GameObjects.none;

            double maxY = controller.Scene.Size.Height - _node.Size.Height / 2;
            double minY = _node.Size.Height / 2;
            double y    = GMath.GenerateRandomInRange(minY, maxY);
            double x    = controller.Scene.Size.Width + _node.Size.Width / 2;

            _node.Position = new CGPoint(x, y);

            var movingAction = SKAction.MoveBy(-100, 0, 1);

            _node.RunActionAsync(SKAction.RepeatActionForever(movingAction));

            controller.Scene.AddChild(_node);

            controller.BonusesInScene.Add(this);
        }
Exemplo n.º 22
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // Called when a touch begins

            // control player motion
            base.TouchesBegan(touches, evt);
            var touch       = (UITouch)touches.AnyObject;
            var touchedNode = GetNodeAtPoint(touch.LocationInNode(this));


            Console.WriteLine(touch.LocationInNode(this));
            Console.WriteLine(gameTitle.Position);
            Console.WriteLine(touchedNode);

            //starts game on title tap
            if (touchedNode.Name == "stumblingMan")
            {
                Console.WriteLine("it worked");
                AddChild(gameSong);
                startScreen.RemoveFromParent();
                gameTitle.RemoveFromParent();
                AddChild(playerObject);
                AddChild(pauseButton);

                startGame();
            }
            else if (touchedNode == helpButton)
            {
                if (tappedHelp == false)
                {
                    tappedHelp = true;
                    AddChild(instructions);
                }
                else
                {
                    tappedHelp = false;
                    instructions.RemoveFromParent();
                }
            }
            else if (touchedNode.Name == "gameOver")
            {
                obstacle.Position  = new CGPoint(Frame.Width / 2, Frame.Bottom + obhalf + 5);
                enemy.Position     = new CGPoint(Frame.Width / 2, Frame.Bottom + obhalf + 5);
                obstacle1.Position = new CGPoint(obstacle1.Frame.X + obstacle1.Frame.Width / 2, Frame.Bottom + obhalf + 1);
                obstacle2.Position = new CGPoint(obstacle2.Frame.X + obstacle2.Frame.Width / 2, Frame.Bottom + obhalf + 1);
                obstacle4.Position = new CGPoint(obstacle4.Frame.X + obstacle4.Frame.Width / 2, Frame.Bottom + obhalf + 1);

                playerObject.Paused = true;
                playerObject.RemoveAllActions();
                speed = 0;
                endGame.RemoveFromParent();
                gameSong.RunAction(SKAction.CreatePlay());
                startGame();
            }
            else if (touchedNode == pauseButton)
            {
                gamePause();
            }

            else if (!gameended)
            {
                playerMove(touch);
            }

            void gamePause()
            {
                if (pauseTouched == false)
                {
                    Console.WriteLine("UNSstartpause");

                    // all obstacles must unsubscribe at the begining of a pause
                    if (inprogress)
                    {
                        timer.Elapsed  -= sendobstacle;
                        timer1.Elapsed -= sendobstacle1;
                        timer2.Elapsed -= sendobstacle2;
                        timer3.Elapsed -= sendobstacle3;
                        timer4.Elapsed -= sendobstacle4;
                    }

                    pauseTouched = true;
                    AddChild(pauseOverlay);
                    AddChild(highScores);

                    for (int i = 0; i < 10; i++)
                    {
                        if (i >= 1)
                        {
                            scorelist[i].Text     = String.Format("Score: {0}", scores[i]);
                            scorelist[i].Position = new CGPoint(Frame.Width / 2, scorelist[i - 1].Position.Y - (scorelist[i - 1].Frame.Height / 2) - 42);
                        }
                        else
                        {
                            scorelist[i].Text     = String.Format("Score: {0}", scores[i]);
                            scorelist[i].Position = new CGPoint(Frame.Width / 2, highScores.Position.Y - (highScores.Frame.Height / 2) - 42);
                        }
                        AddChild(scorelist[i]);
                    }
                    Scene.Paused = true;
                }
                else
                {
                    Console.WriteLine("SUBendpause");

                    //all obstacle timers must subscribe at the end of a pause
                    if (inprogress)
                    {
                        timer.Elapsed  += sendobstacle;
                        timer1.Elapsed += sendobstacle1;
                        timer2.Elapsed += sendobstacle2;
                        timer3.Elapsed += sendobstacle3;
                        timer4.Elapsed += sendobstacle4;
                    }

                    pauseOverlay.RemoveFromParent();
                    highScores.RemoveFromParent();
                    for (int i = 0; i < 10; i++)
                    {
                        scorelist[i].RemoveFromParent();
                    }
                    pauseTouched = false;
                    Scene.Paused = false;
                }
            }

            // detects left and right screen taps, moves player accordingly
            void playerMove(UITouch location)
            {
                if (touch.LocationInNode(this).X >= playerObject.Frame.Right)
                {
                    if (DIR)
                    {
                        Console.WriteLine("clickright + moveright" + speed);
                        playerObject.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(difficulty, 0, 2.0f)));
                        speed = speed + difficulty;
                    }
                    else
                    {
                        Console.WriteLine("clickright + moveleft" + speed);
                        playerObject.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(difficulty - speed, 0, 2.0f)));
                        speed = difficulty;
                        DIR   = true;
                    }
                }
                if (touch.LocationInNode(this).X < playerObject.Frame.Left)
                {
                    if (!DIR)
                    {
                        Console.WriteLine("clickleft + moveleft" + speed);
                        playerObject.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(-difficulty, 0, 2.0f)));
                        speed = speed - difficulty;
                    }
                    else
                    {
                        Console.WriteLine("clickleft + moveleft" + speed);
                        playerObject.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(-difficulty - speed, 0, 2.0f)));
                        speed = -difficulty;
                        DIR   = false;
                    }
                }
            }

            void startGame()
            {
                //setting the game is in progress to true
                playerObject.PhysicsBody.AllowsRotation = false;
                obstacle.PhysicsBody.AllowsRotation     = false;
                enemy.PhysicsBody.AllowsRotation        = false;
                obstacle1.PhysicsBody.AllowsRotation    = false;
                obstacle2.PhysicsBody.AllowsRotation    = false;
                obstacle4.PhysicsBody.AllowsRotation    = false;

                inprogress          = true;
                gameended           = false;
                playerObject.Paused = false;

                #region for timers

                timer          = new System.Timers.Timer();
                timer.Interval = 1000;
                Console.WriteLine("SUB");
                timer.Elapsed  += sendobstacle;
                timer.AutoReset = true;
                timer.Enabled   = true;

                timer1          = new System.Timers.Timer();
                timer1.Interval = 2000;
                Console.WriteLine("SUB");
                timer1.Elapsed  += sendobstacle1;
                timer1.AutoReset = true;
                timer1.Enabled   = true;

                timer2          = new System.Timers.Timer();
                timer2.Interval = 4000;
                Console.WriteLine("SUB");
                timer2.Elapsed  += sendobstacle2;
                timer2.AutoReset = true;
                timer2.Enabled   = true;

                timer3          = new System.Timers.Timer();
                timer3.Interval = 1150;
                Console.WriteLine("SUB");
                timer3.Elapsed  += sendobstacle3;
                timer3.AutoReset = true;
                timer3.Enabled   = true;

                timer4          = new System.Timers.Timer();
                timer4.Interval = 1250;
                Console.WriteLine("SUB");
                timer4.Elapsed  += sendobstacle4;
                timer4.AutoReset = true;
                timer4.Enabled   = true;

                #endregion


                startScreen.RunAction(SKAction.CreatePause());
                Scroll(sidewalk1);
                Scroll(sidewalk2);
                Scroll(sidewalk3);

                playerObject.XScale   = 2.0f;
                playerObject.YScale   = 2.0f;
                playerObject.Position = new CGPoint(Frame.Width / 2, Frame.Height / 4);
                Scroll(road1);
                Scroll(road2);
                Scroll(road3);
                Scroll(road4);
                Scroll(road5);
                Scroll(road6);

                Scroll(building1);
                Scroll(building2);
                Scroll(building3);
                Scroll(building4);
                Scroll(building5);
                Scroll(building6);
                Scroll(building7);
                Scroll(building8);
                Scroll(building9);
                Scroll(building10);
                Scroll(building11);
                Scroll(building12);
                Scroll(building13);
                Scroll(building14);


                animatePlayer();

                playerObject.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(0.001f, 0, 2.0f)));
                DIR = true;
            }
        }
Exemplo n.º 23
0
 // definition of sidewalk scrolling action
 public void Scroll(SKSpriteNode sidewalk)
 {
     walkAnimate = SKAction.RepeatActionForever(SKAction.MoveBy(0.0f, -.09f, 0.0003f));
     sidewalk.RunAction(walkAnimate);
 }
Exemplo n.º 24
0
        public override void DidMoveToView(SKView view)
        {
            road1 = new SKSpriteNode("road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, 89),
                ZPosition = 0.3f
            };
            roadhalf = (road1.Frame.Height / 2) - 1;

            road1.Position = new CGPoint(roadx, roadhalf);

            road2 = new SKSpriteNode("road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, roadhalf + (road1.Frame.Bottom)),
                ZPosition = 0.3f
            };

            road3 = new SKSpriteNode("road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, roadhalf + (road2.Frame.Bottom)),
                ZPosition = 0.3f
            };

            road4 = new SKSpriteNode("road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, roadhalf + (road3.Frame.Bottom)),
                ZPosition = 0.3f
            };

            road5 = new SKSpriteNode("road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, roadhalf + (road4.Frame.Bottom)),
                ZPosition = 0.3f
            };

            road6 = new SKSpriteNode("road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, roadhalf + (road5.Frame.Bottom)),
                ZPosition = 0.3f
            };

            Console.WriteLine(road1.Frame);

            building1 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, 0),
                ZPosition = 0.3f
            };

            buildhalf = (building1.Frame.Height / 2) - 1;

            building2 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building1.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building3 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building2.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building4 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(0 + 327, (65 / 2) + (building3.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building5 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building4.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building6 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building5.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building7 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building6.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building8 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building7.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building9 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building8.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building10 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building9.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building11 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building10.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building12 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building11.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building13 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building12.Frame.Bottom)),
                ZPosition = 0.3f
            };

            building14 = new SKSpriteNode("Building")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(buildx, buildhalf + (building13.Frame.Bottom)),
                ZPosition = 0.3f
            };


            // Setup player character
            playerObject = new SKSpriteNode("Stumbler-1")
            {
                XScale    = 1.6f,
                YScale    = 1.6f,
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 4),
                ZPosition = 0.1f
            };

            // sidewalk sprites, set up to overlap to remove gaps 4 at top 1 at bottom

            sidewalk1 = new SKSpriteNode("Sidewalk")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(Frame.Width / 2, Frame.Bottom - sidehalf),
                ZPosition = 0.0f
            };

            sidewalk2 = new SKSpriteNode("Sidewalk")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(Frame.Width / 2, sidewalk1.Frame.Top - sidehalf),
                ZPosition = 0.0f
            };


            sidewalk3 = new SKSpriteNode("Sidewalk")
            {
                XScale    = 1.0f,
                YScale    = 1.0f,
                Position  = new CGPoint(Frame.Width / 2, sidewalk2.Frame.Top - sidehalf),
                ZPosition = 0.0f
            };


            // definition of player walking animation
            void animatePlayer()

            {
                var textures = Enumerable.Range(1, 4).Select(
                    (i) => SKTexture.FromImageNamed(String.Format("Stumbler-{0}", i))).ToArray();

                playerAnimate = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1));
                playerObject.RunAction(playerAnimate);
            }

            // definition of sidewalk scrolling action
            void Scroll(SKSpriteNode node)
            {
                walkAnimate = SKAction.RepeatActionForever(SKAction.MoveBy(0.0f, -0.1f, 0.0007f));
                node.RunAction(walkAnimate);
            }

            // calls to add sprites to scene
            AddChild(road1);
            AddChild(road2);
            AddChild(road3);
            AddChild(road4);
            AddChild(road5);
            AddChild(road6);

            AddChild(sidewalk1);
            AddChild(sidewalk2);
            AddChild(sidewalk3);

            AddChild(building1);
            AddChild(building2);
            AddChild(building3);
            AddChild(building4);
            AddChild(building5);
            AddChild(building6);
            AddChild(building7);
            AddChild(building8);
            AddChild(building9);
            AddChild(building10);
            AddChild(building11);
            AddChild(building12);
            AddChild(building13);
            AddChild(building14);

            AddChild(playerObject);

            // calls to animation for sprites
            Scroll(sidewalk1);
            Scroll(sidewalk2);
            Scroll(sidewalk3);

            Scroll(road1);
            Scroll(road2);
            Scroll(road3);
            Scroll(road4);
            Scroll(road5);
            Scroll(road6);

            Scroll(building1);
            Scroll(building2);
            Scroll(building3);
            Scroll(building4);
            Scroll(building5);
            Scroll(building6);
            Scroll(building7);
            Scroll(building8);
            Scroll(building9);
            Scroll(building10);
            Scroll(building11);
            Scroll(building12);
            Scroll(building13);
            Scroll(building14);


            animatePlayer();

            //Console.WriteLine(Frame.Bottom);
        }
Exemplo n.º 25
0
        public void FireBullet(int pitch, int heading, nfloat startingx, nfloat startingy)
        {
            this.isFired = true;
            //logic for bullet
            //need a starting point
            this.x_world = (int)startingx;
            this.y_world = (int)startingy;
            int signx      = 0;
            int signy      = 0;
            int dir        = 0;
            int headingcpy = heading;

            this.Bullet.Position = new CoreGraphics.CGPoint(startingx,
                                                            startingy);
            double pitchradians     = (pitch * (Math.PI / 180)) - (Math.PI / 2);
            double heaindingradians = heading * (Math.PI / 180);

            /*while(pitchradians < 0){
             *  pitchradians += (2 * Math.PI);
             * } */

            while (headingcpy < 0)
            {
                headingcpy += 360;
            }

            if ((headingcpy >= 0) && (headingcpy <= 90))
            {
                dir   = 1;
                signx = 1;
                signy = 1;
            }

            else if ((headingcpy > 90) && (headingcpy < 180))
            {
                dir   = 2;
                signx = -1;
                signy = 1;
            }

            else if ((headingcpy >= 180) && (headingcpy < 270))
            {
                dir   = 3;
                signx = -1;
                signy = -1;
            }

            else if ((headingcpy > 270) && (headingcpy <= 360))
            {
                dir   = 4;
                signx = 1;
                signy = -1;
            }

            var action = SKAction.MoveBy((float)(signx * 5000 * Math.Cos((pitch * Math.PI / 180))),
                                         (float)(signy * 5000 * Math.Sin((pitch * Math.PI / 180))), 5.0);

            if ((dir == 1) || (dir == 2))
            {
                var action1 = SKAction.RotateToAngle((nfloat)pitchradians, .25);

                this.Bullet.RunAction(action1); //rotate the missile first
                this.Bullet.RunAction(action);  //launch the missile!
            }

            else if ((dir == 3) || (dir == 4))
            {
                var action1 = SKAction.RotateToAngle((nfloat)(pitchradians + Math.PI), .25);

                this.Bullet.RunAction(action1); //rotate the missile first
                this.Bullet.RunAction(action);  //launch the missile!
            }
        }
Exemplo n.º 26
0
        //**********************************************************************
        //*****Update(double currentTime){}*************************************
        //*****is an event that is your frame per second update feature*********
        //*****essentially your game engine if it's simple enough for writing***
        //*****after every frame checks for collisions between player weapons***
        //*****and enemy towersa label (myLabel1) is updated every 30 frames****
        //***** to display headingthis game is set to around 60 frames per sec**
        //*****for smoothness, Every Sec (60frames) a random enemy will fire****
        //**********************************************************************
        public override void Update(double currentTime)
        {
            // Called before each frame is rendered

            //check fuel

            //update screen gaugues
            SKLabelNode  headingvalue = (SKLabelNode)GetChildNode("myLabel1");
            SKLabelNode  scorelabel   = (SKLabelNode)GetChildNode("ScoreLabel");
            SKSpriteNode NavArrow     = (SKSpriteNode)GetChildNode("NavArrow");
            Random       enemyNumber  = new Random();

            if ((PlayerRide.PlayerSpriteObject != null) && (headingvalue != null))
            {
                if ((FrameNumber % 30) == 0)
                {
                    headingvalue.Text = PlayerRide.GetHeading().ToString();
                    var action = SKAction.MoveBy(PlayerRide.hSpeed, PlayerRide.vSpeed, 1.0);
                    PlayerRide.PlayerSpriteObject.RunAction(action);
                }

                var action2 = SKAction.RotateToAngle((nfloat)((PlayerRide.GetHeading() - 90) * Math.PI / 180), 1.0);
                NavArrow.RunAction(action2);
            }

            if ((FrameNumber % 60) == 0)
            {
                int j = (enemyNumber.Next()) % ((EnemyTowers.Length));
                int y = (enemyNumber.Next()) % ((EnemyTowers[j].GuardMagazine.Length));

                if (EnemyTowers[j].GuardMagazine[y].Bullet != null)
                {
                    if (EnemyTowers[j].GuardMagazine[y].isFired == false)
                    {
                        AddChild(EnemyTowers[j].GuardMagazine[y].Bullet);
                        EnemyTowers[j].FireAtRandom();
                    }
                }
            }

            //EveryFrame we need to check for collisions between the missiles

            //1)check for player missile hits

            for (int i = 0; i < EnemyTowers.Length; i += 1)
            {
                if (PlayerRide.MachineGun[0].BulletCollided(PlayerRide.MachineGun, EnemyTowers[i]))
                {
                    EnemyTowers[i].TowerGotHit();
                    score          += 10;
                    scorelabel.Text = "Score: " + score.ToString();
                }
            }

            for (int i = 0; i < EnemyTowers.Length; i += 1)
            {
                if (EnemyTowers[i].isDead())
                {
                    EnemyTowers[i].tower.RemoveFromParent();
                }
            }

            FrameNumber += 1;

            /*
             * if((FrameNumber% 120) == 0){
             *  for (int x = 0; x < EnemyTowers.Length; x = 1){
             *      for (int y = 0; y < EnemyTowers[x].GuardMagazine.Length; y += 1){
             *          if(EnemyTowers[x].GuardMagazine[y].getXposition() > Frame.Width){
             *              EnemyTowers[x].GuardMagazine[y].Bullet.RemoveFromParent();
             *          }
             *      }
             *  }
             * } */
        }
Exemplo n.º 27
0
 public void Jump()
 {
     Sprite.RunAction(SKAction.MoveBy(0, JUMP_HEIGHT, 0.5));
 }
Exemplo n.º 28
0
        /// <summary>
        /// Point the sprite to move by the vector
        /// </summary>
        /// <param name="vector">Vector.</param>
        public void AttackByVector(CGVector vector)
        {
            var time = Math.Sqrt(Math.Pow(vector.dx, 2) + Math.Pow(vector.dy, 2)) / 300;

            RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(vector, time)));
        }