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();
        }
Ejemplo n.º 2
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);
        }
        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();
        }
        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)
            });
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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 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)
            });
        }
Ejemplo n.º 8
0
        void LoadAchievementInfo(GKAchievementDescription[] descriptions, NSError error)
        {
            if (descriptions == null)
            {
                return;
            }

            GKAchievement.LoadAchievements(delegate(GKAchievement[] achievements, NSError err) {
                int completeOffset   = 0;
                int incompleteOffset = 0;

                foreach (var description in descriptions)
                {
                    bool completed = false;
                    foreach (var achievement in achievements)
                    {
                        if (description.Identifier == achievement.Identifier)
                        {
                            completed |= achievement.Completed;
                        }
                    }

                    int xOffset = completed ? -75 : 75;
                    int yOffset = completed ? completeOffset : incompleteOffset;

                    var achievementLabel = new SKLabelNode("GillSans-Bold")
                    {
                        Text     = description.Title,
                        FontSize = 10,
                        Position = new CGPoint(FrameMidX + xOffset, FrameMidY + 50 + yOffset + 25)
                    };
                    AddChild(achievementLabel);

                    description.LoadImage(delegate(UIImage image, NSError imageError) {
                        if (image == null)
                        {
                            image = UIImage.FromFile("Images/DefaultPlayerPhoto.png");
                        }
                        var sprite      = SKSpriteNode.FromTexture(SKTexture.FromImage(image), new CGSize(32, 32));
                        sprite.Position = new CGPoint(FrameMidX + xOffset, FrameMidY + 50 + yOffset + 50);
                        AddChild(sprite);
                    });

                    if (completed)
                    {
                        completeOffset -= 50;
                    }
                    else
                    {
                        incompleteOffset -= 50;
                    }
                }
            });
        }
Ejemplo n.º 9
0
        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");

            SKEmitterNode fire = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveFire");
            fire.ZPosition = 1;

            SKEmitterNode smoke = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveFireSmoke");

            var sKNode = new SKNode();
            sKNode.Add(fire);
            sKNode.Add(smoke);
            SKNode torch = sKNode;

            sharedCaveBase = SKSpriteNode.FromTexture(atlas.TextureNamed("cave_base.png"));

            // Add two torches either side of the entrance.
            torch.Position = new CGPoint(83, 83);
            sharedCaveBase.AddChild(torch);
            var torchB = (SKNode)torch.Copy();
            torchB.Position = new CGPoint(-83, 83);
            sharedCaveBase.AddChild(torchB);

            sharedCaveTop     = SKSpriteNode.FromTexture(atlas.TextureNamed("cave_top.png"));
            sharedDeathSplort = SKSpriteNode.FromTexture(atlas.TextureNamed("cave_destroyed.png"));

            sharedDamageEmitter = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveDamage");
            sharedDeathEmitter  = GraphicsUtilities.EmitterNodeWithEmitterNamed("CaveDeathSmoke");

            sharedDamageAction = SKAction.Sequence(new [] {
                SKAction.ColorizeWithColor(whiteColor, 1, 0),
                SKAction.WaitForDuration(0.25),
                SKAction.ColorizeWithColorBlendFactor(0, 0.1),
            });
        }
Ejemplo n.º 10
0
        public Kuma(SKScene sceen, CGPoint location, CGSize size)
        {
            _textures = new SKTexture[ImageMax];
            for (var i = 0; i < ImageMax; i++)
            {
                _textures[i] = SKTexture.FromImageNamed(String.Format("Image{0}", i));
            }

            _node             = SKSpriteNode.FromTexture((SKTexture)_textures[0]);
            _node.AnchorPoint = new CGPoint(0, 0);
            _node.Position    = location;
            _node.Size        = size;
            _node.ZPosition   = 0;
            sceen.AddChild(_node);

            _locationX = location.X;
            _locationY = location.Y;
            _width     = size.Width;
        }
Ejemplo n.º 11
0
        // テクスチャから初期化する
        // w 横の画像数
        // h 縦の画像数
        public AnimationNode(String name, int w, int h, double sec, CGSize size)
        {
            textures = new SKTexture[w * h];
            var texture = SKTexture.FromImageNamed(name);
            var c       = 0;

            for (var y = h - 1; y >= 0; y--)
            {
                for (var x = 0; x < w; x++)
                {
                    textures[c++] = SKTexture.FromRectangle(new CGRect(x / (float)w, y / (float)h, 1 / (float)w, 1 / (float)h), texture);
                }
            }
            node           = SKSpriteNode.FromTexture((SKTexture)textures[0]);
            node.Size      = size;
            node.ZPosition = 1;
            node.Position  = new CGPoint(-100, -100);
            action         = SKAction.AnimateWithTextures((SKTexture[])textures, sec);
        }