Exemple #1
0
        private void Attack()
        {
            if (myAttackTurn)
            {
                DealDamage(character, enemyCharacter);
            }
            else
            {
                DealDamage(enemyCharacter, character);
            }

            currentAnimation.Play();
            currentAnimation.FlipX    = myAttackTurn;
            currentAnimation.Position = myAttackTurn ? MyAttackPosition : EnemyAttackPosition;

            if (currentAnimation == specialAnimations[Character.Special.Spy])
            {
                currentAnimation.FlipX    = !currentAnimation.FlipX;
                currentAnimation.Position = myAttackTurn ? MySpySpecialPosition : EnemySpySpecialPosition;
            }
            else if (currentAnimation == specialAnimations[Character.Special.Miner])
            {
                currentAnimation.FlipX    = !currentAnimation.FlipX;
                currentAnimation.Position = myAttackTurn ? MyMinerSpecialPosition : EnemyMinerSpecialPosition;
            }
            else if (currentAnimation == specialAnimations[Character.Special.Bomb])
            {
                currentAnimation.Position = !myAttackTurn ? MyExplosionPosition : EnemyExplosionPosition;
            }
            else if (currentAnimation == specialAnimations[Character.Special.Healer])
            {
                currentAnimation.Position = Main.WindowCenter - Vector2.UnitY * 18;
            }

            isFlickering = false;

            // Set hit interval
            if ((myAttackTurn ? character.special : enemyCharacter.special) == Character.Special.None)
            {
                hitInterval = myAttackTurn ? hitMoments[character.weapon] : hitMoments[enemyCharacter.weapon];
                Globals.soundManager.PlaySound(AudioAssets.weaponSwoosh, 1f);
            }
            else if ((myAttackTurn ? character.special : enemyCharacter.special) == Character.Special.Healer)
            {
                hitInterval = 1.4f;
            }
            else if ((myAttackTurn ? character.special : enemyCharacter.special) == Character.Special.Spy)
            {
                hitInterval = .2f;
            }
            else if ((myAttackTurn ? character.special : enemyCharacter.special) == Character.Special.Bomb)
            {
                hitInterval = .1F;
            }
            else
            {
                hitInterval = .5F;
            }
        }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            // TIMER FOR NEXT ATTACK
            if (!currentAnimation.IsPlayingAnimation)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                // Damage
                damageSpriteAlpha = Math.Max(0, damageSpriteAlpha - FADE_OUT_SPEED);
            }

            // ATTACKING
            if (timer >= ATTACK_INTERVAL)
            {
                timer = 0;

                if (!character.IsDead && !enemyCharacter.IsDead && !isHealing)
                {
                    myAttackTurn = !myAttackTurn;
                    Attack();
                }
                else
                {
                    EndFight();
                }
            }

            // UPDATE WEAPON ANIMATION
            currentAnimation.Update(gameTime);
            hitEffect.Update(gameTime);

            // HIT MOMENT
            if (currentAnimation.Time >= hitInterval && currentAnimation.IsPlayingAnimation && !isFlickering)
            {
                // Play the right hit sound
                PlayHitSound();

                // Lose HP
                if (myAttackTurn)
                {
                    enemyCharacter.hp -= MathHelper.Clamp(damage, enemyCharacter.hp - enemyCharacter.maxHP, enemyCharacter.hp);
                }
                else
                {
                    character.hp -= MathHelper.Clamp(damage, character.hp - character.maxHP, character.hp);
                }

                if (currentAnimation != specialAnimations[Character.Special.Healer])
                {
                    // Set flickering values
                    isFlickering  = true;
                    flickerAmount = 0;
                    show          = false;

                    // Set visual damage
                    damageSprite.position     = myAttackTurn ? MyDamagePosition : EnemyDamagePosition;
                    damageSpriteAlpha         = 1f;
                    damageSprite.CurrentFrame = Math.Min(damage, 3);

                    //hitEffect = currentAnimation != specialAnimations[Character.Special.Spy] ? AnimationAssets.HitEffect : AnimationAssets.SpySpecialHitEffect;
                    hitEffect.Position = myAttackTurn ? MyHitEffectPosition : EnemyHitEffectPosition;
                    hitEffect.Play();
                    hitEffect.FlipX = !myAttackTurn;
                }
                else
                {
                    // Set visual heal
                    damageSprite.position     = myAttackTurn ? MyDamagePosition : EnemyDamagePosition;
                    damageSpriteAlpha         = 1f;
                    damageSprite.CurrentFrame = Math.Min(-damage + 3, 5);

                    isFlickering = true;
                }
            }

            damageSprite.position.Y -= DAMAGE_SPEED;

            // FLICKER EFFECT
            if (flickerAmount < FLICKER_LIMIT && isFlickering)
            {
                flickerTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (flickerTimer >= FLICKER_INTERVAL)
                {
                    show = !show;

                    if (show)
                    {
                        flickerAmount++;
                    }
                    flickerTimer = 0;
                }
            }

            // UPDATE CHARACTER ANIMATION
            character.UpdateSpineAnimation(gameTime);
            enemyCharacter.UpdateSpineAnimation(gameTime);

            // UPDATE HEALTH
            myHealthBar.hp    = character.hp;
            enemyHealthbar.hp = enemyCharacter.hp;
        }