/* Determines the relevant player from the given projectile, and adds to that player's score. */
 public void AddToScoreAfterEnemyKill(int amount, SKNode projectile)
 {
     var userData = new UserData (projectile.UserData);
     Player player = userData.Player;
     player.Score += amount;
     updateHUDFor (player);
 }
Exemplo n.º 2
0
        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;
        }