private async Task AnimateNode(SCNNode node) { var sourcePosition = new SCNVector3(node.PresentationNode.Position.X, node.PresentationNode.Position.Y, node.PresentationNode.Position.Z); var targetPosition = new SCNVector3(node.PresentationNode.Position.X - 0.2f, node.PresentationNode.Position.Y - 0.2f, node.PresentationNode.Position.Z - 0.2f); for (int i = 0; i < 3; i++) { SCNAction toTarget = SCNAction.MoveTo(targetPosition, 0.2f); node.RunAction(toTarget); await Task.Delay(200); SCNAction toSource = SCNAction.MoveTo(sourcePosition, 0.2f); node.RunAction(toSource); await Task.Delay(200); } }
public void CollectBanana(SCNNode banana) { // Flyoff the banana to the screen space position score label. // Don't increment score until the banana hits the score label. // ignore collisions banana.PhysicsBody = null; BananasCollected++; int variance = 60; nfloat duration = 0.25f; nfloat apexY = worldSpaceLabelScorePosition.Y * 0.8f + (new Random().Next(0, variance) - variance / 2); worldSpaceLabelScorePosition.Z = banana.Position.Z; var apex = new SCNVector3(banana.Position.X + 10 + (new Random().Next(0, variance) - variance / 2), apexY, banana.Position.Z); SCNAction startFlyOff = SCNAction.MoveTo(apex, duration); startFlyOff.TimingMode = SCNActionTimingMode.EaseOut; SCNAction endFlyOff = SCNAction.CustomAction(duration, new SCNActionNodeWithElapsedTimeHandler((node, elapsedTime) => { nfloat t = elapsedTime / duration; var v = new SCNVector3( apex.X + ((worldSpaceLabelScorePosition.X - apex.X) * t), apex.Y + ((worldSpaceLabelScorePosition.Y - apex.Y) * t), apex.X + ((worldSpaceLabelScorePosition.Z - apex.Z) * t)); node.Position = v; })); endFlyOff.TimingMode = SCNActionTimingMode.EaseInEaseOut; SCNAction flyoffSequence = SCNAction.Sequence(new SCNAction[] { startFlyOff, endFlyOff }); banana.RunAction(flyoffSequence, () => { Bananas.Remove(banana); banana.RemoveFromParentNode(); // Add to score. Score++; GameSimulation.Sim.PlaySound("deposit.caf"); // Game Over if (Bananas.Count == 0) { DoGameOver(); } }); }
public void MoveShip(int duration) { var xs = new[] { MinX, MaxX }; var ys = new[] { MinY, MaxY }; var zs = new[] { MinZ, MaxZ }; var pos = ShipNode.Position; while (pos == ShipNode.Position) { pos = new SCNVector3(xs.Random(), ys.Random(), zs.Random()); } var moveAction = SCNAction.MoveTo(pos, duration - 1); moveAction.TimingMode = SCNActionTimingMode.EaseInEaseOut; var rotateAction = SCNAction.RotateBy((float)Math.PI / 2, new SCNVector3(0, 0, 1), duration / 4.0); ShipNode.Look(pos); ShipNode.RunAction(moveAction); ShipNode.RunAction(rotateAction); }
public static void MoveTo(this SCNNode node, SCNNode target, double timeInSeconds, SCNActionTimingMode timingMode = SCNActionTimingMode.EaseOut) => node.RunAction(SCNAction.MoveTo(new SCNVector3(target.Position.X, target.Position.Y, target.Position.Z), timeInSeconds).Ease(timingMode));
public void CollectLargeBanana(SCNNode largeBanana) { // When the player hits a large banana, explode it into smaller bananas. // We explode into a predefined pattern: square, diamond, letterA, letterB // ignore collisions largeBanana.PhysicsBody = null; CoinsCollected++; LargeBananas.Remove(largeBanana); largeBanana.RemoveAllParticleSystems(); largeBanana.RemoveFromParentNode(); // Add to score. Score += 100; var square = new string[] { "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" }; var diamond = new string[] { "0", "0", "1", "0", "0", "0", "1", "1", "1", "0", "1", "1", "1", "1", "1", "0", "1", "1", "1", "0", "0", "0", "1", "0", "0" }; var letterA = new string[] { "1", "0", "0", "1", "0", "1", "0", "0", "1", "0", "1", "1", "1", "1", "0", "1", "0", "0", "1", "0", "0", "1", "1", "0", "0" }; var letterB = new string[] { "1", "1", "0", "0", "0", "1", "0", "1", "0", "0", "1", "1", "0", "0", "0", "1", "0", "1", "0", "0", "1", "1", "0", "0", "0" }; var choices = new List <string[]> { square, diamond, letterA, letterB }; float vertSpacing = 40f; float spacing = 0.0075f; string[] choice = choices [new Random().Next(0, choices.Count)]; for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { int place = Int32.Parse(choice [(y * 5) + x]); if (place != 1) { continue; } SCNNode banana = CreateBanana(); RootNode.AddChildNode(banana); banana.Position = largeBanana.Position; banana.PhysicsBody.CategoryBitMask = GameCollisionCategory.NoCollide; banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground; SCNVector3 endPoint = LocationAlongPath(TimeAlongPath + spacing * (x + 1)); endPoint.Y += (vertSpacing * (y + 1)); SCNAction flyoff = SCNAction.MoveTo(endPoint, MathUtils.RandomPercent() * 0.25f); flyoff.TimingMode = SCNActionTimingMode.EaseInEaseOut; banana.RunAction(flyoff, () => { banana.PhysicsBody.CategoryBitMask = GameCollisionCategory.Banana; banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground | GameCollisionCategory.Player; GameSimulation.Sim.PlaySound("deposit.caf"); }); Bananas.Add(banana); } } }