Пример #1
0
        public virtual void DidBeginContact(SCNPhysicsWorld world, SCNPhysicsContact contact)
        {
            if (CurrentGameState == GameState.InGame)
            {
                // Player to banana, large banana, or coconut
                if (contact.NodeA == GameLevel.PlayerCharacter.CollideSphere)
                {
                    PlayerCollideWithContact(contact.NodeB, contact.ContactPoint);
                    return;
                }
                else if (contact.NodeB == GameLevel.PlayerCharacter.CollideSphere)
                {
                    PlayerCollideWithContact(contact.NodeA, contact.ContactPoint);
                    return;
                }

                // Coconut to anything but the player.
                if ((contact.NodeB.CategoryBitMask == GameCollisionCategory.Coconut))
                {
                    HandleCollideForCoconut((Coconut)contact.NodeB);
                }
                else if ((contact.NodeA.CategoryBitMask == GameCollisionCategory.Coconut))
                {
                    HandleCollideForCoconut((Coconut)contact.NodeA);
                }
            }
        }
            public override void DidBeginContact(SCNPhysicsWorld world, SCNPhysicsContact contact)
            {
                var     nodeA  = contact.NodeA;
                var     nodeB  = contact.NodeB;
                SCNNode target = null;

                if (nodeA.PhysicsBody.CategoryBitMask == (int)BitMaskCategory.Pokemon)
                {
                    target = nodeA;
                }
                else if (nodeB.PhysicsBody.CategoryBitMask == (int)BitMaskCategory.Pokemon)
                {
                    target = nodeB;
                }

                if (target != null && !animatedNodes.Contains(target))
                {
                    var targetScale = target.Scale;

                    animatedNodes.Add(target);

                    target.RunAction(SCNAction.Sequence(new SCNAction[] {
                        SCNAction.ScaleTo(0, 1.0f),
                        SCNAction.ScaleTo(targetScale.X, 2.0f),
                    }), () => {
                        animatedNodes.Remove(target);
                    });
                }
            }
Пример #3
0
        public virtual void DidUpdateContact(SCNPhysicsWorld world, SCNPhysicsContact contact)
        {
            if (contact.NodeA?.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
            {
                CharacterNodeHitWallWithContact(contact.NodeB, contact);
            }

            if (contact.NodeB?.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
            {
                CharacterNodeHitWallWithContact(contact.NodeA, contact);
            }
        }
Пример #4
0
        public virtual void DidBeginContact(SCNPhysicsWorld world, SCNPhysicsContact contact)
        {
            if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
            {
                CharacterNodeHitWallWithContact(contact.NodeB, contact);
            }

            if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
            {
                CharacterNodeHitWallWithContact(contact.NodeA, contact);
            }

            if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collectable)
            {
                CollectPearl(contact.NodeA);
            }

            if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collectable)
            {
                CollectPearl(contact.NodeB);
            }

            if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.SuperCollectable)
            {
                CollectFlower(contact.NodeA);
            }

            if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.SuperCollectable)
            {
                CollectFlower(contact.NodeB);
            }

            if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Enemy)
            {
                WasHit();
            }

            if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Enemy)
            {
                WasHit();
            }
        }
		public virtual void DidUpdateContact (SCNPhysicsWorld world, SCNPhysicsContact contact)
		{
			if (contact.NodeA?.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
				CharacterNodeHitWallWithContact (contact.NodeB, contact);

			if (contact.NodeB?.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
				CharacterNodeHitWallWithContact (contact.NodeA, contact);
		}
		public virtual void DidBeginContact (SCNPhysicsWorld world, SCNPhysicsContact contact)
		{
			if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
				CharacterNodeHitWallWithContact (contact.NodeB, contact);

			if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collision)
				CharacterNodeHitWallWithContact (contact.NodeA, contact);

			if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collectable)
				CollectPearl (contact.NodeA);

			if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Collectable)
				CollectPearl (contact.NodeB);

			if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.SuperCollectable)
				CollectFlower (contact.NodeA);

			if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.SuperCollectable)
				CollectFlower (contact.NodeB);

			if (contact.NodeA.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Enemy)
				WasHit ();

			if (contact.NodeB.PhysicsBody.CategoryBitMask == (nuint)(int)Bitmask.Enemy)
				WasHit ();
		}
Пример #7
0
        /// <summary>
        /// go through hierarchy, find all socket nodes + their corresponding join locations
        /// </summary>
        public void InitBehavior(SCNNode levelRoot, SCNPhysicsWorld world)
        {
            if (this.Entity is GameObject entity)
            {
                var root       = entity.ObjectRootNode;
                var systemRoot = root.ParentWithPrefix("_system");
                if (systemRoot != null)
                {
                    // search for ball constraint with name constraint_ball_
                    var ballArray = root.FindAllJoints(ConstrainHierarchyComponent.JointName);
                    foreach (var ballSocket in ballArray)
                    {
                        if (entity.PhysicsNode?.PhysicsBody != null)
                        {
                            entity.PhysicsNode.PhysicsBody.ResetTransform();
                            var socketOffset = ballSocket.ConvertPositionToNode(SCNVector3.Zero, systemRoot);

                            // find in root first
                            var(closestNode, _) = this.FindAttachNodeNearPoint(systemRoot, systemRoot, socketOffset, SearchDist);

                            var attachPhysics = closestNode?.NearestParentGameObject()?.PhysicsNode;
                            var attachBody    = attachPhysics?.PhysicsBody;
                            if (attachBody != null)
                            {
                                attachBody.ResetTransform();
                                this.CreateBallJoint(entity.PhysicsNode.PhysicsBody,
                                                     ballSocket.ConvertPositionToNode(SCNVector3.Zero, entity.PhysicsNode),
                                                     attachBody,
                                                     closestNode.ConvertPositionToNode(SCNVector3.Zero, attachPhysics));
                            }
                        }
                    }

                    var hingeArray = root.FindAllJoints(ConstrainHierarchyComponent.HingeName);
                    foreach (var hingeJoint in hingeArray)
                    {
                        if (entity.PhysicsNode?.PhysicsBody != null)
                        {
                            entity.PhysicsNode.PhysicsBody.ResetTransform();
                            var hingeOffset = hingeJoint.ConvertPositionToNode(SCNVector3.Zero, systemRoot);

                            // find in root first
                            var(closestNode, _) = this.FindAttachNodeNearPoint(systemRoot, systemRoot, hingeOffset, SearchDist);

                            var attachPhysics = closestNode?.NearestParentGameObject()?.PhysicsNode;
                            var attachBody    = attachPhysics?.PhysicsBody;
                            if (attachBody != null)
                            {
                                attachBody.ResetTransform();
                                this.CreateHingeJoint(entity.PhysicsNode.PhysicsBody,
                                                      hingeJoint.ConvertVectorToNode(SCNVector3.UnitY, entity.PhysicsNode),
                                                      hingeJoint.ConvertPositionToNode(SCNVector3.Zero, entity.PhysicsNode),
                                                      attachBody,
                                                      hingeJoint.ConvertVectorToNode(SCNVector3.UnitY, attachPhysics),
                                                      closestNode.ConvertPositionToNode(SCNVector3.Zero, attachPhysics));
                            }
                        }
                    }

                    foreach (var joint in this.joints)
                    {
                        world.AddBehavior(joint);
                    }
                }
            }
        }
Пример #8
0
		public void DidBeginContact (SCNPhysicsWorld world, SCNPhysicsContact contact)
		{
			SCNNode ball;

			if (contact.NodeA.PhysicsBody.Type == SCNPhysicsBodyType.Dynamic) {
				ball = contact.NodeA;
			} else {
				ball = contact.NodeB;
			}

			if (ball != null) {
				DispatchQueue.MainQueue.DispatchAsync (ball.RemoveFromParentNode);

				var plokCopy = (SCNParticleSystem)Plok.Copy ();
				plokCopy.ParticleImage = Plok.ParticleImage; // to workaround an bug in seed #1
				plokCopy.ParticleColor = (SKColor)ball.Geometry.FirstMaterial.Diffuse.Contents;
				Scene.AddParticleSystem (plokCopy, SCNMatrix4.CreateTranslation (contact.ContactPoint.X, contact.ContactPoint.Y, contact.ContactPoint.Z));

				//compute texture coordinate
				var pointA = new SCNVector3 (contact.ContactPoint.X, contact.ContactPoint.Y, contact.ContactPoint.Z + 20);
				var pointB = new SCNVector3 (contact.ContactPoint.X, contact.ContactPoint.Y, contact.ContactPoint.Z - 20);

				var hitTestOptions = new SCNHitTestOptions (NSDictionary.FromObjectAndKey (Torus, SCNHitTest.RootNodeKey));
				var results = SceneView.Scene.RootNode.HitTest (pointA, pointB, hitTestOptions);

				if (results.Length > 0) {
					var hit = results [0];
					AddPaint (hit.GetTextureCoordinatesWithMappingChannel (0), plokCopy.ParticleColor);
				}
			}
		}
Пример #9
0
		public virtual void DidBeginContact (SCNPhysicsWorld world, SCNPhysicsContact contact)
		{
			if (CurrentGameState == GameState.InGame) {
				// Player to banana, large banana, or coconut
				if (contact.NodeA == GameLevel.PlayerCharacter.CollideSphere) {
					PlayerCollideWithContact (contact.NodeB, contact.ContactPoint);
					return;
				} else if (contact.NodeB == GameLevel.PlayerCharacter.CollideSphere) {
					PlayerCollideWithContact (contact.NodeA, contact.ContactPoint);
					return;
				}

				// Coconut to anything but the player.
				if ((contact.NodeB.CategoryBitMask == GameCollisionCategory.Coconut)) {
					HandleCollideForCoconut ((Coconut)contact.NodeB);
				} else if ((contact.NodeA.CategoryBitMask == GameCollisionCategory.Coconut)) {
					HandleCollideForCoconut ((Coconut)contact.NodeA);
				}
			}
		}