コード例 #1
0
 public EnemySprite()
 {
     Texture     = SKTexture.FromImageNamed(ENEMY_DUTY_IMAGE);
     Size        = Texture.Size;
     PhysicsBody = SKPhysicsBody.CreateRectangularBody(Size);
     PhysicsBody.AllowsRotation     = false;
     PhysicsBody.CategoryBitMask    = CollisionCategory.Enemy;
     PhysicsBody.ContactTestBitMask = CollisionCategory.Hero | CollisionCategory.Spell | CollisionCategory.Platform;
     PhysicsBody.CollisionBitMask  ^= CollisionCategory.Spell;
 }
コード例 #2
0
        public void BodyWithEdgeLoopFromRect()
        {
            TestRuntime.AssertXcodeVersion(5, 0, 1);

            // bug 13772 - that call actually return a PKPhysicsBody (private PhysicKit framework)
            var size = new CGSize(3, 2);

            using (var body = SKPhysicsBody.CreateRectangularBody(size)) {
                Assert.That(body, Is.TypeOf <SKPhysicsBody> (), "SKPhysicsBody");
            }
        }
コード例 #3
0
        void AddCollisionWallAtWorldPoint(CGPoint worldPoint, float width, float height)
        {
            var rect = new CGRect(0, 0, width, height);

            var wallNode = SKNode.Create();

            wallNode.Position                     = new CGPoint(worldPoint.X + rect.Size.Width * 0.5f, worldPoint.Y - rect.Size.Height * 0.5f);
            wallNode.PhysicsBody                  = SKPhysicsBody.CreateRectangularBody(rect.Size);
            wallNode.PhysicsBody.Dynamic          = false;
            wallNode.PhysicsBody.CategoryBitMask  = (uint)ColliderType.Wall;
            wallNode.PhysicsBody.CollisionBitMask = 0;

            AddNode(wallNode, WorldLayer.Ground);
        }
コード例 #4
0
        public void BodyWithEdgeLoopFromRect()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            // bug 13772 - that call actually return a PKPhysicsBody (private PhysicKit framework)
            SizeF size = new SizeF(3, 2);

            using (var body = SKPhysicsBody.CreateRectangularBody(size)) {
                Assert.That(body, Is.TypeOf <SKPhysicsBody> (), "SKPhysicsBody");
            }
        }
コード例 #5
0
        public HeroSprite()
        {
            _heroJump   = SKTexture.FromImageNamed(HERO_JUMP_IMAGE);
            _heroStand  = SKTexture.FromImageNamed(HERO_STAND_IMAGE);
            _heroMoving = SKTexture.FromImageNamed(HERO_MOVING_IMAGE);

            Texture     = _heroStand;
            Size        = Texture.Size;
            PhysicsBody = SKPhysicsBody.CreateRectangularBody(Size);
            PhysicsBody.CategoryBitMask    = CollisionCategory.Hero;
            PhysicsBody.ContactTestBitMask = CollisionCategory.Enemy | CollisionCategory.Spell;
            // XOR Spell bitmask to avoid collision
            PhysicsBody.CollisionBitMask ^= CollisionCategory.Spell;
            PhysicsBody.AllowsRotation    = false;
        }
コード例 #6
0
 public void GenerateWalls()
 {
     for (int i = 0; i < NumObs; i++)
     {
         CGSize ObstacleSize = new CGSize(ObstaclePositions[i].width, ObstaclePositions[i].height);
         ObstaclesNodes[i]             = new SKSpriteNode(UIColor.Black, ObstacleSize);
         ObstaclesNodes[i].Size        = ObstacleSize;
         ObstaclesNodes[i].Position    = new CGPoint(ObstaclePositions[i].X, ObstaclePositions[i].Y);
         ObstaclesNodes[i].PhysicsBody = SKPhysicsBody.CreateRectangularBody(ObstaclesNodes[i].Size);
         ObstaclesNodes[i].PhysicsBody.UsesPreciseCollisionDetection = true;
         ObstaclesNodes[i].Name = "Obstacle";
         ObstaclesNodes[i].PhysicsBody.AffectedByGravity = false;
         ObstaclesNodes[i].PhysicsBody.Dynamic           = false;
         Application.GameSceneViewer.AddChild(ObstaclesNodes[i]);
     }
 }
コード例 #7
0
        public LaserBullet(double dmg, string imgName, GameObjects type)
            : base(dmg, imgName, type)
        {
            _node.PhysicsBody = SKPhysicsBody.CreateRectangularBody(_node.Size);
            _node.PhysicsBody.CategoryBitMask = (uint)type;

            if (type == GameObjects.playerBullet)
            {
                _node.PhysicsBody.ContactTestBitMask = (uint)GameObjects.enemy;
            }
            else if (type == GameObjects.enemyBullet)
            {
                _node.PhysicsBody.ContactTestBitMask = (uint)GameObjects.player;
            }

            _node.PhysicsBody.CollisionBitMask = (uint)GameObjects.none;
        }
コード例 #8
0
        public ShotSprite(SpellType type)
        {
            Type = type;
            switch (type)
            {
            case SpellType.Hero:
                Texture = SKTexture.FromImageNamed(SHOT_HERO_PATH);
                break;

            case SpellType.Enemy:
                Texture = SKTexture.FromImageNamed(SHOT_ENEMY_PATH);
                break;
            }
            Size        = Texture.Size;
            PhysicsBody = SKPhysicsBody.CreateRectangularBody(Size);
            PhysicsBody.CategoryBitMask    = CollisionCategory.Spell;
            PhysicsBody.ContactTestBitMask = CollisionCategory.Enemy | CollisionCategory.Platform;
            PhysicsBody.CollisionBitMask   = 0;
            PhysicsBody.AffectedByGravity  = false;
            PhysicsBody.AngularDamping     = 0;
            PhysicsBody.AllowsRotation     = false;
        }
コード例 #9
0
        public PlatformSprite(PlatformType type)
        {
            switch (type)
            {
            case PlatformType.Short:
                Texture = SKTexture.FromImageNamed(SHORT_PLATFORM_IMAGE);
                break;

            case PlatformType.Medium:
                Texture = SKTexture.FromImageNamed(MEDIUM_PLATFORM_IMAGE);
                break;

            case PlatformType.Long:
                Texture = SKTexture.FromImageNamed(LONG_PLATFORM_IMAGE);
                break;
            }
            Size                           = Texture.Size;
            PhysicsBody                    = SKPhysicsBody.CreateRectangularBody(Size);
            PhysicsBody.Dynamic            = false;
            PhysicsBody.CategoryBitMask    = CollisionCategory.Platform;
            PhysicsBody.ContactTestBitMask = CollisionCategory.Hero | CollisionCategory.Enemy;
        }
コード例 #10
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);
        }
コード例 #11
0
        public override void DidMoveToView(SKView view)
        {
            
 var plist = NSUserDefaults.StandardUserDefaults; 
                       for (int i = 0; i < 10; i++)

            {
                
                   {
                    
 var s = plist.IntForKey(String.Format("Score-{0}", i));

                    var ns = Convert.ToInt32(s);

                    scores.Add(ns); 

                }
            }


            // music while player is walking
            gameSong = new SKAudioNode("walking")
            {
                AutoplayLooped = true,
                Positional     = false,
            };

            // sound when player dies
            playerDied = new SKAudioNode("playerDeath")
            {
                AutoplayLooped = false,
                Positional     = false,
            };

            //start screen music
            startScreen = new SKAudioNode("gameTitle")
            {
                AutoplayLooped = true,
                Positional     = false,
            };
            #endregion

            #region sprites
            // sprites

            for (int i = 9; i >= 0; i--)
            {
                SKLabelNode ascore = new SKLabelNode("chalkduster")
                {
                    Text      = String.Format("Score: {0}", scores[i]),
                    FontSize  = 30,
                    FontColor = UIColor.White,
                    Position  = new CGPoint(Frame.Width / 2, Frame.Height / 1.1),
                    ZPosition = 20
                };

                scorelist.Add(ascore);
            }

            instructions = new SKSpriteNode("intro")
            {
                XScale    = 1,
                YScale    = 1,
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 2),
                ZPosition = 50
            };
            var enemySize = new CGSize(25, 25);
            enemy = new SKSpriteNode("walker-1")
            {
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(enemySize),
                Position    = new CGPoint(Frame.Width / 2, Frame.Bottom + 40),
                XScale      = 2.0f,
                YScale      = 2.0f,

                ZPosition = 0.24f
            };
            helpButton = new SKSpriteNode("help")
            {
                XScale    = .25f,
                YScale    = .25f,
                Position  = new CGPoint(buildx + 5, Frame.Bottom - 35),
                ZPosition = 25,
            };
            highScores = new SKLabelNode("chalkduster")
            {
                Text      = "High Scores",
                FontSize  = 30,
                FontColor = UIColor.White,
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 1.1),
                ZPosition = 20
            };

            leftBorder = new SKSpriteNode("overlay")
            {
                XScale      = 0.1f,
                YScale      = 10,
                Position    = new CGPoint(buildx - 10, Frame.Height / 2),
                ZPosition   = .25f,
                Alpha       = .01f,
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(new CGSize(90, 1000)),
            };
            rightBorder = new SKSpriteNode("overlay")
            {
                XScale      = 0.1f,
                YScale      = 10,
                Position    = new CGPoint(roadx + 42, Frame.Height / 2),
                ZPosition   = .25f,
                Alpha       = .01f,
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(new CGSize(80, 1000)),
            };

            pauseOverlay = new SKSpriteNode("overlay")
            {
                XScale    = 20,
                YScale    = 10,
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 2),
                Color     = UIColor.Black,
                ZPosition = 10,
                Alpha     = 0.75f,
            };
            pauseButton = new SKSpriteNode("pauseButton")
            {
                XScale    = .1f,
                YScale    = .1f,
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 10),
                ZPosition = 21f,
            };
            road1 = new SKSpriteNode("Road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, 89),
                ZPosition = 0.2f
            };
            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.2f
            };

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

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

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

            road6 = new SKSpriteNode("Road")
            {
                XScale    = 0.7f,
                YScale    = 0.7f,
                Position  = new CGPoint(roadx, roadhalf + (road5.Frame.Bottom)),
                ZPosition = 0.2f
            };
            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
            };

            scorelabel = new SKLabelNode("Gillsans-UltraBold")
            {
                Text      = String.Format("Score: {0}", score),
                FontSize  = 25,
                FontColor = UIColor.White,
                Name      = "SCORELABEL",
                Position  = new CGPoint(Frame.Width / 2, Frame.Bottom - 27),
                ZPosition = .5f,
            };


            gameTitle = new SKLabelNode("zapfino")
            {
                Text      = "Stumbling Man",
                FontSize  = 27,
                FontColor = UIColor.Black,
                Name      = "stumblingMan",
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 2),
                ZPosition = .5f,
            };

            endGame = new SKLabelNode("GillSans-UltraBold")
            {
                Text      = "Game Over",
                FontSize  = 30,
                Name      = "gameOver",
                FontColor = UIColor.Blue,
                Position  = new CGPoint(Frame.Width / 2, Frame.Height / 2),
                ZPosition = .5f
            };

            var playerSize = new CGSize(25, 25);
            playerObject = new SKSpriteNode("Stumbler-1")
            {
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(playerSize),
                XScale      = 2.0f,
                YScale      = 2.0f,
                Position    = new CGPoint(Frame.Width / 2, Frame.Height / 4),
                ZPosition   = 0.25f
            };


            obstacle = new SKSpriteNode("trash-1")
            {
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(playerSize),
                XScale      = 0.3f,
                YScale      = 0.3f,
                Position    = new CGPoint(Frame.Width / 2, Frame.Bottom),
                ZPosition   = 0.24f
            };

            obhalf            = (obstacle.Frame.Height / 2);
            obstacle.Position = new CGPoint(Frame.Width / 2, Frame.Bottom + obhalf);

            obstacle4 = new SKSpriteNode("trash-1")
            {
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(playerSize),
                XScale      = 0.3f,
                YScale      = 0.3f,
                Position    = new CGPoint(Frame.Width / 2, Frame.Bottom + obhalf),
                ZPosition   = 0.24f
            };

            obstacle1 = new SKSpriteNode("Viper")
            {
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(new CGSize(1, 1)),
                XScale      = 0.3f,
                YScale      = 0.3f,
                Position    = new CGPoint(roadx - 23, Frame.Bottom + obhalf + 1),
                ZPosition   = 0.24f
            };

            obstacle2 = new SKSpriteNode("Taxi")
            {
                PhysicsBody = SKPhysicsBody.CreateRectangularBody(playerSize),
                XScale      = .3f,
                YScale      = .3f,
                Position    = new CGPoint(roadx - 23, Frame.Bottom + obhalf + 1),
                ZPosition   = 0.24f
            };

            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
            };
            #endregion
            // calls to add sprites to scene
            playerObject.PhysicsBody.CategoryBitMask    = playerHit;
            playerObject.PhysicsBody.ContactTestBitMask = obstacleHit | leftHit | rightHit;
            playerObject.PhysicsBody.CollisionBitMask   = obstacleHit | leftHit | rightHit;
            //playerObject.PhysicsBody.Dynamic = false;

            obstacle.PhysicsBody.CategoryBitMask    = obstacleHit;
            obstacle.PhysicsBody.ContactTestBitMask = playerHit;
            obstacle.PhysicsBody.CollisionBitMask   = playerHit;

            obstacle1.PhysicsBody.CategoryBitMask    = obstacleHit;
            obstacle1.PhysicsBody.ContactTestBitMask = playerHit;
            obstacle1.PhysicsBody.CollisionBitMask   = playerHit;

            obstacle2.PhysicsBody.CategoryBitMask    = obstacleHit;
            obstacle2.PhysicsBody.ContactTestBitMask = playerHit;
            obstacle2.PhysicsBody.CollisionBitMask   = playerHit;

            obstacle4.PhysicsBody.CategoryBitMask    = obstacleHit;
            obstacle4.PhysicsBody.ContactTestBitMask = playerHit;
            obstacle4.PhysicsBody.CollisionBitMask   = playerHit;

            leftBorder.PhysicsBody.CategoryBitMask    = leftHit;
            leftBorder.PhysicsBody.ContactTestBitMask = playerHit;
            leftBorder.PhysicsBody.CollisionBitMask   = playerHit;

            rightBorder.PhysicsBody.CategoryBitMask    = rightHit;
            rightBorder.PhysicsBody.ContactTestBitMask = playerHit;
            rightBorder.PhysicsBody.CollisionBitMask   = playerHit;

            enemy.PhysicsBody.CategoryBitMask    = obstacleHit;
            enemy.PhysicsBody.ContactTestBitMask = playerHit;
            enemy.PhysicsBody.CollisionBitMask   = playerHit;
            ////
            PhysicsWorld.ContactDelegate = this;
            /////

            #region gamestart
            void gameStart()

            {
                PhysicsWorld.Gravity = new CGVector(0, 0);

                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(road1);
                AddChild(road2);
                AddChild(road3);
                AddChild(road4);
                AddChild(road5);
                AddChild(road6);
                AddChild(sidewalk1);
                AddChild(sidewalk2);
                AddChild(sidewalk3);
                AddChild(startScreen);
                AddChild(gameTitle);
                AddChild(playerDied);
                AddChild(leftBorder);
                AddChild(rightBorder);
                AddChild(scorelabel);
                AddChild(obstacle);
                AddChild(obstacle1);
                AddChild(obstacle2);
                AddChild(helpButton);
                AddChild(enemy);
                AddChild(obstacle4);
                animateEnemy();
            }

            gameStart();
        }