Exemple #1
0
        public void ShowEndScreen()
        {
            // Congratulation title
            var congratulationsNode = SKSpriteNode.FromImageNamed("Overlays/congratulations.png");

            // Max image
            var characterNode = SKSpriteNode.FromImageNamed("Overlays/congratulations_pandaMax.png");

            characterNode.Position    = new CGPoint(0f, -220f);
            characterNode.AnchorPoint = new CGPoint(0.5f, 0f);

            this.congratulationsGroupNode = new SKNode();
            this.congratulationsGroupNode.AddChild(characterNode);
            this.congratulationsGroupNode.AddChild(congratulationsNode);
            this.AddChild(this.congratulationsGroupNode);

            // Layout the overlay
            this.Layout2DOverlay();

            // Animate
            congratulationsNode.Alpha  = 0f;
            congratulationsNode.XScale = 0f;
            congratulationsNode.YScale = 0f;
            congratulationsNode.RunAction(SKAction.Group(new SKAction[] { SKAction.FadeInWithDuration(0.25),
                                                                          SKAction.Sequence(new SKAction[] { SKAction.ScaleTo(1.22f, 0.25),
                                                                                                             SKAction.ScaleTo(1f, 0.1) }) }));

            characterNode.Alpha  = 0f;
            characterNode.XScale = 0f;
            characterNode.YScale = 0f;
            characterNode.RunAction(SKAction.Sequence(new SKAction[] { SKAction.WaitForDuration(0.5),
                                                                       SKAction.Group(new SKAction[] { SKAction.FadeInWithDuration(0.5),
                                                                                                       SKAction.Sequence(new SKAction[] { SKAction.ScaleTo(1.22f, 0.25),
                                                                                                                                          SKAction.ScaleTo(1f, 0.1) }) }) }));
        }
Exemple #2
0
 internal void loadLabelRespawn(SKNode gameWorld)
 {
     labelRespawn = new Label("");
     SKScene.current.labelList.Remove(labelRespawn);
     labelRespawn.position = startingPosition;
     gameWorld.addChild(labelRespawn);
 }
Exemple #3
0
        internal void touchUp(Touch touch)
        {
            if (parent == null)
            {
                return;
            }

            Vector2 point = touch.locationIn(parent);

            if (this == selectedSpaceship)
            {
                targetNode = null;

                if (contains(point))
                {
                    if (destination != null)
                    {
                        fadeSetDestinationEffect();
                    }
                }
                else
                {
                    physicsBody.BodyType = BodyType.Dynamic;
                    destination          = point;
                    setDestinationEffect();
                }
            }
            else if (contains(point))
            {
                setSelected(this);
            }
        }
Exemple #4
0
        public SKNode getNodeWhole(CGPoint point, int u)
        {
            var nodesArr = GetNodesAtPoint(point);
            var finalN   = new SKNode();
            var nL       = new SKNode();
            var nS       = new SKNode();

            foreach (SKNode t in nodesArr)
            {
                if (t.Name == "aNode")
                {
                    nL = t;
                }
                else if (t.Name != null && t.Name != "aNode")
                {
                    nS = t;
                }
            }


            if (u == 0)
            {
                finalN = nS;
            }
            else if (u == 1)
            {
                finalN = nL;
            }

//			Console.WriteLine ("GOTTEN NODES COUNT::--::" + nodesArr.Length);
//


            return(finalN);
        }
Exemple #5
0
 public Button(SKNode node) : base()
 {
     // Track mouse event
     base.UserInteractionEnabled = true;
     this.size = node.Frame.Size;
     this.AddChild(node);
 }
		public OverlayScene (CGSize size) : base (size)
		{
			AnchorPoint = new CGPoint (0.5f, 0.5f);
			ScaleMode = SKSceneScaleMode.ResizeFill;

			float scale = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 1.5f : 1f;

			var myImage = SKSpriteNode.FromImageNamed (ResourceManager.GetResourcePath ("speedGauge.png"));
			myImage.AnchorPoint = new CGPoint (0.5f, 0f);
			myImage.Position = new CGPoint (size.Width * 0.33f, -size.Height * 0.5f);
			myImage.XScale = 0.8f * scale;
			myImage.YScale = 0.8f * scale;
			AddChild (myImage);

			var needleHandle = SKNode.Create ();
			var needle = SKSpriteNode.FromImageNamed (ResourceManager.GetResourcePath ("needle.png"));
			needleHandle.Position = new CGPoint (0f, 16f);
			needle.AnchorPoint = new CGPoint (0.5f, 0f);
			needle.XScale = 0.7f;
			needle.YScale = 0.7f;
			needle.ZRotation = (float)Math.PI / 2f;
			needleHandle.AddChild (needle);
			myImage.AddChild (needleHandle);

			SpeedNeedle = needleHandle;

			var cameraImage = SKSpriteNode.FromImageNamed (ResourceManager.GetResourcePath ("video_camera.png"));
			cameraImage.Position = new CGPoint (-size.Width * 0.4f, -size.Height * 0.4f);
			cameraImage.Name = "camera";
			cameraImage.XScale = 0.6f * scale;
			cameraImage.YScale = 0.6f * scale;
			AddChild (cameraImage);
		}
Exemple #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);
                        }
                    }
        }
        void OnDidBeginContact(object sender, EventArgs e)
        {
            var contact = (SKPhysicsContact)sender;
            // Either bodyA or bodyB in the collision could be a character.
            var node = contact.BodyA.Node as Character;

            if (node != null)
            {
                node.CollidedWith(contact.BodyB);
            }

            // Check bodyB too.
            node = contact.BodyB.Node as Character;
            if (node != null)
            {
                node.CollidedWith(contact.BodyA);
            }

            // Handle collisions with projectiles.
            var isBodyA = (contact.BodyA.CategoryBitMask & (uint)ColliderType.Projectile) != 0;
            var isBodyB = (contact.BodyB.CategoryBitMask & (uint)ColliderType.Projectile) != 0;

            if (isBodyA || isBodyB)
            {
                SKNode projectile = isBodyA ? contact.BodyA.Node : contact.BodyB.Node;
                projectile.RunAction(SKAction.RemoveFromParent());

                // Build up a "one shot" particle to indicate where the projectile hit.
                var emitter = (SKEmitterNode)SharedProjectileSparkEmitter.Copy();
                AddNode(emitter, WorldLayer.AboveCharacter);
                emitter.Position = projectile.Position;
                GraphicsUtilities.RunOneShotEmitter(emitter, 0.15f);
            }
        }
        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);
                        }
                    }
        }
Exemple #10
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            // Set windows size for comfort playing
            MyGameView.Window.SetFrame(new CoreGraphics.CGRect(0, 0, 1600, 1000), true, true);

            // Getting GameScene for presenting on the window
            var scene = SKNode.FromFile <MenuScene>("GameScenes/MenuScene");


            // Set the scale mode to scale to fit the window
            scene.ScaleMode = SKSceneScaleMode.ResizeFill;


            // Enable debug information
            MyGameView.ShowsPhysics   = true;
            MyGameView.ShowsFPS       = true;
            MyGameView.ShowsNodeCount = true;

            // SpriteKit applies additional optimizations to improve rendering performance
            MyGameView.IgnoresSiblingOrder = true;


            // Present scene on the window
            MyGameView.PresentScene(scene);
        }
Exemple #11
0
        public virtual void Initialize()
        {
            Console.WriteLine(IntPtr.Size);
            Heroes        = new List <HeroCharacter> ();
            players       = new List <Player> (NUM_PLAYERS);
            DefaultPlayer = new Player();
            players.Add(DefaultPlayer);
            for (int i = 1; i < NUM_PLAYERS; i++)
            {
                players.Add(null);
            }

            world = new SKNode()
            {
                Name = "world"
            };
            layers = new List <SKNode> ((int)WorldLayer.Count);
            for (int i = 0; i < (int)WorldLayer.Count; i++)
            {
                var layer = new SKNode {
                    ZPosition = i - (int)WorldLayer.Count
                };
                world.AddChild(layer);
                layers.Add(layer);
            }
            AddChild(world);

            buildHUD();
            updateHUDFor(DefaultPlayer, HUDState.Local);
        }
Exemple #12
0
        public void AttemptMissileLaunch(double currentTime)
        {
            if (health <= 0)
            {
                return;
            }

            double timeSinceLastFired = currentTime - timeLastFiredMissile;

            if (timeSinceLastFired > firingInterval)
            {
                timeLastFiredMissile = currentTime;
                // avoid duplicating costly math ops
                float shipDirection = ShipOrientation;
                float cos           = (float)Math.Cos(shipDirection);
                float sin           = (float)Math.Sin(shipDirection);

                var position = new CGPoint(Position.X + missileLaunchDistance * cos,
                                           Position.Y + missileLaunchDistance * sin);
                SKNode missile = NodeFactory.CreateMissileNode(this);
                missile.Position = position;
                Scene.AddChild(missile);

                missile.PhysicsBody.Velocity = PhysicsBody.Velocity;
                var vector = new CGVector(missileLaunchImpulse * cos, missileLaunchImpulse * sin);
                missile.PhysicsBody.ApplyImpulse(vector);
            }
        }
Exemple #13
0
 internal void setTarget(Mothership mothership)
 {
     fadeSetDestinationEffect();
     physicsBody.BodyType = BodyType.Dynamic;
     destination          = null;
     targetNode           = mothership;
     setTargetEffect(new Vector2(position.X, mothership.position.Y), false);
 }
Exemple #14
0
 internal void setTarget(Spaceship spaceship)
 {
     fadeSetDestinationEffect();
     physicsBody.BodyType = BodyType.Dynamic;
     destination          = null;
     targetNode           = spaceship;
     setTargetEffect(spaceship.position, true);
 }
Exemple #15
0
        void DetonateMissile(SKNode missile)
        {
            SKEmitterNode explosion = new ExplosionNode(this);

            explosion.Position = missile.Position;
            AddChild(explosion);
            missile.RemoveFromParent();
        }
Exemple #16
0
        /* Determines the relevant player from the given projectile, and adds to that player's score. */
        public void AddToScoreAfterEnemyKill(int amount, SKNode projectile)
        {
            var    userData = new UserData(projectile.UserData);
            Player player   = userData.Player;

            player.Score += amount;
            updateHUDFor(player);
        }
        public void DidAddNode(ARSKView view, SKNode node, ARAnchor anchor)
        {
            if (!this.anchorLabels.TryGetValue(anchor.Identifier, out string labelText))
            {
                throw new Exception("missing expected associated label for anchor");
            }

            node.AddChild(new TemplateLabelNode(labelText));
        }
Exemple #18
0
        public virtual void Draw(GameScene scene)
        {
            if (SkNode == null)
            {
                SkNode = new SKSpriteNode(SKTexture.FromImageNamed("Ball"), UIColor.Clear, new CGSize(5, 5));
                scene.AddChild(SkNode);
            }

            SkNode.RunAction(SKAction.MoveTo(new CGPoint(X - (Z / Math.Sqrt(2.0)), Y - (Z / Math.Sqrt(2.0))), 0.5));
        }
Exemple #19
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);
        }
Exemple #20
0
        public void TouchUpAtPoint(CGPoint location)
        {
            SKNode touchedNode = Scene.GetNodeAtPoint(location);

            if (touchedNode != null)
            {
                Hidden = true;
                GameSimulation.Sim.SetGameState(GameState.InGame);
            }
        }
        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();
        }
Exemple #22
0
        public static SKLabelNode AddDescription(this SKNode self, string description, CGPoint position)
        {
            SKLabelNode label = new SKLabelNode("Helvetica")
            {
                Text     = description,
                FontSize = 18,
                Position = position
            };

            self.AddChild(label);
            return(label);
        }
Exemple #23
0
        internal void retreat()
        {
            targetNode           = null;
            physicsBody.BodyType = BodyType.Dynamic;
            destination          = startingPosition;
            setDestinationEffect();

            if (this == selectedSpaceship)
            {
                setSelected(null);
            }
        }
        public ExplosionNode(SKNode target)
            : base((template as NSObject).Copy ().Handle)
        {
            TargetNode = target;
            NumParticlesToEmit = (uint) (defaultDuration * ParticleBirthRate);
            double totalTime = defaultDuration + ParticleLifetime + ParticleLifetimeRange / 2;

            RunAction (SKAction.Sequence (
                SKAction.WaitForDuration (totalTime),
                SKAction.RemoveFromParent ()
            ));
        }
Exemple #25
0
        public ExplosionNode(SKNode target)
            : base((template as NSObject).Copy().Handle)
        {
            TargetNode         = target;
            NumParticlesToEmit = (uint)(defaultDuration * ParticleBirthRate);
            double totalTime = defaultDuration + ParticleLifetime + ParticleLifetimeRange / 2;

            RunAction(SKAction.Sequence(
                          SKAction.WaitForDuration(totalTime),
                          SKAction.RemoveFromParent()
                          ));
        }
Exemple #26
0
        public void SKScene_InitWithSize()
        {
            if (IntPtr.Size != 8)             // SpriteKit is 64-bit only on mac
            {
                return;
            }

            SKNode c = new SKNode();

            //SKScene c = new SKScene (new CGSize (50, 50));
            Assert.IsNotNull(c);
        }
Exemple #27
0
        public override void DidLoadReferenceNode(SKNode node)
        {
            base.DidLoadReferenceNode(node);

            // Apply text to both labels loaded from the template.
            this.localParent = node?.GetChildNode("LabelNode");
            if (this.localParent == null)
            {
                throw new Exception("misconfigured SpriteKit template file");
            }

            this.UpdateText();
        }
        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);
        }
        public override void DidFinishLaunching(NSNotification notification)
        {
            var scene = SKNode.FromFile <GameScene>("GameScene");

            // Set the scale mode to scale to fit the window
            scene.ScaleMode = SKSceneScaleMode.AspectFill;

            MyGameView.PresentScene(scene);

            // SpriteKit applies additional optimizations to improve rendering performance
            MyGameView.IgnoresSiblingOrder = true;

            ProcessName.StringValue = "New Process";
        }
		public static SKEmitterNode CreateExplosionNode (SKNode target, double duration)
		{
			SKEmitterNode emitter = UnarchiveEmitterNode ("explosion");

			// Explosions always place their particles into the scene.
			emitter.TargetNode = target;

			// Stop spawning particles after enough have been spawned.
			emitter.NumParticlesToEmit =(nuint)(duration * emitter.ParticleBirthRate);

			// Calculate a time value that allows all the spawned particles to die. After this, the emitter node can be removed.

			double totalTime = duration + emitter.ParticleLifetime + emitter.ParticleLifetimeRange / 2;
			emitter.RunAction (SKAction.Sequence (SKAction.WaitForDuration (totalTime), SKAction.RemoveFromParent ()));
			return emitter;
		}
 public void ChangePlayerWinsIndicator(int PlayerNo, int Wins)
 {
     if (PlayerWinsIndicator[PlayerNo] != null)
     {
         Players.PlayerWins[PlayerNo] = Wins;
         SKNode LifeNoSpot = PlayerWinsIndicator[PlayerNo].Children[1];
         LifeNoSpot.RemoveAllChildren();
         SKSpriteNode NoNode = new SKSpriteNode("No" + Wins);
         NoNode.Size = new CGSize(15, 15);
         LifeNoSpot.AddChild(NoNode);
     }
     else
     {
         System.Console.WriteLine("Wins Indicators are not initialized yet");
     }
 }
Exemple #32
0
        void Setup()
        {
            // Configure the view.
            GameView.ShowsFPS       = true;
            GameView.ShowsNodeCount = true;
            /* Sprite Kit applies additional optimizations to improve rendering performance */
            GameView.IgnoresSiblingOrder = true;

            // Create and configure the scene.
            var scene = SKNode.FromFile <GameScene>("GameScene");

            scene.ScaleMode = SKSceneScaleMode.AspectFill;

            // Present the scene.
            GameView.PresentScene(scene);
        }
Exemple #33
0
        public static SKEmitterNode CreateExplosionNode(SKNode target, double duration)
        {
            SKEmitterNode emitter = UnarchiveEmitterNode("explosion");

            // Explosions always place their particles into the scene.
            emitter.TargetNode = target;

            // Stop spawning particles after enough have been spawned.
            emitter.NumParticlesToEmit = (nuint)(duration * emitter.ParticleBirthRate);

            // Calculate a time value that allows all the spawned particles to die. After this, the emitter node can be removed.

            double totalTime = duration + emitter.ParticleLifetime + emitter.ParticleLifetimeRange / 2;

            emitter.RunAction(SKAction.Sequence(SKAction.WaitForDuration(totalTime), SKAction.RemoveFromParent()));
            return(emitter);
        }
		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;
		}
        protected ParallaxSprite(SKNode [] sprites, float offset)
        {
            if (sprites == null)
                throw new ArgumentNullException ("offset");

            UsesParallaxEffect = true;

            // Make sure our z layering is correct for the stack.
            float zOffset = 1f / (float)sprites.Length;

            // All nodes in the stack are direct children, with ordered zPosition.
            var ourZPosition = ZPosition;
            int childNumber = 0;
            foreach (var node in sprites) {
                node.ZPosition = ourZPosition + (zOffset + (zOffset * childNumber));
                AddChild (node);
                childNumber++;
            }

            parallaxOffset = offset;
        }
        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);
        }
 void DetonateMissile(SKNode missile)
 {
     SKEmitterNode explosion = new ExplosionNode (this);
     explosion.Position = missile.Position;
     AddChild (explosion);
     missile.RemoveFromParent ();
 }
		public DamageNode (SKNode target)
			: base ((template as NSObject).Copy ().Handle)
		{
			TargetNode = target;
		}
        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 ();
        }
Exemple #40
0
 public Character(SKNode[] sprites, CGPoint position, float offset)
     : base(sprites, offset)
 {
     Initialize (position);
 }
Exemple #41
0
		public void Setup ()
		{
			nfloat w = Bounds.Width;
			nfloat h = Bounds.Height;

			if (w < h) {
				nfloat wTmp = w;
				w = h;
				h = wTmp;
			}

			// Setup the game overlays using SpriteKit
			SKScene skScene = SKScene.FromSize (new CGSize (w, h));
			skScene.ScaleMode = SKSceneScaleMode.ResizeFill;

			overlayGroup = SKNode.Create ();
			skScene.AddChild (overlayGroup);
			overlayGroup.Position = new CGPoint (0f, h);

			// The Max icon
			SKSpriteNode sprite = SKSpriteNode.FromImageNamed ("Images/MaxIcon.png");
			sprite.Position = new CGPoint (50f, -50f);

			overlayGroup.AddChild (sprite);
			sprite.XScale = sprite.YScale = 0.5f;

			for (int i = 0; i < 3; i++) {
				flowers [i] = SKSpriteNode.FromImageNamed ("Images/FlowerEmpty.png");
				flowers [i].Position = new CGPoint (110f + i * 40f, -50f);
				flowers [i].XScale = flowers [i].YScale = 0.25f;
				overlayGroup.AddChild (flowers[i]);
			}

			// The peal icon and count.
			sprite = SKSpriteNode.FromImageNamed ("Images/ItemsPearl.png");
			sprite.Position = new CGPoint (110f, -100f);
			sprite.XScale = sprite.YScale = 0.5f;
			overlayGroup.AddChild (sprite);

			pearlLabel = SKLabelNode.FromFont ("Chalkduster");
			pearlLabel.Text = "x0";
			pearlLabel.Position = new CGPoint (152f, -113f);
			overlayGroup.AddChild (pearlLabel);

			// The D-Pad
			sprite = SKSpriteNode.FromImageNamed ("Images/dpad.png");
			sprite.Position = new CGPoint (100f, 100f);
			sprite.XScale = sprite.YScale = 0.5f;
			skScene.AddChild (sprite);
			padRect = new CGRect (
				(sprite.Position.Y - DPAD_RADIUS) / w,
				1f - (sprite.Position.Y + DPAD_RADIUS) / h,
				2f * DPAD_RADIUS / w,
				2f * DPAD_RADIUS / h
			);

			// Assign the SpriteKit overlay to the SceneKit view.
			OverlayScene = skScene;

			// Setup the pinch gesture
			defaultFov = PointOfView.Camera.XFov;

			var pinch = new UIPinchGestureRecognizer {
				Delegate = this,
				CancelsTouchesInView = false
			};
			pinch.AddTarget (() => PinchWithGestureRecognizer (pinch));

			AddGestureRecognizer (pinch);
		}
 // All sprites in the scene should be added through this method to ensure they are placed in the correct world layer.
 public void AddNode(SKNode node, WorldLayer layer)
 {
     SKNode layerNode = layers [(int)layer];
     layerNode.AddChild (node);
 }
 /* Determines the relevant player from the given projectile, and adds to that player's score. */
 public void AddToScoreAfterEnemyKill(int amount, SKNode projectile)
 {
     var userData = new UserData (projectile.UserData);
     Player player = userData.Player;
     player.Score += amount;
     updateHUDFor (player);
 }
Exemple #44
0
 public Tree(SKNode [] sprites, float offset)
     : base(sprites, offset)
 {
 }
        public virtual void Initialize()
        {
            Console.WriteLine (IntPtr.Size);
            Heroes = new List<HeroCharacter> ();
            players = new List<Player> (NUM_PLAYERS);
            DefaultPlayer = new Player ();
            players.Add (DefaultPlayer);
            for (int i = 1; i < NUM_PLAYERS; i++)
                players.Add (null);

            world = new SKNode () {
                Name = "world"
            };
            layers = new List<SKNode> ((int)WorldLayer.Count);
            for (int i = 0; i < (int)WorldLayer.Count; i++) {
                var layer = new SKNode {
                    ZPosition = i - (int)WorldLayer.Count
                };
                world.AddChild (layer);
                layers.Add (layer);
            }
            AddChild (world);

            buildHUD ();
            updateHUDFor (DefaultPlayer, HUDState.Local);
        }
Exemple #46
0
 // Use projectile alpha to determine potency
 public bool ApplyDamage(nfloat damage, SKNode projectile)
 {
     return ApplyDamage (damage * projectile.Alpha);
 }
        void buildHUD()
        {
            string[] iconNames = new [] {
                "iconWarrior_blue",
                "iconWarrior_green",
                "iconWarrior_pink",
                "iconWarrior_red"
            };
            #if __IOS__
            UIColor[] colors = new [] { UIColor.Green, UIColor.Blue, UIColor.Yellow, UIColor.Red };
            #else
            var colors = new NSColor [] { NSColor.Green, NSColor.Blue, NSColor.Yellow, NSColor.Red };
            #endif
            var hudX = 30.0f;
            var hudY = Frame.Size.Height - 30;
            var hudD = Frame.Size.Width / NUM_PLAYERS;

            hudAvatars = new List<SKSpriteNode> (NUM_PLAYERS);
            hudLabels = new List<SKLabelNode> (NUM_PLAYERS);
            hudScores = new List<SKLabelNode> (NUM_PLAYERS);
            hudLifeHeartArrays = new List<List<SKSpriteNode>> (NUM_PLAYERS);
            var hud = new SKNode ();

            for (int i = 0; i < NUM_PLAYERS; i++) {
                var avatar = new SKSpriteNode (iconNames [i]) {
                    XScale = 0.5f,
                    YScale = 0.5f,
                    Alpha = 0.5f,
                };
                avatar.Position = new CGPoint (hudX + i * hudD + (avatar.Size.Width * 0.5f),
                    Frame.Size.Height - avatar.Size.Height * 0.5f - 8f);
                hudAvatars.Add (avatar);
                hud.AddChild (avatar);

                var label = new SKLabelNode ("Copperplate") {
                    Text = "NO PLAYER",
                    FontColor = colors [i],
                    FontSize = 16,
                    HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left,
                    Position = new CGPoint (hudX + i * hudD + avatar.Size.Width, hudY + 10)
                };
                hudLabels.Add (label);
                hud.AddChild (label);

                var score = new SKLabelNode ("Copperplate") {
                    Text = "SCORE: 0",
                    FontColor = colors [i],
                    FontSize = 16,
                    HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left,
                    Position = new CGPoint (hudX + i * hudD + avatar.Size.Width, hudY - 40)
                };
                hudScores.Add (score);
                hud.AddChild (score);

                var playerHearts = new List<SKSpriteNode> (Player.StartLives);
                hudLifeHeartArrays.Add (playerHearts);
                for (int j = 0; j < Player.StartLives; j++) {
                    var heart = new SKSpriteNode ("lives.png") {
                        XScale = 0.4f,
                        YScale = 0.4f,
                        Alpha = 0.1f
                    };
                    heart.Position = new CGPoint (hudX + i * hudD + avatar.Size.Width + 18 + (heart.Size.Width + 5) * j, hudY - 10);
                    playerHearts.Add (heart);
                    hud.AddChild (heart);
                }
            }

            AddChild (hud);
        }
 protected EnemyCharacter(SKNode[] sprites, CGPoint position, float offset)
     : base(sprites, position, offset)
 {
 }
 // Рисует на сцене спрайт
 protected void DrawSprite(SKNode DrawingSprite)
 {
     if (BackgroundSprite != null)
         BackgroundSprite.AddChild (DrawingSprite);
     else
         ParentScene.AddChild (DrawingSprite);
 }
 public MissileNode(SKNode target, PointF initialPosition)
     : base((template as NSObject).Copy ().Handle)
 {
     TargetNode = target;
     Position = initialPosition;
 }