SCNNode CreateBanana() { //Create model if (bananaCollectable == null) { bananaCollectable = GameSimulation.LoadNodeWithName("banana", GameSimulation.PathForArtResource("level/banana.dae")); bananaCollectable.Scale = new SCNVector3(0.5f, 0.5f, 0.5f); SCNSphere sphereGeometry = SCNSphere.Create(40); SCNPhysicsShape physicsShape = SCNPhysicsShape.Create(sphereGeometry, new SCNPhysicsShapeOptions()); bananaCollectable.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Kinematic, physicsShape); // Only collide with player and ground bananaCollectable.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground; // Declare self in the banana category bananaCollectable.PhysicsBody.CategoryBitMask = GameCollisionCategory.Banana; // Rotate and Hover forever. bananaCollectable.Rotation = new SCNVector4(0.5f, 1f, 0.5f, -(nfloat)Math.PI / 4); SCNAction idleHoverGroupAction = SCNAction.Group(new SCNAction[] { BananaIdleAction, HoverAction }); SCNAction repeatForeverAction = SCNAction.RepeatActionForever(idleHoverGroupAction); bananaCollectable.RunAction(repeatForeverAction); } return(bananaCollectable.Clone()); }
public void DidHitEnemy() { this.model.RunAction(SCNAction.Group(new SCNAction[] { SCNAction.PlayAudioSource(this.hitEnemySound, false), SCNAction.Sequence(new SCNAction[] { SCNAction.Wait(0.5), SCNAction.PlayAudioSource(explodeEnemySound, false) }) })); }
void StartGame() { if (!gameNodes.HasValue) { throw new InvalidProgramException("Nodes not set"); } var startSequence = SCNAction.Sequence(new SCNAction [] { // Wait for 1 second. SCNAction.Wait(1), SCNAction.Group(new SCNAction[] { SCNAction.FadeIn(0.3), // Start the game. SCNAction.Run(node => { if (!gameNodes.HasValue) { return; } var gNodes = gameNodes.Value; var rnd = new Random(); // Compute a random orientation for the object3D. var theta = (float)(Math.PI * rnd.NextDouble()); var phi = (float)(Math.Acos(2 * rnd.NextDouble() - 1) / NMath.PI); var axis = new Vector3 { X = (float)(Math.Cos(theta) * Math.Sin(phi)), Y = (float)(Math.Sin(theta) * Math.Sin(phi)), Z = (float)Math.Cos(theta) }; var angle = (float)(2 * Math.PI * rnd.NextDouble()); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 0.3; SCNTransaction.SetCompletionBlock(() => gameStarted = true); gNodes.ObjectMaterial.Transparency = 1; gNodes.Object.Transform = SCNMatrix4.CreateFromAxisAngle(axis, angle); SCNTransaction.Commit(); }) }) }); gameNodes.Value.Object.RunAction(startSequence); // Load and set the background image. var backgroundImage = UIImage.FromBundle("art.scnassets/background.png"); sceneInterface.Scene.Background.Contents = backgroundImage; // Hide particles, set camera projection to orthographic. particleRemovalTimer?.Invalidate(); gameNodes.Value.CongratulationsLabel.RemoveFromParent(); gameNodes.Value.Confetti.Hidden = true; gameNodes.Value.Camera.UsesOrthographicProjection = true; // Reset the countdown. countdown = 30; gameNodes.Value.CountdownLabel.Text = countdown.ToString(); gameNodes.Value.CountdownLabel.FontColor = GameColors.DefaultFont; gameNodes.Value.CountdownLabel.Position = new CGPoint(ContentFrame.Width / 2, ContentFrame.Height - 30); textUpdateTimer?.Invalidate(); textUpdateTimer = NSTimer.CreateRepeatingScheduledTimer(1, UpdateText); }