Example #1
0
        void Explode()
        {
            // Create a bunch of explosion emitters and send them flying in all directions. Then remove the ship from the scene.
            for (int i = 0; i < numberOfChunks; i++)
            {
                SKEmitterNode explosion = NodeFactory.CreateExplosionNode(Scene, shipExplosionDuration);

                float angle = myRand(0, (float)Math.PI * 2);
                float speed = myRand(shipChunkMinimumSpeed, shipChunkMaximumSpeed);
                var   x     = myRand((float)Position.X - shipChunkDispersion, (float)Position.X + shipChunkDispersion);
                var   y     = myRand((float)Position.Y - shipChunkDispersion, (float)Position.Y + shipChunkDispersion);
                explosion.Position = new CGPoint(x, y);

                var body = SKPhysicsBody.CreateCircularBody(0.25f);
                body.CollisionBitMask   = 0;
                body.ContactTestBitMask = 0;
                body.CategoryBitMask    = 0;
                body.Velocity           = new CGVector((float)Math.Cos(angle) * speed, (float)Math.Sin(angle) * speed);
                explosion.PhysicsBody   = body;

                Scene.AddChild(explosion);
            }

            RunAction(SKAction.Sequence(
                          SKAction.WaitForDuration(removeShipTime),
                          SKAction.RemoveFromParent()
                          ));
        }
Example #2
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()));
        }
        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 FireProjectile()
        {
            var projectile = (SKSpriteNode)Projectile.Copy();

            projectile.Position  = Position;
            projectile.ZRotation = ZRotation;

            var emitter = (SKEmitterNode)ProjectileEmitter.Copy();

            emitter.TargetNode = CharacterScene.GetChildNode("world");
            projectile.AddChild(emitter);

            CharacterScene.AddNode(projectile, WorldLayer.Character);

            var rot = ZRotation;

            float x = -(float)Math.Sin(rot) * HeroProjectileSpeed * HeroProjectileLifetime;
            float y = (float)Math.Cos(rot) * HeroProjectileSpeed * HeroProjectileLifetime;

            projectile.RunAction(SKAction.MoveBy(x, y, HeroProjectileLifetime));

            projectile.RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(HeroProjectileFadeOutTime),
                SKAction.FadeOutWithDuration(HeroProjectileLifetime - HeroProjectileFadeOutTime),
                SKAction.RemoveFromParent()
            }));
            projectile.RunAction(ProjectileSoundAction);

            var userData = new UserData {
                Player = Player
            };


            projectile.UserData = (NSMutableDictionary)userData.Dictionary;
        }
Example #5
0
 public static void RunOneShotEmitter(SKEmitterNode emitter, float duration)
 {
     emitter.RunAction(SKAction.Sequence(new [] {
         SKAction.WaitForDuration(duration),
         SKAction.Run(() => {
             emitter.ParticleBirthRate = 0;
         }),
         SKAction.WaitForDuration(emitter.ParticleLifetime + emitter.ParticleLifetimeRange),
         SKAction.RemoveFromParent()
     }));
 }
Example #6
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()
                          ));
        }
Example #7
0
        public void DidBeginContact(MonoTouch.SpriteKit.SKPhysicsContact contact)
        {
            SKPhysicsBody headBody;
            SKPhysicsBody otherBody;

            if (contact.BodyA.CategoryBitMask == (uint)Categories.Head)
            {
                headBody  = contact.BodyA;
                otherBody = contact.BodyB;
            }
            else
            {
                headBody  = contact.BodyB;
                otherBody = contact.BodyA;
            }

            switch (otherBody.CategoryBitMask)
            {
            case (uint)Categories.Food:
                if (((int)headBody.Node.Position.X != (int)otherBody.Node.Position.X) ||
                    ((int)headBody.Node.Position.Y != (int)otherBody.Node.Position.Y))
                {
                    return;
                }

                RunAction(SKAction.Sequence(new [] {
                    SKAction.PlaySoundFileNamed("Bite.mp3", false),
                    SKAction.PlaySoundFileNamed("Swallow.mp3", false),
                }));

                score        += 10;
                lblScore.Text = score.ToString() + " Points";

                Food food = (Food)otherBody.Node;
                food.RunAction(SKAction.RemoveFromParent());
                addBody = true;
                break;

            case (uint)Categories.Body:
                break;

            case (uint)Categories.Tail:
                break;

            default:
                break;
            }
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// Анимация бонуса Бомба
        /// </summary>
        /// <param name="bomb">Бомба.</param>
        public void AnimateBomb(Gem bomb)
        {
            CGSize  initialSize     = new CGSize(gemCellWidth, gemCellHeight);
            CGSize  newSize         = new CGSize(gemCellWidth * (Properties.BombBlastRadius * 2 + 1), gemCellHeight * (Properties.BombBlastRadius * 2 + 1));
            CGPoint initialPosition = GetPositionFromRowAndColumn(bomb.Row, bomb.Column);

            SKSpriteNode sprite = SKSpriteNode.FromImageNamed("bomb_blast");

            sprite.Size      = initialSize;
            sprite.Position  = initialPosition;
            sprite.ZPosition = 110;

            SKAction resizeSprite = SKAction.ResizeTo(newSize, Properties.LineDestructionDuration / 1000f);

            gemLayer.AddChild(sprite);

            sprite.RunAction(SKAction.Sequence(resizeSprite, SKAction.RemoveFromParent()));
        }
Example #10
0
        protected override SKAction CreateShootAction()
        {
            Mat3 rotationMatrix = new Mat3();

            rotationMatrix.SetRotation(-owner.CurrentRotation);

            Mat3 translationMatrix = new Mat3();

            translationMatrix.SetTranslation(owner.Node.Scene.Size.Width, 0);

            Mat3 transformation = rotationMatrix * translationMatrix;

            var moveAction = SKAction.MoveBy(
                -(nfloat)transformation[6], -(nfloat)transformation[7], 2.5);

            var doneAction = SKAction.RemoveFromParent();

            return(SKAction.Sequence(moveAction, doneAction));
        }
Example #11
0
        /// <summary>
        /// Анимация разрушителей. создает спрайт, на месте бонуса, которому придает анимацию
        /// перемещения к центру (зависит от активированного бонуса - вертикально
        /// или горизонтально), с одновременным растягиванием, иммитируя лазерныйй луч
        /// затем удаляет спрайт со сцены
        /// </summary>
        /// <param name="destroyer">Активированный онус.</param>
        public void AnimateLineDestroyer(Gem destroyer)
        {
            SKSpriteNode sprite;
            CGPoint      centerPoint;
            SKAction     resizeSprite;

            // инициализация спрайта, подготовка координат для анимации, размеров
            if (destroyer.IsHorizontal)
            {
                float newWidth = gemCellWidth * Level.ColumnsNumber;

                sprite = SKSpriteNode.FromImageNamed("destroyer_ray_horisontal");

                centerPoint = new CGPoint(gemCellWidth * Level.ColumnsNumber / 2, destroyer.Sprite.Position.Y);

                resizeSprite = SKAction.ResizeToWidth(newWidth, Properties.LineDestructionDuration / 1000f);
            }
            else
            {
                float newHeight = gemCellHeight * Level.RowsNumber;

                sprite = SKSpriteNode.FromImageNamed("destroyer_ray_vertical");

                centerPoint = new CGPoint(destroyer.Sprite.Position.X, gemCellHeight * Level.RowsNumber / 2);

                resizeSprite = SKAction.ResizeToHeight(newHeight, Properties.LineDestructionDuration / 1000f);
            }

            SKAction moveToCenter = SKAction.MoveTo(centerPoint, Properties.LineDestructionDuration / 1000f);

            CGPoint initialPosition = GetPositionFromRowAndColumn(destroyer.Row, destroyer.Column);
            CGSize  initialSize     = new CGSize(gemCellWidth, gemCellHeight);

            sprite.Size      = initialSize;
            sprite.Position  = initialPosition;
            sprite.ZPosition = 110;

            gemLayer.AddChild(sprite);

            sprite.RunAction(moveToCenter);
            sprite.RunAction(SKAction.Sequence(resizeSprite, SKAction.RemoveFromParent()));
        }
        public override void AnimationDidComplete(AnimationState animation)
        {
            base.AnimationDidComplete(animation);

            if (animation != AnimationState.Death)
            {
                return;
            }

            // In a real game, you'd complete the level here, maybe as shown by commented code below.
            RemoveAllActions();
            RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(3),
                SKAction.FadeOutWithDuration(2),
                SKAction.RemoveFromParent(),
//				SKAction.RunBlock(()=> {
//					CharacterScene.GemeOver();
//				})
            }));
        }
Example #13
0
        /// <summary>
        /// Анимация разрушения цепочек
        /// </summary>
        /// <param name="chains">Список цепочек на разрушение.</param>
        public void AnimateTheDstructionOf(List <GemList> chains)
        {
            // маркер проверки на наличие в разрушенных цепочках разрушителя
            // если был разрушитель - звук разрушения будет другой
            bool hadDestroyers = false;
            bool hadBombs      = false;

            if (chains == null)
            {
                return;
            }

            foreach (GemList chain in chains)
            {
                foreach (Gem gem in chain)
                {
                    SKSpriteNode sprite       = gem.Sprite;
                    SKAction     sprtieAction = SKAction.FadeAlphaTo(0.0f, Properties.DestructionAnimationDuration / 1000f);
                    sprite.RunAction(SKAction.Sequence(sprtieAction, SKAction.RemoveFromParent()));

                    AnimateScore(chain);

                    hadDestroyers |= gem.IsALineDestroyer;
                    hadBombs      |= gem.IsABomb;
                }
            }

            if (hadBombs)
            {
                RunAction(explosionSound);
            }
            else if (hadDestroyers)
            {
                RunAction(destroySound);
            }
            else
            {
                RunAction(dingSound);
            }
        }
Example #14
0
        public override void PerformDeath()
        {
            base.PerformDeath();

            var splort = (SKNode)DeathSplort.Copy();

            splort.ZPosition = -1;
            splort.ZRotation = VirtualZRotation;
            splort.Position  = Position;
            splort.Alpha     = 0.1f;
            splort.RunAction(SKAction.FadeAlphaTo(1, 0.5));

            MultiplayerLayeredCharacterScene scene = CharacterScene;

            scene.AddNode(splort, WorldLayer.BelowCharacter);

            RunAction(SKAction.Sequence(new [] {
                SKAction.FadeAlphaTo(0, 0.5f),
                SKAction.RemoveFromParent()
            }));

            smokeEmitter.RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(2),
                SKAction.Run(() => {
                    smokeEmitter.ParticleBirthRate = 2;
                }),

                SKAction.WaitForDuration(2),
                SKAction.Run(() => {
                    smokeEmitter.ParticleBirthRate = 0;
                }),

                SKAction.WaitForDuration(10),
                SKAction.FadeAlphaTo(0, 0.5),
                SKAction.RemoveFromParent()
            }));

            inactiveGoblins.Clear();
        }
        public override void AnimationDidComplete(AnimationState animation)
        {
            switch (animation)
            {
            case AnimationState.Death:
                var emitter = (SKEmitterNode)DeathEmitter.Copy();
                emitter.ZPosition = -0.8f;
                AddChild(emitter);
                GraphicsUtilities.RunOneShotEmitter(emitter, 4.5f);

                RunAction(SKAction.Sequence(new [] {
                    SKAction.WaitForDuration(4),
                    SKAction.Run(() => CharacterScene.HeroWasKilled(this)),
                    SKAction.RemoveFromParent()
                }));
                break;

            case AnimationState.Attack:
                FireProjectile();
                break;
            }
        }
        void Explode()
        {
            for (int i = 0; i < numberOfChunks; i++)
            {
                float angle    = myRand(0, (float)Math.PI * 2);
                float speed    = myRand(shipChunkMinimumSpeed, shipChunkMaximumSpeed);
                var   position = new CGPoint(myRand((float)Position.X - shipChunkDispersion, (float)Position.Y + shipChunkDispersion),
                                             (nfloat)myRand((float)Position.Y - shipChunkDispersion, (float)Position.Y + shipChunkDispersion));
                var explosion = new ExplosionNode(Scene, position);
                var body      = SKPhysicsBody.CreateCircularBody(0.25f);
                body.CollisionBitMask   = 0;
                body.ContactTestBitMask = 0;
                body.CategoryBitMask    = 0;
                body.Velocity           = new CGVector((float)Math.Cos(angle) * speed, (float)Math.Sin(angle) * speed);
                explosion.PhysicsBody   = body;
                Scene.AddChild(explosion);
            }

            RunAction(SKAction.Sequence(
                          SKAction.WaitForDuration(removeShipTime),
                          SKAction.RemoveFromParent()
                          ));
        }
Example #17
0
 void RemoveSnake()
 {
     Snake.ForEach((sprite) => sprite.RunAction(SKAction.RemoveFromParent()));
     Snake.Clear();
 }
Example #18
0
 /// <summary>
 /// Отключение подсветки выбранного камешка
 /// </summary>
 private void HideSelectionIndicator()
 {
     // открепляем спрайт "подсветки"
     selectedSprite.RunAction(SKAction.Sequence(SKAction.FadeOutWithDuration(Properties.SelectedGemTextureFadeDuration / 1000f), SKAction.RemoveFromParent()));
 }