Exemplo n.º 1
0
 public void PlayGrabBall(Catapult catapult)
 {
     catapult.AudioPlayer.PlayGrabBall();
     // clear the highlight state so we don't play the highlight off
     // sound after the player has grabbed the ball.
     this.highlightedCatapult = null;
 }
Exemplo n.º 2
0
 public void StopStretch(Catapult catapult)
 {
     catapult.AudioPlayer.StopStretch();
     catapult.AudioPlayer.StretchDistance = 0f;
     this.isStretchPlaying    = false;
     this.timeSinceLastHaptic = null;
 }
Exemplo n.º 3
0
        public void PlayLaunch(Catapult catapult, GameVelocity velocity, bool playHaptic)
        {
            if (playHaptic)
            {
                this.hapticsGenerator.GenerateNotificationFeedback(UINotificationFeedbackType.Success);
            }

            catapult.AudioPlayer.PlayLaunch(velocity);
        }
Exemplo n.º 4
0
        public void AddCatapult(Catapult catapult)
        {
            if (this.grabInteraction == null)
            {
                throw new Exception("GrabInteraction not set");
            }

            this.grabInteraction.AddGrabbable(catapult);
            this.catapults[catapult.CatapultId] = catapult;
            this.SetProjectileOnCatapult(catapult, ProjectileType.Cannonball);
        }
Exemplo n.º 5
0
        private bool IsCatapultFloating(Catapult catapult)
        {
            if (this.Delegate == null)
            {
                throw new Exception("No Delegate");
            }

            if (catapult.Base.PhysicsBody != null)
            {
                var contacts = this.Delegate.PhysicsWorld.ContactTest(catapult.Base.PhysicsBody, (SCNPhysicsTest)null);
                return(!contacts.Any());
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
 public void CatapultDidChangeHighlight(Catapult catapult, bool highlighted)
 {
     if (highlighted)
     {
         if (this.highlightedCatapult != catapult)
         {
             catapult.AudioPlayer.PlayHighlightOn();
             this.highlightedCatapult = catapult;
         }
     }
     else
     {
         if (this.highlightedCatapult == catapult)
         {
             catapult.AudioPlayer.PlayHighlightOff();
             this.highlightedCatapult = null;
         }
     }
 }
Exemplo n.º 7
0
        public void SlingBall(Catapult catapult, GameVelocity velocity)
        {
            if (this.Delegate == null)
            {
                throw new Exception("No delegate");
            }

            var newProjectile = this.Delegate.SpawnProjectile();

            newProjectile.Team = catapult.Team;

            this.Delegate.AddNodeToLevel(newProjectile.ObjectRootNode);

            // The lifeTime of projectile needed to sustain the pool is defined by:
            // (Catapult Count) * (1 + (lifeTime) / (cooldownTime)) = (Pool Count)
            var poolCount = this.Delegate.GameObjectPoolCount();
            var lifeTime  = (double)(poolCount / this.catapults.Count - 1) * catapult.CoolDownTime;

            newProjectile.Launch(velocity, lifeTime, this.Delegate.ProjectileDelegate);

            // assign the catapult source to this ball
            if (newProjectile.PhysicsNode?.PhysicsBody != null)
            {
                newProjectile.PhysicsNode.SetValueForKey(NSObject.FromObject(catapult.CatapultId), new NSString("Source"));
                newProjectile.PhysicsNode.PhysicsBody.CollisionBitMask = (int)(CollisionMask.RigidBody | CollisionMask.GlitterObject);
                if (catapult.Team == Team.TeamA)
                {
                    var collisionMask = (CollisionMask)(int)(newProjectile.PhysicsNode.PhysicsBody.CollisionBitMask);
                    newProjectile.PhysicsNode.PhysicsBody.CollisionBitMask = (nuint)(int)(collisionMask | CollisionMask.CatapultTeamB);

                    var categoryBitMask = (CollisionMask)(int)(newProjectile.PhysicsNode.PhysicsBody.CategoryBitMask);
                    newProjectile.PhysicsNode.PhysicsBody.CategoryBitMask = (nuint)(int)(categoryBitMask | CollisionMask.CatapultTeamA);
                }
                else
                {
                    var collisionMask = (CollisionMask)(int)(newProjectile.PhysicsNode.PhysicsBody.CollisionBitMask);
                    newProjectile.PhysicsNode.PhysicsBody.CollisionBitMask = (nuint)(int)(collisionMask | CollisionMask.CatapultTeamA);

                    var categoryBitMask = (CollisionMask)(int)(newProjectile.PhysicsNode.PhysicsBody.CategoryBitMask);
                    newProjectile.PhysicsNode.PhysicsBody.CategoryBitMask = (nuint)(int)(categoryBitMask | CollisionMask.CatapultTeamB);
                }
            }
        }
Exemplo n.º 8
0
        public void PlayCatapultBreak(Catapult catapult, bool vortex)
        {
            // os_log(.info, "play catapult break for catapultID = %d", catapult.catapultID)
            var shouldPlay = true;

            if (vortex)
            {
                if (this.firstVortexCatapultBreak)
                {
                    this.firstVortexCatapultBreak = false;
                }
                else
                {
                    shouldPlay = false;
                }
            }

            if (shouldPlay)
            {
                catapult.AudioPlayer.PlayBreak();
            }
        }
Exemplo n.º 9
0
        private void SetProjectileOnCatapult(Catapult catapult, ProjectileType projectileType)
        {
            if (this.Delegate == null)
            {
                throw new Exception("No delegate");
            }

            var projectile = TrailBallProjectile.Create(this.dummyBall.Clone());

            projectile.IsAlive = true;
            projectile.Team    = catapult.Team;

            if (projectile.PhysicsNode == null)
            {
                throw new Exception("Projectile has no physicsNode");
            }

            projectile.PhysicsNode.PhysicsBody = null;
            this.Delegate.AddNodeToLevel(projectile.PhysicsNode);

            catapult.SetProjectileType(projectileType, projectile.ObjectRootNode);
        }
Exemplo n.º 10
0
        public void PlayStretch(Catapult catapult, float stretchDistance, float stretchRate, bool playHaptic)
        {
            var normalizedDistance = DigitExtensions.Clamp((stretchDistance - 0.1f) / 2f, 0f, 1f);

            if (this.isStretchPlaying)
            {
                // Set the stretch distance and rate on the audio
                // player to module the strech sound effect.
                catapult.AudioPlayer.StretchDistance = normalizedDistance;
                catapult.AudioPlayer.StretchRate     = stretchRate;
            }
            else
            {
                catapult.AudioPlayer.StartStretch();
                this.isStretchPlaying = true;
            }

            if (playHaptic)
            {
                double interval;
                if (normalizedDistance >= 0.25 && normalizedDistance < 0.5)
                {
                    interval = 0.5;
                }
                else if (normalizedDistance >= 0.5)
                {
                    interval = 0.25;
                }
                else
                {
                    interval = 1.0;
                }

                if (this.prevStretchDistance.HasValue)
                {
                    var delta = Math.Abs(stretchDistance - this.prevStretchDistance.Value);
                    this.prevStretchDistance = stretchDistance;
                    if (delta < 0.0075f)
                    {
                        return;
                    }
                }
                else
                {
                    this.prevStretchDistance = stretchDistance;
                }

                if (this.timeSinceLastHaptic.HasValue)
                {
                    if ((DateTime.UtcNow - this.timeSinceLastHaptic.Value).TotalSeconds > interval)
                    {
                        this.hapticsGenerator.GenerateImpactFeedback();
                        this.timeSinceLastHaptic = DateTime.UtcNow;
                    }
                }
                else
                {
                    this.hapticsGenerator.GenerateImpactFeedback();
                    this.timeSinceLastHaptic = DateTime.UtcNow;
                }
            }
        }