Ejemplo n.º 1
0
        /// <summary>
        ///  Player Actions
        /// </summary>

        public void AddPlayers()
        {
            for (int i = 0; i < NumberOfPlayers; i++)
            {
                Player[i]          = new SKSpriteNode(Application.PlayerCharacterOption[i]);
                Player[i].Size     = new CGSize(40, 30);
                Player[i].Position = new CGPoint((Random.Next(GameScene.DisplayDefaultSizes.MinX + 60, GameScene.DisplayDefaultSizes.MaxX - 60)), (Random.Next(GameScene.DisplayDefaultSizes.MinY + 60, GameScene.DisplayDefaultSizes.MaxY - 60)));
                if (i > 0)
                {
                    Player[i].ZRotation = (nfloat)Math.PI;
                }
                Player[i].PhysicsBody = SKPhysicsBody.Create(Player[i].Texture, Player[i].Size);
                Player[i].PhysicsBody.UsesPreciseCollisionDetection = true;
                Player[i].PhysicsBody.AllowsRotation = false;
                Player[i].Name            = "Player" + (i + 1);
                PlayerController[i]       = new SKSpriteNode("CircleArrow");
                PlayerController[i].Size  = new CGSize(100, 100);
                PlayerController[i].Alpha = (nfloat)0.3;
                ///
                GameScene.PlayerWepons[i] = 1;
                Application.GameSceneViewer.ChangeLifeIndicator(i, Application.PlayerSettings.InitialLifes);
                Application.GameSceneViewer.ChangeMunitionIndicator(i, Application.PlayerSettings.InitialBullets);
                Application.GameSceneViewer.ChangePlayerWinsIndicator(i, 0);
            }
            Application.GameSceneViewer.AddNodes(Player);
        }
        public void Create()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            using (var s = new SKScene(new SizeF(320, 240)))
                using (var b1 = SKPhysicsBody.CreateCircularBody(1.0f))
                    using (var b2 = SKPhysicsBody.CreateCircularBody(2.0f)) {
                        // according to Apple docs we should not create this joint before adding it to a scene
                        // <quote>The body must be connected to a node that is already part of the scene’s node tree.</quote>
                        // Note that doing the same for a `SKPhysicsJointLimit` does crash
                        using (var j = SKPhysicsJointFixed.Create(b1, b2, new PointF(10, 20))) {
                            Assert.That(j.BodyA, Is.SameAs(b1), "BodyA");
                            Assert.That(j.BodyB, Is.SameAs(b2), "BodyB");

                            SKNode n1 = new SKNode();
                            n1.PhysicsBody = b1;
                            s.AddChild(n1);

                            SKNode n2 = new SKNode();
                            n2.PhysicsBody = b2;
                            s.AddChild(n2);

                            // using the default ctor (for `j`) would crash (and no way to set the PointF argument)
                            // https://bugzilla.xamarin.com/show_bug.cgi?id=14511
                            s.PhysicsWorld.AddJoint(j);
                        }
                    }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializations
        /// </summary>

        public void InitializeBackground()
        {
            BackgroundObsNo = 0;
            for (int i = 0; i < 12; i++, BackgroundObsNo++)
            {
                int RockNo = random.Next(1, 7);
                if (BackgroundObstaclesNodes[i] == null)
                {
                    BackgroundObstaclesNodes[i] = new SKSpriteNode("Meteor" + RockNo);
                }
                BackgroundObstaclesNodes[i].Position  = GetRandomPosition();
                BackgroundObstaclesNodes[i].Size      = GetRandomSquareSize(10, 80);
                BackgroundObstaclesNodes[i].ZPosition = random.Next(-3, -1);
                bool VisibleElem = Convert.ToBoolean(random.Next(0, 2));
                if (VisibleElem)
                {
                    BackgroundObstaclesNodes[i].Alpha               = (nfloat)1;
                    BackgroundObstaclesNodes[i].PhysicsBody         = SKPhysicsBody.Create(BackgroundObstaclesNodes[i].Texture, BackgroundObstaclesNodes[i].Size);
                    BackgroundObstaclesNodes[i].PhysicsBody.Dynamic = false;
                    BackgroundObstaclesNodes[i].PhysicsBody.UsesPreciseCollisionDetection = true;
                }
                else
                {
                    BackgroundObstaclesNodes[i].Alpha       = (nfloat)0.3;
                    BackgroundObstaclesNodes[i].PhysicsBody = null;
                }
            }
        }
Ejemplo n.º 4
0
        public ShipSprite(CGPoint initialPosition)
            : base(NSBundle.MainBundle.PathForResource("spaceship", "png"))
        {
            CGPath boundingPath = new CGPath();

            boundingPath.MoveToPoint(-12f, -38f);
            boundingPath.AddLineToPoint(12f, -38f);
            boundingPath.AddLineToPoint(9f, 18f);
            boundingPath.AddLineToPoint(2f, 38f);
            boundingPath.AddLineToPoint(-2f, 38f);
            boundingPath.AddLineToPoint(-9f, 18f);
            boundingPath.AddLineToPoint(-12f, -38f);
#if false
            // Debug overlay
            SKShapeNode shipOverlayShape = new SKShapeNode()
            {
                Path        = boundingPath,
                StrokeColor = UIColor.Clear,
                FillColor   = UIColor.FromRGBA(0f, 1f, 0f, 0.5f)
            };
            ship.AddChild(shipOverlayShape);
#endif
            var body = SKPhysicsBody.CreateBodyFromPath(boundingPath);
            body.CategoryBitMask    = Category.Ship;
            body.CollisionBitMask   = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
            body.ContactTestBitMask = body.CollisionBitMask;
            body.LinearDamping      = 0;
            body.AngularDamping     = 0.5f;

            PhysicsBody = body;
            Position    = initialPosition;
        }
Ejemplo n.º 5
0
        void CreateSceneContents()
        {
            BackgroundColor = UIColor.Black;
            ScaleMode       = SKSceneScaleMode.AspectFit;

            // Give the scene an edge and configure other physics info on the scene.
            var body = SKPhysicsBody.CreateEdgeLoop(Frame);

            body.CategoryBitMask    = Category.Edge;
            body.CollisionBitMask   = 0;
            body.ContactTestBitMask = 0;
            PhysicsBody             = body;

            PhysicsWorld.Gravity         = new CGVector(0, 0);
            PhysicsWorld.ContactDelegate = this;

            // In this sample, the positions of everything is hard coded. In an actual game, you might implement this in an archive that is loaded from a file.
            controlledShip = new ShipSprite(new CGPoint(100, 300));
            AddChild(controlledShip);

            // this ship isn't connected to any controls so it doesn't move, except when it collides with something.
            AddChild(new ShipSprite(new CGPoint(200, 300)));

            AddChild(new AsteroidNode(new CGPoint(100, 200)));
            AddChild(new PlanetNode(new CGPoint(300, 100)));
        }
        public new static void LoadSharedAssetsOnce()
        {
                        #if __IOS__
            var whiteColor = UIColor.White;
                        #else
            NSColor whiteColor = null;
            new NSObject().InvokeOnMainThread(() => {
                whiteColor = NSColor.White;
            });
                        #endif

            SKTextureAtlas atlas = SKTextureAtlas.FromName("Environment");

            sharedProjectile             = SKSpriteNode.FromTexture(atlas.TextureNamed("warrior_throw_hammer.png"));
            sharedProjectile.PhysicsBody = SKPhysicsBody.CreateCircularBody(ProjectileCollisionRadius);
            sharedProjectile.Name        = "Projectile";
            sharedProjectile.PhysicsBody.CategoryBitMask    = (uint)ColliderType.Projectile;
            sharedProjectile.PhysicsBody.CollisionBitMask   = (uint)ColliderType.Wall;
            sharedProjectile.PhysicsBody.ContactTestBitMask = sharedProjectile.PhysicsBody.CollisionBitMask;

            sharedProjectileEmitter     = GraphicsUtilities.EmitterNodeWithEmitterNamed("WarriorProjectile");
            sharedIdleAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Idle", "warrior_idle_", WarriorIdleFrames);
            sharedWalkAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Walk", "warrior_walk_", DefaultNumberOfWalkFrames);
            sharedAttackAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Attack", "warrior_attack_", WarriorThrowFrames);
            sharedGetHitAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Warrior_GetHit", "warrior_getHit_", WarriorGetHitFrames);
            sharedDeathAnimationFrames  = GraphicsUtilities.LoadFramesFromAtlas("Warrior_Death", "warrior_death_", WarriorDeathFrames);
            sharedDamageAction          = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 10, 0),
                SKAction.WaitForDuration(0.5),
                SKAction.ColorizeWithColorBlendFactor(0, 0.25)
            });
        }
Ejemplo n.º 7
0
        public void Create()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            using (var s = new SKScene(new SizeF(320, 240)))
                using (var b1 = SKPhysicsBody.CreateCircularBody(1.0f))
                    using (var b2 = SKPhysicsBody.CreateCircularBody(2.0f)) {
                        // <quote>The body must be connected to a node that is already part of the scene’s node tree.</quote>
                        SKNode n1 = new SKNode();
                        n1.PhysicsBody = b1;
                        s.AddChild(n1);

                        SKNode n2 = new SKNode();
                        n2.PhysicsBody = b2;
                        s.AddChild(n2);

                        // if you create the SKPhysicsJointLimit *before* adding the nodes
                        // to a scene then you'll crash and burn. ref: bug #14793
                        using (var j = SKPhysicsJointLimit.Create(b1, b2, PointF.Empty, new PointF(10, 20))) {
                            Assert.That(j.BodyA, Is.SameAs(b1), "BodyA");
                            Assert.That(j.BodyB, Is.SameAs(b2), "BodyB");

                            s.PhysicsWorld.AddJoint(j);
                        }
                    }
        }
Ejemplo n.º 8
0
        public new static void LoadSharedAssetsOnce()
        {
                        #if __IOS__
            var whiteColor = UIColor.White;
                        #else
            NSColor whiteColor = null;
            new NSObject().InvokeOnMainThread(() => {
                whiteColor = NSColor.White;
            });
                        #endif
            sharedProjectile             = SKSpriteNode.FromColor(whiteColor, new CGSize(2, 24));
            sharedProjectile.PhysicsBody = SKPhysicsBody.CreateCircularBody(ProjectileCollisionRadius);
            sharedProjectile.Name        = @"Projectile";
            sharedProjectile.PhysicsBody.CategoryBitMask    = (uint)ColliderType.Projectile;
            sharedProjectile.PhysicsBody.CollisionBitMask   = (uint)ColliderType.Wall;
            sharedProjectile.PhysicsBody.ContactTestBitMask = sharedProjectile.PhysicsBody.CollisionBitMask;

            sharedProjectileEmitter     = GraphicsUtilities.EmitterNodeWithEmitterNamed("ArcherProjectile");
            sharedIdleAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Archer_Idle", "archer_idle_", DefaultNumberOfIdleFrames);
            sharedWalkAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Archer_Walk", "archer_walk_", DefaultNumberOfWalkFrames);
            sharedAttackAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Archer_Attack", "archer_attack_", ArcherAttackFrames);
            sharedGetHitAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Archer_GetHit", "archer_getHit_", ArcherGetHitFrames);
            sharedDeathAnimationFrames  = GraphicsUtilities.LoadFramesFromAtlas("Archer_Death", "archer_death_", ArcherDeathFrames);
            sharedDamageAction          = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 10, 0),
                SKAction.WaitForDuration(0.75),
                SKAction.ColorizeWithColorBlendFactor(0, 0.25)
            });
        }
Ejemplo n.º 9
0
        void Explode()
        {
            // Create a bunch of explosion emitters and send them flying in all directions. Then remove the ship from the scene.
            for (int i = 0; i < numberOfChunks; i++)
            {
                SKEmitterNode explosion = NodeFactory.CreateExplosionNode(Scene, shipExplosionDuration);

                float angle = myRand(0, (float)Math.PI * 2);
                float speed = myRand(shipChunkMinimumSpeed, shipChunkMaximumSpeed);
                var   x     = myRand((float)Position.X - shipChunkDispersion, (float)Position.X + shipChunkDispersion);
                var   y     = myRand((float)Position.Y - shipChunkDispersion, (float)Position.Y + shipChunkDispersion);
                explosion.Position = new CGPoint(x, y);

                var body = SKPhysicsBody.CreateCircularBody(0.25f);
                body.CollisionBitMask   = 0;
                body.ContactTestBitMask = 0;
                body.CategoryBitMask    = 0;
                body.Velocity           = new CGVector((float)Math.Cos(angle) * speed, (float)Math.Sin(angle) * speed);
                explosion.PhysicsBody   = body;

                Scene.AddChild(explosion);
            }

            RunAction(SKAction.Sequence(
                          SKAction.WaitForDuration(removeShipTime),
                          SKAction.RemoveFromParent()
                          ));
        }
Ejemplo n.º 10
0
        public static void AddBonusElem()
        {
            int    Type = random.Next(0, 2);
            string Name;

            if (Type == 1)
            {
                Name = "DoubleGun";
            }
            else
            {
                Name = "Shield";
            }
            if (BonusElemsNo > 4)
            {
                BonusElemsNo = 0;
            }
            if (BonusElems[BonusElemsNo] != null && BonusElems[BonusElemsNo].Parent == Application.GameSceneViewer)
            {
                BonusElems[BonusElemsNo].RemoveFromParent();
            }
            BonusElems[BonusElemsNo]             = new SKSpriteNode(Name);
            BonusElems[BonusElemsNo].Name        = Name;
            BonusElems[BonusElemsNo].Position    = Application.GameSceneViewer.Obstacles.GetRandomPosition();
            BonusElems[BonusElemsNo].ZRotation   = (nfloat)random.NextDouble();
            BonusElems[BonusElemsNo].Size        = new CGSize(25, 25);
            BonusElems[BonusElemsNo].PhysicsBody = SKPhysicsBody.Create(BonusElems[BonusElemsNo].Texture, BonusElems[BonusElemsNo].Size);
            BonusElems[BonusElemsNo].PhysicsBody.CategoryBitMask    = 0x2 << 0;
            BonusElems[BonusElemsNo].PhysicsBody.ContactTestBitMask = 0x2 << 1;
            Application.GameSceneViewer.AddChild(BonusElems[BonusElemsNo]);
            BonusElemsNo++;
        }
Ejemplo n.º 11
0
 public Wall(string name, UIColor color, SizeF size) : base(color, size)
 {
     Name                           = name;
     PhysicsBody                    = SKPhysicsBody.BodyWithRectangleOfSize(size);
     PhysicsBody.Dynamic            = true;
     PhysicsBody.CategoryBitMask    = (uint)Category;
     PhysicsBody.ContactTestBitMask = (uint)Categories.Head;
     PhysicsBody.CollisionBitMask   = 0;
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
        void loadPhysics()
        {
            SKPhysicsBody somePhysicsBody = new SKPhysicsBody(SKScene.defaultSize, ShapeType.Chain);

            somePhysicsBody.BodyType = FarseerPhysics.Dynamics.BodyType.Static;

            physicsBody = somePhysicsBody;

            physicsBody.UserData = this;
        }
Ejemplo n.º 14
0
 public Head(UIColor color, SizeF size, int rowLocation, int columnLocation) : base(color, size)
 {
     PhysicsBody                  = SKPhysicsBody.BodyWithRectangleOfSize(size); // Creates a physics body for the sprite
     PhysicsBody.Dynamic          = true;                                        // The physics engine will not control the movement of the monster.
     PhysicsBody.CategoryBitMask  = (uint)Category;                              // Sets the category bit mask
     PhysicsBody.CollisionBitMask = 0;                                           // Prevents for bouncing
     RowLocation                  = rowLocation;                                 // The row where sprite will appear
     ColumnLocation               = columnLocation;                              // The column where sprite will appear
     Position = GetLocation();                                                   // Calculates the Initial position where sprite will appear, depending of the row and column
 }
Ejemplo n.º 15
0
        void AttackTarget(SKPhysicsBody target, SKNode missile)
        {
            // Only ships take damage from missiles.
            if ((target.CategoryBitMask & Category.Ship) != 0)
            {
                ((ShipSprite)target.Node).ApplyDamage(missileDamage);
            }

            DetonateMissile(missile);
        }
Ejemplo n.º 16
0
        static MissileNode()
        {
            template = UnarchiveNode("missile", "sks");
            // use a local variable to avoid multiple virtual call to the `PhysicsBody` property
            var body = SKPhysicsBody.CreateCircularBody(defaultSize);

            body.CategoryBitMask    = Category.Missile;
            body.ContactTestBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
            body.CollisionBitMask   = 0;
            template.PhysicsBody    = body;
        }
Ejemplo n.º 17
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");
            }
        }
Ejemplo n.º 18
0
        void AttackTarget(SKPhysicsBody target, SKNode missile)
        {
            if ((target.CategoryBitMask & Category.Ship) != 0)
            {
                (target.Node as ShipSprite).ApplyDamage(missileDamage);
            }

            // Detonate! i.e. add an explostion at missile's position and remove the missile
            AddChild(new ExplosionNode(this, missile.Position));
            missile.RemoveFromParent();
        }
 public override void CollidedWith(SKPhysicsBody other)
 {
     if ((other.CategoryBitMask & (uint)ColliderType.GoblinOrBoss) != 0)
     {
         var enemy = (Character)other.Node;
         if (!enemy.Dying)
         {
             ApplyDamage(5);
             RequestedAnimation = AnimationState.GetHit;
         }
     }
 }
        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);
        }
Ejemplo n.º 21
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");
            }
        }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
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]);
     }
 }
        public override void ConfigurePhysicsBody()
        {
            PhysicsBody = SKPhysicsBody.CreateCircularBody(BossCollisionRadius);

            // Our object type for collisions.
            PhysicsBody.CategoryBitMask = (uint)ColliderType.GoblinOrBoss;

            // Collides with these objects.
            PhysicsBody.CollisionBitMask = (uint)(ColliderType.GoblinOrBoss
                                                  | ColliderType.Hero
                                                  | ColliderType.Projectile
                                                  | ColliderType.Wall);

            // We want notifications for colliding with these objects.
            PhysicsBody.ContactTestBitMask = (uint)ColliderType.Projectile;
        }
Ejemplo n.º 25
0
        public override void ConfigurePhysicsBody()
        {
            PhysicsBody         = SKPhysicsBody.CreateCircularBody(CollisionRadius);
            PhysicsBody.Dynamic = false;

            Animated  = false;
            ZPosition = -0.85f;

            // Our object type for collisions
            PhysicsBody.CategoryBitMask = (uint)ColliderType.Cave;

            // Collides with these objects
            PhysicsBody.CollisionBitMask = (uint)(ColliderType.Projectile | ColliderType.Hero);

            // We want notifications for colliding with these objects
            PhysicsBody.ContactTestBitMask = (uint)ColliderType.Projectile;
        }
Ejemplo n.º 26
0
        void loadPhysics()
        {
            physicsBody = new SKPhysicsBody(size, ShapeType.Circle);

            physicsBody.Mass           = 0.0455111116170883f;
            physicsBody.LinearDamping  = 2.0f;
            physicsBody.AngularDamping = 5.0f;

            physicsBody.Restitution = 0.9f;

            physicsBody.BodyType = BodyType.Static;

            maxVelocitySquared = GameMath.spaceshipMaxVelocitySquared(speedAtribute);
            force = maxVelocitySquared / 24000.0f;

            physicsBody.UserData = this;
        }
Ejemplo n.º 27
0
        public AsteroidNode(PointF initialPosition, float size = defaultSize)
        {
            var path = new CGPath();

            path.AddArc(0, 0, size, 0, (float)Math.PI * 2f, true);
            Path        = path;
            StrokeColor = UIColor.Clear;
            FillColor   = UIColor.Brown;
            Position    = initialPosition;
            // use a local variable to avoid multiple virtual call to the `PhysicsBody` property
            var body = SKPhysicsBody.BodyWithCircleOfRadius(size);

            body.CategoryBitMask    = Category.Asteroid;
            body.CollisionBitMask   = Category.Ship | Category.Asteroid | Category.Edge;
            body.ContactTestBitMask = Category.Planet;
            PhysicsBody             = body;
        }
Ejemplo n.º 28
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;
        }
Ejemplo n.º 29
0
        public PlanetNode(CGPoint initialPosition, float size = defaultSize)
        {
            var path = new CGPath();

            path.AddArc(0, 0, size, 0, (float)Math.PI * 2f, true);
            Path        = path;
            StrokeColor = UIColor.Clear;
            FillColor   = UIColor.Green;
            Position    = initialPosition;
            // use a local variable to avoid multiple virtual call to the `PhysicsBody` property
            var body = SKPhysicsBody.CreateCircularBody(size);

            body.CategoryBitMask    = Category.Planet;
            body.CollisionBitMask   = Category.Planet | Category.Edge;
            body.ContactTestBitMask = 0;
            PhysicsBody             = body;
        }
Ejemplo n.º 30
0
        public static SKNode CreateMissileNode(SKNode target)
        {
            // Creates and returns a new missile game object.
            // This method loads a preconfigured emitter from an archive, and then configures it with a physics body.
            SKEmitterNode missile = UnarchiveEmitterNode("missile");

            // The missile particles should be spawned in the scene, not on the missile object.
            missile.TargetNode = target;

            var physicsBody = SKPhysicsBody.CreateCircularBody(shotSize);

            physicsBody.CategoryBitMask    = Category.Missile;
            physicsBody.ContactTestBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
            physicsBody.CollisionBitMask   = 0;

            missile.PhysicsBody = physicsBody;
            return(missile);
        }
Ejemplo n.º 31
0
        void AttackTarget(SKPhysicsBody target, SKNode missile)
        {
            // Only ships take damage from missiles.
            if ((target.CategoryBitMask & Category.Ship) != 0)
                ((ShipSprite)target.Node).ApplyDamage (missileDamage);

            DetonateMissile (missile);
        }
Ejemplo n.º 32
0
 public override void CollidedWith(SKPhysicsBody other)
 {
     if ((other.CategoryBitMask & (uint)ColliderType.GoblinOrBoss) != 0) {
         var enemy = (Character)other.Node;
         if (!enemy.Dying) {
             ApplyDamage (5);
             RequestedAnimation = AnimationState.GetHit;
         }
     }
 }
Ejemplo n.º 33
0
        public override void CollidedWith(SKPhysicsBody other)
        {
            if (Dying)
                return;

            if ((other.CategoryBitMask & (uint)ColliderType.Projectile) != 0) {
                // Apply random damage of either 100% or 50%
                RequestedAnimation = AnimationState.GetHit;

                float damage = Random.Next (2) == 0 ? 50 : 100;
                bool killed = ApplyDamage (damage, other.Node);

                if (killed)
                    CharacterScene.AddToScoreAfterEnemyKill (10, other.Node);
            }
        }
Ejemplo n.º 34
0
 public abstract void CollidedWith(SKPhysicsBody other);
Ejemplo n.º 35
0
        void AttackTarget(SKPhysicsBody target, SKNode missile)
        {
            if ((target.CategoryBitMask & Category.Ship) != 0)
                (target.Node as ShipSprite).ApplyDamage (missileDamage);

            // Detonate! i.e. add an explostion at missile's position and remove the missile
            AddChild (new ExplosionNode (this, missile.Position));
            missile.RemoveFromParent ();
        }