示例#1
0
        public MapNode(Map map)
        {
            this.map = map;
            Name     = "Map";

            UserInteractionEnabled = true;

            int idx = 0;

            atlas = SKTextureAtlas.FromName("TileImages");
            foreach (var tid in map.TIDs)
            {
                Tile t = map.TIDToTile [tid];
                CoreGraphics.CGPoint position = map.PositionToPoint(map.IndexToPosition(idx));

                SKTexture    tex  = atlas.TextureNamed(t.ImageName);
                SKSpriteNode node = SKSpriteNode.FromTexture(tex);
                node.UserInteractionEnabled = false;
                node.Position  = position;
                node.ZPosition = idx;

                node.AnchorPoint = new CoreGraphics.CGPoint(0.5, 0);
                AddChild(node);

                idx++;
            }

            var nc = NSNotificationCenter.DefaultCenter;

            nc.AddObserver((NSString)InventoryComponent.ItemCollectedNotification, HandleItemCollected);
            nc.AddObserver((NSString)InventoryComponent.ItemDroppedNotification, HandleItemDropped);
        }
 public void AddLifeIndicators()
 {
     for (int i = 0; i < Players.NumberOfPlayers; i++)
     {
         LifeIndicator[i] = new SKSpriteNode();
         if (i == 1)
         {
             LifeIndicator[i].Position  = new CGPoint(DisplayDefaultSizes.MinX + 70, DisplayDefaultSizes.MaxY - 40);
             LifeIndicator[i].ZRotation = (nfloat)Math.PI;
         }
         else
         {
             LifeIndicator[i].Position = new CGPoint(DisplayDefaultSizes.MaxX - 70, DisplayDefaultSizes.MinY + 40);
         }
         SKSpriteNode PlayerIcon = new SKSpriteNode(Application.PlayerCharacterOption[i] + "Icon");
         SKSpriteNode LifeNo     = new SKSpriteNode("NoX");
         SKSpriteNode NoS        = new SKSpriteNode();
         LifeNo.Position     = new CGPoint(30, 0);
         NoS.Position        = new CGPoint(50, 0);
         PlayerIcon.Size     = new CGSize(25, 20);
         PlayerIcon.Position = new CGPoint(0, 0);
         LifeIndicator[i].AddChild(PlayerIcon);
         LifeIndicator[i].AddChild(LifeNo);
         LifeIndicator[i].AddChild(NoS);
     }
     AddNodes(LifeIndicator);
 }
        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)
            });
        }
示例#4
0
        public BasicScene(CGSize size) : base(size)
        {
            ScaleMode = SKSceneScaleMode.AspectFill;

            //BackgroundColor = UIColor.FromRGBA (0.15f, 0.15f, 0.3f, 1f);


            bgr          = new SKSpriteNode(SKTexture.FromImageNamed("brickwall1"));
            bgr.Size     = Size;
            bgr.Position = new CGPoint(Size.Width / 2, Size.Height / 2);

            AddChild(bgr);


            UnselectedColor = UIColor.FromRGBA(0f, 0.5f, 0.5f, 1f);
            SelectedColor   = UIColor.FromRGBA(0.5f, 1f, 0.99f, 1f);

            ButtonColor = UIColor.FromRGBA(1f, 1f, 0f, 1f);
            InfoColor   = UIColor.FromRGBA(1f, 1f, 1f, 1f);

            FrameMidX = (float)Frame.GetMidX();
            FrameMidY = (float)Frame.GetMidY();

            transition = SKTransition.MoveInWithDirection(SKTransitionDirection.Right, 0.3);
        }
示例#5
0
        /// <summary>
        /// Анимация счета за уничтожение цепочки
        /// </summary>
        /// <param name="chain">Уничтожаемая цепочка.</param>
        private void AnimateScore(GemList chain)
        {
            SKSpriteNode firstGem = chain.GetFirstGem().Sprite;
            SKSpriteNode lastGem  = chain.GetLastGem().Sprite;

            CGPoint centerPoint = new CGPoint(
                (firstGem.Position.X + lastGem.Position.X) / 2,
                (firstGem.Position.Y + lastGem.Position.Y) / 2 - 8);

            SKLabelNode scoreLabel = new SKLabelNode("GillSans-BoldItalic")
            {
                FontSize  = 16,
                Text      = chain.GetScore() + "",
                Position  = centerPoint,
                ZPosition = 300
            };

            gemLayer.AddChild(scoreLabel);

            SKAction moveAction = SKAction.MoveBy(0, 3, 0.7);

            //.Move(by: CGVector(dx: 0, dy: 3), duration: 0.7)
            moveAction.TimingMode = SKActionTimingMode.EaseOut;
            scoreLabel.RunAction(SKAction.Sequence(moveAction, SKAction.RemoveFromParent()));
        }
        public MyScene(SizeF size)
        {
            this.Size = size;

            // Load the background
            this.Background             = new SKSpriteNode("blue-shooting-stars");
            this.Background.Name        = "background";
            this.Background.AnchorPoint = new PointF(0, 0);
            this.AddChild(Background);

            // Loading the images
            List <string> imageNames = new List <string>()
            {
                "bird", "cat", "dog", "turtle"
            };

            int i = 0;

            foreach (string imageName in imageNames)
            {
                float offsetFraction = ((float)(i++ + 1) / (imageNames.Count + 1));

                SKSpriteNode sprite = new SKSpriteNode(imageName);
                sprite.Name     = ANIMAL_NODE_NAME;
                sprite.Position = new PointF(size.Width * offsetFraction, size.Height / 2);

                this.Background.AddChild(sprite);
            }
        }
示例#7
0
 void CheckEmpty(SKSpriteNode n)
 {
     Assert.IsNotNull(n.Color, "Color");
     Assert.Null(n.Name, "Name");
     Assert.True(n.Size.IsEmpty, "Size");
     Assert.Null(n.Texture, "Texture");
 }
        private void SelectNodeForTouch(PointF touchLocation)
        {
            // get the node that is on the posiion touchLocation
            SKSpriteNode touchedNode = (SKSpriteNode)this.GetNodeAtPoint(touchLocation);

            // if this is a new node being touched then stop all previous animation and set it as the selected node.
            if (this.SelectedNode != touchedNode)
            {
                if (this.SelectedNode != null)
                {
                    this.SelectedNode.RemoveAllActions();
                    this.SelectedNode.RunAction(SKAction.RotateToAngle(0.0f, 0.1));
                }

                this.SelectedNode = touchedNode;

                // if the node we've touched is an animal node then make it wiggle y0!
                if (touchedNode.Name == ANIMAL_NODE_NAME)
                {
                    SKAction sequence = SKAction.Sequence(new SKAction[] {
                        SKAction.RotateByAngle(this.DegreeToRadian(-4.0f), 0.1),
                        SKAction.RotateByAngle(0.0f, 0.1),
                        SKAction.RotateByAngle(this.DegreeToRadian(4.0f), 0.1)
                    });

                    this.SelectedNode.RunAction(SKAction.RepeatActionForever(sequence));
                }
            }
        }
        public 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");

            sharedIdleAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Idle", "goblin_idle_", DefaultNumberOfIdleFrames);
            sharedWalkAnimationFrames   = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Walk", "goblin_walk_", DefaultNumberOfWalkFrames);
            sharedAttackAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Attack", "goblin_attack_", GoblinAttackFrames);
            sharedGetHitAnimationFrames = GraphicsUtilities.LoadFramesFromAtlas("Goblin_GetHit", "goblin_getHit_", GoblinGetHitFrames);
            sharedDeathAnimationFrames  = GraphicsUtilities.LoadFramesFromAtlas("Goblin_Death", "goblin_death_", GoblinDeathFrames);
            sharedDamageEmitter         = GraphicsUtilities.EmitterNodeWithEmitterNamed("Damage");
            sharedDeathSplort           = SKSpriteNode.FromTexture(atlas.TextureNamed("minionSplort.png"));
            sharedDamageAction          = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 1, 0),
                SKAction.WaitForDuration(0.75f),
                SKAction.ColorizeWithColorBlendFactor(0, 0.1)
            });
        }
示例#10
0
        public Slider(int width, int height, string text) : base()
        {
            // create a label
            var fontName = "Optima-ExtraBlack";

            this.label           = SKLabelNode.FromFont(fontName);
            this.label.Text      = text;
            this.label.FontSize  = 18;
            this.label.FontColor = SKColor.White;
            this.label.Position  = new CGPoint(0f, -8f);

            // create background & slider
            this.background             = new SKSpriteNode(SKColor.White, new CGSize(width, 2f));
            this.slider                 = SKShapeNode.FromCircle(height);
            this.slider.FillColor       = SKColor.White;
            this.background.AnchorPoint = new CGPoint(0f, 0.5f);

            this.slider.Position     = new CGPoint(this.label.Frame.Size.Width / 2f + 15f, 0f);
            this.background.Position = new CGPoint(this.label.Frame.Size.Width / 2f + 15f, 0f);

            // add to the root node
            this.AddChild(this.label);
            this.AddChild(this.background);
            this.AddChild(this.slider);

            // track mouse event
            base.UserInteractionEnabled = true;
            this.Value = 0f;
        }
示例#11
0
        public override void TouchesBegan(MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent evt)
        {
            foreach (UITouch touch in touches) {
                var location = touch.LocationInNode (this);

                if (_nbPictures+1 > _maxPictures)
                {
                    var tab = _kaloos.ToArray ();
                    RemoveChildren (tab);
                    _kaloos.Clear ();
                    _nbPictures = 0;
                }

                _nbPictures++;

                string currentPicture = _pictures[_nbPictures % 3];

                var sprite = new SKSpriteNode (currentPicture) {
                    Position =  location,
                };

                _kaloos.Add(sprite);

                var rotation = (float)Math.PI;
                double sec = 1;

                var action = SKAction.RotateByAngle (rotation,sec);
                sprite.RunAction (SKAction.RepeatActionForever (action));

                AddChild (sprite);
            }
        }
        protected override void LoadSceneAssets()
        {
            SKTextureAtlas atlas = SKTextureAtlas.FromName("Environment");

            // Load archived emitters and create copyable sprites.
            sharedProjectileSparkEmitter = GraphicsUtilities.EmitterNodeWithEmitterNamed("ProjectileSplat");
            sharedSpawnEmitter           = GraphicsUtilities.EmitterNodeWithEmitterNamed("Spawn");

            sharedSmallTree = new Tree(new SKNode[] {
                SKSpriteNode.FromTexture(atlas.TextureNamed("small_tree_base.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("small_tree_middle.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("small_tree_top.png"))
            }, 25);
            sharedBigTree = new Tree(new SKNode[] {
                SKSpriteNode.FromTexture(atlas.TextureNamed("big_tree_base.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("big_tree_middle.png")),
                SKSpriteNode.FromTexture(atlas.TextureNamed("big_tree_top.png"))
            }, 150);
            sharedBigTree.FadeAlpha = true;
            sharedLeafEmitterA      = GraphicsUtilities.EmitterNodeWithEmitterNamed("Leaves_01");
            sharedLeafEmitterB      = GraphicsUtilities.EmitterNodeWithEmitterNamed("Leaves_02");

            // Load the tiles that make up the ground layer.
            LoadWorldTiles();

            // Load assets for all the sprites within this scene.
            Cave.LoadSharedAssetsOnce();
            HeroCharacter.LoadSharedAssetsOnce();
            Archer.LoadSharedAssetsOnce();
            Warrior.LoadSharedAssetsOnce();
            Goblin.LoadSharedAssetsOnce();
            Boss.LoadSharedAssetsOnce();
        }
        void LoadWorldTiles()
        {
            var sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("Loading world tiles");

            SKTextureAtlas tileAtlas = SKTextureAtlas.FromName("Tiles");

            backgroundTiles = new SKNode[1024];
            for (int y = 0; y < WorldTileDivisor; y++)
            {
                for (int x = 0; x < WorldTileDivisor; x++)
                {
                    int tileNumber = (y * WorldTileDivisor) + x;

                    var          textureName = string.Format("tile{0}.png", tileNumber);
                    var          texture     = tileAtlas.TextureNamed(textureName);
                    SKSpriteNode tileNode    = SKSpriteNode.FromTexture(texture);

                    int xPos     = x * WorldTileSize - WorldCenter;
                    var yPos     = WorldSize - y * WorldTileSize - WorldCenter;
                    var position = new CGPoint(xPos, yPos);
                    tileNode.Position            = position;
                    tileNode.ZPosition           = -1;
                    tileNode.BlendMode           = SKBlendMode.Replace;
                    backgroundTiles [tileNumber] = tileNode;
                }
            }
            Console.WriteLine("Loaded all world tiles in {0} seconds", sw.Elapsed);
            sw.Stop();
        }
示例#14
0
        /// <summary>
        /// Renders the logo.
        /// </summary>
        void RenderLogo()
        {
            var logo = SKSpriteNode.FromImageNamed(LOGO_IMAGE);

            logo.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY() * 1.75);
            AddChild(logo);
        }
示例#15
0
        public Sprite[,,] Getmap(nfloat Height, nfloat Width, int mapnum)
        {
            block_setup setup = new block_setup();
            fetch_data  fetch = new fetch_data();

            Sprite[,,] sprites = new Sprite[10, 10, 3];
            StreamReader maps = null;

            try
            {
                maps = new StreamReader(fetch.Get_path_map() + "maps.csv");
                Debug.WriteLine("No error for map path");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            string[] row;

            do
            {
                row = maps.ReadLine().Split(',');
                if (int.Parse(row[0]) == mapnum)
                {
                    Sprite.Block block = new Sprite.Block(setup.b(row[3]));
                    block.xPos       = int.Parse(row[1]); block.yPos = int.Parse(row[2]); block.zPos = 0;
                    block.spriteNode = SKSpriteNode.FromImageNamed(block.path);
                    setup.setPos(ref block, ref sprites, Height, Width);
                }
            }while (int.Parse(row[0]) <= mapnum);
            maps.Close();
            return(sprites);
        }
示例#16
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++;
        }
示例#17
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;
                }
            }
        }
示例#18
0
        public LeaderboardScoresScreen(CGSize size) : base(size)
        {
            SKLabelNode title = new SKLabelNode("GillSans-Bold")
            {
                Text     = GameInfo.CurrentLeaderBoard.Title,
                FontSize = 14,
                Position = new CGPoint(FrameMidX, FrameMidY + 190)
            };

            var podiumSprite = SKSpriteNode.FromTexture(SKTexture.FromImageNamed("Images/Podium.png"));

            podiumSprite.Position = new CGPoint(FrameMidX, FrameMidY + 50);

            backButton = new SKLabelNode("GillSans-Bold")
            {
                Text      = "Back",
                FontSize  = 18,
                FontColor = ButtonColor,
                Position  = new CGPoint(FrameMidX, FrameMidY - 200)
            };

            if (GKLocalPlayer.LocalPlayer.Authenticated)
            {
                LoadLeaderboardScoresInfo(GameInfo.CurrentLeaderBoard);
            }

            AddChild(title);
            AddChild(backButton);
            AddChild(podiumSprite);
        }
示例#19
0
        void DisplayScore(GKScore score, int rank, GKPlayer player)
        {
            CGPoint[] podiumPositions = new CGPoint[] {
                new CGPoint(0, 100),
                new CGPoint(-84, 75),
                new CGPoint(84, 50)
            };

            CGPoint currentPoint = podiumPositions [rank];

            SKLabelNode scoreLabel = new SKLabelNode("GillSans-Bold")
            {
                Text     = score.FormattedValue,
                FontSize = 14,
                Position = new CGPoint(FrameMidX + currentPoint.X, FrameMidY + currentPoint.Y - 32)
            };

            player.LoadPhoto(GKPhotoSize.Small, delegate(UIImage photo, NSError error) {
                if (photo == null)
                {
                    photo = UIImage.FromFile("Images/DefaultPlayerPhoto.png");
                }
                var image      = SKSpriteNode.FromTexture(SKTexture.FromImage(photo), new CGSize(32, 32));
                image.Position = new CGPoint(FrameMidX + currentPoint.X, FrameMidY + currentPoint.Y + 16);
                AddChild(image);
            });

            AddChild(scoreLabel);
        }
示例#20
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);
        }
示例#21
0
        void SetCameraConstraints(SKCameraNode camera, SKSpriteNode sprite)
        {
            // Constrain the camera to the player
            var          zeroRange        = new SKRange(0, 0);
            SKConstraint playerConstraint = SKConstraint.CreateDistance(zeroRange, sprite);

            var scaledSize  = new CGSize(Size.Width * camera.XScale, Size.Height * camera.YScale);
            var contentRect = mapNode.CalculateAccumulatedFrame();

            contentRect = new CGRect(contentRect.X, contentRect.Y, contentRect.Width, contentRect.Height + 300);

            nfloat xInset = (nfloat)Math.Min((scaledSize.Width / 2.0) + 10, contentRect.Width / 2.0);
            nfloat yInset = (nfloat)Math.Min((scaledSize.Height / 2.0) + 10, contentRect.Height / 2.0);

            var insetRect = contentRect.Inset(xInset, yInset);

            var xRange = new SKRange(insetRect.GetMinX(), insetRect.GetMaxX());
            var yRange = new SKRange(insetRect.GetMinY(), insetRect.GetMaxY());

            var levelEdgeConstraint = SKConstraint.CreateRestriction(xRange, yRange);

            levelEdgeConstraint.ReferenceNode = this;

            camera.Constraints = new[] { playerConstraint, levelEdgeConstraint };
        }
示例#22
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) }) }) }));
        }
示例#23
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)
            });
        }
示例#24
0
        public void ShowScanAction()
        {
            var size = base.Size;

            _scanText1 = new SKLabelNode("AppleSDGothicNeo-Regular")
            {
                Text     = "Move your phone",
                FontSize = 30,
                Position = new CGPoint(size.Width / 2, 100),
                Color    = UIColor.White,
            };
            AddChild(_scanText1);

            _scanText2 = new SKLabelNode("AppleSDGothicNeo-Regular")
            {
                Text     = "to find a surface",
                FontSize = 30,
                Position = new CGPoint(size.Width / 2, 70),
                Color    = UIColor.White,
            };
            AddChild(_scanText2);

            _phone          = SKSpriteNode.FromImageNamed("phone_scaled");
            _phone.Position = new CGPoint(size.Width / 2, 190);

            var circle        = UIBezierPath.FromRoundedRect(new CGRect(new CGPoint(size.Width / 2 - 20, 190), new CGSize(40, 40)), 20);
            var moveAlongPath = SKAction.RepeatActionForever(SKAction.FollowPath(circle.CGPath, false, false, 2.0));

            _phone.RunAction(moveAlongPath);

            AddChild(_phone);

            ScanActionShowing  = true;
            ScanActionFinished = false;
        }
示例#25
0
        internal void updateSize()
        {
            Texture2D texture2D = SKScene.current.Texture2D("stars");

            removeAllChildren();

            int xMax = (int)(SKScene.currentSize.X / texture2D.Bounds.Size.X);
            int yMax = (int)(SKScene.currentSize.Y / texture2D.Bounds.Size.Y);

            for (int x = 0; x <= xMax; x++)
            {
                for (int y = 0; y <= yMax; y++)
                {
                    SKSpriteNode spriteNode = new SKSpriteNode(texture2D);
                    spriteNode.position = new Vector2(
                        texture2D.Bounds.Size.X * x,
                        texture2D.Bounds.Size.Y * y
                        );
                    addChild(spriteNode);

                    //spriteNode.zRotation = MathHelper.PiOver2 * (int)(MathHelper.ToDegrees((float)(random.NextDouble() * MathHelper.TwoPi)) / 90.0f);
                }
            }

            Vector2 size = new Vector2(
                texture2D.Bounds.Size.X * xMax,
                texture2D.Bounds.Size.Y * yMax
                );

            position = new Vector2(
                -size.X / 2.0f,
                -size.Y / 2.0f
                );
        }
示例#26
0
        public void addItemBackground(CGPoint itemPos)
        {
            var bottleCap = new SKSpriteNode(SKTexture.FromImageNamed("capitem1"));

            bottleCap.SetScale(0.4f);
            bottleCap.Position = itemPos;
            AddChild(bottleCap);
        }
示例#27
0
 public void Color()
 {
     using (var n = new SKSpriteNode(UIColor.Blue, SizeF.Empty)) {
         Assert.That(n.Color.ToString(), Is.EqualTo("UIColor [A=255, R=0, G=0, B=255]"), "Color-1");
         n.Color = null;
         Assert.That(n.Color.ToString(), Is.EqualTo("UIColor [A=0, R=0, G=0, B=0]"), "Color-2");
     }
 }
		void AddColoredSprite ()
		{
			using (SKSpriteNode sprite = new SKSpriteNode (UIColor.Red, new CGSize (128, 128))) {
				sprite.Position = new CGPoint (Scene.Frame.GetMidX () + 200, Scene.Frame.GetMidY ());
				sprite.AddDescription ("Color Sprite", new CGPoint (0, -sprite.Size.Height / 2 - 30));
				Scene.AddChild (sprite);
			}
		}
		void AddTexturedSprite ()
		{
			using (SKSpriteNode sprite = new SKSpriteNode ("Art/rocket.png")) {
				sprite.Position = new CGPoint (Scene.Frame.GetMidX () - 200, Scene.Frame.GetMidY ());
				sprite.AddDescription ("Texture Sprite", new CGPoint (0, -sprite.Size.Height / 2 - 30));
				Scene.AddChild (sprite);
			}
		}
示例#30
0
 public void FinishActionPlacement()
 {
     if (_check != null)
     {
         _check.RemoveFromParent();
         _check = null;
     }
 }
 void AddTexturedSprite()
 {
     using (SKSpriteNode sprite = new SKSpriteNode("Art/rocket.png")) {
         sprite.Position = new CGPoint(Scene.Frame.GetMidX() - 200, Scene.Frame.GetMidY());
         sprite.AddDescription("Texture Sprite", new CGPoint(0, -sprite.Size.Height / 2 - 30));
         Scene.AddChild(sprite);
     }
 }
 void AddColoredSprite()
 {
     using (SKSpriteNode sprite = new SKSpriteNode(UIColor.Red, new CGSize(128, 128))) {
         sprite.Position = new CGPoint(Scene.Frame.GetMidX() + 200, Scene.Frame.GetMidY());
         sprite.AddDescription("Color Sprite", new CGPoint(0, -sprite.Size.Height / 2 - 30));
         Scene.AddChild(sprite);
     }
 }
 public void DefaultCtor()
 {
     using (var Scene = new SKScene(UIScreen.MainScreen.Bounds.Size))
         using (var b = new SKSpriteNode(UIColor.Red, new CGSize(10, 10))) {
             b.PhysicsBody = new SKPhysicsBody();
             Scene.AddChild(b);              //BOOM
         }
 }
示例#34
0
            public WeatherScene(CGSize size)
                : base(size)
            {
                backgroundSprite = SKSpriteNode.FromImageNamed ("b11.png");

                backgroundSprite.Position = new CGPoint (Size.Width / 2, Size.Height / 2);
                backgroundSprite.Size = new CGSize(this.Size.Height / backgroundSprite.Size.Height * backgroundSprite.Size.Width, Size.Height);

                AddChild(backgroundSprite);
            }
 void AddLight()
 {
     SKSpriteNode sprite = new SKSpriteNode ("Art/spark.png") {
         Position = GetRandomPosition (),
         BlendMode = SKBlendMode.Add,
         Alpha = 0.5f,
         Scale = 2.0f
     };
     Scene.AddChild (sprite);
 }
示例#36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Boing.BoingScene"/> class.
        /// </summary>
        /// <param name="size">Size of the scene in screen units.</param>
        public BoingScene(SizeF size)
            : base(size)
        {
            this.ScaleMode = SKSceneScaleMode.AspectFill;

            // We're true retro fans, so let's use the correct background color of the Amiga original version.
            this.BackgroundColor = UIColor.FromRGB (0, 0, 0);

            // Create the background grid and add it to the center of the scene.
            var gridNode = CreateBackgroundNode (this.Frame.Size);
            gridNode.Position = new PointF (0, 0);
            this.AddChild (gridNode);

            // Create our bouncing ball sprite.
            this.ballNode = CreateBallNode (true);
            // Add the ball to the scene.
            this.AddChild (this.ballNode);

            // Place the ball in the center of the screen to start.
            this.ballNode.Position = new PointF (this.Frame.Width * .5f, this.Frame.Height - this.ballNode.Frame.Height * .5f);

            // Create a shadow version of the ball. This does not have physics and gets repositioned whenever the ball itself has moved.
            var ballShadowNode = CreateBallNode (false);
            ballShadowNode.Alpha = 0.8f;
            ballShadowNode.Color = UIColor.Black;
            ballShadowNode.ColorBlendFactor = 0.8f;
            ballShadowNode.Position = new PointF (SHADOW_OFFSET, -SHADOW_OFFSET);
            ballShadowNode.ZPosition = this.ballNode.ZPosition - 1;
            // Add the shadow as a child to the ball.
            ballNode.AddChild (ballShadowNode);

            // Let our scene have some gravity that is way lower then real earth's gravity, so the ball bounces nice and slowly.
            this.PhysicsWorld.Gravity = new CGVector (0, -1.5f);

            // Create some walls around the scene to make the ball bounce.
            this.PhysicsBody = SKPhysicsBody.BodyWithEdgeLoopFromRect (this.Frame);
            // Let the collission detection system know that this is a wall.
            this.PhysicsBody.SetCategoryBitMask (CONTACT_BITS.Wall);

            // Xamarin nicely wraps the SKPhysicsWorldDelegate protocol into C# events.
            this.PhysicsWorld.DidBeginContact += this.HandleDidBeginContact;

            // And for fancyness: let it snow! This demonstrated how to easily load a particle system that was created using Xcode's particle editor.
            var particleSystem = NSKeyedUnarchiver.UnarchiveFile ("./assets/SnowParticles.sks") as SKEmitterNode;
            particleSystem.Position = new PointF (this.Frame.Width * .5f, this.Frame.Height);
            particleSystem.Name = "SnowParticle";
            this.particleRate = particleSystem.ParticleBirthRate;
            // Turn snow off initially.
            particleSystem.ParticleBirthRate = 0;
            particleSystem.ParticleTexture = SKTexture.FromImageNamed ("./assets/spark.png");
            this.AddChild(particleSystem);

            // Init ramdomizer.
            this.rand = new Random ();
        }
		void AddAnimatedAnchor ()
		{
			SKSpriteNode animatedSprite = new SKSpriteNode ("Art/rocket.png") {
				Position = new CGPoint (Scene.Frame.GetMidX () + 200, Scene.Frame.GetMidY ()),
				AnchorPoint = CGPoint.Empty
			};
			Scene.AddChild (animatedSprite);
			AddAnchorDotToSprite (animatedSprite);

			animatedSprite.RunAction (NewAnimateAnchorAction ());
		}
示例#38
0
        public MonkeyScene(SizeF size)
            : base(size)
        {
            monkey = SKSpriteNode.FromImageNamed ("frame-1");
            monkey.Position = new PointF (Size.Width / 2, Size.Height / 2);
            AddChild (monkey);

            var textures = Enumerable.Range (1, 8).Select (
                (i) => SKTexture.FromImageNamed (String.Format ("frame-{0}", i))).ToArray ();

             	animate = SKAction.RepeatActionForever (SKAction.AnimateWithTextures (textures, 0.1));
        }
		void AddAnchorDotToSprite (SKSpriteNode sprite)
		{
			CGPath myPath = new CGPath ();
			myPath.AddArc (0, 0, 10, 0, (float) Math.PI * 2, true);
			myPath.CloseSubpath ();

			SKShapeNode dot = new SKShapeNode () {
				Path = myPath,
				FillColor = UIColor.Green,
				LineWidth = 0.0f
			};
			sprite.AddChild (dot);
		}
示例#40
0
        public override void TouchesBegan(MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent evt)
        {
            foreach (UITouch touch in touches) {
                var location = touch.LocationInNode (this);
                var sprite = new SKSpriteNode ("Spaceship") {
                    Position =  location,
                };

                var action = SKAction.RotateByAngle ((float)Math.PI, 1);
                sprite.RunAction (SKAction.RepeatActionForever (action));

                AddChild (sprite);
            }
        }
		void AddAnchorGrid ()
		{
			for (int x = 0; x <= 4; x++) {
				for (int y = 0; y <= 4; y++) {
					SKSpriteNode sprite = new SKSpriteNode ("Art/rocket.png") {
						AnchorPoint = new CGPoint (0.25f * x, 0.25f * y),
						Position = new CGPoint (Scene.Frame.GetMidX () - 400 + 100 * x,
						                       Scene.Frame.GetMidY () - 200 + 100 * y)
					};
					sprite.SetScale (0.25f);
					Scene.AddChild (sprite);
					AddAnchorDotToSprite (sprite);
				}
			}
		}
        protected override void CreateSceneContents()
        {
            base.CreateSceneContents ();

            template = new SKSpriteNode ("Art/rocket.png");
            template.SetScale (0.5f);

            AddBlendFactorLabels ();

            AddColorRow (UIColor.Red, 0);
            AddColorRow (UIColor.Green, 1);
            AddColorRow (UIColor.Blue, 2);
            AddColorRow (UIColor.Yellow, 3);

            AddAnimatedSprite ();
        }
示例#43
0
 public void Color()
 {
     using (var n = new SKSpriteNode (UIColor.Blue, SizeF.Empty)) {
     #if MONOMAC
         Assert.That (n.Color.ToString (), Is.EqualTo ("Device RGB(0.016804177314043,0.198350995779037,1,1)"), "Color-1");
     #else
         Assert.That (n.Color.ToString (), Is.EqualTo ("UIColor [A=255, R=0, G=0, B=255]"), "Color-1");
     #endif
         n.Color = null;
     #if MONOMAC
         Assert.That (n.Color.ToString (), Is.EqualTo ("Device RGB(0,0,0,0)"), "Color-2");
     #else
         Assert.That (n.Color.ToString (), Is.EqualTo ("UIColor [A=0, R=0, G=0, B=0]"), "Color-2");
     #endif
     }
 }
        protected override void CreateSceneContents()
        {
            base.CreateSceneContents ();

            SKTexture[] walkFrames = LoadFrames ("Art/warrior_walk_", 28);

            SKSpriteNode sprite = new SKSpriteNode (walkFrames [0]) {
                Position = new PointF (Scene.Frame.GetMidX (), Scene.Frame.GetMidY ())
            };
            Scene.AddChild (sprite);

            //Cycle through the frame
            var animation = SKAction.AnimateWithTextures (walkFrames, 1.0f / 28, true, false);
            sprite.RunAction (SKAction.RepeatActionForever (animation));

            Scene.AddDescription ("This sprite is animating through a series of texture images.",
                new PointF (Scene.Frame.GetMidX (), 100));
        }
示例#45
0
		public MainMenu (CGSize frameSize)
		{
			Position = new CGPoint (frameSize.Width * 0.5f, frameSize.Height * 0.15f);
			UserInteractionEnabled = true;

			gameLogo = new SKSpriteNode ("art.scnassets/level/interface/logo_bananas.png");

			// resize logo to fit the screen
			CGSize size = gameLogo.Size;
			nfloat factor = frameSize.Width / size.Width;
			size.Width *= factor;
			size.Height *= factor;
			gameLogo.Size = size;

			gameLogo.AnchorPoint = new CGPoint (1f, 0f);
			gameLogo.Position = new CGPoint (Frame.GetMidX (), Frame.GetMidY ());
			AddChild (gameLogo);
		}
示例#46
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // Called when a touch begins
            foreach (var touch in touches) {
                var location = ((UITouch)touch).LocationInNode (this);

                var sprite = new SKSpriteNode ("Spaceship") {
                    Position = location,
                    XScale = 0.4f,
                    YScale = 0.4f
                };

                var action = SKAction.RotateByAngle ((float)Math.PI, 1.0);

                sprite.RunAction (SKAction.RepeatActionForever (action));

                AddChild (sprite);
            }
        }
		protected override void CreateSceneContents ()
		{
			base.CreateSceneContents ();

			SKTexture texture = SKTexture.FromImageNamed ("Art/stretchable_image.png");
			SKAction resizeSpritesAction = GetResizeAction (texture);

			SKSpriteNode defaultSprite = new SKSpriteNode (texture);
			defaultSprite.Position = new CGPoint (Scene.Frame.GetMidX () - 192, Scene.Frame.GetMidY ());
			defaultSprite.AddDescription ("Resized with default stretching", new CGPoint (0, -128));
			Scene.AddChild (defaultSprite);
			defaultSprite.RunAction (resizeSpritesAction);

			SKSpriteNode customSprite = new SKSpriteNode (texture);
			customSprite.Position = new CGPoint (Scene.Frame.GetMidX () + 192, Scene.Frame.GetMidY ());
			customSprite.CenterRect = new CGRect (12.0f / 28.0f, 12.0f / 28.0f, 4.0f / 28.0f, 4.0f / 28.0f);
			customSprite.AddDescription ("Resized with custom stretching", new CGPoint (0, -128));
			Scene.AddChild (customSprite);
			customSprite.RunAction (resizeSpritesAction);
		}
示例#48
0
        void Initialize(CGPoint position)
        {
            var atlas = SKTextureAtlas.FromName ("Environment");

            ShadowBlob = new SKSpriteNode (atlas.TextureNamed ("blobShadow.png")) {
                ZPosition = -1f
            };

            Position = position;

            Health = 100f;
            MovementSpeed = Velocity;
            Animated = true;
            AnimationSpeed = 1f / 28f;

            ConfigurePhysicsBody ();
        }
示例#49
0
        SKSpriteNode GetSpriteForCell(MineCell cell)
        {
            SKSpriteNode sprite;
            switch (cell.Display) {
            case MineCellDisplayType.Unclicked:
            default:
                sprite = new SKSpriteNode (UnclickedSpotImageName);
                break;
            case MineCellDisplayType.Bomb:
                sprite = new SKSpriteNode (BombImageName);
                break;
            case MineCellDisplayType.Flag:
                sprite = new SKSpriteNode (FlagImageName);
                break;
            case MineCellDisplayType.Number1:
                sprite = new SKSpriteNode ("Spot1");
                break;
            case MineCellDisplayType.Number2:
                sprite = new SKSpriteNode ("Spot2");
                break;
            case MineCellDisplayType.Number3:
                sprite = new SKSpriteNode ("Spot3");
                break;
            case MineCellDisplayType.Number4:
                sprite = new SKSpriteNode ("Spot4");
                break;
            case MineCellDisplayType.Number5:
                sprite = new SKSpriteNode ("Spot5");
                break;
            case MineCellDisplayType.Number6:
                sprite = new SKSpriteNode ("Spot6");
                break;
            case MineCellDisplayType.Number7:
                sprite = new SKSpriteNode ("Spot7");
                break;
            case MineCellDisplayType.Number8:
                sprite = new SKSpriteNode ("Spot8");
                break;
            case MineCellDisplayType.NoSurroundingBombs:
                sprite = new SKSpriteNode (ClickedSpotImageName);
                break;
            }

            sprite.Position = GetCellPosition (cell.X, cell.Y);
            sprite.Size = new CGSize (cellWidth, cellHeight);

            return sprite;
        }
        public MyScene(CGSize size)
            : base(size)
        {
            // Setup your scene here
            BackgroundColor = new UIColor(0.15f, 0.15f, 0.3f, 1.0f);

            var myLabel = new SKLabelNode("Chalkduster")
            {
                Text = "Hello, World!",
                FontSize = 30,
                Position = new CGPoint(Frame.Width / 2, Frame.Height / 2)
            };
            AddChild(myLabel);

            CeilingNode = new SKSpriteNode
            {
                Color = UIColor.Orange,
                Size = new CGSize(Frame.Size.Width, 50),
                Position = new CGPoint(Frame.GetMaxX() / 2, Frame.GetMaxY() - 20),

            };
            CeilingNode.PhysicsBody = SKPhysicsBody.CreateRectangularBody(CeilingNode.Size);
            CeilingNode.PhysicsBody.Dynamic = false;
            AddChild(CeilingNode);

            FloorNode = new SKSpriteNode
            {
                Color = UIColor.Orange,
                Size = new CGSize(Frame.Size.Width, 50),
                Position = new CGPoint(Frame.GetMaxX() / 2, 20),

            };
            FloorNode.PhysicsBody = SKPhysicsBody.CreateRectangularBody(FloorNode.Size);
            FloorNode.PhysicsBody.Dynamic = false;
            AddChild(FloorNode);

            SpaceShip = new SKSpriteNode("Spaceship")
            {
                Position = new CGPoint(Frame.X + 100, Frame.GetMidY()),
                XScale = 0.4f,
                YScale = 0.4f,
            };
            SpaceShip.PhysicsBody = SKPhysicsBody.CreateRectangularBody(SpaceShip.Size);
            AddChild(SpaceShip);

            var timer = new Timer()
            {
                Enabled = true,
                AutoReset = true,
                Interval = 300
            };
            timer.Elapsed += (sender, args) =>
            {
                var wall1 = new Wall(UIColor.Blue, new CGSize(50, Frame.Height - 100))
                {
                    Position = new CGPoint(Frame.GetMaxX(), Frame.GetMidY())
                };
                wall1.PhysicsBody = SKPhysicsBody.CreateRectangularBody(wall1.Size);

                AddChild(wall1);
                this.Walls.Add(wall1);
            };
        }
示例#51
0
        public static new 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)
            });
        }
示例#52
0
        public static new 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)
            });
        }
示例#53
0
 public void CtorColor()
 {
     using (var n = new SKSpriteNode ((UIColor) null, SizeF.Empty)) {
         CheckEmpty (n);
     }
 }
示例#54
0
 public void Ctor()
 {
     using (var n = new SKSpriteNode ()) {
         CheckEmpty (n);
     }
 }
示例#55
0
        public void ProcessControllerAction(TVControllerAction item)
        {
            if (map.IsGameOver && item == TVControllerAction.Flag)
                item = TVControllerAction.Tap;

            switch (item) {
            case TVControllerAction.Left:
                CurrentX--;
                if (CurrentX < 0)
                    CurrentX = 0;
                break;
            case TVControllerAction.Right:
                CurrentX++;
                if (CurrentX >= map.MapColumns)
                    CurrentX = map.MapColumns - 1;
                break;
            case TVControllerAction.Up:
                CurrentY--;
                if (CurrentY < 0)
                    CurrentY = 0;
                break;
            case TVControllerAction.Down:
                CurrentY++;
                if (CurrentY >= map.MapRows)
                    CurrentY = map.MapRows - 1;
                break;
            case TVControllerAction.Flag:
                var flagResults = map.FlagSpot (CurrentX, CurrentY);

                flagResults.AffectedSpots.ForEach (RedisplaySpot);

                if (flagResults.GameReset) {
                    DisplayMap ();
                }

                MoveCurrentPositionToTop ();
                UpdateLevelDisplay ();

                break;
            case TVControllerAction.Tap:
                var actionDetails = map.ClickOnSpot (CurrentX, CurrentY);

                actionDetails.AffectedSpots.ForEach (RedisplaySpot);

                if (actionDetails.GameOver) {
                    RedisplaySpot (new Spot (CurrentX, CurrentY));

                    // Blow up all the spots
                    MakeExplosionAtPoint (new Spot (CurrentX, CurrentY));

                    var allMines = map.GetAllMinesNear (new Spot (CurrentX, CurrentY));
                    allMines.ForEach (MakeExplosionAtPoint);

                    gameOverNode = new SKLabelNode (displayFontGameOver) {
                        Text = "Game Over",
                            Position = new CGPoint(Scene.Frame.GetMidX(), Scene.Frame. GetMidY()),
                        FontColor = UIColor.Blue,
                        FontSize = displayFontSizeGameOver,
                        VerticalAlignmentMode = SKLabelVerticalAlignmentMode.Center,
                        HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center
                    };
                        float miniBuffer = 3f;
                    gameOverNode2 = new SKLabelNode (displayFontGameOver) {
                        Text = "Game Over",
                            Position = new CGPoint(gameOverNode.Position.X + miniBuffer, gameOverNode.Position.Y - miniBuffer),
                            FontColor = UIColor.FromRGBA(0.0f, 0f, 0f, 0.25f),
                        FontSize = displayFontSizeGameOver,
                        VerticalAlignmentMode = SKLabelVerticalAlignmentMode.Center,
                        HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center
                    };

                    AddChild (gameOverNode2);
                    AddChild (gameOverNode);

                    gameOverNode.RunAction (SKAction.RotateByAngle (
                        (nfloat)(Math.PI / 180) * 720,
                        1.0));
                    gameOverNode2.RunAction (SKAction.RotateByAngle (
                        (nfloat)(Math.PI / 180) * 720,
                        1.0));

                    currentSpot.RunAction(SKAction.RemoveFromParent());
                    currentSpot = null;
                }

                if (actionDetails.GameReset) {
                    DisplayMap ();
                }

                MoveCurrentPositionToTop ();
                UpdateLevelDisplay ();

                break;
            }

            UpdateCurrentSpot();

            currentSpot.RunAction (SKAction.MoveTo (
                GetCellPosition (CurrentX, CurrentY), 0.25
            ));
        }
示例#56
0
 void CheckEmpty(SKSpriteNode n)
 {
     Assert.IsNotNull (n.Color, "Color");
     Assert.Null (n.Name, "Name");
     Assert.True (n.Size.IsEmpty, "Size");
     Assert.Null (n.Texture, "Texture");
 }
示例#57
0
 public void Texture()
 {
     using (var t = SKTexture.FromImageNamed ("basn3p08.png"))
     using (var n = new SKSpriteNode (t)) {
         Assert.AreSame (n.Texture, t, "Texture-1");
         n.Texture = null;
         Assert.IsNull (n.Texture, "Texture-2");
     }
 }
示例#58
0
 public void CtorTextureColor()
 {
     using (var n = new SKSpriteNode (null, null, SizeF.Empty)) {
         CheckEmpty (n);
     }
 }
示例#59
0
 public void CtorTexture()
 {
     using (var n = new SKSpriteNode ((SKTexture) null)) {
         CheckEmpty (n);
     }
 }
示例#60
0
        void UpdateCurrentSpot()
        {
            currentSpot?.RemoveFromParent ();

            currentSpot = GetSpriteForCell(CurrentX, CurrentY);
            var action = SKAction.RepeatActionForever (
                SKAction.Sequence (
                    SKAction.ScaleBy (2f, 0.6),
                    SKAction.ScaleBy (0.5f, 0.6)
                ));
            currentSpot.RunAction (action);
            AddChild (currentSpot);
        }